cloud-web-corejs 1.0.325 → 1.0.328
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 -1
- package/src/app-bootstrap.js +4 -0
- package/src/app-bootstrap.sync.js +4 -0
- package/src/components/baseAutocomplete/README.md +157 -0
- package/src/components/baseAutocomplete/index.vue +489 -0
- package/src/components/baseAutocomplete/query.js +36 -0
- package/src/components/xform/form-designer/form-widget/field-widget/autocomplete-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/cascader-widget.vue +403 -10
- package/src/components/xform/form-designer/form-widget/field-widget/fieldMixin.js +6 -0
- package/src/components/xform/form-designer/form-widget/field-widget/vabUpload2-widget.vue +411 -112
- package/src/components/xform/form-designer/setting-panel/indexMixin.js +52 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/event-handler/onClear-editor.vue +30 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/event-handler/onLazyLoad-editor.vue +34 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/field-cascader/cascader-lazy-editor.vue +108 -0
- package/src/components/xform/form-designer/setting-panel/propertyRegister.js +3 -0
- package/src/components/xform/form-designer/widget-panel/widgetsConfig.js +7 -0
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
tabindex="0"
|
|
78
78
|
></i>
|
|
79
79
|
</div>
|
|
80
|
-
<div class="el-icon-tagEdit">
|
|
80
|
+
<div class="el-icon-tagEdit" v-if="field.options.showDownload !== false">
|
|
81
81
|
<el-tooltip
|
|
82
82
|
class="item"
|
|
83
83
|
effect="dark"
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
</div>
|
|
94
94
|
</div>
|
|
95
95
|
<div
|
|
96
|
-
v-if="!field.options.disabled"
|
|
96
|
+
v-if="!field.options.disabled && showUploadBtn"
|
|
97
97
|
class="el-upload el-upload--picture"
|
|
98
98
|
style="vertical-align: middle; display: inline-block; float: left"
|
|
99
99
|
>
|
|
@@ -102,7 +102,9 @@
|
|
|
102
102
|
class="upload-demo"
|
|
103
103
|
action="https://jsonplaceholder.typicode.com/posts/"
|
|
104
104
|
:http-request="uploadSectionFile"
|
|
105
|
-
:
|
|
105
|
+
:multiple="isMulti"
|
|
106
|
+
:limit="pickLimit"
|
|
107
|
+
:on-exceed="handleUploadExceed"
|
|
106
108
|
>
|
|
107
109
|
<button type="button" class="avatar-uploader">
|
|
108
110
|
<i class="el-icon-plus avatar-uploader-icon"></i>
|
|
@@ -126,6 +128,126 @@ import FormItemWrapper from "./form-item-wrapper";
|
|
|
126
128
|
import emitter from "../../../../../components/xform/utils/emitter";
|
|
127
129
|
import i18n from "../../../../../components/xform/utils/i18n";
|
|
128
130
|
import fieldMixin from "../../../../../components/xform/form-designer/form-widget/field-widget/fieldMixin";
|
|
131
|
+
import settingConfig from "@/settings.js";
|
|
132
|
+
|
|
133
|
+
const SINGLE_UPLOAD_API = "/api/v1.0/FileOperation/UploadFilesFromPortal";
|
|
134
|
+
const BATCH_UPLOAD_API = "/api/v1.0/FileOperation/BatchUploadFilesFromPortal";
|
|
135
|
+
/** 全部处理完显示 100 后,再停一会儿关闭加载。 */
|
|
136
|
+
const HX_UPLOAD_DONE_DELAY = 200;
|
|
137
|
+
|
|
138
|
+
function parseJsonValue(value) {
|
|
139
|
+
if (value == null || value === "") return null;
|
|
140
|
+
if (typeof value === "object") return value;
|
|
141
|
+
if (typeof value !== "string") return null;
|
|
142
|
+
try {
|
|
143
|
+
return JSON.parse(value);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 单文件用 UploadFilesFromPortal,多文件用 BatchUploadFilesFromPortal。
|
|
151
|
+
* 配置只返回其中一个时,按名称推出另一个,不互相覆盖。
|
|
152
|
+
*/
|
|
153
|
+
function resolveHisenseUploadUrls(domain, uploadApi) {
|
|
154
|
+
const api = uploadApi || "";
|
|
155
|
+
const base = domain || "";
|
|
156
|
+
const isBatch = /BatchUploadFilesFromPortal/i.test(api);
|
|
157
|
+
const isSingle = !isBatch && /UploadFilesFromPortal/i.test(api);
|
|
158
|
+
let singleApi = api;
|
|
159
|
+
let batchApi = api;
|
|
160
|
+
if (isBatch) {
|
|
161
|
+
singleApi = api.replace(/BatchUploadFilesFromPortal/i, "UploadFilesFromPortal");
|
|
162
|
+
} else if (isSingle) {
|
|
163
|
+
batchApi = api.replace(/UploadFilesFromPortal/i, "BatchUploadFilesFromPortal");
|
|
164
|
+
} else if (!api) {
|
|
165
|
+
singleApi = SINGLE_UPLOAD_API;
|
|
166
|
+
batchApi = BATCH_UPLOAD_API;
|
|
167
|
+
} else {
|
|
168
|
+
batchApi = BATCH_UPLOAD_API;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
singleUploadUrl: base + singleApi,
|
|
172
|
+
batchUploadUrl: base + batchApi,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** settings.hxFileLocalProxyEnabled 打开且处于 npm run dev 时,把海信绝对地址改写到本地 /hx-file。 */
|
|
177
|
+
function toDevProxyUrl(absoluteUrl) {
|
|
178
|
+
if (settingConfig.hxFileLocalProxyEnabled !== true) return absoluteUrl;
|
|
179
|
+
if (process.env.NODE_ENV !== "development") return absoluteUrl;
|
|
180
|
+
if (typeof window === "undefined" || !absoluteUrl) return absoluteUrl;
|
|
181
|
+
if (!/^https?:\/\//i.test(absoluteUrl)) return absoluteUrl;
|
|
182
|
+
try {
|
|
183
|
+
const parsed = new URL(absoluteUrl);
|
|
184
|
+
return (
|
|
185
|
+
window.location.origin +
|
|
186
|
+
"/hx-file/" +
|
|
187
|
+
parsed.host +
|
|
188
|
+
parsed.pathname +
|
|
189
|
+
parsed.search
|
|
190
|
+
);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
return absoluteUrl;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 单上传 data 是一个文件对象。
|
|
198
|
+
* 批量上传外层 code=1000 只表示批次受理,再看每条明细的 code;外层非 1000 整批失败。
|
|
199
|
+
*/
|
|
200
|
+
function adaptHisenseBatchUploadResponse(responseData) {
|
|
201
|
+
const body = responseData || {};
|
|
202
|
+
const outerCode = Number(body.code);
|
|
203
|
+
const fail = (message) => ({
|
|
204
|
+
success: false,
|
|
205
|
+
message: message || "上传失败",
|
|
206
|
+
fullResponse: body,
|
|
207
|
+
data: null,
|
|
208
|
+
files: [],
|
|
209
|
+
});
|
|
210
|
+
if (outerCode !== 1000) {
|
|
211
|
+
return fail(body.message);
|
|
212
|
+
}
|
|
213
|
+
const parsed = parseJsonValue(body.data);
|
|
214
|
+
if (parsed && !Array.isArray(parsed) && parsed.filename) {
|
|
215
|
+
return {
|
|
216
|
+
success: true,
|
|
217
|
+
message: body.message || "ok",
|
|
218
|
+
fullResponse: body,
|
|
219
|
+
data: parsed,
|
|
220
|
+
files: [parsed],
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (!Array.isArray(parsed) || !parsed.length) {
|
|
224
|
+
return fail(body.message);
|
|
225
|
+
}
|
|
226
|
+
const files = [];
|
|
227
|
+
const errors = [];
|
|
228
|
+
parsed.forEach((item) => {
|
|
229
|
+
if (Number(item && item.code) !== 1000) {
|
|
230
|
+
errors.push((item && item.message) || body.message || "上传失败");
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const fileInfo = parseJsonValue(item.data);
|
|
234
|
+
if (!fileInfo) {
|
|
235
|
+
errors.push((item && item.message) || body.message || "上传失败");
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
files.push(fileInfo);
|
|
239
|
+
});
|
|
240
|
+
if (!files.length) {
|
|
241
|
+
return fail(errors.filter(Boolean).join(";") || body.message);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
success: errors.length === 0,
|
|
245
|
+
message: errors.filter(Boolean).join(";") || "ok",
|
|
246
|
+
fullResponse: body,
|
|
247
|
+
data: files[0],
|
|
248
|
+
files,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
129
251
|
|
|
130
252
|
export default {
|
|
131
253
|
name: "vabUpload2-widget",
|
|
@@ -157,25 +279,7 @@ export default {
|
|
|
157
279
|
},
|
|
158
280
|
responseAdapter: {
|
|
159
281
|
type: Function,
|
|
160
|
-
default
|
|
161
|
-
// 默认适配器:假设返回格式为
|
|
162
|
-
/* {
|
|
163
|
-
"code": 1000,
|
|
164
|
-
"message": "ok",
|
|
165
|
-
"data": "{\"name\":\"8aafaaad-f033-4f46-a8f3-fe2639204f6a-source.jpg\",\"size\":186847,\"date\":1754711199966,\"id\":\"f3056c29-f65a-4d1b-8778-c2df5fa53775\",\"filename\":\"f3056c29-f65a-4d1b-8778-c2df5fa53775.jpg\",\"user\":\"1\",\"type\":\"工单\",\"url\":\"\"}"
|
|
166
|
-
} */
|
|
167
|
-
let data = null;
|
|
168
|
-
if (responseData.code === 1000 && responseData.data) {
|
|
169
|
-
data = JSON.parse(responseData.data);
|
|
170
|
-
}
|
|
171
|
-
return {
|
|
172
|
-
success: responseData.code === 1000,
|
|
173
|
-
// url: responseData.objx?.url,
|
|
174
|
-
message: responseData.message || "success",
|
|
175
|
-
fullResponse: responseData,
|
|
176
|
-
data: data,
|
|
177
|
-
};
|
|
178
|
-
},
|
|
282
|
+
default: adaptHisenseBatchUploadResponse,
|
|
179
283
|
},
|
|
180
284
|
},
|
|
181
285
|
components: {
|
|
@@ -191,6 +295,8 @@ export default {
|
|
|
191
295
|
isH5: false,
|
|
192
296
|
|
|
193
297
|
uploadUrl: null,
|
|
298
|
+
singleUploadUrl: null,
|
|
299
|
+
batchUploadUrl: null,
|
|
194
300
|
|
|
195
301
|
token: null,
|
|
196
302
|
deleteUrl: null,
|
|
@@ -201,6 +307,7 @@ export default {
|
|
|
201
307
|
showViewer: false,
|
|
202
308
|
ownedBlobUrls: [],
|
|
203
309
|
componentDestroyed: false,
|
|
310
|
+
uploadingCount: 0,
|
|
204
311
|
};
|
|
205
312
|
},
|
|
206
313
|
watch: {
|
|
@@ -213,6 +320,33 @@ export default {
|
|
|
213
320
|
let formRef = this.getFormRef();
|
|
214
321
|
return formRef.dataId;
|
|
215
322
|
},
|
|
323
|
+
/* 与 baseUpload 一致:空 / 0 不限制,1 为单文件,大于 1 为上限 */
|
|
324
|
+
uploadLimit() {
|
|
325
|
+
let limit = this.field.options.limit;
|
|
326
|
+
if (limit === null || limit === undefined || limit === "") return null;
|
|
327
|
+
let num = Number(limit);
|
|
328
|
+
return num > 0 ? num : null;
|
|
329
|
+
},
|
|
330
|
+
isMulti() {
|
|
331
|
+
return this.uploadLimit !== 1;
|
|
332
|
+
},
|
|
333
|
+
attachmentCount() {
|
|
334
|
+
return Array.isArray(this.fieldModel) ? this.fieldModel.length : 0;
|
|
335
|
+
},
|
|
336
|
+
showUploadBtn() {
|
|
337
|
+
let size = this.attachmentCount + this.uploadingCount;
|
|
338
|
+
if (!this.isMulti) {
|
|
339
|
+
return size === 0;
|
|
340
|
+
}
|
|
341
|
+
return this.uploadLimit ? this.uploadLimit > size : true;
|
|
342
|
+
},
|
|
343
|
+
/* 单文件限 1;有上限时限剩余名额;不限制时不传 limit,文件框可多选 */
|
|
344
|
+
pickLimit() {
|
|
345
|
+
if (!this.isMulti) return 1;
|
|
346
|
+
if (!this.uploadLimit) return undefined;
|
|
347
|
+
let remain = this.uploadLimit - this.attachmentCount - this.uploadingCount;
|
|
348
|
+
return remain > 0 ? remain : 1;
|
|
349
|
+
},
|
|
216
350
|
},
|
|
217
351
|
beforeCreate() {
|
|
218
352
|
/* 这里不能访问方法和属性!! */
|
|
@@ -239,6 +373,7 @@ export default {
|
|
|
239
373
|
|
|
240
374
|
beforeDestroy() {
|
|
241
375
|
this.componentDestroyed = true;
|
|
376
|
+
this.closeHxUploadLoading();
|
|
242
377
|
this.revokeOwnedBlobUrls();
|
|
243
378
|
this.unregisterFromRefList();
|
|
244
379
|
},
|
|
@@ -425,10 +560,13 @@ export default {
|
|
|
425
560
|
let token = objx.apiToken;
|
|
426
561
|
if (token) {
|
|
427
562
|
this.token = token;
|
|
428
|
-
|
|
429
|
-
this.
|
|
563
|
+
const uploadUrls = resolveHisenseUploadUrls(objx.domain, objx.uploadApi);
|
|
564
|
+
this.singleUploadUrl = toDevProxyUrl(uploadUrls.singleUploadUrl);
|
|
565
|
+
this.batchUploadUrl = toDevProxyUrl(uploadUrls.batchUploadUrl);
|
|
566
|
+
this.uploadUrl = this.singleUploadUrl;
|
|
567
|
+
this.deleteUrl = toDevProxyUrl(objx.domain + objx.deleteApi);
|
|
430
568
|
// https://crm-dev.hisense.com/api/v1.0/fileoperation/GetFile?fileName=e24a1ad9-6821-41c3-957c-0916077bb97f.jpg
|
|
431
|
-
this.viewApiUrl = objx.domain + objx.viewApi;
|
|
569
|
+
this.viewApiUrl = toDevProxyUrl(objx.domain + objx.viewApi);
|
|
432
570
|
// this.initShowUrl();
|
|
433
571
|
// this.initCustomConfig();
|
|
434
572
|
}
|
|
@@ -480,114 +618,245 @@ export default {
|
|
|
480
618
|
Math.random() * 100000 + Math.random() * 20000 + Math.random() * 5000
|
|
481
619
|
);
|
|
482
620
|
},
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
let
|
|
499
|
-
|
|
500
|
-
var form = new FormData();
|
|
501
|
-
// 文件对象
|
|
502
|
-
form.append("file", fileObj);
|
|
503
|
-
|
|
504
|
-
let customParam = {};
|
|
505
|
-
let entityId = this.formDataId;
|
|
506
|
-
customParam = {
|
|
621
|
+
// 同一轮选择的文件先收齐:1 个走单上传,多个走一次批量上传
|
|
622
|
+
uploadSectionFile(param, isCustom, uploadConfig) {
|
|
623
|
+
if (!this.hxPendingUploads) {
|
|
624
|
+
this.hxPendingUploads = [];
|
|
625
|
+
}
|
|
626
|
+
this.hxPendingUploads.push({ param, isCustom, uploadConfig });
|
|
627
|
+
if (this.hxFlushScheduled) return;
|
|
628
|
+
this.hxFlushScheduled = true;
|
|
629
|
+
setTimeout(() => {
|
|
630
|
+
this.hxFlushScheduled = false;
|
|
631
|
+
const pending = this.hxPendingUploads.splice(0);
|
|
632
|
+
this.flushHxUpload(pending);
|
|
633
|
+
}, 0);
|
|
634
|
+
},
|
|
635
|
+
buildHxUploadParam(fileObj) {
|
|
636
|
+
let customParam = {
|
|
507
637
|
fileName: fileObj.name,
|
|
508
638
|
entityName: "msdyn_workorder",
|
|
509
|
-
entityId,
|
|
639
|
+
entityId: this.formDataId,
|
|
510
640
|
backendwriteback: "10",
|
|
511
641
|
fileCategory: "工单",
|
|
512
642
|
user: window.$vueRoot.$store.getters.nickName,
|
|
513
|
-
// user: "1",
|
|
514
643
|
};
|
|
515
644
|
let uploadParam =
|
|
516
645
|
this.handleCustomEvent(this.field.options.vabupload2_uploadParam) || {};
|
|
517
646
|
Object.assign(customParam, uploadParam);
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
647
|
+
return customParam;
|
|
648
|
+
},
|
|
649
|
+
appendHxUploadFields(form, fileObj, prefix) {
|
|
650
|
+
form.append(prefix ? prefix + "File" : "file", fileObj);
|
|
651
|
+
let customParam = this.buildHxUploadParam(fileObj);
|
|
652
|
+
Object.keys(customParam).forEach((key) => {
|
|
653
|
+
if (key === "file" || key === "File") return;
|
|
654
|
+
let fieldKey = prefix && key.indexOf("requests[") !== 0 ? prefix + key : key;
|
|
655
|
+
form.append(fieldKey, customParam[key]);
|
|
656
|
+
});
|
|
657
|
+
},
|
|
658
|
+
flushHxUpload(pending) {
|
|
659
|
+
if (!pending.length || this.componentDestroyed) return;
|
|
660
|
+
let isCustom = !!pending[0].isCustom;
|
|
661
|
+
let target = this.$refs.upload;
|
|
662
|
+
if (!isCustom && !this.showUploadBtn) {
|
|
663
|
+
target && target.clearFiles();
|
|
664
|
+
return;
|
|
523
665
|
}
|
|
666
|
+
target && target.clearFiles();
|
|
524
667
|
|
|
525
|
-
let
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
668
|
+
let fileObjs = pending.map((item) => item.param && item.param.file).filter(Boolean);
|
|
669
|
+
if (!isCustom && this.uploadLimit) {
|
|
670
|
+
let remain = this.uploadLimit - this.attachmentCount - this.uploadingCount;
|
|
671
|
+
if (remain <= 0) return;
|
|
672
|
+
fileObjs = fileObjs.slice(0, remain);
|
|
529
673
|
}
|
|
674
|
+
if (!fileObjs.length) return;
|
|
530
675
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
let config = {
|
|
538
|
-
useToken: false,
|
|
539
|
-
isLoading: true,
|
|
540
|
-
headers: {
|
|
541
|
-
"Content-Type": "multipart/form-data",
|
|
542
|
-
Authorization: `Bearer ${this.token}`,
|
|
543
|
-
},
|
|
544
|
-
/* cancelToken: new imFun.axios.CancelToken(function executor(c) {
|
|
545
|
-
if (!isCustom) {
|
|
546
|
-
abort = c;
|
|
547
|
-
if (file) file.abort = c;
|
|
548
|
-
}
|
|
549
|
-
}), */
|
|
550
|
-
onUploadProgress: (progressEvent) => {
|
|
551
|
-
if (isCustom || file) {
|
|
552
|
-
// progressEvent.loaded:已上传文件大小
|
|
553
|
-
// progressEvent.total:被上传文件的总大小
|
|
554
|
-
progressEvent.percent = Math.floor(
|
|
555
|
-
(progressEvent.loaded * 100) / progressEvent.total
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
},
|
|
559
|
-
failMsg: false,
|
|
560
|
-
}; //添加请求头
|
|
676
|
+
const batch = fileObjs.length > 1;
|
|
677
|
+
const uploadUrl = batch
|
|
678
|
+
? this.batchUploadUrl
|
|
679
|
+
: this.singleUploadUrl || this.uploadUrl;
|
|
680
|
+
if (!uploadUrl) return;
|
|
561
681
|
|
|
562
|
-
|
|
563
|
-
|
|
682
|
+
let customEnabled = this.customEnabled || false;
|
|
683
|
+
const form = new FormData();
|
|
684
|
+
fileObjs.forEach((fileObj, index) => {
|
|
685
|
+
this.appendHxUploadFields(form, fileObj, batch ? `requests[${index}].` : "");
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
let fileOrder = 0;
|
|
689
|
+
if (!isCustom) {
|
|
690
|
+
if (this.uploadingCount === 0) {
|
|
691
|
+
this.hxUploadTotal = 0;
|
|
692
|
+
this.openHxUploadLoading();
|
|
564
693
|
}
|
|
694
|
+
this.uploadingCount++;
|
|
695
|
+
this.hxUploadTotal++;
|
|
696
|
+
fileOrder = this.hxUploadTotal;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
let config = {
|
|
700
|
+
useToken: false,
|
|
701
|
+
isLoading: false,
|
|
702
|
+
headers: {
|
|
703
|
+
"Content-Type": "multipart/form-data",
|
|
704
|
+
Authorization: `Bearer ${this.token}`,
|
|
705
|
+
},
|
|
706
|
+
onUploadProgress: (progressEvent) => {
|
|
707
|
+
const percent = progressEvent.total
|
|
708
|
+
? Math.floor((progressEvent.loaded * 100) / progressEvent.total)
|
|
709
|
+
: 0;
|
|
710
|
+
if (!isCustom) {
|
|
711
|
+
this.setHxUploadProgress(fileOrder, percent);
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
failMsg: false,
|
|
715
|
+
};
|
|
565
716
|
|
|
566
|
-
|
|
717
|
+
if (customEnabled && config?.httpConfig) {
|
|
718
|
+
config = extendDeeply(config, config.httpConfig);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
this.enqueueHxUpload(() => {
|
|
722
|
+
if (this.componentDestroyed || !this.getFormRef()) {
|
|
723
|
+
this.finishHxUpload(!isCustom);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
if (!isCustom) {
|
|
727
|
+
this.setHxUploadProgress(fileOrder, 0);
|
|
728
|
+
}
|
|
729
|
+
let batchDone = false;
|
|
730
|
+
return this.getFormRef()
|
|
567
731
|
.$http.post(uploadUrl, form, config)
|
|
568
732
|
.then((res1) => {
|
|
569
|
-
|
|
733
|
+
if (this.componentDestroyed) return;
|
|
734
|
+
const isLast = !isCustom && this.uploadingCount <= 1;
|
|
735
|
+
if (isLast) {
|
|
736
|
+
this.setHxUploadPercentText(99);
|
|
737
|
+
}
|
|
738
|
+
pending.forEach((item) => {
|
|
739
|
+
item.uploadConfig &&
|
|
740
|
+
item.uploadConfig.callback &&
|
|
741
|
+
item.uploadConfig.callback(res1, item.param && item.param.file);
|
|
742
|
+
});
|
|
570
743
|
|
|
571
744
|
const adaptedResponse = this.responseAdapter(res1);
|
|
745
|
+
const files = Array.isArray(adaptedResponse.files)
|
|
746
|
+
? adaptedResponse.files
|
|
747
|
+
: adaptedResponse.data
|
|
748
|
+
? [adaptedResponse.data]
|
|
749
|
+
: [];
|
|
572
750
|
|
|
573
751
|
if (!isCustom) {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
// this.initShowUrl();
|
|
583
|
-
}
|
|
752
|
+
files.forEach((data) => {
|
|
753
|
+
this.appendUploadedFile({
|
|
754
|
+
...data,
|
|
755
|
+
showUrl: null,
|
|
756
|
+
});
|
|
757
|
+
});
|
|
758
|
+
if (files.length && adaptedResponse.success) {
|
|
759
|
+
batchDone = isLast;
|
|
584
760
|
} else {
|
|
585
|
-
|
|
586
|
-
|
|
761
|
+
if (isLast) {
|
|
762
|
+
this.closeHxUploadLoading();
|
|
763
|
+
}
|
|
764
|
+
if (adaptedResponse.message) {
|
|
765
|
+
this.$baseAlert(adaptedResponse.message);
|
|
766
|
+
}
|
|
587
767
|
}
|
|
588
768
|
}
|
|
769
|
+
})
|
|
770
|
+
.finally(() => {
|
|
771
|
+
return this.finishHxUpload(!isCustom, batchDone);
|
|
589
772
|
});
|
|
773
|
+
});
|
|
774
|
+
},
|
|
775
|
+
/**
|
|
776
|
+
* 同一控件内串行上传。上一次请求结束后立刻发下一次,
|
|
777
|
+
* 避免海信回写工单字段时后一次覆盖前一次。
|
|
778
|
+
*/
|
|
779
|
+
enqueueHxUpload(task) {
|
|
780
|
+
if (!this.hxUploadChain) {
|
|
781
|
+
this.hxUploadChain = Promise.resolve();
|
|
590
782
|
}
|
|
783
|
+
const scheduled = this.hxUploadChain.then(() => task());
|
|
784
|
+
this.hxUploadChain = scheduled.catch(() => {});
|
|
785
|
+
return scheduled;
|
|
786
|
+
},
|
|
787
|
+
openHxUploadLoading() {
|
|
788
|
+
if (this.hxUploadLoading) return;
|
|
789
|
+
this.hxUploadLoading = this.$baseLoading({
|
|
790
|
+
target: document.body,
|
|
791
|
+
background: "unset",
|
|
792
|
+
customClass: "hx-upload-loading",
|
|
793
|
+
text: "",
|
|
794
|
+
});
|
|
795
|
+
},
|
|
796
|
+
setHxUploadProgress(index, percent) {
|
|
797
|
+
if (!this.hxUploadLoading || typeof this.hxUploadLoading.setText !== "function") {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
const total = this.hxUploadTotal || 1;
|
|
801
|
+
const safePercent = Number.isFinite(percent) ? Math.min(percent, 98) : 0;
|
|
802
|
+
const text = total > 1 ? `${index}/${total}` : `${safePercent}%`;
|
|
803
|
+
this.hxUploadLoading.setText(text);
|
|
804
|
+
},
|
|
805
|
+
setHxUploadPercentText(percent) {
|
|
806
|
+
if (!this.hxUploadLoading || typeof this.hxUploadLoading.setText !== "function") {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
this.hxUploadLoading.setText(`${percent}%`);
|
|
810
|
+
},
|
|
811
|
+
closeHxUploadLoading() {
|
|
812
|
+
const loading = this.hxUploadLoading;
|
|
813
|
+
if (!loading) return;
|
|
814
|
+
this.hxUploadLoading = null;
|
|
815
|
+
loading.close();
|
|
816
|
+
},
|
|
817
|
+
finishHxUpload(counted, showDone) {
|
|
818
|
+
if (!counted) return;
|
|
819
|
+
this.uploadingCount = Math.max(0, this.uploadingCount - 1);
|
|
820
|
+
if (this.uploadingCount !== 0) return;
|
|
821
|
+
if (!showDone) {
|
|
822
|
+
this.closeHxUploadLoading();
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
this.setHxUploadPercentText(100);
|
|
826
|
+
return new Promise((resolve) => {
|
|
827
|
+
setTimeout(() => {
|
|
828
|
+
this.closeHxUploadLoading();
|
|
829
|
+
resolve();
|
|
830
|
+
}, HX_UPLOAD_DONE_DELAY);
|
|
831
|
+
});
|
|
832
|
+
},
|
|
833
|
+
handleUploadExceed(files) {
|
|
834
|
+
let limit = this.pickLimit || this.uploadLimit;
|
|
835
|
+
let errorMsg = this.$t1('当前限制选择 {p0} 个文件,本次选择了 {p1} 个文件', { p0: limit, p1: files.length });
|
|
836
|
+
this.$message({
|
|
837
|
+
message: this.$t2(errorMsg, "components.VabUpload.warnMsg2", {
|
|
838
|
+
limit,
|
|
839
|
+
size: files.length,
|
|
840
|
+
}),
|
|
841
|
+
type: "error",
|
|
842
|
+
duration: 5 * 1000,
|
|
843
|
+
});
|
|
844
|
+
},
|
|
845
|
+
appendUploadedFile(fileInfo) {
|
|
846
|
+
if (!Array.isArray(this.fieldModel)) {
|
|
847
|
+
this.fieldModel = [];
|
|
848
|
+
}
|
|
849
|
+
if (!this.isMulti) {
|
|
850
|
+
this.fieldModel.forEach((item) => {
|
|
851
|
+
this.revokeBlobUrl(item && (item.showUrl || item.url));
|
|
852
|
+
});
|
|
853
|
+
this.fieldModel = [fileInfo];
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
if (this.uploadLimit && this.fieldModel.length >= this.uploadLimit) {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
this.fieldModel.push(fileInfo);
|
|
591
860
|
},
|
|
592
861
|
initShowImageUrl(attachment, callback) {
|
|
593
862
|
let filename = attachment.filename;
|
|
@@ -674,41 +943,41 @@ export default {
|
|
|
674
943
|
throw new TypeError("输入必须是字符串格式");
|
|
675
944
|
}
|
|
676
945
|
if (!fileUrl.trim()) {
|
|
677
|
-
throw new Error(
|
|
946
|
+
throw new Error(this.$t1('URL不能为空'));
|
|
678
947
|
}
|
|
679
948
|
|
|
680
949
|
// 基本URL格式验证
|
|
681
950
|
const urlRegex = /^(https?:\/\/)?([\w.-]+)(:\d+)?(\/[^?#]*)?(\?[^#]*)?(#.*)?$/i;
|
|
682
951
|
if (!urlRegex.test(fileUrl)) {
|
|
683
|
-
throw new Error(
|
|
952
|
+
throw new Error(this.$t1('无效的URL格式'));
|
|
684
953
|
}
|
|
685
954
|
|
|
686
955
|
// 提取域名部分
|
|
687
956
|
const domainRegex = /^(https?:\/\/[^\/]+)/i;
|
|
688
957
|
const domainMatch = fileUrl.match(domainRegex);
|
|
689
958
|
if (!domainMatch) {
|
|
690
|
-
throw new Error(
|
|
959
|
+
throw new Error(this.$t1('URL缺少协议或域名部分'));
|
|
691
960
|
}
|
|
692
961
|
const domain = domainMatch[0];
|
|
693
962
|
|
|
694
963
|
// 提取完整路径
|
|
695
964
|
const url = fileUrl.substring(domain.length);
|
|
696
965
|
if (!url || url === "/") {
|
|
697
|
-
throw new Error(
|
|
966
|
+
throw new Error(this.$t1('URL缺少文件路径部分'));
|
|
698
967
|
}
|
|
699
968
|
|
|
700
969
|
// 提取带扩展名的文件名
|
|
701
970
|
const filenameRegex = /[^\/]+$/;
|
|
702
971
|
const filenameMatch = url.match(filenameRegex);
|
|
703
972
|
if (!filenameMatch) {
|
|
704
|
-
throw new Error(
|
|
973
|
+
throw new Error(this.$t1('无法从路径中提取文件名'));
|
|
705
974
|
}
|
|
706
975
|
const fullFilename = filenameMatch[0];
|
|
707
976
|
|
|
708
977
|
// 验证文件名格式(至少1字符+扩展名)
|
|
709
978
|
const nameFormat = /^.+\..+$/;
|
|
710
979
|
if (!nameFormat.test(fullFilename)) {
|
|
711
|
-
throw new Error(
|
|
980
|
+
throw new Error(this.$t1('无效的文件名格式: {p0}', { p0: fullFilename }));
|
|
712
981
|
}
|
|
713
982
|
|
|
714
983
|
// 修复点:更可靠的文件名和扩展名分离
|
|
@@ -775,3 +1044,33 @@ export default {
|
|
|
775
1044
|
}
|
|
776
1045
|
}
|
|
777
1046
|
</style>
|
|
1047
|
+
|
|
1048
|
+
<style lang="scss">
|
|
1049
|
+
/* 进度写在转圈中间。全局 spinner 被 zoom:2 放大,这里单独收回来,避免文字掉到圈外。 */
|
|
1050
|
+
body .el-loading-mask.hx-upload-loading .el-loading-spinner {
|
|
1051
|
+
zoom: 1;
|
|
1052
|
+
margin-top: -42px;
|
|
1053
|
+
|
|
1054
|
+
.circular {
|
|
1055
|
+
width: 84px;
|
|
1056
|
+
height: 84px;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
.el-loading-text {
|
|
1060
|
+
zoom: 1;
|
|
1061
|
+
position: absolute;
|
|
1062
|
+
left: 50%;
|
|
1063
|
+
top: 42px;
|
|
1064
|
+
width: 52px;
|
|
1065
|
+
margin: 0;
|
|
1066
|
+
padding: 0;
|
|
1067
|
+
transform: translate(-50%, -50%);
|
|
1068
|
+
font-size: 14px;
|
|
1069
|
+
line-height: 1;
|
|
1070
|
+
text-align: center;
|
|
1071
|
+
white-space: nowrap;
|
|
1072
|
+
overflow: hidden;
|
|
1073
|
+
color: #409eff;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
</style>
|