@hzab/form-render 1.6.17 → 1.6.19

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +291 -283
  2. package/README.md +239 -239
  3. package/package.json +57 -57
  4. package/src/common/formily-utils.ts +125 -125
  5. package/src/common/schema-handler.ts +253 -253
  6. package/src/common/schema-merge.ts +68 -68
  7. package/src/components/ArrayBase/index.tsx +349 -349
  8. package/src/components/ArrayBase/style.less +90 -90
  9. package/src/components/ArrayBase/style.ts +2 -2
  10. package/src/components/ArrayCards/index.tsx +149 -149
  11. package/src/components/ArrayCards/style.less +14 -14
  12. package/src/components/ArrayCards/style.ts +4 -4
  13. package/src/components/ArrayTable/index.tsx +411 -411
  14. package/src/components/ArrayTable/style.less +52 -52
  15. package/src/components/ArrayTable/style.ts +7 -7
  16. package/src/components/DatePicker/index.tsx +108 -108
  17. package/src/components/LocationListPicker/assets/icon.js +1 -1
  18. package/src/components/LocationListPicker/components/AddrList/index.less +55 -55
  19. package/src/components/LocationListPicker/components/AddrList/index.tsx +75 -75
  20. package/src/components/LocationListPicker/components/Popup/address.schema.json +21 -21
  21. package/src/components/LocationListPicker/components/Popup/index.less +22 -22
  22. package/src/components/LocationListPicker/components/Popup/index.tsx +92 -92
  23. package/src/components/LocationListPicker/index.less +34 -34
  24. package/src/components/LocationListPicker/index.tsx +521 -520
  25. package/src/components/LocationPicker/Map/AMap/common/loader.ts +58 -58
  26. package/src/components/LocationPicker/Map/AMap/common/utils.ts +431 -431
  27. package/src/components/LocationPicker/Map/AMap/index.jsx +51 -51
  28. package/src/components/LocationPicker/README.md +44 -44
  29. package/src/components/LocationPicker/common/utils.ts +30 -30
  30. package/src/components/LocationPicker/components/ModalContent/index.tsx +387 -387
  31. package/src/components/LocationPicker/components/PickerInfo/index.tsx +109 -109
  32. package/src/components/LocationPicker/components/ResInfo/index.less +38 -38
  33. package/src/components/LocationPicker/components/ResInfo/index.tsx +65 -65
  34. package/src/components/LocationPicker/index.tsx +197 -197
  35. package/src/components/PersonnelSelect/index.less +21 -21
  36. package/src/components/PersonnelSelect/index.module.less +33 -33
  37. package/src/components/PersonnelSelect/index.tsx +305 -300
  38. package/src/components/PersonnelSelect/type.ts +92 -92
  39. package/src/components/RichEditor/index.less +38 -38
  40. package/src/components/RichEditor/index.tsx +238 -238
  41. package/src/components/TreeCheckbox/components/CheckboxTable/index.tsx +55 -55
  42. package/src/components/TreeCheckbox/components/TabsRender/index.tsx +58 -58
  43. package/src/components/TreeCheckbox/index.less +12 -12
  44. package/src/components/TreeCheckbox/index.tsx +63 -63
  45. package/src/components/Upload/README.md +64 -64
  46. package/src/components/Upload/common/OfflineUpload.ts +339 -339
  47. package/src/components/Upload/common/customRequest.ts +81 -81
  48. package/src/components/Upload/common/fileName.ts +142 -142
  49. package/src/components/Upload/common/handleIOFileList.ts +393 -393
  50. package/src/components/Upload/common/nanoid.ts +7 -7
  51. package/src/components/Upload/common/ossUpload.js +159 -159
  52. package/src/components/Upload/common/utils.js +194 -194
  53. package/src/components/Upload/components/ItemList/index.tsx +52 -52
  54. package/src/components/Upload/components/PreviewModal/previewRender.tsx +80 -80
  55. package/src/components/Upload/index.tsx +17 -17
  56. package/src/components/Upload/uploader-input.jsx +187 -187
  57. package/src/components/Upload/uploader.jsx +316 -316
  58. package/src/components/UserSelect/index.tsx +123 -123
  59. package/src/components/index.tsx +17 -17
  60. package/src/index.tsx +198 -198
