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.
@@ -0,0 +1,385 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { httpUpload } from './upload';
4
+ import { httpPost } from './ajax';
5
+ import { urlDownloadDomain, setUrlQuery } from '../utils';
6
+ /** 分片上传接口地址 */
7
+ var BASE_URL = '/petrel/petrel-file-center-api/lesoon/oss/file/chunk/upload';
8
+ /**
9
+ * 分片上传文件
10
+ *
11
+ * @param config 分片上传配置
12
+ * @returns 返回包含 promise、cancel 方法和 uploadId 的对象
13
+ */
14
+ export var httpUploadByChunk = function httpUploadByChunk(config) {
15
+ var file = config.file,
16
+ createTransactionUrl = config.createTransactionUrl,
17
+ uploadChunkUrl = config.uploadChunkUrl,
18
+ commitUrl = config.commitUrl,
19
+ cancelUrl = config.cancelUrl,
20
+ _config$chunkSize = config.chunkSize,
21
+ chunkSizeMB = _config$chunkSize === void 0 ? 2 : _config$chunkSize,
22
+ _config$needGateWay = config.needGateWay,
23
+ needGateWay = _config$needGateWay === void 0 ? true : _config$needGateWay,
24
+ _config$useDownloadDo = config.useDownloadDomain,
25
+ useDownloadDomain = _config$useDownloadDo === void 0 ? true : _config$useDownloadDo,
26
+ onProgress = config.onProgress,
27
+ _config$maxRetries = config.maxRetries,
28
+ maxRetries = _config$maxRetries === void 0 ? 3 : _config$maxRetries,
29
+ _config$code = config.code,
30
+ code = _config$code === void 0 ? 'RETAIL' : _config$code,
31
+ _config$catalogName = config.catalogName,
32
+ catalogName = _config$catalogName === void 0 ? 'mdm' : _config$catalogName,
33
+ _config$batchSize = config.batchSize,
34
+ batchSize = _config$batchSize === void 0 ? 1 : _config$batchSize;
35
+ var uploadId;
36
+ var isCancelled = false;
37
+ var cancelFunctions = [];
38
+ var chunkSize = chunkSizeMB * 1024 * 1024;
39
+ // 计算总分片数
40
+ var totalChunks = Math.ceil(file.size / chunkSize);
41
+ // 进度管理器:记录每个分片的上传进度(0-1)
42
+ var chunkProgressMap = new Map();
43
+ var lastReportedProgress = 0;
44
+ /** 更新并报告进度,确保进度只增不减 */
45
+ var updateProgress = function updateProgress() {
46
+ // 计算所有分片的累计进度
47
+ var totalProgress = 0;
48
+ chunkProgressMap.forEach(function (progress) {
49
+ totalProgress += progress;
50
+ });
51
+ // 计算总体进度百分比(0-100)
52
+ var currentProgress = Math.min(Math.round(totalProgress / totalChunks * 100), 100);
53
+ // 确保进度只增不减
54
+ var finalProgress = Math.max(currentProgress, lastReportedProgress);
55
+ // 只有当进度增加时才回调
56
+ if (finalProgress > lastReportedProgress) {
57
+ lastReportedProgress = finalProgress;
58
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(finalProgress);
59
+ }
60
+ };
61
+ /** 创建上传事务 */
62
+ var createTransaction = /*#__PURE__*/function () {
63
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
64
+ var _result$flag;
65
+ var params, api, finalUrl, result, _result$flag2;
66
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
67
+ while (1) switch (_context.prev = _context.next) {
68
+ case 0:
69
+ params = {
70
+ chunkNumbers: totalChunks,
71
+ fileName: encodeURIComponent(file.name),
72
+ contentType: encodeURIComponent(file.type),
73
+ fileSize: file.size
74
+ };
75
+ api = setUrlQuery(createTransactionUrl || "".concat(BASE_URL, "/transaction/").concat(code, "?catalogName=").concat(catalogName), params);
76
+ finalUrl = useDownloadDomain ? urlDownloadDomain(api) : api;
77
+ _context.next = 5;
78
+ return httpPost(finalUrl, {}, true, needGateWay);
79
+ case 5:
80
+ result = _context.sent;
81
+ if (!(((_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0' && result.data)) {
82
+ _context.next = 10;
83
+ break;
84
+ }
85
+ return _context.abrupt("return", result.data);
86
+ case 10:
87
+ throw new Error(((_result$flag2 = result.flag) === null || _result$flag2 === void 0 ? void 0 : _result$flag2.retMsg) || '创建上传事务失败');
88
+ case 11:
89
+ case "end":
90
+ return _context.stop();
91
+ }
92
+ }, _callee);
93
+ }));
94
+ return function createTransaction() {
95
+ return _ref.apply(this, arguments);
96
+ };
97
+ }();
98
+ /**
99
+ * 上传单个分片
100
+ *
101
+ * @param chunk Blob 分片
102
+ * @param chunkIndex 分片索引(从 1 开始)
103
+ * @param retryCount 当前重试次数
104
+ */
105
+ var uploadChunk = /*#__PURE__*/function () {
106
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chunk, chunkIndex) {
107
+ var retryCount,
108
+ params,
109
+ api,
110
+ _result$flag3,
111
+ uploadResult,
112
+ result,
113
+ _result$flag4,
114
+ _args2 = arguments;
115
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
116
+ while (1) switch (_context2.prev = _context2.next) {
117
+ case 0:
118
+ retryCount = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : 0;
119
+ if (!isCancelled) {
120
+ _context2.next = 3;
121
+ break;
122
+ }
123
+ throw new Error('上传已取消');
124
+ case 3:
125
+ if (uploadId) {
126
+ _context2.next = 5;
127
+ break;
128
+ }
129
+ throw new Error('上传事务 ID 不存在');
130
+ case 5:
131
+ params = {
132
+ uploadId: uploadId,
133
+ chunkSequence: chunkIndex,
134
+ size: chunk.size
135
+ };
136
+ api = setUrlQuery(uploadChunkUrl || "".concat(BASE_URL, "/").concat(code, "?catalogName=").concat(catalogName), params);
137
+ _context2.prev = 7;
138
+ // 初始化分片进度为 0
139
+ chunkProgressMap.set(chunkIndex, 0);
140
+ // 使用 httpUpload 上传分片
141
+ uploadResult = httpUpload(api, new File([chunk], file.name, {
142
+ type: file.type
143
+ }), {}, 'file', needGateWay, function (progress) {
144
+ // 更新当前分片的上传进度(0-1)
145
+ chunkProgressMap.set(chunkIndex, progress / 100);
146
+ // 更新总体进度
147
+ updateProgress();
148
+ }, useDownloadDomain); // 保存取消函数
149
+ cancelFunctions.push(uploadResult.cancel);
150
+ // 等待上传完成
151
+ _context2.next = 13;
152
+ return uploadResult.promise;
153
+ case 13:
154
+ result = _context2.sent;
155
+ if (!(((_result$flag3 = result.flag) === null || _result$flag3 === void 0 ? void 0 : _result$flag3.retCode) === '0')) {
156
+ _context2.next = 19;
157
+ break;
158
+ }
159
+ // 分片上传成功,标记为完成(进度为 1)
160
+ chunkProgressMap.set(chunkIndex, 1);
161
+ // 更新总体进度
162
+ updateProgress();
163
+ _context2.next = 21;
164
+ break;
165
+ case 19:
166
+ // 上传失败,重置进度
167
+ chunkProgressMap.set(chunkIndex, 0);
168
+ throw new Error(((_result$flag4 = result.flag) === null || _result$flag4 === void 0 ? void 0 : _result$flag4.retMsg) || '分片上传失败');
169
+ case 21:
170
+ _context2.next = 30;
171
+ break;
172
+ case 23:
173
+ _context2.prev = 23;
174
+ _context2.t0 = _context2["catch"](7);
175
+ if (!(retryCount < maxRetries && !isCancelled)) {
176
+ _context2.next = 28;
177
+ break;
178
+ }
179
+ // 重置进度后重试
180
+ chunkProgressMap.set(chunkIndex, 0);
181
+ return _context2.abrupt("return", uploadChunk(chunk, chunkIndex, retryCount + 1));
182
+ case 28:
183
+ // 重试失败,重置进度
184
+ chunkProgressMap.set(chunkIndex, 0);
185
+ throw _context2.t0;
186
+ case 30:
187
+ case "end":
188
+ return _context2.stop();
189
+ }
190
+ }, _callee2, null, [[7, 23]]);
191
+ }));
192
+ return function uploadChunk(_x, _x2) {
193
+ return _ref2.apply(this, arguments);
194
+ };
195
+ }();
196
+ /** 提交合并请求 */
197
+ var commitUpload = /*#__PURE__*/function () {
198
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
199
+ var _result$flag5;
200
+ var params, api, finalUrl, result, _result$flag6;
201
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
202
+ while (1) switch (_context3.prev = _context3.next) {
203
+ case 0:
204
+ if (uploadId) {
205
+ _context3.next = 2;
206
+ break;
207
+ }
208
+ throw new Error('上传事务 ID 不存在');
209
+ case 2:
210
+ params = {
211
+ uploadId: uploadId
212
+ };
213
+ api = setUrlQuery(commitUrl || "".concat(BASE_URL, "/commit/normal/").concat(code), params);
214
+ finalUrl = useDownloadDomain ? urlDownloadDomain(api) : api;
215
+ _context3.next = 7;
216
+ return httpPost(finalUrl, {}, true, needGateWay);
217
+ case 7:
218
+ result = _context3.sent;
219
+ if (!(((_result$flag5 = result.flag) === null || _result$flag5 === void 0 ? void 0 : _result$flag5.retCode) === '0')) {
220
+ _context3.next = 12;
221
+ break;
222
+ }
223
+ return _context3.abrupt("return", result);
224
+ case 12:
225
+ throw new Error(((_result$flag6 = result.flag) === null || _result$flag6 === void 0 ? void 0 : _result$flag6.retMsg) || '合并文件失败');
226
+ case 13:
227
+ case "end":
228
+ return _context3.stop();
229
+ }
230
+ }, _callee3);
231
+ }));
232
+ return function commitUpload() {
233
+ return _ref3.apply(this, arguments);
234
+ };
235
+ }();
236
+ /** 取消上传 */
237
+ var cancel = /*#__PURE__*/function () {
238
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
239
+ var api, finalUrl;
240
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
241
+ while (1) switch (_context4.prev = _context4.next) {
242
+ case 0:
243
+ if (!isCancelled) {
244
+ _context4.next = 2;
245
+ break;
246
+ }
247
+ return _context4.abrupt("return");
248
+ case 2:
249
+ isCancelled = true;
250
+ // 取消所有正在上传的分片
251
+ cancelFunctions.forEach(function (cancelFn) {
252
+ try {
253
+ cancelFn();
254
+ } catch (e) {
255
+ // 忽略取消错误
256
+ }
257
+ });
258
+ cancelFunctions.length = 0;
259
+ // 如果已有上传事务 ID,发送取消请求
260
+ if (!uploadId) {
261
+ _context4.next = 15;
262
+ break;
263
+ }
264
+ _context4.prev = 6;
265
+ // 处理 URL 参数,支持 ? 和 & 开头
266
+ api = setUrlQuery(cancelUrl || "".concat(BASE_URL, "/cancel/").concat(code), {
267
+ uploadId: uploadId
268
+ });
269
+ finalUrl = useDownloadDomain ? urlDownloadDomain(api) : api;
270
+ _context4.next = 11;
271
+ return httpPost(finalUrl, {}, true, needGateWay);
272
+ case 11:
273
+ _context4.next = 15;
274
+ break;
275
+ case 13:
276
+ _context4.prev = 13;
277
+ _context4.t0 = _context4["catch"](6);
278
+ case 15:
279
+ case "end":
280
+ return _context4.stop();
281
+ }
282
+ }, _callee4, null, [[6, 13]]);
283
+ }));
284
+ return function cancel() {
285
+ return _ref4.apply(this, arguments);
286
+ };
287
+ }();
288
+ /** 执行分片上传流程 */
289
+ var promise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
290
+ var chunks, chunkIndex, start, end, chunk, i, batch, result;
291
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
292
+ while (1) switch (_context5.prev = _context5.next) {
293
+ case 0:
294
+ _context5.prev = 0;
295
+ _context5.next = 3;
296
+ return createTransaction();
297
+ case 3:
298
+ uploadId = _context5.sent;
299
+ if (!isCancelled) {
300
+ _context5.next = 6;
301
+ break;
302
+ }
303
+ throw new Error('上传已取消');
304
+ case 6:
305
+ // 第二步:计算所有分片
306
+ chunks = [];
307
+ chunkIndex = 1;
308
+ for (start = 0; start < file.size; start += chunkSize) {
309
+ end = Math.min(start + chunkSize, file.size);
310
+ chunk = file.slice(start, end);
311
+ chunks.push({
312
+ blob: chunk,
313
+ index: chunkIndex
314
+ });
315
+ chunkIndex++;
316
+ }
317
+ // 初始化所有分片的进度为 0
318
+ chunks.forEach(function (chunkInfo) {
319
+ chunkProgressMap.set(chunkInfo.index, 0);
320
+ });
321
+ // 第三步:分批并发上传分片
322
+ i = 0;
323
+ case 11:
324
+ if (!(i < chunks.length)) {
325
+ _context5.next = 20;
326
+ break;
327
+ }
328
+ if (!isCancelled) {
329
+ _context5.next = 14;
330
+ break;
331
+ }
332
+ throw new Error('上传已取消');
333
+ case 14:
334
+ // 获取当前批次的分片
335
+ batch = chunks.slice(i, i + batchSize); // 并发上传当前批次的所有分片
336
+ _context5.next = 17;
337
+ return Promise.all(batch.map(function (chunkInfo) {
338
+ return uploadChunk(chunkInfo.blob, chunkInfo.index);
339
+ }));
340
+ case 17:
341
+ i += batchSize;
342
+ _context5.next = 11;
343
+ break;
344
+ case 20:
345
+ // 确保所有分片上传完成,进度为 100%
346
+ if (chunks.length > 0) {
347
+ chunks.forEach(function (chunkInfo) {
348
+ chunkProgressMap.set(chunkInfo.index, 1);
349
+ });
350
+ updateProgress();
351
+ }
352
+ if (!isCancelled) {
353
+ _context5.next = 23;
354
+ break;
355
+ }
356
+ throw new Error('上传已取消');
357
+ case 23:
358
+ _context5.next = 25;
359
+ return commitUpload();
360
+ case 25:
361
+ result = _context5.sent;
362
+ // 上传完成,确保进度为 100%
363
+ lastReportedProgress = 100;
364
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(100);
365
+ return _context5.abrupt("return", result);
366
+ case 31:
367
+ _context5.prev = 31;
368
+ _context5.t0 = _context5["catch"](0);
369
+ // 如果出错,确保进度回调被调用
370
+ if (!isCancelled) {
371
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(0);
372
+ }
373
+ throw _context5.t0;
374
+ case 35:
375
+ case "end":
376
+ return _context5.stop();
377
+ }
378
+ }, _callee5, null, [[0, 31]]);
379
+ }))();
380
+ return {
381
+ promise: promise,
382
+ cancel: cancel,
383
+ uploadId: uploadId
384
+ };
385
+ };
@@ -4,19 +4,19 @@ import { UploadProgressCallback } from '../http';
4
4
  *
