printTest.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <gui-page :custom-header="true" :header-class="['gui-theme-background-color']">
  3. <template #gHeader>
  4. <view style="height:44px;" class="gui-flex gui-nowrap gui-rows gui-align-items-center">
  5. <!-- 使用组件实现返回按钮及返回首页按钮 -->
  6. <text style="font-size:44rpx;" class="gui-header-leader-btns gui-color-white font-icons"
  7. @tap="goHome">&#xe6c5;</text>
  8. <!-- 导航文本此处也可以是其他自定义内容 -->
  9. <text
  10. class="gui-h4 gui-blod gui-flex1 gui-text-center gui-ellipsis gui-color-white gui-primary-text">打印测试</text>
  11. <!-- 此处加一个右侧展位元素与左侧同宽,实现标题居中 -->
  12. <!-- 实际宽度请根据自己情况设置 -->
  13. <view style="width:40px;" />
  14. <!-- 如果右侧有其他内容可以利用条件编译和定位来实现-->
  15. </view>
  16. </template>
  17. <template #gBody>
  18. <list class="form">
  19. <cell>
  20. <uni-data-select v-model="printName" :localdata="locationList" />
  21. <button @click="Print">打印</button>
  22. </cell>
  23. </list>
  24. </template>
  25. </gui-page>
  26. </template>
  27. <script>
  28. import {
  29. CCPrintingAPI
  30. } from "@/unit/CCPrintingAPI.min.vue.js";
  31. import {
  32. onMounted,
  33. ref
  34. } from 'vue'
  35. import {
  36. defineComponent
  37. } from 'vue'
  38. export default defineComponent({
  39. setup() {
  40. const printName = ref('')
  41. const locationList = ref([])
  42. const GetPrinters = function() {
  43. var cfgData = new Object;
  44. cfgData.XAction = "Printers";
  45. cfgData.XOpenId = "10000004";
  46. cfgData.XTokens = "+fdBeHkvLvJgWBKF/6iODpmABblarwVz";
  47. cfgData.XUrl = "http://192.168.1.58:51320";
  48. // uniapp 1 其它 0
  49. cfgData.FaceType = "1";
  50. CCPrintingAPI.Excute(cfgData,
  51. function(XTimeout) {},
  52. function(XFail) {
  53. // document.getElementById("tipsmessage").innerHTML = "API可能未安装或未启动";
  54. },
  55. function(XSuccess) {
  56. var apiResult = JSON.parse(XSuccess.trim());
  57. console.log(apiResult);
  58. if (apiResult.Status == "1") {
  59. /*获取到打印机列表*/
  60. if (apiResult.Message.length > 1) {
  61. for (var i = 1; i < apiResult.Message.length; i++) {
  62. locationList.value.push({
  63. text: apiResult.Message[i],
  64. value: apiResult.Message[i]
  65. })
  66. }
  67. /*设置上次使用的打印机*/
  68. // prts.options[0].selected = 'selected';
  69. }
  70. }
  71. }
  72. );
  73. }
  74. onMounted(() => {
  75. GetPrinters();
  76. })
  77. const Print = function(e) {
  78. var cfgData = new Object;
  79. cfgData.XAction = "Print"
  80. cfgData.XOpenId = "10000004";
  81. cfgData.XTokens = "+fdBeHkvLvJgWBKF/6iODpmABblarwVz";
  82. cfgData.XUrl = "http://192.168.1.58:51320";
  83. // uniapp 1 其它 0
  84. cfgData.FaceType = "1";
  85. /*指定打印机*/
  86. cfgData.PrinterName = printName.value;
  87. /*模板方式,0-客户端模板,1-远程模板,
  88. 2-如果本地模板存在,使用本地,不存在使用远程模板,3-不使用模板*/
  89. cfgData.TemplateMode = "2";
  90. /*远程模板URL或本地模板的文件夹*/
  91. // cfgData.TemplateURL = "http://img.51321.cn/web/chicore/VPrinting/API";
  92. cfgData.TemplateURL = "http://113.105.183.190:9163/bucket163";
  93. // cfgData.TemplateURL = "D:\\\\";
  94. /*模板文件名*/
  95. // cfgData.TemplateName = "183601-70X40.Lblx";
  96. cfgData.TemplateName = "2024-01-23-11-03-47-1705979027368_Label3.Lblx";
  97. // cfgData.TemplateName = "Label2.Lblx";
  98. /*打印数据的类型,0-数组,1-Json数组,元素为JSON对象,字段:值*/
  99. cfgData.PrintDataType = 1;
  100. // 随机数据列表
  101. const supplierNameList = ['昆山鼎翔材料科技有限公司', '深圳市新联科技有限公司']
  102. const productSpecList = ['70mm * 40mm', '1.0mm * 1000mm', '1.0mm * 1000mm',
  103. '1.0mm * 1000mm', '1.0mm * 1000mm', '1.0mm * 1000mm', '1.0mm * 1000mm'
  104. ]
  105. const locationNameList = ['A1', 'A2', 'A3', 'A4', 'A5', 'A6']
  106. const materialNameList = ['0.05mm蓝色单层硅胶保护膜7-10g(LZKLGP55-3)',
  107. '0.036mm蓝色非离型面防静电离型膜75±15g(LPT50ZC#EE(C)-36 )', '绿色高温胶带(LCE-P101-G)', 'PPBRFA 背胶磁芯 FA',
  108. '10.19mm磁芯 DEV03-PCS', '0.025白色离型膜1-5g(JHS-WP025004)'
  109. ]
  110. const storageEnvironmentList = ['常温', '17-23℃ 40-60%RH', '7-11℃ 25-30%RH', '常湿']
  111. /*传递打印数据 Json数组*/
  112. /*内容不允许 半角的逗号及半角的分隔符*/
  113. var arr = [{
  114. qrCode: 'SN' + Math.round(Math.random() * 1000000010),
  115. size: Math.round(Math.random() * 10000) + 'mm * ' + Math.round(Math.random() *
  116. 10000) + 'mm',
  117. materialName: materialNameList[Math.floor(Math.random() * materialNameList
  118. .length)],
  119. materialCode: 'LZKLGP55-3',
  120. materialLots: 'A0038-20240114-0008-0004-1001',
  121. supplierName: supplierNameList[Math.floor(Math.random() * supplierNameList
  122. .length)],
  123. createTime: '2024-01-14',
  124. inspectTime: '2024-01-14',
  125. produceDate: '2024-01-14',
  126. validityDate: '2024-01-14',
  127. size: productSpecList[Math.floor(Math.random() * productSpecList.length)],
  128. qty: Math.round(Math.random() * 1000000),
  129. batchNumber: '20240114000' + Math.round(Math.random() * 1000),
  130. wmsStockLocationName: locationNameList[Math.floor(Math.random() * locationNameList
  131. .length)],
  132. storageEnvironment: storageEnvironmentList[Math.floor(Math.random() *
  133. storageEnvironmentList.length)],
  134. slittingOrderNo: '20240114000' + Math.round(Math.random() * 1000),
  135. },
  136. // { sku: 'OBJ100001', name: '测试1', kw: 'D12-1', bh: 'RKD123451' },
  137. // { sku: 'OBJ100002', name: '测试2', kw: 'D12-2', bh: 'RKD123452' },
  138. // { sku: 'OBJ100003', name: '测试3', kw: 'D12-3', bh: 'RKD123453' },
  139. ];
  140. cfgData.PrintData = JSON.stringify(arr);
  141. /*打印 发送给打印机进行打印*/
  142. CCPrintingAPI.Excute(cfgData,
  143. function(XTimeout) {},
  144. function(XFail) {
  145. document.getElementById("tipsmessage").innerHTML = "API可能未安装或未启动";
  146. },
  147. function(XSuccess) {
  148. var apiResult = JSON.parse(XSuccess.trim());
  149. if (apiResult.Status == "1") {
  150. document.getElementById("tipsmessage").innerHTML = apiResult.Message[0] +
  151. apiResult.Message[1];
  152. }
  153. }
  154. );
  155. }
  156. const goHome = function() {
  157. uni.$goHome()
  158. }
  159. return {
  160. goHome,
  161. printName,
  162. Print,
  163. locationList
  164. }
  165. }
  166. })
  167. </script>
  168. <style lang="scss" scoped>
  169. .gui-header-leader-btns {
  170. color: black;
  171. font-size: 24px !important;
  172. margin-left: 24rpx;
  173. }
  174. .gui-sbody {
  175. font-size: 14px;
  176. background-color: rgba(234, 239, 242, 1);
  177. }
  178. .form {
  179. margin-top: 85px;
  180. }
  181. .row-1,
  182. .row-2,
  183. .row-3,
  184. .row-4 {
  185. margin-top: 10px;
  186. height: 55px;
  187. display: flex;
  188. justify-content: center;
  189. background-color: white;
  190. }
  191. .row-1 {
  192. margin-top: 0px;
  193. }
  194. .row-1,
  195. .row-2 {
  196. .row-1-card,
  197. .row-2-card {
  198. display: flex;
  199. flex-direction: row;
  200. justify-content: space-between;
  201. align-items: center;
  202. width: 100%;
  203. padding-left: 10px;
  204. padding-right: 10px;
  205. }
  206. }
  207. .row-3 {
  208. height: 140px;
  209. .row-3-card {
  210. display: flex;
  211. flex-direction: column;
  212. .row-space-between {
  213. flex: 1;
  214. width: calc(100vw - 40px);
  215. display: flex;
  216. flex-direction: row;
  217. justify-content: space-between;
  218. align-items: center;
  219. padding-top: 12px;
  220. padding-bottom: 12px;
  221. }
  222. }
  223. }
  224. .row-4 {
  225. height: 300px;
  226. .row-4-card {
  227. display: flex;
  228. flex-direction: column;
  229. .row-space-between {
  230. flex: 1;
  231. width: calc(100vw - 40px);
  232. display: flex;
  233. flex-direction: row;
  234. justify-content: space-between;
  235. align-items: center;
  236. margin-top: 12px;
  237. margin-bottom: 12px;
  238. }
  239. }
  240. }
  241. .row-operation {
  242. height: 110px;
  243. padding-left: 20px;
  244. padding-right: 20px;
  245. display: flex;
  246. flex-direction: row;
  247. justify-content: center;
  248. align-items: center;
  249. .row-operation-card {
  250. flex: 1;
  251. .btn-row-1 {
  252. margin-bottom: 5px !important;
  253. }
  254. }
  255. }
  256. .input-200 {
  257. width: 200px;
  258. padding-left: 10px;
  259. }
  260. .input-300 {
  261. width: 300px;
  262. padding-left: 10px;
  263. }
  264. .font-icons {
  265. width: 40px;
  266. font-size: 20px;
  267. }
  268. .select-group {
  269. display: flex;
  270. flex-direction: column;
  271. flex: 1;
  272. .select-item {
  273. display: flex;
  274. flex-direction: row;
  275. align-items: center;
  276. margin-bottom: 10px;
  277. .store-text {
  278. margin-right: 14px;
  279. }
  280. }
  281. }
  282. </style>