ci-plus 1.6.3 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ import { ElMessage } from 'element-plus'
15
15
  * 如果blob对象是JSON格式,则尝试解析为JavaScript对象,并显示相应的错误消息。
16
16
  * 如果解析失败,则直接以原始格式下载blob对象。
17
17
  */
18
- const downFileFn = function (blob: Blob | BlobPart, fileName: string) {
18
+ const downFileFn = function (blob: Blob | BlobPart, fileName: string, resolve?: Function, reject?: Function) {
19
19
  // 创建一个新的Blob对象,指定类型为application/json,假设blob是我们需要转换的Blob对象
20
20
  let b = new Blob([blob], {
21
21
  type: 'application/json',
@@ -35,7 +35,7 @@ const downFileFn = function (blob: Blob | BlobPart, fileName: string) {
35
35
  let response = JSON.parse(text as string)
36
36
  console.log(response) // 这里是解析后object对象
37
37
  ElMessage.error(response.msg)
38
- return
38
+ return reject && reject(response)
39
39
  } catch (error) {
40
40
  // 如果解析失败,将Blob对象转换为URL并创建下载链接
41
41
  // console.error('Error parsing JSON', error)
@@ -47,8 +47,9 @@ const downFileFn = function (blob: Blob | BlobPart, fileName: string) {
47
47
  link.setAttribute('download', fileName)
48
48
  document.body.appendChild(link)
49
49
  link.click()
50
- ElMessage.success('导出完成!请打开浏览器自带下载器查看文件!')
50
+ ElMessage.success('操作成功,请打开浏览器自带下载器查看文件!')
51
51
  link = null
52
+ resolve && resolve({ msg: '操作成功,请打开浏览器自带下载器查看文件!' })
52
53
  }
53
54
  }
54
55
 
@@ -69,6 +70,7 @@ interface Config {
69
70
  cbpercentage?: Function // 获取下载进度的回调函数
70
71
  fileName?: string, // 下载后的文件名
71
72
  chunkSize?: number, // 每次下载的块大小,默认为 10KB
73
+ body?: string, // 请求体
72
74
  }
73
75
  const ajaxBox = {
74
76
  downFile: function (blob: Blob | BlobPart, fileName: string) {
@@ -267,7 +269,7 @@ const ajaxBox = {
267
269
  console.log('下载完成.')
268
270
  // 处理下载完成的数据,例如将其保存或显示
269
271
  downFileFn(blob, _fileName)
270
- resolve(true)
272
+ // resolve(true)
271
273
  }
272
274
  }
273
275
  }
@@ -277,7 +279,120 @@ const ajaxBox = {
277
279
  reject(error)
278
280
  })
279
281
  })
280
- }
282
+ },
283
+
284
+ // 下载文件:3.0版本:优先使用传递的文件名,若不传递文件问就使用后端返回的文件名
285
+ downFileFetchV3: function (url: string, params?: Obj, config?: Config) {
286
+ let options: any = {
287
+ method: config?.method || 'GET',
288
+ }
289
+ let _headers
290
+ let _fileName = ''
291
+ if (options.method === 'GET' || options.method === 'get') {
292
+ _headers = {
293
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
294
+ }
295
+ } else if (options.method === 'POST' || options.method === 'post') {
296
+ _headers = {
297
+ 'Content-Type': 'application/json', // 设置为json格式
298
+ }
299
+ }
300
+ // 数组请求头: 优先使用传递的请求头,如果没有传递,则使用默认的请求头
301
+ options['headers'] = config?.headers || _headers
302
+
303
+ // 判断请求是否为get请求,若是get请求,则将params参数拼接在url后面
304
+ if (options.method === 'GET') {
305
+ const queryString = new URLSearchParams(params).toString()
306
+ url = url + '?' + queryString
307
+ }
308
+ // 处理post请求的参数
309
+ if ((options.method === 'post' || options.method === 'POST') && params) {
310
+ options['body'] = JSON.stringify(params)
311
+ }
312
+
313
+ // 定义每次读取的数据块大小(字节)
314
+ let chunkSize = config?.chunkSize || 10240 // 例如,10KB
315
+
316
+ // 初始化已下载的字节数
317
+ let downloaded = 0
318
+ // 初始化 Blob 切片起始点
319
+ let start = 0
320
+
321
+ return new Promise((resolve, reject) => {
322
+ fetch(url, options)
323
+ .then((res: any) => {
324
+ if (config?.fileName && res.ok) {
325
+ // 如果传递了文件名,则直接返回 Blob
326
+ _fileName = config?.fileName || '附件.xlsx'
327
+ return res.blob().then((blob: Blob) => ({ blob, _fileName }))
328
+ } else if (!config?.fileName && res.ok) {
329
+ // 如果没传递文件名,则使后端返回文件名
330
+ // 获取响应头中的 Content-Disposition(此属性中包含文件名)如:'attachment; filename="测试文件.xlsx"'
331
+ const contentDisposition = res.headers.get('Content-Disposition')
332
+ console.log('后端返回的文件名字符串: ', contentDisposition)
333
+ if (contentDisposition) {
334
+ // 解析文件名
335
+ const fileNameMatch = contentDisposition.match(/filename="(.+)"/)
336
+ // console.log('文件名数组: ', fileNameMatch)
337
+ if (fileNameMatch.length > 1) {
338
+ // 匹配到文件名,则将文件名解码并赋值给 _fileName
339
+ _fileName = decodeURIComponent(fileNameMatch[1])
340
+ console.log('后端返回的文件名: ', _fileName)
341
+ return res.blob().then((blob: Blob) => ({ blob, _fileName }))
342
+ }
343
+ }
344
+ }
345
+
346
+ if (!res.ok) {
347
+ console.log('res: ', res)
348
+ throw new Error('网络响应不正常!或其他错误')
349
+ }
350
+ // 如果没有找到文件名,直接返回 Blob
351
+ return res.blob().then((blob: Blob) => ({ blob, _fileName }))
352
+ })
353
+ .then(({ blob, _fileName }) => {
354
+ // console.log('blob: ', blob, _fileName)
355
+ const reader = new FileReader() // 创建 FileReader 对象
356
+ const readBlobInChunks = () => {
357
+ // 创建一个 Blob 切片,大小为 chunkSize
358
+ const chunkBlob = blob.slice(start, start + chunkSize)
359
+ start += chunkSize // 更新起始点
360
+ // 读取 Blob 切片
361
+ reader.readAsArrayBuffer(chunkBlob)
362
+ reader.onload = () => {
363
+ // 累加已下载的字节数
364
+ // downloaded += reader.result.byteLength
365
+ if (typeof reader.result === 'string' || reader.result === null) {
366
+ console.log('reader.result不为 ArrayBuffer')
367
+ // 处理字符串的情况,可能需要转换为 ArrayBuffer 或者其他处理逻辑
368
+ } else {
369
+ downloaded += reader.result.byteLength
370
+ }
371
+ // 计算下载进度百分比
372
+ const total = blob.size
373
+ const progress = ((downloaded / total) * 100).toFixed(2)
374
+ config?.cbpercentage && config?.cbpercentage(progress) // 如果传递了获取下载进度的回调函数,则调用回调函数传递进度百分比
375
+ console.log(`下载进度: ${progress}%`)
376
+ // 如果还有数据未读取,则继续读取
377
+ if (start < total) {
378
+ readBlobInChunks()
379
+ } else {
380
+ console.log('下载完成.')
381
+ // 处理下载完成的数据,例如将其保存或显示
382
+ downFileFn(blob, _fileName, resolve, reject)
383
+ // resolve(true)
384
+ }
385
+ }
386
+ }
387
+ readBlobInChunks()
388
+ })
389
+ .catch((error) => {
390
+ console.error('下载文件时出错:', error)
391
+ reject(error)
392
+ })
393
+ })
394
+ },
395
+
281
396
 