5
5
  * @example
6
6
  * ```tsx // 在 TextArea 组件中使用
7
- * const handlePaste = async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
8
- * event.preventDefault(); // 阻止默认粘贴行为
9
- * try {
10
- * const result = await pasteUpload(event, { userId: '123' }, 'imgs');
11
- * // 处理上传结果
12
- * console.log('图片URL:', result.rows?.[0]?.shareUrl);
13
- * } catch (error) {
14
- * message.error('图片上传失败');
15
- * }
16
- * };
7
+ * const handlePaste = async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
8
+ * event.preventDefault(); // 阻止默认粘贴行为
9
+ * try {
10
+ * const result = await pasteUpload(event, { userId: '123' }, 'imgs');
11
+ * // 处理上传结果
12
+ * console.log('图片URL:', result.rows?.[0]?.shareUrl);
13
+ * } catch (error) {
14
+ * message.error('图片上传失败');
15
+ * }
16
+ * };
17
17
  *
18
- * <Input.TextArea onPaste={handlePaste} />
19
- * ```;
18
+ * <Input.TextArea onPaste={handlePaste} />
19
+ * ```;
20
20
  *
21
21
  * @param event 粘贴事件对象
22
22
  * @param params 附加其它参数 {key:value}
@@ -24,4 +24,4 @@ import { UploadProgressCallback } from '../http';
24
24
  * @param onProgress 上传进度回调函数,参数为 0-100 的进度百分比
25
25
  * @returns 返回上传结果的 Promise,resolve 时返回上传成功的数据,reject 时返回错误信息
26
26
  */
27
- export declare const pasteUpload: (event: React.ClipboardEvent<any> | ClipboardEvent, params?: Record<string, any>, catalogName?: string, onProgress?: UploadProgressCallback | undefined) => Promise<any>;
27
+ export declare const pasteUpload: (event: React.ClipboardEvent<any> | ClipboardEvent, params?: Record<string, any>, catalogName?: string, onProgress?: UploadProgressCallback | undefined, ifDownloadDomain?: boolean | undefined) => Promise<any>;
@@ -6,19 +6,19 @@ import { httpUpload } from '../http';
6
6
  *
7
7
  * @example
8
8
  * ```tsx // 在 TextArea 组件中使用
