ci-plus 1.4.9 → 1.5.1
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/package.json +2 -2
- package/src/utils/ajaxBox.ts +122 -15
- package/src/utils/cardPrint.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ci-plus",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "ci组件库",
|
|
5
5
|
"main": "./index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"vue",
|
|
13
13
|
"element-plus",
|
|
14
14
|
"ui组件库二次封装",
|
|
15
|
-
"
|
|
15
|
+
"标识卡模板中将下道工序改为显示名称"
|
|
16
16
|
],
|
|
17
17
|
"type": "module",
|
|
18
18
|
"author": {
|
package/src/utils/ajaxBox.ts
CHANGED
|
@@ -59,10 +59,102 @@ const downFileFn = function (blob: Blob | BlobPart, fileName: string) {
|
|
|
59
59
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
type Obj = {
|
|
63
|
+
[key: string]: any
|
|
64
|
+
}
|
|
62
65
|
const ajaxBox = {
|
|
63
66
|
downFile: function (blob: Blob | BlobPart, fileName: string) {
|
|
64
67
|
downFileFn(blob, fileName);
|
|
65
68
|
},
|
|
69
|
+
|
|
70
|
+
// 下载文件
|
|
71
|
+
/**
|
|
72
|
+
* 下载文件函数
|
|
73
|
+
* @param fillAddress string 表示服务端接口url地址
|
|
74
|
+
* @param fileName string 下载后的文件名
|
|
75
|
+
* @param method string 如果不想写get呢,你就写个null,但是你得写进去
|
|
76
|
+
* @param headers Object 请求头
|
|
77
|
+
* @param params Object 请求参数
|
|
78
|
+
* 将给定的blob对象转换为文件,并提供一个下载链接以供用户下载。
|
|
79
|
+
* 如果blob对象是JSON格式,则尝试解析为JavaScript对象,并显示相应的错误消息。
|
|
80
|
+
* 如果解析失败,则直接以原始格式下载blob对象。
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
downFileFetch: function (fillAddress: string, fileName: string, method: string, headers: Obj, params: Obj, cbpercentage: Function) {
|
|
85
|
+
let options = {
|
|
86
|
+
method: method || 'GET',
|
|
87
|
+
}
|
|
88
|
+
// 判断请求是否为get请求,若是get请求,则将params参数拼接在url后面
|
|
89
|
+
if (method === 'GET') {
|
|
90
|
+
const queryString = new URLSearchParams(params).toString()
|
|
91
|
+
fillAddress = fillAddress + '?' + queryString
|
|
92
|
+
}
|
|
93
|
+
if (headers) {
|
|
94
|
+
options['headers'] = headers
|
|
95
|
+
}
|
|
96
|
+
if ((method === 'post' || method === 'POST') && params) {
|
|
97
|
+
options['body'] = JSON.stringify(params)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 定义每次读取的数据块大小(字节)
|
|
101
|
+
let chunkSize = 10240 // 例如,10KB
|
|
102
|
+
// 如果在params中传递了chunkSize参数,则使用其值作为块大小
|
|
103
|
+
if (params && params.chunkSize) {
|
|
104
|
+
chunkSize = params.chunkSize
|
|
105
|
+
}
|
|
106
|
+
// 初始化已下载的字节数
|
|
107
|
+
let downloaded = 0
|
|
108
|
+
// 初始化 Blob 切片起始点
|
|
109
|
+
let start = 0
|
|
110
|
+
|
|
111
|
+
fetch(fillAddress, options)
|
|
112
|
+
.then((res) => {
|
|
113
|
+
// console.log('resssssss: ', res)
|
|
114
|
+
if (!res.ok) {
|
|
115
|
+
throw new Error('Network response was not ok')
|
|
116
|
+
}
|
|
117
|
+
return res.blob()
|
|
118
|
+
})
|
|
119
|
+
.then((blob) => {
|
|
120
|
+
// console.log('blob: ', blob)
|
|
121
|
+
const reader = new FileReader() // 创建 FileReader 对象
|
|
122
|
+
const readBlobInChunks = () => {
|
|
123
|
+
// 创建一个 Blob 切片,大小为 chunkSize
|
|
124
|
+
const chunkBlob = blob.slice(start, start + chunkSize)
|
|
125
|
+
start += chunkSize // 更新起始点
|
|
126
|
+
// 读取 Blob 切片
|
|
127
|
+
reader.readAsArrayBuffer(chunkBlob)
|
|
128
|
+
reader.onload = () => {
|
|
129
|
+
// 累加已下载的字节数
|
|
130
|
+
// downloaded += reader.result.byteLength
|
|
131
|
+
if (typeof reader.result === 'string' || reader.result === null) {
|
|
132
|
+
console.log('reader.result不为 ArrayBuffer');
|
|
133
|
+
// 处理字符串的情况,可能需要转换为 ArrayBuffer 或者其他处理逻辑
|
|
134
|
+
} else {
|
|
135
|
+
downloaded += reader.result.byteLength;
|
|
136
|
+
}
|
|
137
|
+
// 计算下载进度百分比
|
|
138
|
+
const total = blob.size
|
|
139
|
+
const progress = ((downloaded / total) * 100).toFixed(2)
|
|
140
|
+
cbpercentage && cbpercentage(progress) // 如果传递了获取下载进度的回调函数,则调用回调函数传递进度百分比
|
|
141
|
+
console.log(`下载进度: ${progress}%`)
|
|
142
|
+
// 如果还有数据未读取,则继续读取
|
|
143
|
+
if (start < total) {
|
|
144
|
+
readBlobInChunks()
|
|
145
|
+
} else {
|
|
146
|
+
console.log('下载完成.')
|
|
147
|
+
// 处理下载完成的数据,例如将其保存或显示
|
|
148
|
+
// downFileFn(blob, fileName)
|
|
149
|
+
downFileFn(blob, fileName)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
readBlobInChunks()
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
66
158
|
/*
|
|
67
159
|
sendJSONP: function (url, callbackName, callback) {
|
|
68
160
|
const script = document.createElement('script');
|
|
@@ -80,22 +172,37 @@ const ajaxBox = {
|
|
|
80
172
|
delete window[callbackName];
|
|
81
173
|
};
|
|
82
174
|
},
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
|
|
83
178
|
|
|
84
|
-
downFileFetch: function (fillAddress, fileName, method, headers, params) {
|
|
85
|
-
let options = {
|
|
86
|
-
method: method || 'GET',
|
|
87
|
-
}
|
|
88
|
-
if (headers) {
|
|
89
|
-
options['headers'] = headers;
|
|
90
|
-
}
|
|
91
|
-
if ((method === 'post' || method === 'POST') && params) {
|
|
92
|
-
options['body'] = JSON.stringify(params)
|
|
93
|
-
}
|
|
94
|
-
fetch(fillAddress, options).then(res => res.blob()).then((blob) => {
|
|
95
|
-
downFileFn(blob, fileName);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
*/
|
|
99
179
|
|
|
100
180
|
}
|
|
101
181
|
export default ajaxBox;
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 使用下载示例
|
|
186
|
+
const exportFile = () => {
|
|
187
|
+
let rowData = InventoryTableRef.value!.getSelectionRows()
|
|
188
|
+
|
|
189
|
+
const url = storageModule + 'storage_standing_book_batch_export_get/'
|
|
190
|
+
const headers = {
|
|
191
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
192
|
+
}
|
|
193
|
+
const params = {
|
|
194
|
+
ids: JSON.stringify(rowData.map((v: { id: any }) => v.id)),
|
|
195
|
+
state: 1,
|
|
196
|
+
org_id: UserData.orgId,
|
|
197
|
+
storage_type: 'CAILIAO',
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
CiPlus.Fn.ajaxBox.downFileFetch(
|
|
201
|
+
url,
|
|
202
|
+
'材料库_库存台账数据.xlsx',
|
|
203
|
+
'GET',
|
|
204
|
+
headers,
|
|
205
|
+
params,
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
*/
|
package/src/utils/cardPrint.ts
CHANGED
|
@@ -171,7 +171,7 @@ export const cardPrint = (
|
|
|
171
171
|
r5c4: item.card_code, // 标识卡号
|
|
172
172
|
r6c2: item.center_data[0]?.tail_reason, // 尾料原因
|
|
173
173
|
r7c2: item.process_name, // 本工序
|
|
174
|
-
r7c4: item.
|
|
174
|
+
r7c4: item.next_process_name, // 下工序
|
|
175
175
|
r8c2: item.current_inventory, // 本箱数量
|
|
176
176
|
r8c4: item.opt_user_name, // 操作工/自检员
|
|
177
177
|
r9c2: item.center_data[0]?.inspector, // 检验员
|
|
@@ -632,7 +632,7 @@ export const cardPrint = (
|
|
|
632
632
|
r50c3: '本工序',
|
|
633
633
|
r50c4: item.process_name,
|
|
634
634
|
r51c1: '下工序',
|
|
635
|
-
r51c2: item.
|
|
635
|
+
r51c2: item.next_process_name,
|
|
636
636
|
r51c3: '本箱数量',
|
|
637
637
|
r51c4: item.current_inventory,
|
|
638
638
|
r52c1: '操作员',
|