cloud-web-corejs 1.0.327 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloud-web-corejs",
3
3
  "private": false,
4
- "version": "1.0.327",
4
+ "version": "1.0.328",
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
7
7
  "check:package-resources": "node build/check-package-resources.js",
@@ -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"
@@ -130,6 +130,7 @@ import i18n from "../../../../../components/xform/utils/i18n";
130
130
  import fieldMixin from "../../../../../components/xform/form-designer/form-widget/field-widget/fieldMixin";
131
131
  import settingConfig from "@/settings.js";
132
132
 
133
+ const SINGLE_UPLOAD_API = "/api/v1.0/FileOperation/UploadFilesFromPortal";
133
134
  const BATCH_UPLOAD_API = "/api/v1.0/FileOperation/BatchUploadFilesFromPortal";
134
135
  /** 全部处理完显示 100 后,再停一会儿关闭加载。 */
135
136
  const HX_UPLOAD_DONE_DELAY = 200;
@@ -145,17 +146,31 @@ function parseJsonValue(value) {
145
146
  }
146
147
  }
147
148
 
148
- /** 配置仍返回旧地址时,换成批量上传;已是批量地址则原样使用。 */
149
- function resolveBatchUploadUrl(domain, uploadApi) {
150
- let api = uploadApi || "";
151
- if (!/BatchUploadFilesFromPortal/i.test(api)) {
152
- if (/UploadFilesFromPortal/i.test(api)) {
153
- api = api.replace(/UploadFilesFromPortal/i, "BatchUploadFilesFromPortal");
154
- } else {
155
- api = BATCH_UPLOAD_API;
156
- }
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;
157
169
  }
158
- return (domain || "") + api;
170
+ return {
171
+ singleUploadUrl: base + singleApi,
172
+ batchUploadUrl: base + batchApi,
173
+ };
159
174
  }
160
175
 
161
176
  /** settings.hxFileLocalProxyEnabled 打开且处于 npm run dev 时,把海信绝对地址改写到本地 /hx-file。 */
@@ -179,17 +194,18 @@ function toDevProxyUrl(absoluteUrl) {
179
194
  }
180
195
 
181
196
  /**
182
- * 批量接口一次只带一个文件(requests[0])。
183
- * 外层 code=1000 只表示批次受理,需看明细 code;外层 2020 视为整批失败。
197
+ * 单上传 data 是一个文件对象。
198
+ * 批量上传外层 code=1000 只表示批次受理,再看每条明细的 code;外层非 1000 整批失败。
184
199
  */
185
200
  function adaptHisenseBatchUploadResponse(responseData) {
186
201
  const body = responseData || {};
187
202
  const outerCode = Number(body.code);
188
203
  const fail = (message) => ({
189
204
  success: false,
190
- message: message || this.$t1('上传失败'),
205
+ message: message || "上传失败",
191
206
  fullResponse: body,
192
207
  data: null,
208
+ files: [],
193
209
  });
194
210
  if (outerCode !== 1000) {
195
211
  return fail(body.message);
@@ -201,24 +217,35 @@ function adaptHisenseBatchUploadResponse(responseData) {
201
217
  message: body.message || "ok",
202
218
  fullResponse: body,
203
219
  data: parsed,
220
+ files: [parsed],
204
221
  };
205
222
  }
206
223
  if (!Array.isArray(parsed) || !parsed.length) {
207
224
  return fail(body.message);
208
225
  }
209
- const item = parsed[0] || {};
210
- if (Number(item.code) !== 1000) {
211
- return fail(item.message || body.message);
212
- }
213
- const fileInfo = parseJsonValue(item.data);
214
- if (!fileInfo) {
215
- return fail(item.message || body.message);
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);
216
242
  }
217
243
  return {
218
- success: true,
219
- message: item.message || "ok",
244
+ success: errors.length === 0,
245
+ message: errors.filter(Boolean).join(";") || "ok",
220
246
  fullResponse: body,
221
- data: fileInfo,
247
+ data: files[0],
248
+ files,
222
249
  };
223
250
  }
224
251
 
