edit.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 list_vue = new Vue({
  24. el: "#print-template",
  25. data: {
  26. printTemplate : '{!! $template !!}',
  27. printParts: [
  28. @foreach($printParts as $items)
  29. {
  30. name: '{{ $items['name'] }}', value: {
  31. @foreach($items['value'] as $key=>$value)
  32. '{{$key}}': '{{$value}}',
  33. @endforeach
  34. }
  35. },
  36. @endforeach
  37. ],
  38. imgPrefix:"{{asset("/storage")}}",
  39. images:{!! $printPartImages ?? [] !!},
  40. filterPrintParts: [],
  41. producePanel: {}, // 背景版
  42. selectProducePanel: false, // 是否选中背景版
  43. productionParts: {
  44. id: null,
  45. bg: null,
  46. printParts: [], // 组件
  47. editPart: {
  48. id:null
  49. }, // 编辑中的组件
  50. editIndex: {}, // 编辑中组件的下标
  51. addPart: {}, // 添加模板
  52. },
  53. partIsSelected: false, // 表示模块被选中
  54. selectPrintPart: {}, // 选中模块
  55. selectPrintPartPoint: {x: '', y: ''}, // 选中模块时模块 point
  56. mousePointStart: {x: '', y: ''}, // 开始拖动时的 point
  57. mousePointEnd: {x: '', y: ''}, // 结束拖动时的 point
  58. selectPrintPartOffset: {left: '', top: ''}, // 选中时的left 和 top
  59. z_index: 10,
  60. },
  61. mounted() {
  62. $('.navbar,.nav1,.nav2').hide();
  63. $('.nav3').on('mouseenter', function () {
  64. $('.navbar,.nav1,.nav2').show();
  65. });
  66. $('.body').on('mouseenter', function () {
  67. $('.navbar,.nav1,.nav2').hide();
  68. });
  69. $("#print-template").removeClass('d-none');
  70. let template = JSON.parse(this.printTemplate)
  71. this.productionParts.bg = template.value.filter(function(item){
  72. return item.type === 'bg';
  73. }).shift();
  74. this.productionParts.printParts = template.value.filter(function(item){
  75. return item.type !== 'bg';
  76. });
  77. let self = this;
  78. this.productionParts.printParts.forEach(function(item,index,array){
  79. if (self.z_index < item['z_index'])self.z_index = item['z_index']+1;
  80. });
  81. this.productionParts.addPart.name = template.name;
  82. this.productionParts.id = template.id;
  83. this.initCode();
  84. },
  85. methods: {
  86. initCode(){
  87. let self = this;
  88. this.productionParts.printParts.forEach(function(item){
  89. if (item.type==="stripeCode"){
  90. setTimeout(function () {
  91. window.setBarcode("0123456789", "#svg" + item.id, 2, 50, true)
  92. }, 1000);
  93. }else if(item.type === 'qRCode'){
  94. setTimeout(function () {
  95. new QRCode(document.getElementById(item.id), {
  96. text: "占位二维码",
  97. width: item.height,
  98. height: item.height,
  99. colorDark : "#000000",
  100. colorLight : "#ffffff",
  101. correctLevel : QRCode.CorrectLevel.H
  102. });
  103. }, 1000)
  104. } else if(item.type === "image"){
  105. setTimeout(function () {
  106. let images = self.images.filter(function(img){
  107. return img.name === item.text;
  108. })
  109. if (images.length === 0) {
  110. window.tempTip.show("获取图片失败");
  111. return
  112. }
  113. let img = images.shift();
  114. let element = document.getElementById(item.id);
  115. element.setAttribute('src',self.getImageSrc(img))
  116. }, 1000)
  117. }
  118. });
  119. },
  120. // 添加组件至面板上
  121. // 添加组件至面板上
  122. _addPartToProductionPanel(printPart) {
  123. let _clone = JSON.parse(JSON.stringify(printPart));
  124. let print_part = _clone.value
  125. if (!this.productionParts.bg && print_part.type !== 'bg') {
  126. window.tempTip.show('先添加背景组件在进行其他组件的添加');
  127. return
  128. } else if (this.productionParts.bg && print_part.type === 'bg') {
  129. window.tempTip.show('背景组件请勿重复添加');
  130. return
  131. }
  132. if (print_part.type === 'bg') {
  133. this.productionParts.bg = print_part;
  134. return;
  135. }
  136. print_part.index = this.productionParts.printParts.length;
  137. this.z_index+=1
  138. print_part.z_index = this.z_index;
  139. print_part.id = "id" + this.z_index;
  140. print_part.text = null;
  141. this.productionParts.printParts.push(print_part); // 添加入组件列表中
  142. if (print_part.type === "stripeCode") {
  143. setTimeout(function () {
  144. window.setBarcode("0123456789", "#svg" + print_part.id, 2, 50, true)
  145. }, 100);
  146. } else if (print_part.type === "qRCode") {
  147. setTimeout(function () {
  148. new QRCode(document.getElementById(print_part.id), {
  149. text: "0123456789",
  150. width: print_part.width,
  151. height: print_part.height,
  152. colorDark : "#000000",
  153. colorLight : "#ffffff",
  154. correctLevel : QRCode.CorrectLevel.H
  155. });
  156. }, 1000)
  157. } else if (print_part.type === "image") {
  158. }
  159. },
  160. // 从面板删除组件
  161. _removePartToProductionPanel(editPart) {
  162. this.productionParts.editPart = null;
  163. let index = this.productionParts.printParts.indexOf(editPart);
  164. this.productionParts.printParts.splice(index, 1);
  165. },
  166. //
  167. _alignContentToProductionPanel() {
  168. this.productionParts.printParts.splice(this.productionParts.editIndex, 1);
  169. this.$forceUpdate();
  170. },
  171. // 打开保存modal
  172. showSaveModal() {
  173. $('#saveModal').modal('show');
  174. },
  175. // 保存modal
  176. _savePrintTemplate() {
  177. tempTip.setDuration(3000);
  178. tempTip.setIndex(1999);
  179. let printTemplate = JSON.parse(JSON.stringify(this.productionParts.printParts));
  180. printTemplate.push(this.productionParts.bg);
  181. let data = {
  182. id: this.productionParts.id,
  183. name: this.productionParts.addPart.name,
  184. value: printTemplate
  185. };
  186. window.axios.post("{{url('apiLocal/maintenance/expressPrinting/template/update')}}", data).then(res => {
  187. if (res.data.success) {
  188. tempTip.showSuccess('保存成功!');
  189. $('#saveModal').modal('hide');
  190. return;
  191. }
  192. tempTip.show(res.data.message);
  193. }).catch(err => {
  194. tempTip.show(err);
  195. });
  196. },
  197. // 开始拖动元素时触发
  198. _dragstart(item, $event) {
  199. this.selectPrintPartPoint = {x: parseInt(item.left), y: parseInt(item.top)};
  200. this.mousePointStart = {x: $event.offsetX, y: $event.offsetY};
  201. },
  202. // 结束拖动元素时触发
  203. _dragend(item, $event) {
  204. this.mousePointEnd = {x: $event.offsetX, y: $event.offsetY};
  205. let left = item.left - (this.mousePointStart.x - this.mousePointEnd.x);
  206. let top = item.top - (this.mousePointStart.y - this.mousePointEnd.y);
  207. item.left = left > 0 ? left : 0;
  208. item.top = top > 0 ? top : 0;
  209. },
  210. getProducePanelStyle() {
  211. return {
  212. width: this.producePanel.width + 'px',
  213. height: this.producePanel.height + 'px',
  214. }
  215. },
  216. getStyle(item) {
  217. let style = {
  218. width: item.width + 'px',
  219. height: item.height + 'px',
  220. left: item.left + 'px',
  221. top: item.top + 'px',
  222. 'z-index' : item['z_index'],
  223. };
  224. if (item.type === 'textBox'){
  225. style['font-size'] = item['font-size'];
  226. style['border-width'] = item['border-width']+'px';
  227. style['border-color'] = '#000';
  228. style['border-style'] = 'solid';
  229. style['display'] = 'flex'
  230. style['justify-content'] = item['justify-content']
  231. style['align-items'] = item['align-items']
  232. style['text-align'] = 'center'
  233. } else if (item.type === 'qRCode'){
  234. style.width = 100+'px';
  235. style.height = 100+'px';
  236. let scale = item.scale;
  237. if(scale){
  238. style.transform = `scale(${scale},${scale})`;
  239. }
  240. } else if (item.type === 'stripeCode'){
  241. let scale = item.scale;
  242. style.transform = `scale(${scale},${scale})`;
  243. }
  244. return style;
  245. },
  246. getImageSrc(image){
  247. return this.imgPrefix+image.file.url+'.'+image.file.type
  248. },
  249. setImageBg(image){
  250. let src = this.getImageSrc(image);
  251. this.productionParts.editPart.text = image.name;
  252. document.getElementById(this.productionParts.editPart.id).setAttribute('src',src) ;
  253. },
  254. changeStripeCodeWidth(){
  255. let default_width = 404;
  256. if (this.productionParts.editPart.type === 'qRCode')default_width = 100;
  257. this.productionParts.editPart.scale = this.productionParts.editPart.width / default_width;
  258. },
  259. changeStripeCodeScale(){
  260. let default_width = 404;
  261. if (this.productionParts.editPart.type === 'qRCode')default_width = 100;
  262. this.productionParts.editPart.width = default_width * this.productionParts.editPart.scale;
  263. },
  264. }
  265. });
  266. </script>
  267. @endsection