create.blade.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. @extends('layouts.app')
  2. @section('title')模板-创建@endsection
  3. @section('content')
  4. <div class="container-fluid d-none row m-1" id="print-template">
  5. <div class="col-lg-2 col-sm-3 p-0" id="part_panel">
  6. {{-- 组件选择面板 --}}
  7. @include('maintenance.expressPrinting.template._select')
  8. </div>
  9. <div class="col-lg-8 col-sm-6 p-0" id="production_panel">
  10. {{-- 模板制作面板 --}}
  11. @include('maintenance.expressPrinting.template._produce')
  12. </div>
  13. <div class="col-lg-2 col-sm-3 p-0" id="compile_panel">
  14. {{-- 模板编辑页面 --}}
  15. @include('maintenance.expressPrinting.template._compile')
  16. </div>
  17. </div>
  18. @endsection
  19. @section('lastScript')
  20. <script type="text/javascript" src="{{mix('js/utilities/barcode.js')}}"></script>
  21. <script type="text/javascript" src="{{mix('/js/utilities/qrcode.js')}}"></script>
  22. <script>
  23. let vue = new Vue({
  24. el: "#print-template",
  25. data: {
  26. printParts: [
  27. @foreach($printParts as $items)
  28. {
  29. name: '{{ $items['name'] }}', value: {
  30. @foreach($items['value'] as $key=>$value)
  31. '{{$key}}': '{{$value}}',
  32. @endforeach
  33. }
  34. },
  35. @endforeach
  36. ],
  37. imgPrefix:"{{asset("/storage")}}",
  38. images:{!! $printPartImages ?? [] !!},
  39. filterPrintParts: [],
  40. producePanel: {}, // 背景版
  41. selectProducePanel: false, // 是否选中背景版
  42. productionParts: {
  43. bg: null,
  44. printParts: [], // 组件
  45. editPart: {
  46. id:null
  47. }, // 编辑中的组件
  48. editIndex: {}, // 编辑中组件的下标
  49. addPart: {}, // 添加模板
  50. },
  51. partIsSelected: false, // 表示模块被选中
  52. selectPrintPart: {}, // 选中模块
  53. selectPrintPartPoint: {x: '', y: ''}, // 选中模块时模块 point
  54. mousePointStart: {x: '', y: ''}, // 开始拖动时的 point
  55. mousePointEnd: {x: '', y: ''}, // 结束拖动时的 point
  56. selectPrintPartOffset: {left: '', top: ''}, // 选中时的left 和 top
  57. z_index: 10,
  58. },
  59. mounted() {
  60. $('.navbar,.nav1,.nav2').hide();
  61. $('.nav3').on('mouseenter', function () {
  62. $('.navbar,.nav1,.nav2').show();
  63. });
  64. $('.body').on('mouseenter', function () {
  65. $('.navbar,.nav1,.nav2').hide();
  66. });
  67. $("#print-template").removeClass('d-none');
  68. },
  69. methods: {
  70. // 添加组件至面板上
  71. _addPartToProductionPanel(printPart) {
  72. let _clone = JSON.parse(JSON.stringify(printPart));
  73. let print_part = _clone.value
  74. if (!this.productionParts.bg && print_part.type !== 'bg') {
  75. window.tempTip.show('先添加背景组件在进行其他组件的添加');
  76. return
  77. } else if (this.productionParts.bg && print_part.type === 'bg') {
  78. window.tempTip.show('背景组件请勿重复添加');
  79. return
  80. }
  81. if (print_part.type === 'bg') {
  82. this.productionParts.bg = print_part;
  83. return;
  84. }
  85. print_part.index = this.productionParts.printParts.length;
  86. this.z_index+=1
  87. print_part.z_index = this.z_index;
  88. print_part.id = "id" + this.z_index;
  89. print_part.text = null;
  90. this.productionParts.printParts.push(print_part); // 添加入组件列表中
  91. if (print_part.type === "stripeCode") {
  92. setTimeout(function () {
  93. window.setBarcode("0123456789", "#svg" + print_part.id, 2, 50, true)
  94. }, 100);
  95. } else if (print_part.type === "qRCode") {
  96. setTimeout(function () {
  97. new QRCode(document.getElementById(print_part.id), {
  98. text: "0123456789",
  99. width: print_part.width,
  100. height: print_part.height,
  101. colorDark : "#000000",
  102. colorLight : "#ffffff",
  103. correctLevel : QRCode.CorrectLevel.H
  104. });
  105. }, 1000)
  106. } else if (print_part.type === "image") {
  107. }
  108. },
  109. // 从面板删除组件
  110. _removePartToProductionPanel(editPart) {
  111. this.productionParts.editPart = null;
  112. let index = this.productionParts.printParts.indexOf(editPart);
  113. this.productionParts.printParts.splice(index, 1);
  114. },
  115. //
  116. _alignContentToProductionPanel() {
  117. this.productionParts.printParts.splice(this.productionParts.editIndex, 1);
  118. this.$forceUpdate();
  119. },
  120. // 打开保存modal
  121. showSaveModal() {
  122. $('#saveModal').modal('show');
  123. },
  124. // 保存modal
  125. _savePrintTemplate() {
  126. tempTip.setDuration(3000);
  127. tempTip.setIndex(1999);
  128. let printTemplate = JSON.parse(JSON.stringify(this.productionParts.printParts));
  129. printTemplate.push(this.productionParts.bg);
  130. let data = {
  131. name: this.productionParts.addPart.name,
  132. value: printTemplate
  133. };
  134. window.axios.post("{{url('apiLocal/maintenance/expressPrinting/template/create')}}", data).then(res => {
  135. if (res.data.success) {
  136. tempTip.showSuccess('保存成功!');
  137. $('#saveModal').modal('hide');
  138. return;
  139. }
  140. tempTip.show(res.data.message);
  141. }).catch(err => {
  142. tempTip.show(err);
  143. });
  144. },
  145. // 开始拖动元素时触发
  146. _dragstart(item, $event) {
  147. console.log(item)
  148. this.selectPrintPartPoint = {x: parseInt(item.left), y: parseInt(item.top)};
  149. this.mousePointStart = {x: $event.offsetX, y: $event.offsetY};
  150. },
  151. // 结束拖动元素时触发
  152. _dragend(item, $event) {
  153. console.log(item)
  154. this.mousePointEnd = {x: $event.offsetX, y: $event.offsetY};
  155. let left = item.left - (this.mousePointStart.x - this.mousePointEnd.x);
  156. let top = item.top - (this.mousePointStart.y - this.mousePointEnd.y);
  157. item.left = left > 0 ? left : 0;
  158. item.top = top > 0 ? top : 0;
  159. },
  160. getProducePanelStyle() {
  161. return {
  162. width: this.producePanel.width + 'px',
  163. height: this.producePanel.height + 'px',
  164. }
  165. },
  166. getStyle(item) {
  167. let style = {
  168. width: item.width + 'px',
  169. height: item.height + 'px',
  170. left: item.left + 'px',
  171. top: item.top + 'px',
  172. 'z-index' : item['z_index'],
  173. };
  174. if (item.type === 'textBox'){
  175. style['font-size'] = item['font-size'];
  176. style['border-width'] = item['border-width']+'px';
  177. style['border-color'] = '#000';
  178. style['border-style'] = 'solid';
  179. style['display'] = 'flex'
  180. style['justify-content'] = item['justify-content']
  181. style['align-items'] = item['align-items']
  182. style['text-align'] = 'center'
  183. } else if (item.type === 'qRCode'){
  184. style.heigth = style.width;
  185. let scale = item.scale;
  186. style.transform = `scale(${scale},${scale})`;
  187. } else if (item.type === 'stripeCode'){
  188. let scale = item.scale;
  189. style.transform = `scale(${scale},${scale})`;
  190. }
  191. return style;
  192. },
  193. getImageSrc(image){
  194. return this.imgPrefix+image.file.url+'.'+image.file.type
  195. },
  196. setImageBg(image){
  197. let src = this.getImageSrc(image);
  198. this.productionParts.editPart.text = image.name;
  199. document.getElementById(this.productionParts.editPart.id).setAttribute('src',src) ;
  200. },
  201. changeStripeCodeWidth(){
  202. let default_width = 404;
  203. if (this.productionParts.editPart.type === 'qRCode')default_width = 100;
  204. this.productionParts.editPart.scale = this.productionParts.editPart.width / default_width;
  205. },
  206. changeStripeCodeScale(){
  207. let default_width = 404;
  208. if (this.productionParts.editPart.type === 'qRCode')default_width = 100;
  209. this.productionParts.editPart.width = default_width * this.productionParts.editPart.scale;
  210. }
  211. }
  212. });
  213. </script>
  214. @endsection