282
397
 
283
398
  /*
@@ -363,4 +478,27 @@ const exportFile = () => {
363
478
  loading.close() // 关闭加载中
364
479
  })
365
480
  }
481
+ // 版本3.0:提供了.then和.catch方法,可以更方便地处理异步操作的结果和错误。
482
+ const loading = ElLoading.service({
483
+ lock: true,
484
+ text: 'Loading',
485
+ background: 'rgba(0, 0, 0, 0.7)',
486
+ })
487
+ const url = CrossAuditModule + 'generate_report_get/'
488
+ const params = {
489
+ ids: ids,
490
+ }
491
+ ajaxBox
492
+ .downFileFetchV3(url, params, {
493
+ method: 'POST',
494
+ })
495
+ .then((res) => {
496
+ console.log('成功: ', res)
497
+ })
498
+ .catch((err) => {
499
+ console.log('失败: ', err)
500
+ }).finally(() => {
501
+ loading.close() // 关闭加载中
502
+ })
503
+
366
504
  */
@@ -2,9 +2,10 @@
2
2
  * @module cardPrint
3
3
  * @author : 卖女孩的小火柴
4
4
  * !description : 标识卡打印
5
- * @version : 1.0.3
5
+ * @version : 1.3.1
6
6
  * @since : 创建时间 2024-03-15 15:16:12
