@hzab/form-render 1.6.18 → 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.
- package/CHANGELOG.md +4 -0
- package/README.md +239 -239
- package/package.json +57 -57
- package/src/common/formily-utils.ts +125 -125
- package/src/common/schema-handler.ts +253 -253
- package/src/common/schema-merge.ts +68 -68
- package/src/components/ArrayBase/index.tsx +349 -349
- package/src/components/ArrayBase/style.less +90 -90
- package/src/components/ArrayBase/style.ts +2 -2
- package/src/components/ArrayCards/index.tsx +149 -149
- package/src/components/ArrayCards/style.less +14 -14
- package/src/components/ArrayCards/style.ts +4 -4
- package/src/components/ArrayTable/index.tsx +411 -411
- package/src/components/ArrayTable/style.less +52 -52
- package/src/components/ArrayTable/style.ts +7 -7
- package/src/components/DatePicker/index.tsx +108 -108
- package/src/components/LocationListPicker/assets/icon.js +1 -1
- package/src/components/LocationListPicker/components/AddrList/index.less +55 -55
- package/src/components/LocationListPicker/components/AddrList/index.tsx +75 -75
- package/src/components/LocationListPicker/components/Popup/address.schema.json +21 -21
- package/src/components/LocationListPicker/components/Popup/index.less +22 -22
- package/src/components/LocationListPicker/components/Popup/index.tsx +92 -92
- package/src/components/LocationListPicker/index.less +34 -34
- package/src/components/LocationListPicker/index.tsx +521 -520
- package/src/components/LocationPicker/Map/AMap/common/loader.ts +58 -58
- package/src/components/LocationPicker/Map/AMap/common/utils.ts +431 -431
- package/src/components/LocationPicker/Map/AMap/index.jsx +51 -51
- package/src/components/LocationPicker/README.md +44 -44
- package/src/components/LocationPicker/common/utils.ts +30 -30
- package/src/components/LocationPicker/components/ModalContent/index.tsx +387 -387
- package/src/components/LocationPicker/components/PickerInfo/index.tsx +109 -109
- package/src/components/LocationPicker/components/ResInfo/index.less +38 -38
- package/src/components/LocationPicker/components/ResInfo/index.tsx +65 -65
- package/src/components/LocationPicker/index.tsx +197 -197
- package/src/components/PersonnelSelect/index.less +21 -21
- package/src/components/PersonnelSelect/index.module.less +33 -33
- package/src/components/PersonnelSelect/type.ts +92 -92
- package/src/components/RichEditor/index.less +38 -38
- package/src/components/RichEditor/index.tsx +238 -238
- package/src/components/TreeCheckbox/components/CheckboxTable/index.tsx +55 -55
- package/src/components/TreeCheckbox/components/TabsRender/index.tsx +58 -58
- package/src/components/TreeCheckbox/index.less +12 -12
- package/src/components/TreeCheckbox/index.tsx +63 -63
- package/src/components/Upload/README.md +64 -64
- package/src/components/Upload/common/OfflineUpload.ts +339 -339
- package/src/components/Upload/common/customRequest.ts +81 -81
- package/src/components/Upload/common/fileName.ts +142 -142
- package/src/components/Upload/common/handleIOFileList.ts +393 -393
- package/src/components/Upload/common/nanoid.ts +7 -7
- package/src/components/Upload/common/ossUpload.js +159 -159
- package/src/components/Upload/common/utils.js +194 -194
- package/src/components/Upload/components/ItemList/index.tsx +52 -52
- package/src/components/Upload/components/PreviewModal/previewRender.tsx +80 -80
- package/src/components/Upload/index.tsx +17 -17
- package/src/components/Upload/uploader-input.jsx +187 -187
- package/src/components/Upload/uploader.jsx +316 -316
- package/src/components/UserSelect/index.tsx +123 -123
- package/src/components/index.tsx +17 -17
- package/src/index.tsx +198 -198
|
@@ -1,339 +1,339 @@
|
|
|
1
|
-
import { axios } from "@hzab/data-model";
|
|
2
|
-
|
|
3
|
-
import { getFileNameByFileObj } from "./fileName";
|
|
4
|
-
import { formatDirStr, mergeDirStr } from "./utils";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 获取上传相关配置入参
|
|
8
|
-
*/
|
|
9
|
-
export interface IGetSignatureOpt {
|
|
10
|
-
/**
|
|
11
|
-
* 配置接口地址
|
|
12
|
-
*/
|
|
13
|
-
serverUrl?: string;
|
|
14
|
-
/**
|
|
15
|
-
* axios 实例
|
|
16
|
-
*/
|
|
17
|
-
axios?: Object;
|
|
18
|
-
/**
|
|
19
|
-
* axios 配置
|
|
20
|
-
*/
|
|
21
|
-
axiosConf?: Object;
|
|
22
|
-
/**
|
|
23
|
-
* 请求入参
|
|
24
|
-
*/
|
|
25
|
-
params?: {
|
|
26
|
-
path?: string;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IOfflineUploadProps {
|
|
31
|
-
/**
|
|
32
|
-
* axios 实例
|
|
33
|
-
*/
|
|
34
|
-
axios?: Object;
|
|
35
|
-
/**
|
|
36
|
-
* axios 配置
|
|
37
|
-
*/
|
|
38
|
-
axiosConf?: Object;
|
|
39
|
-
/**
|
|
40
|
-
* 配置接口地址
|
|
41
|
-
*/
|
|
42
|
-
serverUrl?: string;
|
|
43
|
-
/**
|
|
44
|
-
* 获取配置接口请求入参
|
|
45
|
-
*/
|
|
46
|
-
signatureParams?: {
|
|
47
|
-
path?: string;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 文件上传入参
|
|
53
|
-
*/
|
|
54
|
-
export interface IUploadOpt {
|
|
55
|
-
/**
|
|
56
|
-
* 配置接口地址
|
|
57
|
-
*/
|
|
58
|
-
serverUrl?: string;
|
|
59
|
-
/**
|
|
60
|
-
* 是否开启 Hash 命名
|
|
61
|
-
*/
|
|
62
|
-
useHashName?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* 文件上传接口地址
|
|
65
|
-
*/
|
|
66
|
-
uploadUrl?: string;
|
|
67
|
-
/**
|
|
68
|
-
* 获取配置接口请求入参
|
|
69
|
-
*/
|
|
70
|
-
params?: {
|
|
71
|
-
path?: string;
|
|
72
|
-
// 兼容 老数据
|
|
73
|
-
dir?: string;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* 文件上传请求入参
|
|
77
|
-
*/
|
|
78
|
-
ossParams?: {
|
|
79
|
-
path?: string;
|
|
80
|
-
// 兼容 老数据
|
|
81
|
-
dir?: string;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* axios 实例
|
|
85
|
-
*/
|
|
86
|
-
axios?: Object;
|
|
87
|
-
/**
|
|
88
|
-
* axios 配置
|
|
89
|
-
*/
|
|
90
|
-
axiosConf?: Object;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 获取上传配置
|
|
95
|
-
* @param opt
|
|
96
|
-
* @returns
|
|
97
|
-
*/
|
|
98
|
-
export function getSignature(opt: IGetSignatureOpt = {}) {
|
|
99
|
-
const { serverUrl = "/api/v1/upload/init" } = opt;
|
|
100
|
-
// 减 10 秒,避免发起请求时 刚好过期的情况
|
|
101
|
-
const { axios: _ax = axios, params = {}, axiosConf } = opt;
|
|
102
|
-
if (
|
|
103
|
-
window._$offlineSignatureRes &&
|
|
104
|
-
window._$offlineSignatureRes.data &&
|
|
105
|
-
serverUrl + JSON.stringify(params) === window._$offlineSignatureRes.serverUrlParams &&
|
|
106
|
-
Date.now() - window._$offlineSignatureRes.__saveTime < window._$offlineSignatureRes.expireTimeMillis - 10000
|
|
107
|
-
) {
|
|
108
|
-
return Promise.resolve(window._$offlineSignatureRes.data);
|
|
109
|
-
}
|
|
110
|
-
// 处理 path 格式,必须为非 / 开头, / 结尾。如: test/
|
|
111
|
-
params.path = formatDirStr(params.path);
|
|
112
|
-
|
|
113
|
-
return _ax
|
|
114
|
-
.post(
|
|
115
|
-
serverUrl,
|
|
116
|
-
{
|
|
117
|
-
...params,
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
...axiosConf,
|
|
121
|
-
},
|
|
122
|
-
)
|
|
123
|
-
.then((res) => {
|
|
124
|
-
if (res?.data?.code === 500) {
|
|
125
|
-
return Promise.reject(res.data);
|
|
126
|
-
}
|
|
127
|
-
if (res?.data?.code === 200) {
|
|
128
|
-
window._$offlineSignatureRes = {
|
|
129
|
-
data: res?.data?.data,
|
|
130
|
-
};
|
|
131
|
-
if (window._$offlineSignatureRes) {
|
|
132
|
-
window._$offlineSignatureRes.__saveTime = Date.now();
|
|
133
|
-
window._$offlineSignatureRes.serverUrlParams = serverUrl + JSON.stringify(params);
|
|
134
|
-
}
|
|
135
|
-
return window._$offlineSignatureRes.data;
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export interface IGetPreviewUrlsOpt {
|
|
141
|
-
previewUrl?: string;
|
|
142
|
-
params?: Object;
|
|
143
|
-
axios?: Object;
|
|
144
|
-
axiosConf?: Object;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 获取预览地址-批量
|
|
149
|
-
* @param urlList
|
|
150
|
-
* @param opt
|
|
151
|
-
* @returns
|
|
152
|
-
*/
|
|
153
|
-
export const getPreviewUrls = function (urlList, opt: IGetPreviewUrlsOpt = {}) {
|
|
154
|
-
return new Promise(async (resolve, reject) => {
|
|
155
|
-
const { axios: _ax = axios, axiosConf, previewUrl } = opt || {};
|
|
156
|
-
|
|
157
|
-
const _axios = _ax;
|
|
158
|
-
|
|
159
|
-
let _list = urlList;
|
|
160
|
-
if (_list && !Array.isArray(_list)) {
|
|
161
|
-
_list = [_list];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return _axios
|
|
165
|
-
.post(previewUrl || "/api/v1/upload/preview", _list, { ...axiosConf })
|
|
166
|
-
.then((res) => {
|
|
167
|
-
if (res?.data?.code == 200) {
|
|
168
|
-
resolve(res?.data?.data);
|
|
169
|
-
} else {
|
|
170
|
-
reject(res);
|
|
171
|
-
}
|
|
172
|
-
return res;
|
|
173
|
-
})
|
|
174
|
-
.catch((err) => {
|
|
175
|
-
console.error("offline upload err", err);
|
|
176
|
-
reject(err);
|
|
177
|
-
return Promise.reject(err);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 获取预览地址
|
|
184
|
-
* @param url
|
|
185
|
-
* @param opt
|
|
186
|
-
* @returns
|
|
187
|
-
*/
|
|
188
|
-
export const getPreviewUrl = function (url, opt: IGetPreviewUrlsOpt = {}) {
|
|
189
|
-
return new Promise(async (resolve, reject) => {
|
|
190
|
-
const { axios: _ax = axios, axiosConf, previewUrl } = opt || {};
|
|
191
|
-
|
|
192
|
-
const _axios = _ax;
|
|
193
|
-
|
|
194
|
-
return _axios
|
|
195
|
-
.post(previewUrl || "/api/v1/upload/preview", [url], { ...axiosConf })
|
|
196
|
-
.then((res) => {
|
|
197
|
-
if (res?.data?.code == 200) {
|
|
198
|
-
resolve(res?.data?.data?.[0]);
|
|
199
|
-
} else {
|
|
200
|
-
reject(res);
|
|
201
|
-
}
|
|
202
|
-
return res;
|
|
203
|
-
})
|
|
204
|
-
.catch((err) => {
|
|
205
|
-
console.error("offline upload err", err);
|
|
206
|
-
reject(err);
|
|
207
|
-
return Promise.reject(err);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* 私有部署版文件上传
|
|
214
|
-
*/
|
|
215
|
-
export class OfflineUpload {
|
|
216
|
-
axios;
|
|
217
|
-
axiosConf;
|
|
218
|
-
serverUrl;
|
|
219
|
-
signatureParams;
|
|
220
|
-
constructor(props: IOfflineUploadProps = {}) {
|
|
221
|
-
this.axios = props.axios || axios;
|
|
222
|
-
this.axiosConf = props.axiosConf || {};
|
|
223
|
-
this.serverUrl = props.serverUrl || "/api/v1/upload/init";
|
|
224
|
-
this.signatureParams = props.signatureParams || {};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
getSignature(serverUrl = this.serverUrl, opt) {
|
|
228
|
-
// path 前缀 oss-upload 文件目录
|
|
229
|
-
opt.params.path = mergeDirStr("web-upload/", opt.params.path ?? opt.params.dir);
|
|
230
|
-
return getSignature({
|
|
231
|
-
...opt,
|
|
232
|
-
serverUrl,
|
|
233
|
-
axios: opt?.axios || this.axios,
|
|
234
|
-
axiosConf: { ...this.axiosConf, ...opt?.axiosConf },
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
upload(file, opt: IUploadOpt = {}) {
|
|
239
|
-
return new Promise(async (resolve, reject) => {
|
|
240
|
-
// filename 表示待上传的本地文件名称。
|
|
241
|
-
const filename = getFileNameByFileObj(file, opt);
|
|
242
|
-
try {
|
|
243
|
-
const fileInfo = await this.getSignature(opt.serverUrl || this.serverUrl, {
|
|
244
|
-
...opt,
|
|
245
|
-
params: {
|
|
246
|
-
/** 最终保存的文件名称(不传默认文件名) */
|
|
247
|
-
filename,
|
|
248
|
-
/** 存储路径(不传默认基础路径) */
|
|
249
|
-
path: opt.params?.dir || this.signatureParams?.dir,
|
|
250
|
-
/** 文件存储平台(1、s3,2、本地存储,3、FTP,默认s3) */
|
|
251
|
-
platformCode: undefined,
|
|
252
|
-
...this.signatureParams,
|
|
253
|
-
...opt.params,
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
const { uploadUrl, ossParams: propOssParams } = opt || {};
|
|
257
|
-
const formData = new FormData();
|
|
258
|
-
formData.set("fileInfo", fileInfo);
|
|
259
|
-
formData.set("file", file);
|
|
260
|
-
|
|
261
|
-
if (propOssParams) {
|
|
262
|
-
for (const key in propOssParams) {
|
|
263
|
-
if (Object.hasOwnProperty.call(propOssParams, key)) {
|
|
264
|
-
formData.set(key, propOssParams[key]);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const _axios = opt?.axios || this.axios;
|
|
270
|
-
|
|
271
|
-
return _axios
|
|
272
|
-
.post(uploadUrl || "/api/v1/upload/execute", formData, { ...this.axiosConf, ...opt?.axiosConf })
|
|
273
|
-
.then((res) => {
|
|
274
|
-
if (res?.data?.code == 200) {
|
|
275
|
-
resolve(res?.data?.data);
|
|
276
|
-
} else {
|
|
277
|
-
reject(res);
|
|
278
|
-
}
|
|
279
|
-
return res;
|
|
280
|
-
})
|
|
281
|
-
.catch((err) => {
|
|
282
|
-
console.error("offline upload err", err);
|
|
283
|
-
reject(err);
|
|
284
|
-
return Promise.reject(err);
|
|
285
|
-
});
|
|
286
|
-
} catch (error) {
|
|
287
|
-
reject(error);
|
|
288
|
-
return Promise.reject(error);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* 获取预览地址
|
|
295
|
-
* @param urlList
|
|
296
|
-
* @param opt
|
|
297
|
-
* @returns
|
|
298
|
-
*/
|
|
299
|
-
getPreviewUrls(urlList, opt) {
|
|
300
|
-
return getPreviewUrls(urlList, {
|
|
301
|
-
...opt,
|
|
302
|
-
axios: opt?.axios || this.axios,
|
|
303
|
-
axiosConf: { ...this.axiosConf, ...opt?.axiosConf },
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* 批量处理预览地址
|
|
310
|
-
* @param fileList
|
|
311
|
-
* @param opt
|
|
312
|
-
* @returns
|
|
313
|
-
*/
|
|
314
|
-
export const handlePreviewUrls = async function (fileList, opt: IGetPreviewUrlsOpt) {
|
|
315
|
-
const res = await getPreviewUrls(
|
|
316
|
-
fileList?.map((it) => it.storeUrl || it.url),
|
|
317
|
-
{
|
|
318
|
-
...opt,
|
|
319
|
-
},
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
fileList.forEach((it, i) => {
|
|
323
|
-
// TODO: storeUrl 来源于【本地 url 直接使用预览地址,解决 previewFile 无法正常使用 previewUrl 的问题】
|
|
324
|
-
if (!it.storeUrl) {
|
|
325
|
-
it.storeUrl = it.url;
|
|
326
|
-
}
|
|
327
|
-
// TODO: 本地 url 直接使用预览地址,解决 previewFile 无法正常使用 previewUrl 的问题
|
|
328
|
-
it.url = res[i].presignedUrl;
|
|
329
|
-
|
|
330
|
-
// 常规预览地址写法
|
|
331
|
-
it.previewUrl = res[i].presignedUrl;
|
|
332
|
-
if (it.uploadInfo) {
|
|
333
|
-
it.uploadInfo.previewUrl = it.previewUrl;
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
return fileList;
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
export default OfflineUpload;
|
|
1
|
+
import { axios } from "@hzab/data-model";
|
|
2
|
+
|
|
3
|
+
import { getFileNameByFileObj } from "./fileName";
|
|
4
|
+
import { formatDirStr, mergeDirStr } from "./utils";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 获取上传相关配置入参
|
|
8
|
+
*/
|
|
9
|
+
export interface IGetSignatureOpt {
|
|
10
|
+
/**
|
|
11
|
+
* 配置接口地址
|
|
12
|
+
*/
|
|
13
|
+
serverUrl?: string;
|
|
14
|
+
/**
|
|
15
|
+
* axios 实例
|
|
16
|
+
*/
|
|
17
|
+
axios?: Object;
|
|
18
|
+
/**
|
|
19
|
+
* axios 配置
|
|
20
|
+
*/
|
|
21
|
+
axiosConf?: Object;
|
|
22
|
+
/**
|
|
23
|
+
* 请求入参
|
|
24
|
+
*/
|
|
25
|
+
params?: {
|
|
26
|
+
path?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IOfflineUploadProps {
|
|
31
|
+
/**
|
|
32
|
+
* axios 实例
|
|
33
|
+
*/
|
|
34
|
+
axios?: Object;
|
|
35
|
+
/**
|
|
36
|
+
* axios 配置
|
|
37
|
+
*/
|
|
38
|
+
axiosConf?: Object;
|
|
39
|
+
/**
|
|
40
|
+
* 配置接口地址
|
|
41
|
+
*/
|
|
42
|
+
serverUrl?: string;
|
|
43
|
+
/**
|
|
44
|
+
* 获取配置接口请求入参
|
|
45
|
+
*/
|
|
46
|
+
signatureParams?: {
|
|
47
|
+
path?: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 文件上传入参
|
|
53
|
+
*/
|
|
54
|
+
export interface IUploadOpt {
|
|
55
|
+
/**
|
|
56
|
+
* 配置接口地址
|
|
57
|
+
*/
|
|
58
|
+
serverUrl?: string;
|
|
59
|
+
/**
|
|
60
|
+
* 是否开启 Hash 命名
|
|
61
|
+
*/
|
|
62
|
+
useHashName?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* 文件上传接口地址
|
|
65
|
+
*/
|
|
66
|
+
uploadUrl?: string;
|
|
67
|
+
/**
|
|
68
|
+
* 获取配置接口请求入参
|
|
69
|
+
*/
|
|
70
|
+
params?: {
|
|
71
|
+
path?: string;
|
|
72
|
+
// 兼容 老数据
|
|
73
|
+
dir?: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* 文件上传请求入参
|
|
77
|
+
*/
|
|
78
|
+
ossParams?: {
|
|
79
|
+
path?: string;
|
|
80
|
+
// 兼容 老数据
|
|
81
|
+
dir?: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* axios 实例
|
|
85
|
+
*/
|
|
86
|
+
axios?: Object;
|
|
87
|
+
/**
|
|
88
|
+
* axios 配置
|
|
89
|
+
*/
|
|
90
|
+
axiosConf?: Object;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 获取上传配置
|
|
95
|
+
* @param opt
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
export function getSignature(opt: IGetSignatureOpt = {}) {
|
|
99
|
+
const { serverUrl = "/api/v1/upload/init" } = opt;
|
|
100
|
+
// 减 10 秒,避免发起请求时 刚好过期的情况
|
|
101
|
+
const { axios: _ax = axios, params = {}, axiosConf } = opt;
|
|
102
|
+
if (
|
|
103
|
+
window._$offlineSignatureRes &&
|
|
104
|
+
window._$offlineSignatureRes.data &&
|
|
105
|
+
serverUrl + JSON.stringify(params) === window._$offlineSignatureRes.serverUrlParams &&
|
|
106
|
+
Date.now() - window._$offlineSignatureRes.__saveTime < window._$offlineSignatureRes.expireTimeMillis - 10000
|
|
107
|
+
) {
|
|
108
|
+
return Promise.resolve(window._$offlineSignatureRes.data);
|
|
109
|
+
}
|
|
110
|
+
// 处理 path 格式,必须为非 / 开头, / 结尾。如: test/
|
|
111
|
+
params.path = formatDirStr(params.path);
|
|
112
|
+
|
|
113
|
+
return _ax
|
|
114
|
+
.post(
|
|
115
|
+
serverUrl,
|
|
116
|
+
{
|
|
117
|
+
...params,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
...axiosConf,
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
.then((res) => {
|
|
124
|
+
if (res?.data?.code === 500) {
|
|
125
|
+
return Promise.reject(res.data);
|
|
126
|
+
}
|
|
127
|
+
if (res?.data?.code === 200) {
|
|
128
|
+
window._$offlineSignatureRes = {
|
|
129
|
+
data: res?.data?.data,
|
|
130
|
+
};
|
|
131
|
+
if (window._$offlineSignatureRes) {
|
|
132
|
+
window._$offlineSignatureRes.__saveTime = Date.now();
|
|
133
|
+
window._$offlineSignatureRes.serverUrlParams = serverUrl + JSON.stringify(params);
|
|
134
|
+
}
|
|
135
|
+
return window._$offlineSignatureRes.data;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface IGetPreviewUrlsOpt {
|
|
141
|
+
previewUrl?: string;
|
|
142
|
+
params?: Object;
|
|
143
|
+
axios?: Object;
|
|
144
|
+
axiosConf?: Object;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 获取预览地址-批量
|
|
149
|
+
* @param urlList
|
|
150
|
+
* @param opt
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
export const getPreviewUrls = function (urlList, opt: IGetPreviewUrlsOpt = {}) {
|
|
154
|
+
return new Promise(async (resolve, reject) => {
|
|
155
|
+
const { axios: _ax = axios, axiosConf, previewUrl } = opt || {};
|
|
156
|
+
|
|
157
|
+
const _axios = _ax;
|
|
158
|
+
|
|
159
|
+
let _list = urlList;
|
|
160
|
+
if (_list && !Array.isArray(_list)) {
|
|
161
|
+
_list = [_list];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return _axios
|
|
165
|
+
.post(previewUrl || "/api/v1/upload/preview", _list, { ...axiosConf })
|
|
166
|
+
.then((res) => {
|
|
167
|
+
if (res?.data?.code == 200) {
|
|
168
|
+
resolve(res?.data?.data);
|
|
169
|
+
} else {
|
|
170
|
+
reject(res);
|
|
171
|
+
}
|
|
172
|
+
return res;
|
|
173
|
+
})
|
|
174
|
+
.catch((err) => {
|
|
175
|
+
console.error("offline upload err", err);
|
|
176
|
+
reject(err);
|
|
177
|
+
return Promise.reject(err);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 获取预览地址
|
|
184
|
+
* @param url
|
|
185
|
+
* @param opt
|
|
186
|
+
* @returns
|
|
187
|
+
*/
|
|
188
|
+
export const getPreviewUrl = function (url, opt: IGetPreviewUrlsOpt = {}) {
|
|
189
|
+
return new Promise(async (resolve, reject) => {
|
|
190
|
+
const { axios: _ax = axios, axiosConf, previewUrl } = opt || {};
|
|
191
|
+
|
|
192
|
+
const _axios = _ax;
|
|
193
|
+
|
|
194
|
+
return _axios
|
|
195
|
+
.post(previewUrl || "/api/v1/upload/preview", [url], { ...axiosConf })
|
|
196
|
+
.then((res) => {
|
|
197
|
+
if (res?.data?.code == 200) {
|
|
198
|
+
resolve(res?.data?.data?.[0]);
|
|
199
|
+
} else {
|
|
200
|
+
reject(res);
|
|
201
|
+
}
|
|
202
|
+
return res;
|
|
203
|
+
})
|
|
204
|
+
.catch((err) => {
|
|
205
|
+
console.error("offline upload err", err);
|
|
206
|
+
reject(err);
|
|
207
|
+
return Promise.reject(err);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 私有部署版文件上传
|
|
214
|
+
*/
|
|
215
|
+
export class OfflineUpload {
|
|
216
|
+
axios;
|
|
217
|
+
axiosConf;
|
|
218
|
+
serverUrl;
|
|
219
|
+
signatureParams;
|
|
220
|
+
constructor(props: IOfflineUploadProps = {}) {
|
|
221
|
+
this.axios = props.axios || axios;
|
|
222
|
+
this.axiosConf = props.axiosConf || {};
|
|
223
|
+
this.serverUrl = props.serverUrl || "/api/v1/upload/init";
|
|
224
|
+
this.signatureParams = props.signatureParams || {};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
getSignature(serverUrl = this.serverUrl, opt) {
|
|
228
|
+
// path 前缀 oss-upload 文件目录
|
|
229
|
+
opt.params.path = mergeDirStr("web-upload/", opt.params.path ?? opt.params.dir);
|
|
230
|
+
return getSignature({
|
|
231
|
+
...opt,
|
|
232
|
+
serverUrl,
|
|
233
|
+
axios: opt?.axios || this.axios,
|
|
234
|
+
axiosConf: { ...this.axiosConf, ...opt?.axiosConf },
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
upload(file, opt: IUploadOpt = {}) {
|
|
239
|
+
return new Promise(async (resolve, reject) => {
|
|
240
|
+
// filename 表示待上传的本地文件名称。
|
|
241
|
+
const filename = getFileNameByFileObj(file, opt);
|
|
242
|
+
try {
|
|
243
|
+
const fileInfo = await this.getSignature(opt.serverUrl || this.serverUrl, {
|
|
244
|
+
...opt,
|
|
245
|
+
params: {
|
|
246
|
+
/** 最终保存的文件名称(不传默认文件名) */
|
|
247
|
+
filename,
|
|
248
|
+
/** 存储路径(不传默认基础路径) */
|
|
249
|
+
path: opt.params?.dir || this.signatureParams?.dir,
|
|
250
|
+
/** 文件存储平台(1、s3,2、本地存储,3、FTP,默认s3) */
|
|
251
|
+
platformCode: undefined,
|
|
252
|
+
...this.signatureParams,
|
|
253
|
+
...opt.params,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
const { uploadUrl, ossParams: propOssParams } = opt || {};
|
|
257
|
+
const formData = new FormData();
|
|
258
|
+
formData.set("fileInfo", fileInfo);
|
|
259
|
+
formData.set("file", file);
|
|
260
|
+
|
|
261
|
+
if (propOssParams) {
|
|
262
|
+
for (const key in propOssParams) {
|
|
263
|
+
if (Object.hasOwnProperty.call(propOssParams, key)) {
|
|
264
|
+
formData.set(key, propOssParams[key]);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const _axios = opt?.axios || this.axios;
|
|
270
|
+
|
|
271
|
+
return _axios
|
|
272
|
+
.post(uploadUrl || "/api/v1/upload/execute", formData, { ...this.axiosConf, ...opt?.axiosConf })
|
|
273
|
+
.then((res) => {
|
|
274
|
+
if (res?.data?.code == 200) {
|
|
275
|
+
resolve(res?.data?.data);
|
|
276
|
+
} else {
|
|
277
|
+
reject(res);
|
|
278
|
+
}
|
|
279
|
+
return res;
|
|
280
|
+
})
|
|
281
|
+
.catch((err) => {
|
|
282
|
+
console.error("offline upload err", err);
|
|
283
|
+
reject(err);
|
|
284
|
+
return Promise.reject(err);
|
|
285
|
+
});
|
|
286
|
+
} catch (error) {
|
|
287
|
+
reject(error);
|
|
288
|
+
return Promise.reject(error);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* 获取预览地址
|
|
295
|
+
* @param urlList
|
|
296
|
+
* @param opt
|
|
297
|
+
* @returns
|
|
298
|
+
*/
|
|
299
|
+
getPreviewUrls(urlList, opt) {
|
|
300
|
+
return getPreviewUrls(urlList, {
|
|
301
|
+
...opt,
|
|
302
|
+
axios: opt?.axios || this.axios,
|
|
303
|
+
axiosConf: { ...this.axiosConf, ...opt?.axiosConf },
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 批量处理预览地址
|
|
310
|
+
* @param fileList
|
|
311
|
+
* @param opt
|
|
312
|
+
* @returns
|
|
313
|
+
*/
|
|
314
|
+
export const handlePreviewUrls = async function (fileList, opt: IGetPreviewUrlsOpt) {
|
|
315
|
+
const res = await getPreviewUrls(
|
|
316
|
+
fileList?.map((it) => it.storeUrl || it.url),
|
|
317
|
+
{
|
|
318
|
+
...opt,
|
|
319
|
+
},
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
fileList.forEach((it, i) => {
|
|
323
|
+
// TODO: storeUrl 来源于【本地 url 直接使用预览地址,解决 previewFile 无法正常使用 previewUrl 的问题】
|
|
324
|
+
if (!it.storeUrl) {
|
|
325
|
+
it.storeUrl = it.url;
|
|
326
|
+
}
|
|
327
|
+
// TODO: 本地 url 直接使用预览地址,解决 previewFile 无法正常使用 previewUrl 的问题
|
|
328
|
+
it.url = res[i].presignedUrl;
|
|
329
|
+
|
|
330
|
+
// 常规预览地址写法
|
|
331
|
+
it.previewUrl = res[i].presignedUrl;
|
|
332
|
+
if (it.uploadInfo) {
|
|
333
|
+
it.uploadInfo.previewUrl = it.previewUrl;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
return fileList;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
export default OfflineUpload;
|