@@ -1,393 +1,393 @@
1
- import { getFileURL, getFileType, isBase64Str } from "./utils";
2
- import { getUFileName, getFileName, getFullFileName, getFileExt, getFileNameObj } from "./fileName";
3
- import { nanoid } from "./nanoid";
4
-
5
- /**
6
- * 出入参归一化
7
- * 统一成对象格式用于内部处理
8
- {
9
- }
10
-
11
- */
12
-
13
- /**
14
- * 出入参数据子项处理配置项
15
- */
16
- export interface IFile {
17
- uid?: string;
18
- /** 唯一 id */
19
- id: string;
20
- /** 文件地址 */
21
- url: string;
22
- /** 存储的文件地址 */
23
- storeUrl: string;
24
- /** 存储的文件名称 */
25
- name?: string;
26
- /** 存储的文件名称 */
27
- filename?: string;
28
- /** 上传的文件名称 */
29
- originalFilename: string;
30
- /** 基础路径 */
31
- basePath?: string;
32
- /** 存储路径 */
33
- path?: string;
34
- /** 文件后缀 */
35
- ext?: string;
36
- /** 文件类型 */
37
- contentType: string;
38
- /** 上传平台 */
39
- platform: string;
40
- /** 文件预览地址 */
41
- previewUrl?: string;
42
- /** 文件类型 */
43
- type: string;
44
- /** 文件大小 */
45
- size: number;
46
- /** 原始 file 文件 */
47
- originFileObj?: File;
48
- /** 文件上传时间 */
49
- createTime?: string;
50
- /** 最后更新时间戳 */
51
- lastModified?: number;
52
- }
53
-
54
- /**
55
- * 出入参数据处理配置项
56
- */
57
- export interface IHandlerOpt {
58
- /** 列表数据模式:数组 | 字符串 */
59
- listMode: "array" | "jsonStr" | "splitStr";
60
- /** 字符串列表数据模式下的分隔符 */
61
- split: string;
62
- /** 子项数据模式: 格式化对象 | file 文件格式 | url 地址 | JSON 序列化字符串 */
63
- itemMode: "object" | "file" | "url" | "jsonStr";
64
- /** 预览配置参数 */
65
- previewConfig?: Object;
66
- }
67
-
68
- /** 内部文件格式 */
69
- const fileTpl: IFile = {
70
- /** 唯一 id */
71
- uid: "",
72
- id: "",
73
- /** 文件地址 */
74
- url: "",
75
- /** 存储的文件地址 */
76
- storeUrl: "",
77
- /** 存储的文件名称 */
78
- name: "",
79
- /** 存储的文件名称 */
80
- filename: "",
81
- /** 上传的文件名称 */
82
- originalFilename: "",
83
- /** 基础路径 */
84
- basePath: "",
85
- /** 存储路径 */
86
- path: "",
87
- /** 文件后缀 */
88
- ext: "",
89
- /** 文件类型 */
90
- type: "",
91
- /** 文件类型 */
92
- contentType: "",
93
- /** 文件预览地址 */
94
- previewUrl: undefined,
95
- /** 文件大小 */
96
- size: undefined,
97
- /** 上传平台 */
98
- platform: undefined,
99
- /** 最后更新时间戳 */
100
- lastModified: undefined,
101
- /** 文件上传时间 */
102
- createTime: undefined,
103
- /** 源文件 */
104
- originFileObj: undefined,
105
- };
106
-
107
- /**
108
- * 对象字符串转为对象
109
- * @param objStr
110
- */
111
- export const objStrToObj = function (objStr) {
112
- let _objStr = objStr;
113
- if (typeof _objStr === "object") {
114
- return _objStr;
115
- }
116
- // 对象字符串 转为 对象
117
- if (typeof _objStr === "string") {
118
- _objStr = _objStr.trim();
119
- if (/^\[.*\]$|^\{.*\}$/.test(_objStr)) {
120
- try {
121
- _objStr = JSON.parse(_objStr);
122
- } catch (error) {}
123
- }
124
- }
125
- return _objStr;
126
- };
127
-
128
- /**
129
- * 预览 url 添加前缀
130
- * @param {*} uri
131
- * @param {*} previewConfig
132
- * @returns
133
- */
134
- export function mergePreviewConfig(uri, previewConfig) {
135
- let _uri = uri;
136
- let basePath = "";
137
- if (typeof _uri === "object") {
138
- basePath = _uri.basePath;
139
- _uri = _uri.previewUrl || _uri.url;
140
- }
141
- if (typeof _uri !== "string") {
142
- return _uri;
143
- }
144
- _uri = _uri?.trim();
145
- // base64 直接返回
146
- if (isBase64Str(_uri)) {
147
- return _uri;
148
- }
149
- const isUriPattern = /http[s]?:\/\/[^\s]+/.test(_uri);
150
- const query = previewConfig?.query?.trim() ? "?" + previewConfig?.query?.trim() : "";
151
-
152
- if (isUriPattern) {
153
- // 源地址为 http 地址,直接拼接 query 参数
154
- return `${_uri}${query}`;
155
- }
156
-
157
- if (previewConfig) {
158
- // 拼接前缀
159
- return `${previewConfig?.url?.trim()}/${_uri}${query}`?.trim();
160
- }
161
-
162
- return _uri;
163
- }
164
-
165
- /**
166
- * 子项数据归一化
167
- * 字符串:url、base64
168
- * 对象:
169
- * 统一成对象格式用于内部处理
170
- */
171
- export const handleInputItem = (data, opt: IHandlerOpt) => {
172
- if (!data) {
173
- console.warn("Upload handleInputData 请传入正确的数据");
174
- return data;
175
- }
176
- let file = {
177
- ...fileTpl,
178
- };
179
- // 对象字符串 转为 对象
180
- const _data = objStrToObj(data);
181
- if (typeof _data === "string") {
182
- const obj = getFileNameObj(_data);
183
- file.id = obj?.id;
184
- file.uid = file.id;
185
- file.url = _data;
186
- file.storeUrl = _data;
187
- file.name = getFullFileName(file.url);
188
- file.filename = file.name;
189
- file.originalFilename = getFullFileName(file.url);
190
- file.type = getFileType(file.url);
191
- file.ext = getFileExt(file.url);
192
- } else if (typeof _data === "object") {
193
- const sourceData = _data.originFileObj || _data;
194
- file.id = _data.id || _data.uid;
195
- file.url = sourceData.url || sourceData.ossUrl;
196
- file.storeUrl = file.url;
197
- file.originalFilename = _data.originalFilename || getFullFileName(file.url) || _data.name;
198
- file.name = _data.filename || _data.name || getFullFileName(file.url);
199
- file.filename = file.name;
200
- file.originFileObj = data instanceof File ? data : undefined;
201
- file.lastModified = _data.lastModified;
202
- /** 基础路径 */
203
- file.basePath = _data.basePath;
204
- /** 存储路径 */
205
- file.path = _data.path;
206
- /** 文件后缀 */
207
- file.ext = getFileExt(file.url);
208
- /** 文件类型 */
209
- file.type = _data.contentType || _data.type;
210
- /** 文件类型 */
211
- file.contentType = file.type;
212
- /** 文件大小 */
213
- file.size = _data.size;
214
- /** 上传平台 */
215
- file.platform = _data.platform;
216
- /** 上传平台 */
217
- file.createTime = _data.createTime;
218
- }
219
- if (!file.id) {
220
- file.id =
221
- file.uid || `${getFileName(file.url || file.name || file.filename) || "rc-upload"}-${Date.now()}-${nanoid()}`;
222
- }
223
- if (!file.name) {
224
- file.name = file.id;
225
- }
226
- if (!file.filename) {
227
- file.filename = file.name;
228
- }
229
- if (!file.storeUrl) {
230
- file.storeUrl = file.url;
231
- }
232
-
233
- const { previewConfig } = opt || {};
234
-
235
- // 合并预览地址?
236
- file.previewUrl = mergePreviewConfig(file, previewConfig);
237
-
238
- return file;
239
- };
240
-
241
- /**
242
- * fileList 数据归一化
243
- * 统一成对象格式用于内部处理
244
- */
245
- export const handleInputFileList = (fileList, opt: IHandlerOpt) => {
246
- if (!fileList) {
247
- return [];
248
- }
249
-
250
- let _fileList = fileList;
251
- const { listMode, split } = opt || {};
252
-
253
- // splitStr jsonStr 模式下 Upload 自动将字符串嵌套了数组,需要手动处理
254
- if (listMode === "splitStr" || listMode === "jsonStr") {
255
- if (typeof _fileList === "string") {
256
- if (listMode === "splitStr") {
257
- // @ts-ignore
258
- _fileList = _fileList?.split(split ?? ", ");
259
- }
260
-
261
- if (listMode === "jsonStr") {
262
- _fileList = objStrToObj(_fileList);
263
- }
264
- }
265
- }
266
-
267
- // 统一成数组格式
268
- if (_fileList !== null && _fileList !== undefined && !Array.isArray(_fileList)) {
269
- _fileList = [_fileList];
270
- }
271
-
272
- if (Array.isArray(_fileList)) {
273
- const arrRes = [];
274
- _fileList.forEach((it) => {
275
- const itRes = handleInputItem(it, opt);
276
- itRes && arrRes.push(itRes);
277
- });
278
- return arrRes;
279
- }
280
- return _fileList;
281
- };
282
-
283
- export const handleFileName = function () {};
284
-
285
- /**
286
- * 子项数据归一化
287
- * @param data
288
- * @returns
289
- */
290
- export const formatItem = function (data) {
291
- // TODO: storeUrl 来源于【本地 url 直接使用预览地址,解决 previewFile 无法正常使用 previewUrl 的问题】
292
- const url = data.storeUrl || data.url || (data instanceof File ? getFileURL(data) : data.url);
293
- const uid = data.uid ?? data.id ?? getUFileName(data.name || data.filename);
294
- const filename = data.filename || data.uploadInfo?.filename || (data.url ? getFullFileName(data.url) : data.name);
295
- const res = {
296
- uid: uid,
297
- /** 唯一 id */
298
- id: uid,
299
- /** 文件地址 */
300
- url: url,
301
- /** 存储的文件名称 */
302
- name: filename,
303
- /** 存储的文件名称 */
304
- filename: filename,
305
- /** 上传的文件名称 */
306
- originalFilename: data.originalFilename || data.uploadInfo?.originalFilename || data.name || data.filename,
307
- /** 基础路径 */
308
- basePath: data.basePath || data.uploadInfo?.basePath,
309
- /** 存储路径 */
310
- path: data.path || data.uploadInfo?.path,
311
- /** 文件后缀 */
312
- ext: data.ext || data.uploadInfo?.ext || getFileExt(url),
313
- /** 文件类型 */
314
- type: data.type,
315
- /** 文件类型 */
316
- contentType: data.type,
317
- /** 文件大小 */
318
- size: data.size,
319
- /** 上传平台 */
320
- platform: data.platform || data.uploadInfo?.platform,
321
- /** 最后更新时间戳 */
322
- lastModified: data.lastModified,
323
- /** 文件上传时间 */
324
- createTime: data.createTime || data.uploadInfo?.createTime,
325
- /** 源文件 */
326
- originFileObj: data instanceof File ? data : undefined,
327
- };
328
- if (!res.name) {
329
- res.name = res.id ?? res.uid;
330
- }
331
- if (!res.filename) {
332
- res.filename = res.id ?? res.uid;
333
- }
334
- if (!res.originalFilename) {
335
- res.originalFilename = res.name || res.filename;
336
- }
337
- return res;
338
- };
339
-
340
- /**
341
- * 出参子项归一化
342
- * 根据配置,将 对象 处理成所需格式
343
- */
344
- export const handleUploadItem = function (file, opt: IHandlerOpt) {
345
- const { itemMode = "object" } = opt || {};
346
- if (itemMode === "file") {
347
- return file?.originFileObj || file;
348
- }
349
- if (itemMode === "object") {
350
- return formatItem(file);
351
- }
352
- if (itemMode === "jsonStr" && typeof file !== "string") {
353
- const { originFileObj, ...jFile } = formatItem(file);
354
- return JSON.stringify({ ...jFile });
355
- }
356
- if (itemMode === "url") {
357
- return typeof file === "string" ? file : file.originFileObj?.url || file?.url;
358
- }
359
- return file;
360
- };
361
-
362
- /**
363
- * 出参 fileList 归一化
364
- * 根据配置,将 对象 处理成所需格式
365
- */
366
- export const handleOutputFileList = function (fileList, opt: IHandlerOpt) {
367
- if (!fileList) {
368
- return undefined;
369
- }
370
-
371
- const { listMode, split } = opt || {};
372
-
373
- let _fileList = fileList;
374
- if (_fileList && !Array.isArray(_fileList)) {
375
- _fileList = [fileList];
376
- }
377
-
378
- // 数组
379
- if (listMode === "array") {
380
- return _fileList?.map((it) => handleUploadItem(it, opt));
381
- }
382
- // 序列化后的字符串
383
- if (listMode === "jsonStr") {
384
- return JSON.stringify(_fileList?.map((it) => handleUploadItem(it, opt)));
385
- }
386
- // join 后的字符串
387
- if (listMode === "splitStr") {
388
- return _fileList
389
- ?.map((it) => handleUploadItem(it, opt))
390
- .filter((it) => it)
391
- .join(split ?? ", ");
392
- }
393
- };
1
+ import { getFileURL, getFileType, isBase64Str } from "./utils";
2
+ import { getUFileName, getFileName, getFullFileName, getFileExt, getFileNameObj } from "./fileName";
3
+ import { nanoid } from "./nanoid";
4
+
5
+ /**
6
+ * 出入参归一化
7
+ * 统一成对象格式用于内部处理
8
+ {
9
+ }
10
+
11
+ */
12
+
13
+ /**
14
+ * 出入参数据子项处理配置项
15
+ */
16
+ export interface IFile {
17
+ uid?: string;
18
+ /** 唯一 id */
19
+ id: string;
20
+ /** 文件地址 */
21
+ url: string;
22
+ /** 存储的文件地址 */
23
+ storeUrl: string;
24
+ /** 存储的文件名称 */
25
+ name?: string;
26
+ /** 存储的文件名称 */
27
+ filename?: string;
28
+ /** 上传的文件名称 */
29
+ originalFilename: string;
30
+ /** 基础路径 */
31
+ basePath?: string;
32
+ /** 存储路径 */
33
+ path?: string;
34
+ /** 文件后缀 */
35
+ ext?: string;
36
+ /** 文件类型 */
37
+ contentType: string;
38
+ /** 上传平台 */
39
+ platform: string;
40
+ /** 文件预览地址 */
41
+ previewUrl?: string;
42
+ /** 文件类型 */
43
+ type: string;
44
+ /** 文件大小 */
45
+ size: number;
46
+ /** 原始 file 文件 */
47
+ originFileObj?: File;
48
+ /** 文件上传时间 */
49
+ createTime?: string;
50
+ /** 最后更新时间戳 */
51
+ lastModified?: number;
52
+ }
53
+
54
+ /**
55
+ * 出入参数据处理配置项
56
+ */
57
+ export interface IHandlerOpt {
58
+ /** 列表数据模式:数组 | 字符串 */
59
+ listMode: "array" | "jsonStr" | "splitStr";
60
+ /** 字符串列表数据模式下的分隔符 */
61
+ split: string;
62
+ /** 子项数据模式: 格式化对象 | file 文件格式 | url 地址 | JSON 序列化字符串 */
63
+ itemMode: "object" | "file" | "url" | "jsonStr";
64
+ /** 预览配置参数 */
65
+ previewConfig?: Object;
66
+ }
67
+
68
+ /** 内部文件格式 */
69
+ const fileTpl: IFile = {
70
+ /** 唯一 id */
71
+ uid: "",
72
+ id: "",
73
+ /** 文件地址 */
74
+ url: "",
75
+ /** 存储的文件地址 */
76
+ storeUrl: "",
77
+ /** 存储的文件名称 */
78
+ name: "",
79
+ /** 存储的文件名称 */
80
+ filename: "",
81
+ /** 上传的文件名称 */
82
+ originalFilename: "",
83
+ /** 基础路径 */
84
+ basePath: "",
85
+ /** 存储路径 */
86
+ path: "",
87
+ /** 文件后缀 */
88
+ ext: "",
89
+ /** 文件类型 */
90
+ type: "",
91
+ /** 文件类型 */
92
+ contentType: "",
93
+ /** 文件预览地址 */
94
+ previewUrl: undefined,
95
+ /** 文件大小 */
96
+ size: undefined,
97
+ /** 上传平台 */
98
+ platform: undefined,
99
+ /** 最后更新时间戳 */
100
+ lastModified: undefined,
101
+ /** 文件上传时间 */
102
+ createTime: undefined,
103
+ /** 源文件 */
104
+ originFileObj: undefined,
105
+ };
106
+
107
+ /**
108
+ * 对象字符串转为对象
109
+ * @param objStr
110
+ */
111
+ export const objStrToObj = function (objStr) {
112
+ let _objStr = objStr;
113
+ if (typeof _objStr === "object") {
114
+ return _objStr;
115
+ }
116
+ // 对象字符串 转为 对象
117
+ if (typeof _objStr === "string") {
118
+ _objStr = _objStr.trim();
119
+ if (/^\[.*\]$|^\{.*\}$/.test(_objStr)) {
120
+ try {
121
+ _objStr = JSON.parse(_objStr);
122
+ } catch (error) {}
123
+ }
124
+ }
125
+ return _objStr;
126
+ };
127
+
128
+ /**
129
+ * 预览 url 添加前缀
130
+ * @param {*} uri
131
+ * @param {*} previewConfig
132
+ * @returns
133
+ */
134
+ export function mergePreviewConfig(uri, previewConfig) {
135
+ let _uri = uri;
136
+ let basePath = "";
137
+ if (typeof _uri === "object") {
138
+ basePath = _uri.basePath;
139
+ _uri = _uri.previewUrl || _uri.url;
140
+ }
141
+ if (typeof _uri !== "string") {
142
+ return _uri;
143
+ }
144
+ _uri = _uri?.trim();
145
+ // base64 直接返回
146
+ if (isBase64Str(_uri)) {
147
+ return _uri;
148
+ }
149
+ const isUriPattern = /http[s]?:\/\/[^\s]+/.test(_uri);
150
+ const query = previewConfig?.query?.trim() ? "?" + previewConfig?.query?.trim() : "";
151
+
152
+ if (isUriPattern) {
153
+ // 源地址为 http 地址,直接拼接 query 参数
154
+ return `${_uri}${query}`;
155
+ }
156
+
157
+ if (previewConfig) {
158
+ // 拼接前缀
159
+ return `${previewConfig?.url?.trim()}/${_uri}${query}`?.trim();
160
+ }
161
+
162
+ return _uri;
163
+ }
164
+
165
+ /**
166
+ * 子项数据归一化
167
+ * 字符串:url、base64
168
+ * 对象:
169
+ * 统一成对象格式用于内部处理
170
+ */
171
+ export const handleInputItem = (data, opt: IHandlerOpt) => {
172
+ if (!data) {
173
+ console.warn("Upload handleInputData 请传入正确的数据");
174
+ return data;
175
+ }
176
+ let file = {
177
+ ...fileTpl,
178
+ };
179
+ // 对象字符串 转为 对象
180
+ const _data = objStrToObj(data);
181
+ if (typeof _data === "string") {
182
+ const obj = getFileNameObj(_data);
183
+ file.id = obj?.id;
184
+ file.uid = file.id;
185
+ file.url = _data;
186
+ file.storeUrl = _data;
187
+ file.name = getFullFileName(file.url);
188
+ file.filename = file.name;
189
+ file.originalFilename = getFullFileName(file.url);
190
+ file.type = getFileType(file.url);
191
+ file.ext = getFileExt(file.url);
192
+ } else if (typeof _data === "object") {
193
+ const sourceData = _data.originFileObj || _data;
194
+ file.id = _data.id || _data.uid;
195
+ file.url = sourceData.url || sourceData.ossUrl;
196
+ file.storeUrl = file.url;
197
+ file.originalFilename = _data.originalFilename || getFullFileName(file.url) || _data.name;
198
+ file.name = _data.filename || _data.name || getFullFileName(file.url);
199
+ file.filename = file.name;
200
+ file.originFileObj = data instanceof File ? data : undefined;
201
+ file.lastModified = _data.lastModified;
202
+ /** 基础路径 */
203
+ file.basePath = _data.basePath;
204
+ /** 存储路径 */
205
+ file.path = _data.path;
206
+ /** 文件后缀 */
207
+ file.ext = getFileExt(file.url);
208
+ /** 文件类型 */
209
+ file.type = _data.contentType || _data.type;
210
+ /** 文件类型 */
211
+ file.contentType = file.type;
212
+ /** 文件大小 */
213
+ file.size = _data.size;
214
+ /** 上传平台 */
215
+ file.platform = _data.platform;
216
+ /** 上传平台 */
217
+ file.createTime = _data.createTime;
218
+ }
219
+ if (!file.id) {
220
+ file.id =
221
+ file.uid || `${getFileName(file.url || file.name || file.filename) || "rc-upload"}-${Date.now()}-${nanoid()}`;
222
+ }
223
+ if (!file.name) {
224
+ file.name = file.id;
225
+ }
226
+ if (!file.filename) {
227
+ file.filename = file.name;
228
+ }
229
+ if (!file.storeUrl) {
230
+ file.storeUrl = file.url;
231
+ }
232
+
233
+ const { previewConfig } = opt || {};
234
+
235
+ // 合并预览地址?
236
+ file.previewUrl = mergePreviewConfig(file, previewConfig);
237
+
238
+ return file;
239
+ };
240
+
241
+ /**
242
+ * fileList 数据归一化
243
+ * 统一成对象格式用于内部处理
244
+ */
245
+ export const handleInputFileList = (fileList, opt: IHandlerOpt) => {
246
+ if (!fileList) {
247
+ return [];
248
+ }
249
+
250
+ let _fileList = fileList;
251
+ const { listMode, split } = opt || {};
252
+
253
+ // splitStr jsonStr 模式下 Upload 自动将字符串嵌套了数组,需要手动处理
254
+ if (listMode === "splitStr" || listMode === "jsonStr") {
255
+ if (typeof _fileList === "string") {
256
+ if (listMode === "splitStr") {
257
+ // @ts-ignore
258
+ _fileList = _fileList?.split(split ?? ", ");
259
+ }
260
+
261
+ if (listMode === "jsonStr") {
262
+ _fileList = objStrToObj(_fileList);
263
+ }
264
+ }
265
+ }
266
+
267
+ // 统一成数组格式
268
+ if (_fileList !== null && _fileList !== undefined && !Array.isArray(_fileList)) {
269
+ _fileList = [_fileList];
270
+ }
271
+
272
+ if (Array.isArray(_fileList)) {
273
+ const arrRes = [];
274
+ _fileList.forEach((it) => {
275
+ const itRes = handleInputItem(it, opt);
276
+ itRes && arrRes.push(itRes);
277
+ });
278
+ return arrRes;
279
+ }
280
+ return _fileList;
281
+ };
282
+
283
+ export const handleFileName = function () {};
284
+
285
+ /**
286
+ * 子项数据归一化
287
+ * @param data
288
+ * @returns
289
+ */
290
+ export const formatItem = function (data) {
291
+ // TODO: storeUrl 来源于【本地 url 直接使用预览地址,解决 previewFile 无法正常使用 previewUrl 的问题】
292
+ const url = data.storeUrl || data.url || (data instanceof File ? getFileURL(data) : data.url);
293
+ const uid = data.uid ?? data.id ?? getUFileName(data.name || data.filename);
294
+ const filename = data.filename || data.uploadInfo?.filename || (data.url ? getFullFileName(data.url) : data.name);
295
+ const res = {
296
+ uid: uid,
297
+ /** 唯一 id */
298
+ id: uid,
299
+ /** 文件地址 */
300
+ url: url,
301
+ /** 存储的文件名称 */
302
+ name: filename,
303
+ /** 存储的文件名称 */
304
+ filename: filename,
305
+ /** 上传的文件名称 */
306
+ originalFilename: data.originalFilename || data.uploadInfo?.originalFilename || data.name || data.filename,
307
+ /** 基础路径 */
308
+ basePath: data.basePath || data.uploadInfo?.basePath,
309
+ /** 存储路径 */
310
+ path: data.path || data.uploadInfo?.path,
311
+ /** 文件后缀 */
312
+ ext: data.ext || data.uploadInfo?.ext || getFileExt(url),
313
+ /** 文件类型 */
314
+ type: data.type,
315
+ /** 文件类型 */
316
+ contentType: data.type,
317
+ /** 文件大小 */
318
+ size: data.size,
319
+ /** 上传平台 */
320
+ platform: data.platform || data.uploadInfo?.platform,
321
+ /** 最后更新时间戳 */
322
+ lastModified: data.lastModified,
323
+ /** 文件上传时间 */
324
+ createTime: data.createTime || data.uploadInfo?.createTime,
325
+ /** 源文件 */
326
+ originFileObj: data instanceof File ? data : undefined,
327
+ };
328
+ if (!res.name) {
329
+ res.name = res.id ?? res.uid;
330
+ }
331
+ if (!res.filename) {
332
+ res.filename = res.id ?? res.uid;
333
+ }
334
+ if (!res.originalFilename) {
335
+ res.originalFilename = res.name || res.filename;
336
+ }
337
+ return res;
338
+ };
339
+
340
+ /**
341
+ * 出参子项归一化
342
+ * 根据配置,将 对象 处理成所需格式
343
+ */
344
+ export const handleUploadItem = function (file, opt: IHandlerOpt) {
345
+ const { itemMode = "object" } = opt || {};
346
+ if (itemMode === "file") {
347
+ return file?.originFileObj || file;
348
+ }
349
+ if (itemMode === "object") {
350
+ return formatItem(file);
351
+ }
352
+ if (itemMode === "jsonStr" && typeof file !== "string") {
353
+ const { originFileObj, ...jFile } = formatItem(file);
354
+ return JSON.stringify({ ...jFile });
355
+ }
356
+ if (itemMode === "url") {
357
+ return typeof file === "string" ? file : file.originFileObj?.url || file?.url;
358
+ }
359
+ return file;
360
+ };
361
+
362
+ /**
363
+ * 出参 fileList 归一化
364
+ * 根据配置,将 对象 处理成所需格式
365
+ */
366
+ export const handleOutputFileList = function (fileList, opt: IHandlerOpt) {
367
+ if (!fileList) {
368
+ return undefined;
369
+ }
370
+
371
+ const { listMode, split } = opt || {};
372
+
373
+ let _fileList = fileList;
374
+ if (_fileList && !Array.isArray(_fileList)) {
375
+ _fileList = [fileList];
376
+ }
377
+
378
+ // 数组
379
+ if (listMode === "array") {
380
+ return _fileList?.map((it) => handleUploadItem(it, opt));
381
+ }
382
+ // 序列化后的字符串
383
+ if (listMode === "jsonStr") {
384
+ return JSON.stringify(_fileList?.map((it) => handleUploadItem(it, opt)));
385
+ }
386
+ // join 后的字符串
387
+ if (listMode === "splitStr") {
388
+ return _fileList
389
+ ?.map((it) => handleUploadItem(it, opt))
390
+ .filter((it) => it)
391
+ .join(split ?? ", ");
392
+ }
393
+ };