7
7
  * @update : 2024-11-5 13:26:12更新标识卡模板,删除为尚工厂的一些字段
8
+ * !update : 2024-11.12 芜湖伦比公司的成品工厂的"毛坯标识卡"使用为尚工厂的"产品标识卡"模板
8
9
  */
9
10
  // import { scan_card_code_get } from '@/api/InventoryBatch'
10
11
  import { ElMessage, MessageParamsWithType } from 'element-plus'
@@ -147,9 +148,9 @@ export const cardPrint = (
147
148
  r9c3: '收货人员',
148
149
  r9c4: item.center_data[0]?.consignee,
149
150
  r10c1: '净重',
150
- r10c2: item.net_weight,
151
+ r10c2: item.net_weight + item.net_weight_unit,
151
152
  r10c3: '单重',
152
- r10c4: item.piece_weight,
153
+ r10c4: item.piece_weight + item.piece_weight_unit,
153
154
  r11c1: '产线',
154
155
  r11c2: item.line_name,
155
156
  r11c3: '工单号',
@@ -383,7 +384,7 @@ export const cardPrint = (
383
384
  r10c1: '责废总数', // 建
384
385
  r10c2: item.storage_scrap_count,
385
386
  r10c3: '单重',
386
- r10c4: item.piece_weight,
387
+ r10c4: item.piece_weight + item.piece_weight_unit,
387
388
  r11c1: '工序',
388
389
  r11c2: item.process_name,
389
390
  r11c3: '本批数量',
@@ -855,7 +856,7 @@ export const cardPrint = (
855
856
  r10c1: '料废总数',
856
857
  r10c2: item.storage_scrap_count,
857
858
  r10c3: '单重',
858
- r10c4: item.piece_weight,
859
+ r10c4: item.piece_weight + item.piece_weight_unit,
859
860
  r11c1: '工序',
860
861
  r11c2: item.process_name,
861
862
  r11c3: '本批数量',
@@ -905,7 +906,7 @@ export const cardPrint = (
905
906
  r7c4: item.center_data[0]?.material_batch_number,
906
907
  data: [
907
908
  {
908
- opt_time: setDate(item.opt_time), // 日期
909
+ opt_time: item.opt_time, // 日期
909
910
  sr: item.record_type === 1 ? item.inventory : '', // 收入
910
911
  fc: item.record_type === 2 ? item.inventory : '', // 发出
911
912
  balance_count: item.balance_count, //结存
@@ -925,48 +926,111 @@ export const cardPrint = (
925
926
  // 工厂类型:1:为尚工厂 | 2:成品工厂
926
927
  factoryType: item.is_finished_goods,
927
928
  r1c2: '毛坯标识卡',
928
- r1c3: '产品类别',
929
+ r1c3: '产品类别', // (为 类型/名称 拼接)
929
930
  r1c4: item.material_name,
930
- r2c1: '物料编码',
931
- r2c2: item.material_code,
931
+ r2c1: '分布场所代号',
932
+ r2c2: item.center_data[0]?.distribute_place_name,
932
933
  r2c4: baseUrls + item.qr_code_path, // 二维码地址
933
- r3c1: '产品型号',
934
- r3c2: item.material_model,
934
+ r3c1: '客户名称',
935
+ r3c2: item.customer_name || item.center_data[0]?.customer_name || '',
935
936
  r4c1: '供应商',
936
937
  r4c2: item.center_data[0]?.supplier_name,
937
- r5c1: '材料厂商',
938
+ r5c1: '材料厂家',
938
939
  r5c2: item.center_data[0]?.material_manufacturer,
939
940
  r5c4: item.card_code, // 标识卡号
940
- r6c1: '本箱数量',
941
- r6c2: item.current_inventory,
942
- r6c3: '生产日期',
943
- r6c4: item.product_date,
944
- r7c1: '检验员',
945
- r7c2: item.center_data[0]?.inspector,
946
- r7c3: '检验日期',
947
- r7c4: item.center_data[0]?.inspect_time,
948
- r8c1: '材料炉号',
949
- r8c2: item.center_data[0]?.material_heat_number,
950
- r8c3: '材料批次',
951
- r8c4: item.center_data[0]?.material_batch_number,
952
- r9c1: '本批数量',
953
- r9c2: item.center_data[0]?.batch_count,
954
- r9c3: '件数规格',
955
- r9c4: item.center_data[0]?.case_count_str,
956
- r10c1: '规值',
957
- r10c2: item.value,
958
- r10c3: '采购单号',
959
- r10c4: item.center_data[0]?.purchase_number,
960
- r11c1: '批次序列号',
961
- r11c2: item.center_data[0]?.b2b_batch_number,
962
- r11c3: '采购单行号',
963
- r11c4: item.center_data[0]?.purchase_order,
964
- r12c1: '热处理批号',
965
- r12c2: item.center_data[0]?.heat_batch_number,
941
+
942
+ r6c1: '淬火件型号',
943
+ r6c2: item.quenching_material_model,
944
+ r6c3: '材料炉号',
945
+ r6c4: item.center_data[0]?.material_heat_number,
946
+ r7c1: '淬火件编码',
947
+ r7c2: item.quenching_material_code,
948
+ r7c3: '材料牌号',
949
+ r7c4: item.center_data[0]?.material_mark,
950
+ r8c1: '产品物料号',
951
+ r8c2: item.material_code,
952
+ r8c3: '库位',
953
+ r8c4: item.location_name,
954
+ r9c1: '产品型号',
955
+ r9c2: item.material_model,
956
+ r9c3: '收货人员',
957
+ r9c4: item.center_data[0]?.consignee,
958
+ r10c1: '净重',
959
+ r10c2: item.net_weight + item.net_weight_unit,
960
+ r10c3: '单重',
961
+ r10c4: item.piece_weight + item.piece_weight_unit,
962
+ r11c1: '产线',
963
+ r11c2: item.line_name,
964
+ r11c3: '工单号',
965
+ r11c4: item.wip_order_number,
966
+ r12c1: '本箱数量',
967
+ r12c2: item.current_inventory,
968
+ r12c3: '本批数量',
969
+ r12c4: item.center_data[0]?.batch_count,
970
+ r13c1: '总箱数',
971
+ r13c2: item.total_row,
972
+ r13c3: '生产日期',
973
+ r13c4: item.product_date,
974
+ r14c1: '热处理批号',
975
+ r14c2: item.center_data[0]?.heat_batch_number,
976
+ r14c3: '件数规格',
977
+ r14c4: item.center_data[0]?.case_count_str,
978
+ r15c1: '包装方式',
979
+ r15c2: item.packaging_specifications_name,
980
+ r15c3: '',
981
+ r15c4: '',
982
+
966
983
  r40c1: '备注', // 备注
967
- r40c2: item.remark, // 备注
968
- r41c1: item.center_data[0]?.b2b_batch_number || '', //条形码文本
984
+ r40c2: item.remark, // 备注key
985
+ r41c1: item.center_data[0]?.b2b_batch_number || '', //条形码文本666
969
986
  }
987
+ // obj = {
988
+ // card_state: item.card_state, // 标识卡类型
989
+ // // 工厂类型:1:为尚工厂 | 2:成品工厂
990
+ // factoryType: item.is_finished_goods,
991
+ // r1c2: '毛坯标识卡',
992
+ // r1c3: '产品类别',
993
+ // r1c4: item.material_name,
994
+ // r2c1: '物料编码',
995
+ // r2c2: item.material_code,
996
+ // r2c4: baseUrls + item.qr_code_path, // 二维码地址
997
+ // r3c1: '产品型号',
998
+ // r3c2: item.material_model,
999
+ // r4c1: '供应商',
1000
+ // r4c2: item.center_data[0]?.supplier_name,
1001
+ // r5c1: '材料厂商',
1002
+ // r5c2: item.center_data[0]?.material_manufacturer,
1003
+ // r5c4: item.card_code, // 标识卡号
1004
+ // r6c1: '本箱数量',
1005
+ // r6c2: item.current_inventory,
1006
+ // r6c3: '生产日期',
1007
+ // r6c4: item.product_date,
1008
+ // r7c1: '检验员',
1009
+ // r7c2: item.center_data[0]?.inspector,
1010
+ // r7c3: '检验日期',
1011
+ // r7c4: item.center_data[0]?.inspect_time,
1012
+ // r8c1: '材料炉号',
1013
+ // r8c2: item.center_data[0]?.material_heat_number,
1014
+ // r8c3: '材料批次',
1015
+ // r8c4: item.center_data[0]?.material_batch_number,
1016
+ // r9c1: '本批数量',
1017
+ // r9c2: item.center_data[0]?.batch_count,
1018
+ // r9c3: '件数规格',
1019
+ // r9c4: item.center_data[0]?.case_count_str,
1020
+ // r10c1: '规值',
1021
+ // r10c2: item.value,
1022
+ // r10c3: '采购单号',
1023
+ // r10c4: item.center_data[0]?.purchase_number,
1024
+ // r11c1: '批次序列号',
1025
+ // r11c2: item.center_data[0]?.b2b_batch_number,
1026
+ // r11c3: '采购单行号',
1027
+ // r11c4: item.center_data[0]?.purchase_order,
1028
+ // r12c1: '热处理批号',
1029
+ // r12c2: item.center_data[0]?.heat_batch_number,
1030
+ // r40c1: '备注', // 备注
1031
+ // r40c2: item.remark, // 备注
1032
+ // r41c1: item.center_data[0]?.b2b_batch_number || '', //条形码文本
1033
+ // }
970
1034
  }
971
1035
  // 为尚工厂-毛坯标识卡
972
1036
  else if (item.card_state == 'MAOPI' && item.is_finished_goods == 1) {
@@ -1007,11 +1071,11 @@ export const cardPrint = (
1007
1071
  r10c1: '本箱数量',
1008
1072
  r10c2: item.current_inventory,
1009
1073
  r10c3: '单重',
1010
- r10c4: item.piece_weight,
1074
+ r10c4: item.piece_weight + item.piece_weight_unit,
1011
1075
  r11c1: '总箱数',
1012
1076
  r11c2: item.total_row,
1013
1077
  r11c3: '净重',
1014
- r11c4: item.net_weight,
1078
+ r11c4: item.net_weight + item.net_weight_unit,
1015
1079
  r12c1: '包装方式',
1016
1080
  r12c2: item.packaging_specifications_name,
1017
1081
  r12c3: '生产日期',
@@ -2,7 +2,7 @@
2
2
  * @module cardPrint
3
3
  * @author : 卖女孩的小火柴
4
4
  * !description : 标识卡打印
5
- * @version : 1.0.0
5
+ * @version : 1.2.0
6
6
  * @since : 创建时间 2024-03-15 15:16:12
7
7
  */
8
8
  // import { scan_card_code_get } from '@/api/InventoryBatch'
@@ -125,7 +125,7 @@ export const cardPrint = (
125
125
  r10c1: '抽检结果', // (无)
126
126
  r10c2: '',
127
127
  r10c3: '单重',
128
- r10c4: item.piece_weight,
128
+ r10c4: item.piece_weight + item.piece_weight_unit,
129
129
  r11c1: '本箱数量',
130
130
  r11c2: item.current_inventory,
131
131
  r11c3: '抽检人员',
@@ -308,7 +308,7 @@ export const cardPrint = (
308
308
  r10c1: '总箱数', // 建
309
309
  r10c2: item.total_row,
310
310
  r10c3: '单重',
311
- r10c4: item.piece_weight,
311
+ r10c4: item.piece_weight + item.piece_weight_unit,
312
312
  r11c1: '责废总数',
313
313
  r11c2: item.storage_scrap_count,
314
314
  r11c3: '本批数量',
@@ -764,7 +764,7 @@ export const cardPrint = (
764
764
  r10c1: '总箱数',
765
765
  r10c2: item.total_row,
766
766
  r10c3: '单重',
767
- r10c4: item.piece_weight,
767
+ r10c4: item.piece_weight + item.piece_weight_unit,
768
768
  r11c1: '料废总数',
769
769
  r11c2: item.storage_scrap_count,
770
770
  r11c3: '本批数量',