create.blade.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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" class="form form-control">
  19. </div>
  20. <div class="form-group">
  21. <label for="template-border-type">边框类型</label>
  22. <select class="form-control" id="template-border-type" v-model="template.borderStyle">
  23. <option v-for="style in borderStyles" :value="style.value">@{{ style.name }}</option>
  24. </select>
  25. </div>
  26. <div class="form-group">
  27. <label for="template-border-weight">边框大小</label>
  28. <input type="number" id="template-border-weight" v-model="template.borderWidth" class="form form-control">
  29. </div>
  30. </div>
  31. <div class="card-footer">
  32. <button type="button" class="btn btn-success" @click="show">保存当前模板</button>
  33. </div>
  34. </div>
  35. </div>
  36. <div class="col-6 justify-content-center align-items-center flex-fill" >
  37. {{-- 模板展示--}}
  38. <div v-if="template.type==='text'" :style="getStyle()">
  39. <span >@{{ template.text }}</span>
  40. </div>
  41. {{-- 二维码展示 --}}
  42. <svg v-show="template.type!=='text'" :style="{width:template.width,height:template.height}" id="barcodeDiv1">
  43. </svg>
  44. </div>
  45. <div class="col-3">
  46. {{-- 属性 --}}
  47. <div class="card">
  48. <div class="card-header">
  49. 设置
  50. </div>
  51. <div class="card-body">
  52. <div class="form-group">
  53. <label for="template-type">组件类型</label>
  54. <select class="form-control" v-model="template.type" @change="setContent">
  55. <option v-for="type in types" :value="type.value">@{{ type.name }}</option>
  56. </select>
  57. </div>
  58. <div class="form-group">
  59. <label for="template-text">内容</label>
  60. <textarea id="template-text" class="form-text form-control" cols="5" rows="5" v-model="template.text"></textarea>
  61. </div>
  62. <div class="form-group">
  63. <label for="template-text-align">文本对齐方式</label>
  64. <select name="" id="template-text-align" v-model="template.justifyContent" class="form form-control">
  65. <option v-for="justifyContent in justifyContents" :value="justifyContent.value">@{{ justifyContent.name }}</option>
  66. </select>
  67. </div>
  68. <div class="form-group">
  69. <label for="template-text-align">文本垂直对齐</label>
  70. <select name="" id="template-text-align" v-model="template.alignItems" class="form form-control">
  71. <option v-for="alignItem in alignItems" :value="alignItem.value">@{{ alignItem.name }}</option>
  72. </select>
  73. </div>
  74. <div class="form-group">
  75. <label for="template-font-size">字体大小</label>
  76. <input type="text" id="template-font-size" v-model="template.fontSize" class="form form-control">
  77. </div>
  78. <div class="form-group">
  79. <label for="template-font-weight">字体宽</label>
  80. <select id="template-font-weight" v-model="template.fontWeight" class="form-control">
  81. <option v-for="fontWeight in fontWeights" :value="fontWeight.value" >@{{ fontWeight.name }}</option>
  82. </select>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="modal fade" id="saveModal" tabindex="-1" aria-hidden="true">
  89. <div class="modal-dialog">
  90. <div class="modal-content">
  91. <div class="modal-header">
  92. <h5 class="modal-title" id="saveModalLabel">保存组件</h5>
  93. <button type="button" class="close" data-dismiss="modal" aria-label="Close" >
  94. <span aria-hidden="true">&times;</span>
  95. </button>
  96. </div>
  97. <div class="modal-body">
  98. <form>
  99. <div class="form-group">
  100. <label for="recipient-name" class="col-form-label">组件名称</label>
  101. <input type="text" id="recipient-name" class="form-control" v-model="printPart.name">
  102. </div>
  103. </form>
  104. </div>
  105. <div class="modal-footer">
  106. <button type="button" class="btn btn-secondary" data-dismiss="modal" >关闭</button>
  107. <button type="button" class="btn btn-success" @click="create">保存</button>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. @endsection
  114. @section('lastScript')
  115. <script type="text/javascript" src="{{mix('js/utilities/barcode.js')}}"></script>
  116. <script>
  117. let vue = new Vue({
  118. el:"#create-print-part",
  119. data:{
  120. printPart:{name:'',value:''},
  121. template:{
  122. type:'text',
  123. width:200,
  124. height:100,
  125. borderStyle:'solid',
  126. borderWidth:1,
  127. fontSize:12,
  128. text:'',
  129. fontWeight:'normal', //normal lighter bold
  130. justifyContent:'', //文字水平对齐方式
  131. alignItems:'center', //文字垂直对齐
  132. },
  133. types:[
  134. {name:"文本框",value:"text"},
  135. {name:"条纹码",value:"StripeCode"},
  136. ],
  137. fontWeights:[
  138. {name:"正常",value:"normal"},
  139. {name:"细体",value:"lighter"},
  140. {name:"粗体",value:"bold"},
  141. ],
  142. justifyContents:[
  143. {name:"左对齐",value:""},
  144. {name:"居中",value:"center"},
  145. {name:"右对齐",value:"flex-end"},
  146. ],
  147. alignItems:[
  148. {name:"顶部",value:""},
  149. {name:"居中",value:"center"},
  150. {name:"底部",value:"flex-end"},
  151. ],
  152. borderStyles:[
  153. {name:"默认边框",value:"solid"},
  154. {name:"无边框",value:"none"},
  155. {name:"虚线边框",value:"dashed"},
  156. ]
  157. },
  158. mounted() {
  159. $("#create-print-part").removeClass('d-none');
  160. },
  161. methods:{
  162. show(){
  163. $('#saveModal').modal('show');
  164. },
  165. getStyle(){
  166. return {
  167. 'display':'flex',
  168. 'width':this.template.width+'px',
  169. 'height':this.template.height+'px',
  170. 'border-style':this.template.borderStyle,
  171. 'border-width':this.template.borderWidth+'px',
  172. 'font-size':this.template.fontSize+'px',
  173. 'font-weight':this.template.fontWeight,
  174. 'justify-content':this.template.justifyContent,
  175. 'align-items':this.template.alignItems,
  176. };
  177. },
  178. create(){
  179. tempTip.setDuration(3000);
  180. tempTip.setIndex(2000);
  181. let value = JSON.stringify(this.template);
  182. let data = {name:this.printPart.name,value:value};
  183. window.axios.post('{{url('apiLocal/maintenance/expressPrinting/part/create')}}',data).then(res=>{
  184. if(res.data.success){
  185. tempTip.showSuccess(res.data.data);
  186. $('#saveModal').modal('hide');
  187. return;
  188. }
  189. tempTip.show(res.data.message);
  190. }).catch(err=>{
  191. tempTip.show('网络异常:'+err);
  192. });
  193. },
  194. setContent(){
  195. if(this.template.type === "text")return;
  196. this.template.borderStyle = 'none';
  197. let div = $("#barcodeDiv1");
  198. window.setBarcode("0123456789","#barcodeDiv1",2,50,true)
  199. this.template.width = div.width();
  200. this.template.height = div.height();
  201. }
  202. }
  203. });
  204. </script>
  205. @endsection