@@ -268,6 +295,8 @@ export default {
268
295
  isH5: false,
269
296
 
270
297
  uploadUrl: null,
298
+ singleUploadUrl: null,
299
+ batchUploadUrl: null,
271
300
 
272
301
  token: null,
273
302
  deleteUrl: null,
@@ -531,9 +560,10 @@ export default {
531
560
  let token = objx.apiToken;
532
561
  if (token) {
533
562
  this.token = token;
534
- this.uploadUrl = toDevProxyUrl(
535
- resolveBatchUploadUrl(objx.domain, objx.uploadApi)
536
- );
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;
537
567
  this.deleteUrl = toDevProxyUrl(objx.domain + objx.deleteApi);
538
568
  // https://crm-dev.hisense.com/api/v1.0/fileoperation/GetFile?fileName=e24a1ad9-6821-41c3-957c-0916077bb97f.jpg
539
569
  this.viewApiUrl = toDevProxyUrl(objx.domain + objx.viewApi);
@@ -588,156 +618,159 @@ export default {
588
618
  Math.random() * 100000 + Math.random() * 20000 + Math.random() * 5000
589
619
  );
590
620
  },
591
- //自定义上传
592
- async uploadSectionFile(param, isCustom, uploadConfig) {
593
- let customConfig = this.customConfig || {};
594
- let customEnabled = this.customEnabled || false;
595
- /* if (customEnabled && !this.uploadUrl) {
596
- if(customConfig.uploadUrl){
597
- this.uploadUrl = customConfig.uploadUrl;
598
- }else{
599
- await this.initUploadUrl();
600
- }
601
-
602
- } */
603
- let that = this;
604
- var fileObj = param.file;
605
-
606
- let source;
607
-
608
- var form = new FormData();
609
- // 一个文件一次请求,索引固定为 0
610
- const fieldPrefix = "requests[0].";
611
- form.append(fieldPrefix + "File", fileObj);
612
-
613
- let customParam = {};
614
- let entityId = this.formDataId;
615
- 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 = {
616
637
  fileName: fileObj.name,
617
638
  entityName: "msdyn_workorder",
618
- entityId,
639
+ entityId: this.formDataId,
619
640
  backendwriteback: "10",
620
641
  fileCategory: "工单",
621
642
  user: window.$vueRoot.$store.getters.nickName,
622
- // user: "1",
623
643
  };
624
644
  let uploadParam =
625
645
  this.handleCustomEvent(this.field.options.vabupload2_uploadParam) || {};
626
646
  Object.assign(customParam, uploadParam);
627
- if (customParam) {
628
- Object.keys(customParam).forEach((key) => {
629
- if (key === "file" || key === "File") return;
630
- let fieldKey = key.indexOf("requests[") === 0 ? key : fieldPrefix + key;
631
- let value = customParam[key];
632
- form.append(fieldKey, value);
633
- });
634
- }
635
-
636
- let target = that.$refs.upload;
637
- let file = target ? target.getFile(fileObj) : null;
638
- if (file) {
639
- file.status = "uploading";
640
- }
641
-
642
- let isLoading = uploadConfig?.isLoading === true;
643
- var uploadUrl = this.uploadUrl;
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;
644
662
  if (!isCustom && !this.showUploadBtn) {
645
663
  target && target.clearFiles();
646
664
  return;
647
665
  }
648
- target.clearFiles();
649
- if (uploadUrl) {
650
- let fileOrder = 0;
651
- if (!isCustom) {
652
- if (this.uploadingCount === 0) {
653
- this.hxUploadTotal = 0;
654
- this.openHxUploadLoading();
655
- }
656
- this.uploadingCount++;
657
- this.hxUploadTotal++;
658
- fileOrder = this.hxUploadTotal;
659
- }
660
- var abort;
666
+ target && target.clearFiles();
661
667
 
662
- let config = {
663
- useToken: false,
664
- // 串行时每个请求单独 isLoading,上一个的延迟关闭会把后一个的遮罩关掉,中间空一截
665
- isLoading: false,
666
- headers: {
667
- "Content-Type": "multipart/form-data",
668
- Authorization: `Bearer ${this.token}`,
669
- },
670
- /* cancelToken: new imFun.axios.CancelToken(function executor(c) {
671
- if (!isCustom) {
672
- abort = c;
673
- if (file) file.abort = c;
674
- }
675
- }), */
676
- onUploadProgress: (progressEvent) => {
677
- const percent = progressEvent.total
678
- ? Math.floor((progressEvent.loaded * 100) / progressEvent.total)
679
- : 0;
680
- if (isCustom || file) {
681
- progressEvent.percent = percent;
682
- }
683
- if (!isCustom) {
684
- this.setHxUploadProgress(fileOrder, percent);
685
- }
686
- },
687
- failMsg: false,
688
- }; //添加请求头
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);
673
+ }
674
+ if (!fileObjs.length) return;
675
+
676
+ const batch = fileObjs.length > 1;
677
+ const uploadUrl = batch
678
+ ? this.batchUploadUrl
679
+ : this.singleUploadUrl || this.uploadUrl;
680
+ if (!uploadUrl) return;
689
681
 
690
- if (customEnabled && config?.httpConfig) {
691
- config = extendDeeply(config, config.httpConfig);
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();
692
693
  }
694
+ this.uploadingCount++;
695
+ this.hxUploadTotal++;
696
+ fileOrder = this.hxUploadTotal;
697
+ }
693
698
 
694
- this.enqueueHxUpload(() => {
695
- if (this.componentDestroyed || !this.getFormRef()) {
696
- this.finishHxUpload(!isCustom);
697
- return;
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;
699
710
  if (!isCustom) {
700
- this.setHxUploadProgress(fileOrder, 0);
711
+ this.setHxUploadProgress(fileOrder, percent);
701
712
  }
702
- let batchDone = false;
703
- return this.getFormRef()
704
- .$http.post(uploadUrl, form, config)
705
- .then((res1) => {
706
- if (this.componentDestroyed) return;
707
- const isLast = !isCustom && this.uploadingCount <= 1;
708
- if (isLast) {
709
- this.setHxUploadPercentText(99);
710
- }
711
- uploadConfig && uploadConfig.callback && uploadConfig.callback(res1, fileObj);
713
+ },
714
+ failMsg: false,
715
+ };
716
+
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()
731
+ .$http.post(uploadUrl, form, config)
732
+ .then((res1) => {
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
+ });
712
743
 
713
- const adaptedResponse = this.responseAdapter(res1);
744
+ const adaptedResponse = this.responseAdapter(res1);
745
+ const files = Array.isArray(adaptedResponse.files)
746
+ ? adaptedResponse.files
747
+ : adaptedResponse.data
748
+ ? [adaptedResponse.data]
749
+ : [];
714
750
 
715
- if (!isCustom) {
716
- if (adaptedResponse.success) {
717
- // this.initShowImageUrl(adaptedResponse.data)
718
- if (adaptedResponse.data) {
719
- let fileInfo = {
720
- ...adaptedResponse.data,
721
- showUrl: null,
722
- };
723
- this.appendUploadedFile(fileInfo);
724
- // this.initShowUrl();
725
- }
726
- batchDone = isLast;
727
- } else {
728
- if (isLast) {
729
- this.closeHxUploadLoading();
730
- }
731
- // param.onError(new Error(res1.content || '上传异常'));
751
+ if (!isCustom) {
752
+ files.forEach((data) => {
753
+ this.appendUploadedFile({
754
+ ...data,
755
+ showUrl: null,
756
+ });
757
+ });
758
+ if (files.length && adaptedResponse.success) {
759
+ batchDone = isLast;
760
+ } else {
761
+ if (isLast) {
762
+ this.closeHxUploadLoading();
763
+ }
764
+ if (adaptedResponse.message) {
732
765
  this.$baseAlert(adaptedResponse.message);
733
766
  }
734
767
  }
735
- })
736
- .finally(() => {
737
- return this.finishHxUpload(!isCustom, batchDone);
738
- });
739
- });
740
- }
768
+ }
769
+ })
770
+ .finally(() => {
771
+ return this.finishHxUpload(!isCustom, batchDone);
772
+ });
773
+ });
741
774
  },
742
775
  /**
743
776
  * 同一控件内串行上传。上一次请求结束后立刻发下一次,