9
- * const handlePaste = async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
10
- * event.preventDefault(); // 阻止默认粘贴行为
11
- * try {
12
- * const result = await pasteUpload(event, { userId: '123' }, 'imgs');
13
- * // 处理上传结果
14
- * console.log('图片URL:', result.rows?.[0]?.shareUrl);
15
- * } catch (error) {
16
- * message.error('图片上传失败');
17
- * }
18
- * };
9
+ * const handlePaste = async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
10
+ * event.preventDefault(); // 阻止默认粘贴行为
11
+ * try {
12
+ * const result = await pasteUpload(event, { userId: '123' }, 'imgs');
13
+ * // 处理上传结果
14
+ * console.log('图片URL:', result.rows?.[0]?.shareUrl);
15
+ * } catch (error) {
16
+ * message.error('图片上传失败');
17
+ * }
18
+ * };
19
19
  *
20
- * <Input.TextArea onPaste={handlePaste} />
21
- * ```;
20
+ * <Input.TextArea onPaste={handlePaste} />
21
+ * ```;
22
22
  *
23
23
  * @param event 粘贴事件对象
24
24
  * @param params 附加其它参数 {key:value}
@@ -31,6 +31,7 @@ export var pasteUpload = /*#__PURE__*/function () {
31
31
  var params,
32
32
  catalogName,
33
33
  onProgress,
34
+ ifDownloadDomain,
34
35
  clipboardData,
35
36
  file,
36
37
  items,
@@ -47,41 +48,42 @@ export var pasteUpload = /*#__PURE__*/function () {
47
48
  params = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
48
49
  catalogName = _args.length > 2 && _args[2] !== undefined ? _args[2] : 'imgs';
49
50
  onProgress = _args.length > 3 ? _args[3] : undefined;
51
+ ifDownloadDomain = _args.length > 4 ? _args[4] : undefined;
50
52
  clipboardData = event.clipboardData;
51
53
  if (clipboardData) {
52
- _context.next = 6;
54
+ _context.next = 7;
53
55
  break;
54
56
  }
55
57
  return _context.abrupt("return");
56
- case 6:
58
+ case 7:
57
59
  file = null; // 优先从剪贴板 items 中获取文件
58
60
  items = clipboardData.items;
59
61
  if (!items) {
60
- _context.next = 19;
62
+ _context.next = 20;
61
63
  break;
62
64
  }
63
65
  i = 0;
64
- case 10:
66
+ case 11:
65
67
  if (!(i < items.length)) {
66
- _context.next = 19;
68
+ _context.next = 20;
67
69
  break;
68
70
  }
69
71
  item = items[i]; // 检查是否为图片类型
70
72
  if (!(item.kind === 'file' && item.type.startsWith('image/'))) {
71
- _context.next = 16;
73
+ _context.next = 17;
72
74
  break;
73
75
  }
74
76
  file = item.getAsFile();
75
77
  if (!file) {
76
- _context.next = 16;
78
+ _context.next = 17;
77
79
  break;
78
80
  }
79
- return _context.abrupt("break", 19);
80
- case 16:
81
+ return _context.abrupt("break", 20);
82
+ case 17:
81
83
  i++;
82
- _context.next = 10;
84
+ _context.next = 11;
83
85
  break;
84
- case 19:
86
+ case 20:
85
87
  // 如果 items 中没有找到,尝试从 files 属性获取
86
88
  if (!file && clipboardData.files && clipboardData.files.length > 0) {
87
89
  files = Array.from(clipboardData.files); // 查找第一个图片文件
@@ -90,22 +92,22 @@ export var pasteUpload = /*#__PURE__*/function () {
90
92
  }) || null;
91
93
  }
92
94
  if (file) {
93
- _context.next = 22;
95
+ _context.next = 23;
94
96
  break;
95
97
  }
96
98
  return _context.abrupt("return");
97
- case 22:
99
+ case 23:
98
100
  if (file.type.startsWith('image/')) {
99
- _context.next = 24;
101
+ _context.next = 25;
100
102
  break;
101
103
  }
102
104
  return _context.abrupt("return");
103
- case 24:
105
+ case 25:
104
106
  // 构建上传 URL
105
107
  uploadUrl = "/petrel/petrel-file-center-api/lesoon/oss/file/upload/RETAIL-PUBLIC?catalogName=".concat(catalogName); // 调用上传接口
106
- _httpUpload = httpUpload(uploadUrl, file, params, 'file', false, onProgress), promise = _httpUpload.promise;
108
+ _httpUpload = httpUpload(uploadUrl, file, params, 'file', false, onProgress, ifDownloadDomain), promise = _httpUpload.promise;
107
109
  return _context.abrupt("return", promise);
108
- case 27:
110
+ case 28:
109
111
  case "end":
110
112
  return _context.stop();
111
113
  }
