create.blade.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. @extends('layouts.app')
  2. @section('title')组件创建@endsection
  3. @section('content')
  4. <div class="container-fluid d-none" id="create-print-part">
  5. <div class="row">
  6. <div class="col-3">
  7. <div class="card">
  8. <div class="card-header">
  9. 基础设置
  10. </div>
  11. <div class="card-body">
  12. <div class="form-group">
  13. <label for="template-width">宽</label>
  14. <input type="number" id="template-width" v-model="template.width" class="form form-control">
  15. </div>
  16. <div class="form-group">
  17. <label for=template-height>高</label>
  18. <input type="number" id="template-height" v-model="template.height"
  19. class="form form-control">
  20. </div>
  21. <div class="form-group">
  22. <label for="template-border-type">边框类型</label>
  23. <select class="form-control" id="template-border-type" v-model="template.borderStyle">
  24. <option v-for="style in borderStyles" :value="style.value">@{{ style.name }}</option>
  25. </select>
  26. </div>
  27. <div class="form-group">
  28. <label for="template-border-weight">边框大小</label>
  29. <input type="number" id="template-border-weight" v-model="template.borderWidth"
  30. class="form form-control">
  31. </div>
  32. </div>
  33. <div class="card-footer">
  34. <button type="button" class="btn btn-success" @click="show">保存当前模板</button>
  35. </div>
  36. </div>
  37. </div>
  38. <div class="col-6 justify-content-center align-items-center flex-fill">
  39. {{-- 模板展示--}}
  40. <div v-if="template.type==='text'" :style="getStyle()">
  41. <span>@{{ template.text }}</span>
  42. </div>
  43. {{-- 条纹码展示 --}}
  44. <svg v-show="template.type === 'StripeCode'" :style="{width:template.width,height:template.height}"
  45. id="barcodeDiv">
  46. </svg>
  47. {{-- 二维码展示 --}}
  48. <div v-show="template.type ==='QrCode'" :style="{width:template.width,height:template.height}"
  49. id="qrCodeDiv">
  50. </div>
  51. {{-- 图片展示 --}}
  52. <div v-show="template.type ==='QrCode'" :style="{width:template.width,height:template.height}"
  53. id="ImageDiv">
  54. </div>
  55. </div>
  56. <div class="col-3">
  57. {{-- 属性 --}}
  58. <div class="card">
  59. <div class="card-header">
  60. 设置
  61. </div>
  62. <div class="card-body">
  63. <div class="form-group">
  64. <label for="template-type">组件类型</label>
  65. <select class="form-control" id="template-type" v-model="template.type" @change="setContent">
  66. <option v-for="type in types" :value="type.value">@{{ type.name }}</option>
  67. </select>
  68. </div>
  69. <div v-if="template.type === 'Image'">
  70. <button @click="showUploadModal" class="btn btn-sm btn-primary">上传文件</button>
  71. </div>
  72. {{-- <div class="form-group">--}}
  73. {{-- <label for="template-text">内容</label>--}}
  74. {{-- <textarea id="template-text" class="form-text form-control" cols="5" rows="5"--}}
  75. {{-- v-model="template.text"></textarea>--}}
  76. {{-- </div>--}}
  77. {{-- <div class="form-group">--}}
  78. {{-- <label for="template-text-align">文本对齐方式</label>--}}
  79. {{-- <select name="" id="template-text-align" v-model="template.justifyContent"--}}
  80. {{-- class="form form-control">--}}
  81. {{-- <option v-for="justifyContent in justifyContents" :value="justifyContent.value">--}}
  82. {{-- @{{ justifyContent.name }}--}}
  83. {{-- </option>--}}
  84. {{-- </select>--}}
  85. {{-- </div>--}}
  86. {{-- <div class="form-group">--}}
  87. {{-- <label for="template-text-align">文本垂直对齐</label>--}}
  88. {{-- <select name="" id="template-text-align" v-model="template.alignItems"--}}
  89. {{-- class="form form-control">--}}
  90. {{-- <option v-for="alignItem in alignItems" :value="alignItem.value">--}}
  91. {{-- @{{ alignItem.name }}--}}
  92. {{-- </option>--}}
  93. {{-- </select>--}}
  94. {{-- </div>--}}
  95. {{-- <div class="form-group">--}}
  96. {{-- <label for="template-font-size">字体大小</label>--}}
  97. {{-- <input type="text" id="template-font-size" v-model="template.fontSize"--}}
  98. {{-- class="form form-control">--}}
  99. {{-- </div>--}}
  100. {{-- <div class="form-group">--}}
  101. {{-- <label for="template-font-weight">字体宽</label>--}}
  102. {{-- <select id="template-font-weight" v-model="template.fontWeight" class="form-control">--}}
  103. {{-- <option v-for="fontWeight in fontWeights" :value="fontWeight.value">--}}
  104. {{-- @{{ fontWeight.name }}--}}
  105. {{-- </option>--}}
  106. {{-- </select>--}}
  107. {{-- </div>--}}
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="modal fade" id="saveModal" tabindex="-1" aria-hidden="true">
  113. <div class="modal-dialog modal-dialog-centered">
  114. <div class="modal-content">
  115. <div class="modal-header">
  116. <h5 class="modal-title" id="saveModalLabel">保存组件</h5>
  117. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  118. <span aria-hidden="true">&times;</span>
  119. </button>
  120. </div>
  121. <div class="modal-body">
  122. <form>
  123. <div class="form-group">
  124. <label for="recipient-name" class="col-form-label">组件名称</label>
  125. <input type="text" id="recipient-name" class="form-control" v-model="printPart.name">
  126. </div>
  127. </form>
  128. </div>
  129. <div class="modal-footer">
  130. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  131. <button type="button" class="btn btn-success" @click="create">保存</button>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <div v-if="template.type === 'Image'">
  137. <template v-for="value in printImages.values">
  138. <div class="list-group">
  139. @{{ value }}
  140. </div>
  141. </template>
  142. </div>
  143. <div class="modal" tabindex="-1" id="uploadFileModel">
  144. <div class="modal-dialog modal-dialog-centered">
  145. <div class="modal-content">
  146. <div class="modal-header">
  147. <h5 class="modal-title">上传图片</h5>
  148. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  149. <span aria-hidden="true">&times;</span>
  150. </button>
  151. </div>
  152. <div class="modal-body">
  153. <div class="form-inline form-group">
  154. <label for="fileName" class="col-sm-3 col-form-label text-right ">图片名称</label>
  155. <input type="name" class="form-control" id="fileName" placeholder="图片名">
  156. </div>
  157. <div class="form-inline form-group">
  158. <label for="uploadfile" class="col-sm-3 col-form-label text-right ">图片</label>
  159. <input type="file" id="uploadfile" class="form-control" name="image" accept="image/*" ref="upload">
  160. </div>
  161. </div>
  162. <div class="modal-footer">
  163. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  164. <button type="button" class="btn btn-primary" @click="pushImage">上传</button>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. @endsection
  171. @section('lastScript')
  172. <script type="text/javascript" src="{{mix('js/utilities/barcode.js')}}"></script>
  173. <script type="text/javascript" src="{{mix('/js/utilities/qrcode.js')}}"></script>
  174. <script>
  175. let vue = new Vue({
  176. el: "#create-print-part",
  177. data: {
  178. printPart: {name: '', value: ''},
  179. printImages:{!! $imgPrintPart->toJson() !!},
  180. template: {
  181. type: 'text',
  182. width: 200,
  183. height: 100,
  184. borderStyle: 'solid',
  185. borderWidth: 1,
  186. fontSize: 12,
  187. text: '',
  188. fontWeight: 'normal', //normal lighter bold
  189. justifyContent: '', //文字水平对齐方式
  190. alignItems: 'center', //文字垂直对齐
  191. },
  192. types: [
  193. {name: "文本框", value: "text"},
  194. {name: "条纹码", value: "StripeCode"},
  195. {name: "二维码", value: "QrCode"},
  196. {name: "图片", value: "Image"},
  197. ],
  198. fontWeights: [
  199. {name: "正常", value: "normal"},
  200. {name: "细体", value: "lighter"},
  201. {name: "粗体", value: "bold"},
  202. ],
  203. justifyContents: [
  204. {name: "左对齐", value: ""},
  205. {name: "居中", value: "center"},
  206. {name: "右对齐", value: "flex-end"},
  207. ],
  208. alignItems: [
  209. {name: "顶部", value: ""},
  210. {name: "居中", value: "center"},
  211. {name: "底部", value: "flex-end"},
  212. ],
  213. borderStyles: [
  214. {name: "默认边框", value: "solid"},
  215. {name: "无边框", value: "none"},
  216. {name: "虚线边框", value: "dashed"},
  217. ]
  218. },
  219. mounted() {
  220. $("#create-print-part").removeClass('d-none');
  221. },
  222. methods: {
  223. show() {
  224. $('#saveModal').modal('show');
  225. },
  226. showUploadModal(){
  227. $('#uploadFileModel').modal('show');
  228. },
  229. getStyle() {
  230. return {
  231. 'display': 'flex',
  232. 'width': this.template.width + 'px',
  233. 'height': this.template.height + 'px',
  234. 'border-style': this.template.borderStyle,
  235. 'border-width': this.template.borderWidth + 'px',
  236. 'font-size': this.template.fontSize + 'px',
  237. 'font-weight': this.template.fontWeight,
  238. 'justify-content': this.template.justifyContent,
  239. 'align-items': this.template.alignItems,
  240. };
  241. },
  242. create() {
  243. tempTip.setDuration(3000);
  244. tempTip.setIndex(2000);
  245. let value = JSON.stringify(this.template);
  246. let data = {name: this.printPart.name, value: value};
  247. window.axios.post('{{url('apiLocal/maintenance/expressPrinting/part/create')}}', data).then(res => {
  248. if (res.data.success) {
  249. tempTip.showSuccess(res.data.data);
  250. $('#saveModal').modal('hide');
  251. return;
  252. }
  253. tempTip.show(res.data.message);
  254. }).catch(err => {
  255. tempTip.show('网络异常:' + err);
  256. });
  257. },
  258. setContent() {
  259. if (this.template.type === "text") return;
  260. if (this.template.type === "StripeCode") {
  261. let div = $("#barcodeDiv");
  262. this.template.borderStyle = 'none';
  263. window.setBarcode("0123456789", "#barcodeDiv1", 2, 50, true)
  264. this.template.width = div.width();
  265. this.template.height = div.height();
  266. } else if (this.template.type === "QrCode") {
  267. $("#qrCodeDiv").html("");
  268. new QRCode(document.getElementById("qrCodeDiv"), {
  269. text: "占位二维码",
  270. width: 128,
  271. height: 128,
  272. colorDark: "#000000",
  273. colorLight: "#fff",
  274. correctLevel: QRCode.CorrectLevel.H,
  275. });
  276. } else if (this.template.type === "Image") {
  277. $("#qrCodeDiv").html("#ImageDiv");
  278. }
  279. },
  280. pushImage(){
  281. let url = '{{url("apiLocal/maintenance/expressPrinting/part/pushImage")}}'
  282. let data = new FormData();
  283. data.set("name",$("#fileName").val());
  284. let file= this.$refs.upload.files[0];
  285. data.set("file",file);
  286. window.tempTip.setIndex(2000);
  287. window.axios.post(url,data,{
  288. 'Content-Type': 'multipart/form-data'
  289. }).then(res=>{
  290. if(res.data.success){
  291. window.tempTip.showSuccess("文件添加成功");
  292. $('#uploadFileModel').modal('hide');
  293. return
  294. }
  295. window.tempTip.show(res.data.message);
  296. }).catch(err=>{
  297. window.tempTip.show(err)
  298. });
  299. },
  300. }
  301. });
  302. </script>
  303. @endsection