ci-plus 1.6.4 → 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.
package/README.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
##
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
## 历史更新
|
|
2
|
+
1.6.5
|
|
3
|
+
```sh
|
|
4
|
+
1、将1.2.0 版本中标识卡模板的'单重'和'净重'后面追加单位字段。
|
|
5
|
+
2、附件下载函数ajaxBox.ts中新增 downFileFetchV3 函数:不传递文件名称时使用后端返回文件名导出。
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
1.6.4
|
|
9
|
+
```sh
|
|
10
|
+
1、标识卡模板更新到1.5.6版本
|
|
11
|
+
```
|
|
12
|
+
## 安装本组件库 特别注意:
|
|
4
13
|
|
|
5
14
|
```sh
|
|
6
15
|
# 本组件库是二次封装,所以依赖一些其他库,需要安装以下库:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ci-plus",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"description": "ci组件库",
|
|
5
5
|
"main": "./index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
"keywords": [
|
|
12
12
|
"vue",
|
|
13
13
|
"element-plus",
|
|
14
|
-
"ui组件库二次封装"
|
|
15
|
-
"标识卡模板更新到1.5.6"
|
|
14
|
+
"ui组件库二次封装"
|
|
16
15
|
],
|
|
17
16
|
"type": "module",
|
|
18
17
|
"author": {
|
package/src/utils/ajaxBox.ts
CHANGED
|
@@ -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
|
*/
|
package/src/utils/cardPrint.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module cardPrint
|
|
3
3
|
* @author : 卖女孩的小火柴
|
|
4
4
|
* !description : 标识卡打印
|
|
5
|
-
* @version : 1.
|
|
5
|
+
* @version : 1.3.1
|
|
6
6
|
* @since : 创建时间 2024-03-15 15:16:12
|
|
7
7
|
* @update : 2024-11-5 13:26:12更新标识卡模板,删除为尚工厂的一些字段
|
|
8
8
|
* !update : 2024-11.12 芜湖伦比公司的成品工厂的"毛坯标识卡"使用为尚工厂的"产品标识卡"模板
|
|
@@ -148,9 +148,9 @@ export const cardPrint = (
|
|
|
148
148
|
r9c3: '收货人员',
|
|
149
149
|
r9c4: item.center_data[0]?.consignee,
|
|
150
150
|
r10c1: '净重',
|
|
151
|
-
r10c2: item.net_weight,
|
|
151
|
+
r10c2: item.net_weight + item.net_weight_unit,
|
|
152
152
|
r10c3: '单重',
|
|
153
|
-
r10c4: item.piece_weight,
|
|
153
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
154
154
|
r11c1: '产线',
|
|
155
155
|
r11c2: item.line_name,
|
|
156
156
|
r11c3: '工单号',
|
|
@@ -384,7 +384,7 @@ export const cardPrint = (
|
|
|
384
384
|
r10c1: '责废总数', // 建
|
|
385
385
|
r10c2: item.storage_scrap_count,
|
|
386
386
|
r10c3: '单重',
|
|
387
|
-
r10c4: item.piece_weight,
|
|
387
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
388
388
|
r11c1: '工序',
|
|
389
389
|
r11c2: item.process_name,
|
|
390
390
|
r11c3: '本批数量',
|
|
@@ -856,7 +856,7 @@ export const cardPrint = (
|
|
|
856
856
|
r10c1: '料废总数',
|
|
857
857
|
r10c2: item.storage_scrap_count,
|
|
858
858
|
r10c3: '单重',
|
|
859
|
-
r10c4: item.piece_weight,
|
|
859
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
860
860
|
r11c1: '工序',
|
|
861
861
|
r11c2: item.process_name,
|
|
862
862
|
r11c3: '本批数量',
|
|
@@ -956,9 +956,9 @@ export const cardPrint = (
|
|
|
956
956
|
r9c3: '收货人员',
|
|
957
957
|
r9c4: item.center_data[0]?.consignee,
|
|
958
958
|
r10c1: '净重',
|
|
959
|
-
r10c2: item.net_weight,
|
|
959
|
+
r10c2: item.net_weight + item.net_weight_unit,
|
|
960
960
|
r10c3: '单重',
|
|
961
|
-
r10c4: item.piece_weight,
|
|
961
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
962
962
|
r11c1: '产线',
|
|
963
963
|
r11c2: item.line_name,
|
|
964
964
|
r11c3: '工单号',
|
|
@@ -1071,11 +1071,11 @@ export const cardPrint = (
|
|
|
1071
1071
|
r10c1: '本箱数量',
|
|
1072
1072
|
r10c2: item.current_inventory,
|
|
1073
1073
|
r10c3: '单重',
|
|
1074
|
-
r10c4: item.piece_weight,
|
|
1074
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
1075
1075
|
r11c1: '总箱数',
|
|
1076
1076
|
r11c2: item.total_row,
|
|
1077
1077
|
r11c3: '净重',
|
|
1078
|
-
r11c4: item.net_weight,
|
|
1078
|
+
r11c4: item.net_weight + item.net_weight_unit,
|
|
1079
1079
|
r12c1: '包装方式',
|
|
1080
1080
|
r12c2: item.packaging_specifications_name,
|
|
1081
1081
|
r12c3: '生产日期',
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module cardPrint
|
|
3
3
|
* @author : 卖女孩的小火柴
|
|
4
4
|
* !description : 标识卡打印
|
|
5
|
-
* @version : 1.
|
|
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: '本批数量',
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module cardPrint
|
|
3
3
|
* @author : 卖女孩的小火柴
|
|
4
4
|
* !description : 标识卡打印
|
|
5
|
-
* @version : 1.
|
|
5
|
+
* @version : 1.1.0
|
|
6
6
|
* @since : 创建时间 2024-03-15 15:16:12
|
|
7
7
|
* @update : 2024-11-5 13:26:12更新标识卡模板,删除为尚工厂的一些字段
|
|
8
8
|
*/
|
|
@@ -147,9 +147,9 @@ export const cardPrint = (
|
|
|
147
147
|
r9c3: '收货人员',
|
|
148
148
|
r9c4: item.center_data[0]?.consignee,
|
|
149
149
|
r10c1: '净重',
|
|
150
|
-
r10c2: item.net_weight,
|
|
150
|
+
r10c2: item.net_weight + item.net_weight_unit,
|
|
151
151
|
r10c3: '单重',
|
|
152
|
-
r10c4: item.piece_weight,
|
|
152
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
153
153
|
r11c1: '产线',
|
|
154
154
|
r11c2: item.line_name,
|
|
155
155
|
r11c3: '工单号',
|
|
@@ -383,7 +383,7 @@ export const cardPrint = (
|
|
|
383
383
|
r10c1: '责废总数', // 建
|
|
384
384
|
r10c2: item.storage_scrap_count,
|
|
385
385
|
r10c3: '单重',
|
|
386
|
-
r10c4: item.piece_weight,
|
|
386
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
387
387
|
r11c1: '工序',
|
|
388
388
|
r11c2: item.process_name,
|
|
389
389
|
r11c3: '本批数量',
|
|
@@ -855,7 +855,7 @@ export const cardPrint = (
|
|
|
855
855
|
r10c1: '料废总数',
|
|
856
856
|
r10c2: item.storage_scrap_count,
|
|
857
857
|
r10c3: '单重',
|
|
858
|
-
r10c4: item.piece_weight,
|
|
858
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
859
859
|
r11c1: '工序',
|
|
860
860
|
r11c2: item.process_name,
|
|
861
861
|
r11c3: '本批数量',
|
|
@@ -1007,11 +1007,11 @@ export const cardPrint = (
|
|
|
1007
1007
|
r10c1: '本箱数量',
|
|
1008
1008
|
r10c2: item.current_inventory,
|
|
1009
1009
|
r10c3: '单重',
|
|
1010
|
-
r10c4: item.piece_weight,
|
|
1010
|
+
r10c4: item.piece_weight + item.piece_weight_unit,
|
|
1011
1011
|
r11c1: '总箱数',
|
|
1012
1012
|
r11c2: item.total_row,
|
|
1013
1013
|
r11c3: '净重',
|
|
1014
|
-
r11c4: item.net_weight,
|
|
1014
|
+
r11c4: item.net_weight + item.net_weight_unit,
|
|
1015
1015
|
r12c1: '包装方式',
|
|
1016
1016
|
r12c2: item.packaging_specifications_name,
|
|
1017
1017
|
r12c3: '生产日期',
|