@@ -23,7 +23,7 @@ import { useMemo, useState, useEffect, useContext, useRef } from 'react';
23
23
  import { ProFormText, ProFormContext } from 'ls-pro-form';
24
24
  import { PlusOutlined, UploadOutlined, SearchOutlined, CloseOutlined } from '@ant-design/icons';
25
25
  import { httpGet } from '../http';
26
- import { getCache, showError, showWarn, showSuccess } from '../utils';
26
+ import { getCache, showError, showWarn, showSuccess, urlDownloadDomain } from '../utils';
27
27
  var fileCenter = getCache('ossPath') || '/petrel/petrel-file-center-api/lesoon/oss/file/';
28
28
  function ImageSelector(prop) {
29
29
  var _rest$fieldProps3;
@@ -79,7 +79,8 @@ function ImageSelector(prop) {
79
79
  rest = _objectWithoutProperties(prop, _excluded);
80
80
  // 上传地址
81
81
  var uploadImgApi = useMemo(function () {
82
- return fileCenter + 'upload/' + code + '?catalogName=' + type;
82
+ var url = fileCenter + 'upload/' + code + '?catalogName=' + type;
83
+ return urlDownloadDomain(url);
83
84
  }, [code, type]);
84
85
  // 分页加载列表地址
85
86
  var pageImgApi = useMemo(function () {
@@ -182,7 +182,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
182
182
  */
183
183
  var loadData = /*#__PURE__*/function () {
184
184
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
185
- var current, pageSize, restParams, _selectRowRef$current, _rows, data, _tableRef$current2, _tableRef$current2$cl, beforeParam, result, rows, formValue, val, _selectRowRef$current2, arr, pageSelectedRows;
185
+ var current, pageSize, restParams, _selectRowRef$current, _rows, data, _tableRef$current3, _tableRef$current3$cl, beforeParam, result, rows, formValue, val, _selectRowRef$current2, arr, pageSelectedRows;
186
186
  return _regeneratorRuntime.wrap(function _callee$(_context) {
187
187
  while (1) switch (_context.prev = _context.next) {
188
188
  case 0:
@@ -199,8 +199,9 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
199
199
  })));
200
200
  setSelectedKeys(Array.from(new Set(selectedKeys)));
201
201
  requestIdleCallback(function () {
202
- var _tableRef$current, _tableRef$current$rel;
203
- (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : (_tableRef$current$rel = _tableRef$current.reload) === null || _tableRef$current$rel === void 0 ? void 0 : _tableRef$current$rel.call(_tableRef$current);
202
+ var _tableRef$current, _tableRef$current$onS, _tableRef$current2, _tableRef$current2$re;
203
+ (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : (_tableRef$current$onS = _tableRef$current.onSelectedRows) === null || _tableRef$current$onS === void 0 ? void 0 : _tableRef$current$onS.call(_tableRef$current, _rows);
204
+ (_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : (_tableRef$current2$re = _tableRef$current2.reload) === null || _tableRef$current2$re === void 0 ? void 0 : _tableRef$current2$re.call(_tableRef$current2);
204
205
  });
205
206
  return _context.abrupt("return", {
206
207
  data: _rows,
@@ -223,7 +224,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
223
224
  }
224
225
  if (!keepSelect) {
225
226
  selectRowRef.current = [];
226
- (_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : (_tableRef$current2$cl = _tableRef$current2.clearSelected) === null || _tableRef$current2$cl === void 0 ? void 0 : _tableRef$current2$cl.call(_tableRef$current2);
227
+ (_tableRef$current3 = tableRef.current) === null || _tableRef$current3 === void 0 ? void 0 : (_tableRef$current3$cl = _tableRef$current3.clearSelected) === null || _tableRef$current3$cl === void 0 ? void 0 : _tableRef$current3$cl.call(_tableRef$current3);
227
228
  }
228
229
  if (!beforeLoad) {
229
230
  _context.next = 18;
@@ -299,11 +300,9 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
299
300
  * 如果初始有值时,调用此方法初始化名称
300
301
  *
301
302
  * @param val
302
- * @param updateTxt
303
303
  * @returns
304
304
  */
305
305
  var initName = function initName(val) {
306
- var updateTxt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
307
306
  if (!val) return;
308
307
  // 当返回值列不在表格配置中不查询,因为有可能会导致查询别名问题报错。
309
308
  var valueColumn = columns.find(function (o) {
@@ -325,7 +324,6 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
325
324
  param[fieldName] = val;
326
325
  loadData(param).then(function (result) {
327
326
  initRows.current = result.data;
328
- if (!updateTxt) return;
329
327
  var rows = (result.data || []).filter(function (o) {
330
328
  return o;
331
329
  });
@@ -355,7 +353,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
355
353
  initName(val);
356
354
  }
357
355
  } else if (multiple) {
358
- initName(val, false);
356
+ initName(val);
359
357
  }
360
358
  }
361
359
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -408,10 +406,10 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
408
406
  }
409
407
  };
410
408
  var handleClear = function handleClear() {
411
- var _tableRef$current3, _tableRef$current3$cl;
409
+ var _tableRef$current4, _tableRef$current4$cl;
412
410
  selectRowRef.current = [];
413
411
  setSelectedKeys([]);
414
- (_tableRef$current3 = tableRef.current) === null || _tableRef$current3 === void 0 ? void 0 : (_tableRef$current3$cl = _tableRef$current3.clearSelected) === null || _tableRef$current3$cl === void 0 ? void 0 : _tableRef$current3$cl.call(_tableRef$current3);
412
+ (_tableRef$current4 = tableRef.current) === null || _tableRef$current4 === void 0 ? void 0 : (_tableRef$current4$cl = _tableRef$current4.clearSelected) === null || _tableRef$current4$cl === void 0 ? void 0 : _tableRef$current4$cl.call(_tableRef$current4);
415
413
  setText('');
416
414
  var formValue = getFormValue();
417
415
  if (!formValue) return;
@@ -471,15 +469,15 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
471
469
  });
472
470
  useEffect(function () {
473
471
  if (!text && multiple) {
474
- var _tableRef$current4, _tableRef$current4$cl;
472
+ var _tableRef$current5, _tableRef$current5$cl;
475
473
  selectRowRef.current = [];
476
- (_tableRef$current4 = tableRef.current) === null || _tableRef$current4 === void 0 ? void 0 : (_tableRef$current4$cl = _tableRef$current4.clearSelected) === null || _tableRef$current4$cl === void 0 ? void 0 : _tableRef$current4$cl.call(_tableRef$current4);
474
+ (_tableRef$current5 = tableRef.current) === null || _tableRef$current5 === void 0 ? void 0 : (_tableRef$current5$cl = _tableRef$current5.clearSelected) === null || _tableRef$current5$cl === void 0 ? void 0 : _tableRef$current5$cl.call(_tableRef$current5);
477
475
  }
478
476
  }, [text, multiple]);
479
477
  useEffect(function () {
480
478
  if (visible && loadOnShow) {
481
- var _tableRef$current5, _tableRef$current5$re;
482
- (_tableRef$current5 = tableRef.current) === null || _tableRef$current5 === void 0 ? void 0 : (_tableRef$current5$re = _tableRef$current5.reload) === null || _tableRef$current5$re === void 0 ? void 0 : _tableRef$current5$re.call(_tableRef$current5);
479
+ var _tableRef$current6, _tableRef$current6$re;
480
+ (_tableRef$current6 = tableRef.current) === null || _tableRef$current6 === void 0 ? void 0 : (_tableRef$current6$re = _tableRef$current6.reload) === null || _tableRef$current6$re === void 0 ? void 0 : _tableRef$current6$re.call(_tableRef$current6);
483
481
  }
484
482
  }, [visible, loadOnShow]);
485
483
  // 处理有值时,可清空