ls-pro-common 3.1.57 → 3.1.59
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/dist/common.css +3887 -2605
- package/dist/common.js +1 -1
- package/dist/common.min.css +3887 -2605
- package/dist/common.min.js +1 -1
- package/es/components/ImageSelector.js +3 -2
- package/es/components/InputTable.js +12 -14
- package/es/http/ajax.d.ts +73 -0
- package/es/http/ajax.js +611 -0
- package/es/http/bizAjax.d.ts +34 -0
- package/es/http/bizAjax.js +120 -0
- package/es/http/index.d.ts +5 -125
- package/es/http/index.js +5 -974
- package/es/http/mdmRequest.js +1 -1
- package/es/http/upload.d.ts +24 -0
- package/es/http/upload.js +252 -0
- package/es/http/uploadByChunk.d.ts +37 -0
- package/es/http/uploadByChunk.js +385 -0
- package/es/utils/pasteUpload.d.ts +13 -13
- package/es/utils/pasteUpload.js +31 -29
- package/lib/components/ImageSelector.js +3 -2
- package/lib/components/InputTable.js +12 -14
- package/lib/http/ajax.d.ts +73 -0
- package/lib/http/ajax.js +611 -0
- package/lib/http/bizAjax.d.ts +34 -0
- package/lib/http/bizAjax.js +120 -0
- package/lib/http/index.d.ts +5 -125
- package/lib/http/index.js +5 -974
- package/lib/http/mdmRequest.js +1 -1
- package/lib/http/upload.d.ts +24 -0
- package/lib/http/upload.js +252 -0
- package/lib/http/uploadByChunk.d.ts +37 -0
- package/lib/http/uploadByChunk.js +385 -0
- package/lib/utils/pasteUpload.d.ts +13 -13
- package/lib/utils/pasteUpload.js +31 -29
- package/package.json +1 -1
package/lib/http/mdmRequest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
import { httpBatchGet } from '
|
|
3
|
+
import { httpBatchGet } from './ajax';
|
|
4
4
|
import { getCache, setCache, clearCache } from '../utils';
|
|
5
5
|
import { getMdmCache, setMdmCache, deleteMdmCache, clearMdmCache as clearMdmCacheInMemory } from './mdmCache';
|
|
6
6
|
/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** 上传文件进度回调 */
|
|
2
|
+
export interface UploadProgressCallback {
|
|
3
|
+
(progress: number): void;
|
|
4
|
+
}
|
|
5
|
+
/** 上传文件返回值 */
|
|
6
|
+
export interface UploadResult {
|
|
7
|
+
promise: Promise<any>;
|
|
8
|
+
cancel: () => void;
|
|
9
|
+
xhr?: XMLHttpRequest;
|
|
10
|
+
uploadId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 上传文件,因fetch不支持进度回调,使用XMLHttpRequest实现上传文件
|
|
14
|
+
*
|
|
15
|
+
* @param url 上传接口地址
|
|
16
|
+
* @param file 要上传的文件
|
|
17
|
+
* @param params 附加其它参数 {key:value}
|
|
18
|
+
* @param labelName 对应后端接口的文件字段名,默认为 'file'
|
|
19
|
+
* @param needGateWay 是否需要网关,默认为 true,如果url里已包含网关,则不需要网关
|
|
20
|
+
* @param onProgress 进度回调函数,参数为 0-100 的进度百分比
|
|
21
|
+
* @param useDownloadDomain 是否使用下载域名来上传,默认为 false
|
|
22
|
+
* @returns 返回包含 promise 和 cancel 方法的对象
|
|
23
|
+
*/
|
|
24
|
+
export declare const httpUpload: (url: string, file: File, params?: Record<string, any>, labelName?: string, needGateWay?: boolean, onProgress?: UploadProgressCallback | undefined, useDownloadDomain?: boolean) => UploadResult;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { getCache, getUrlQuery, setUrlQuery, getCookie, getCacheSessionFirst, getResourceProps, showError, httpError, toGatewayUrl, reLogin, getBrowserId, setCache, isDingtalk, urlDownloadDomain } from '../utils';
|
|
2
|
+
import { ajaxHeader, httpStatus } from './ajax';
|
|
3
|
+
/**
|
|
4
|
+
* 上传文件,因fetch不支持进度回调,使用XMLHttpRequest实现上传文件
|
|
5
|
+
*
|
|
6
|
+
* @param url 上传接口地址
|
|
7
|
+
* @param file 要上传的文件
|
|
8
|
+
* @param params 附加其它参数 {key:value}
|
|
9
|
+
* @param labelName 对应后端接口的文件字段名,默认为 'file'
|
|
10
|
+
* @param needGateWay 是否需要网关,默认为 true,如果url里已包含网关,则不需要网关
|
|
11
|
+
* @param onProgress 进度回调函数,参数为 0-100 的进度百分比
|
|
12
|
+
* @param useDownloadDomain 是否使用下载域名来上传,默认为 false
|
|
13
|
+
* @returns 返回包含 promise 和 cancel 方法的对象
|
|
14
|
+
*/
|
|
15
|
+
export var httpUpload = function httpUpload(url, file) {
|
|
16
|
+
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
17
|
+
var labelName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'file';
|
|
18
|
+
var needGateWay = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
19
|
+
var onProgress = arguments.length > 5 ? arguments[5] : undefined;
|
|
20
|
+
var useDownloadDomain = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
|
|
21
|
+
var formData = new FormData();
|
|
22
|
+
// 处理附加参数,转换为FormData格式
|
|
23
|
+
Object.keys(params).forEach(function (key) {
|
|
24
|
+
var value = params[key];
|
|
25
|
+
if (value !== undefined && value !== null) {
|
|
26
|
+
formData.append(key, typeof value === 'string' ? value : JSON.stringify(value));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
// 添加文件
|
|
30
|
+
formData.append(labelName, file);
|
|
31
|
+
// 如果需要网关,转换 URL
|
|
32
|
+
var finalUrl = needGateWay ? toGatewayUrl(url) : url;
|
|
33
|
+
// 创建 XMLHttpRequest 以实现进度追踪和取消功能
|
|
34
|
+
var xhr = new XMLHttpRequest();
|
|
35
|
+
var isCancelled = false;
|
|
36
|
+
var promise = new Promise(function (resolve, reject) {
|
|
37
|
+
var _window$crypto$random, _window$crypto;
|
|
38
|
+
// 处理 URL(模拟拦截器的逻辑)
|
|
39
|
+
var requestUrl = finalUrl;
|
|
40
|
+
if (useDownloadDomain) {
|
|
41
|
+
requestUrl = urlDownloadDomain(requestUrl);
|
|
42
|
+
}
|
|
43
|
+
// 移除 noToken 参数
|
|
44
|
+
requestUrl = requestUrl.replace('&noToken=1', '').replace('noToken=1', '');
|
|
45
|
+
// 处理 resCode
|
|
46
|
+
var resCode = getUrlQuery('resCode', requestUrl) || window.__currentResCode__ || getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId');
|
|
47
|
+
// 添加时间戳和随机数参数
|
|
48
|
+
var param = {
|
|
49
|
+
_t1: Date.now(),
|
|
50
|
+
__r: ((_window$crypto$random = (_window$crypto = window.crypto)['randomUUID']) === null || _window$crypto$random === void 0 ? void 0 : _window$crypto$random.call(_window$crypto)) || Math.random()
|
|
51
|
+
};
|
|
52
|
+
// 当没有明文参数resCode的时候,添加resCode参数为资源Id
|
|
53
|
+
if (resCode && !getUrlQuery('resCode', requestUrl)) {
|
|
54
|
+
param.resCode = resCode;
|
|
55
|
+
}
|
|
56
|
+
requestUrl = setUrlQuery(requestUrl, param);
|
|
57
|
+
// 设置请求头
|
|
58
|
+
xhr.open('POST', requestUrl, true);
|
|
59
|
+
xhr.timeout = 60000 * 10; // 10分钟超时
|
|
60
|
+
// 设置请求头(模拟拦截器的逻辑)
|
|
61
|
+
var headers = {};
|
|
62
|
+
if (ajaxHeader.browserId) {
|
|
63
|
+
headers.browserId = ajaxHeader.browserId;
|
|
64
|
+
} else if (getCache('browserId')) {
|
|
65
|
+
ajaxHeader.browserId = getCache('browserId');
|
|
66
|
+
headers.browserId = ajaxHeader.browserId;
|
|
67
|
+
} else {
|
|
68
|
+
// 异步获取 browserId(不影响当前请求)
|
|
69
|
+
getBrowserId().then(function (id) {
|
|
70
|
+
ajaxHeader.browserId = id;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
var shopNo = getCacheSessionFirst('shopNo');
|
|
74
|
+
if (shopNo) {
|
|
75
|
+
headers.shopNo = shopNo;
|
|
76
|
+
}
|
|
77
|
+
var shopCode = getCacheSessionFirst('shopCode');
|
|
78
|
+
if (shopCode) {
|
|
79
|
+
headers.shopCode = shopCode;
|
|
80
|
+
}
|
|
81
|
+
var storeNo = getCacheSessionFirst('storeNo');
|
|
82
|
+
if (storeNo) {
|
|
83
|
+
headers.storeNo = storeNo;
|
|
84
|
+
}
|
|
85
|
+
var tag = getCookie('x-asm-prefer-tag');
|
|
86
|
+
if (tag) {
|
|
87
|
+
headers['x-asm-prefer-tag'] = tag;
|
|
88
|
+
}
|
|
89
|
+
if (isDingtalk) {
|
|
90
|
+
headers.terminal = 'APP';
|
|
91
|
+
} else {
|
|
92
|
+
headers.terminal = 'PC';
|
|
93
|
+
}
|
|
94
|
+
var expireWarnFlag = getCache('expireWarnFlag', true);
|
|
95
|
+
headers.expireWarnFlag = expireWarnFlag === '1' ? '1' : '0';
|
|
96
|
+
var token = getCookie('token');
|
|
97
|
+
if (token && requestUrl.indexOf('noToken=1') === -1) {
|
|
98
|
+
headers.token = token;
|
|
99
|
+
}
|
|
100
|
+
Object.keys(headers).forEach(function (key) {
|
|
101
|
+
xhr.setRequestHeader(key, headers[key]);
|
|
102
|
+
});
|
|
103
|
+
// 监听上传进度
|
|
104
|
+
if (onProgress && xhr.upload) {
|
|
105
|
+
xhr.upload.addEventListener('progress', function (e) {
|
|
106
|
+
if (e.lengthComputable && !isCancelled) {
|
|
107
|
+
var percent = Math.round(e.loaded / e.total * 100);
|
|
108
|
+
onProgress(percent);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// 监听请求完成
|
|
113
|
+
xhr.onload = function () {
|
|
114
|
+
var _navigator, _navigator$userAgent;
|
|
115
|
+
if (isCancelled) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
var noMsg = getUrlQuery('noMsg', requestUrl);
|
|
119
|
+
var userAgent = (_navigator = navigator) === null || _navigator === void 0 ? void 0 : (_navigator$userAgent = _navigator.userAgent) === null || _navigator$userAgent === void 0 ? void 0 : _navigator$userAgent.toLowerCase();
|
|
120
|
+
var isMobile = /mobile/i.test(userAgent);
|
|
121
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
122
|
+
try {
|
|
123
|
+
var _response$flag, _response$flag2, _response$flag3;
|
|
124
|
+
var response = JSON.parse(xhr.responseText);
|
|
125
|
+
// 处理业务异常(模拟响应拦截器的逻辑)
|
|
126
|
+
var retCode = (response === null || response === void 0 ? void 0 : (_response$flag = response.flag) === null || _response$flag === void 0 ? void 0 : _response$flag.retCode) || '0';
|
|
127
|
+
var retMsg = (response === null || response === void 0 ? void 0 : (_response$flag2 = response.flag) === null || _response$flag2 === void 0 ? void 0 : _response$flag2.retMsg) || '请求的服务出错';
|
|
128
|
+
var status = (getUrlQuery('apiStatus', requestUrl) || '0').split(',');
|
|
129
|
+
var faultCode = response === null || response === void 0 ? void 0 : (_response$flag3 = response.flag) === null || _response$flag3 === void 0 ? void 0 : _response$flag3.faultCode;
|
|
130
|
+
var is99110 = false;
|
|
131
|
+
// wms 提示,是否排班标识
|
|
132
|
+
if (retCode === '99110') {
|
|
133
|
+
is99110 = true;
|
|
134
|
+
if (getCache('expireWarnFlag', true) === '1' || ajaxHeader.ifExpireWarn) {
|
|
135
|
+
resolve(response);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
ajaxHeader.ifExpireWarn = true;
|
|
139
|
+
setCache('expireWarnFlag', '1', true);
|
|
140
|
+
}
|
|
141
|
+
if (retCode && !status.includes(retCode) && noMsg !== '1') {
|
|
142
|
+
if ((retCode === 'timeout' || retCode === '4011' || retCode === '4013' || retCode === '9009' && retMsg === '令牌不能为空') && !isMobile) {
|
|
143
|
+
if (!getCookie('token')) {
|
|
144
|
+
(window.top || window).location.href = location.pathname === '/' || location.pathname.startsWith('/login') ? '/login' : '/login?redirect=' + encodeURIComponent(location.href);
|
|
145
|
+
} else {
|
|
146
|
+
reLogin();
|
|
147
|
+
}
|
|
148
|
+
reject(new Error(retMsg));
|
|
149
|
+
return;
|
|
150
|
+
} else if (faultCode) {
|
|
151
|
+
var text;
|
|
152
|
+
if (retCode === '4012') {
|
|
153
|
+
text = '用户已禁用,无权限进行操作';
|
|
154
|
+
}
|
|
155
|
+
httpError(text || retMsg, retCode, faultCode, {
|
|
156
|
+
title: is99110 ? '账号到期提醒' : '请求接口出错'
|
|
157
|
+
});
|
|
158
|
+
reject(new Error(retMsg));
|
|
159
|
+
return;
|
|
160
|
+
} else {
|
|
161
|
+
showError(retMsg);
|
|
162
|
+
reject(new Error(retMsg));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
resolve(response);
|
|
167
|
+
} catch (e) {
|
|
168
|
+
resolve(xhr.responseText);
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
// HTTP 状态码错误
|
|
172
|
+
try {
|
|
173
|
+
var _response$flag4, _response$flag5, _response$flag6;
|
|
174
|
+
var _response = JSON.parse(xhr.responseText);
|
|
175
|
+
var _retCode = (_response$flag4 = _response.flag) === null || _response$flag4 === void 0 ? void 0 : _response$flag4.retCode;
|
|
176
|
+
var _retMsg = (_response$flag5 = _response.flag) === null || _response$flag5 === void 0 ? void 0 : _response$flag5.retMsg;
|
|
177
|
+
var _faultCode = (_response$flag6 = _response.flag) === null || _response$flag6 === void 0 ? void 0 : _response$flag6.faultCode;
|
|
178
|
+
var _is = false;
|
|
179
|
+
// wms 提示,是否排班标识
|
|
180
|
+
if (_retCode === '99110') {
|
|
181
|
+
_is = true;
|
|
182
|
+
if (getCache('expireWarnFlag', true) === '1' || ajaxHeader.ifExpireWarn) {
|
|
183
|
+
reject(new Error(_retMsg || httpStatus[xhr.status] || xhr.statusText));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
ajaxHeader.ifExpireWarn = true;
|
|
187
|
+
setCache('expireWarnFlag', '1', true);
|
|
188
|
+
}
|
|
189
|
+
if (noMsg !== '1') {
|
|
190
|
+
if (_faultCode) {
|
|
191
|
+
var _text;
|
|
192
|
+
if (_retCode === '4012') {
|
|
193
|
+
_text = '用户已禁用,无权限进行操作';
|
|
194
|
+
}
|
|
195
|
+
httpError(_text || _retMsg, _retCode, _faultCode, {
|
|
196
|
+
title: _is ? '账号到期提醒' : '请求接口出错'
|
|
197
|
+
});
|
|
198
|
+
} else {
|
|
199
|
+
var _text2 = httpStatus[xhr.status];
|
|
200
|
+
if (xhr.status === 503 && xhr.statusText === 'no healthy upstream') {
|
|
201
|
+
_text2 = '请求的服务未启动';
|
|
202
|
+
} else if (xhr.status === 503 && xhr.statusText === 'reached concurrency limit') {
|
|
203
|
+
_text2 = '请求的服务被限流';
|
|
204
|
+
}
|
|
205
|
+
showError(_text2 || _retMsg || xhr.statusText);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
reject(new Error(_retMsg || httpStatus[xhr.status] || xhr.statusText));
|
|
209
|
+
} catch (e) {
|
|
210
|
+
var _text3 = httpStatus[xhr.status];
|
|
211
|
+
if (xhr.status === 503 && xhr.statusText === 'no healthy upstream') {
|
|
212
|
+
_text3 = '请求的服务未启动';
|
|
213
|
+
} else if (xhr.status === 503 && xhr.statusText === 'reached concurrency limit') {
|
|
214
|
+
_text3 = '请求的服务被限流';
|
|
215
|
+
}
|
|
216
|
+
var httpStatusText = _text3 || e.message || xhr.statusText;
|
|
217
|
+
if (noMsg !== '1') {
|
|
218
|
+
showError(httpStatusText);
|
|
219
|
+
}
|
|
220
|
+
reject(new Error(httpStatusText));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
// 监听错误
|
|
225
|
+
xhr.onerror = function () {
|
|
226
|
+
if (!isCancelled) {
|
|
227
|
+
reject(new Error('网络错误'));
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
// 监听超时
|
|
231
|
+
xhr.ontimeout = function () {
|
|
232
|
+
if (!isCancelled) {
|
|
233
|
+
showError('请求超时');
|
|
234
|
+
reject(new Error('请求超时'));
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
// 发送请求
|
|
238
|
+
xhr.send(formData);
|
|
239
|
+
});
|
|
240
|
+
// 取消方法
|
|
241
|
+
var cancel = function cancel() {
|
|
242
|
+
if (!isCancelled) {
|
|
243
|
+
isCancelled = true;
|
|
244
|
+
xhr.abort();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
return {
|
|
248
|
+
promise: promise,
|
|
249
|
+
cancel: cancel,
|
|
250
|
+
xhr: xhr
|
|
251
|
+
};
|
|
252
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type UploadProgressCallback, type UploadResult } from './upload';
|
|
2
|
+
/** 分片上传配置 */
|
|
3
|
+
export interface HttpUploadByChunkConfig {
|
|
4
|
+
/** 文件对象 */
|
|
5
|
+
file: File;
|
|
6
|
+
/** 桶名(如果不传,默认放在 RETAIL 中) */
|
|
7
|
+
code?: string;
|
|
8
|
+
/** 分类(如果不传,默认放在 mdm 中) */
|
|
9
|
+
catalogName?: string;
|
|
10
|
+
/** 创建上传事务的接口地址(如果不传,默认为`/petrel/petrel-file-center-api/lesoon/oss/file/chunk/upload/transaction/${code}?catalogName=${catalogName}`) */
|
|
11
|
+
createTransactionUrl?: string;
|
|
12
|
+
/** 上传分片的接口地址(如果不传,默认为`/petrel/petrel-file-center-api/lesoon/oss/file/chunk/upload/${code}?catalogName=${catalogName}`) */
|
|
13
|
+
uploadChunkUrl?: string;
|
|
14
|
+
/** 提交合并的接口地址(如果不传,默认为`/petrel/petrel-file-center-api/lesoon/oss/file/chunk/upload/commit/${code}`) */
|
|
15
|
+
commitUrl?: string;
|
|
16
|
+
/** 取消上传的接口地址(如果不传,默认为`/petrel/petrel-file-center-api/lesoon/oss/file/chunk/upload/cancel/${code}`) */
|
|
17
|
+
cancelUrl?: string;
|
|
18
|
+
/** 每个分片的大小(MB),默认 2MB */
|
|
19
|
+
chunkSize?: number;
|
|
20
|
+
/** 是否需要网关,默认为 true */
|
|
21
|
+
needGateWay?: boolean;
|
|
22
|
+
/** 是否使用下载域名,默认为 true */
|
|
23
|
+
useDownloadDomain?: boolean;
|
|
24
|
+
/** 进度回调函数,参数为 0-100 的进度百分比 */
|
|
25
|
+
onProgress?: UploadProgressCallback;
|
|
26
|
+
/** 分片上传失败重试次数,默认 3 次 */
|
|
27
|
+
maxRetries?: number;
|
|
28
|
+
/** 每批并发上传的分片数量,默认 1 个 */
|
|
29
|
+
batchSize?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 分片上传文件
|
|
33
|
+
*
|
|
34
|
+
* @param config 分片上传配置
|
|
35
|
+
* @returns 返回包含 promise、cancel 方法和 uploadId 的对象
|
|
36
|
+
*/
|
|
37
|
+
export declare const httpUploadByChunk: (config: HttpUploadByChunkConfig) => UploadResult;
|