cloud-web-corejs 1.1.0-dev.76 → 1.1.0-dev.77

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.1.0-dev.76",
4
+ "version": "1.1.0-dev.77",
5
5
  "scripts": {
6
6
  "build:ace-resources": "node build/build-ace-resources.js",
7
7
  "build:tinymce-resources": "node build/build-tinymce-resources.js",
@@ -183,6 +183,24 @@ let allRows = grid.getTableData().fullData;
183
183
 
184
184
  `getCheckboxRecords(true)` 取出跨页勾选的行。`addTableData` 的第二个参数是去重字段,例如 `table.addTableData(rows, "id")`。
185
185
 
186
+ `addTableData` 只用于普通表。树表(`isTreeTable: true`)新增走 `addTreeRows`,它会补临时节点身份,并把父字段写成根值。
187
+
188
+ ```javascript
189
+ let table = this.getFormRef().getWidgetRef("表格字段名");
190
+
191
+ table.addTreeRows([{
192
+ f_attr_sid: this.$generateUUID()
193
+ }]);
194
+ ```
195
+
196
+ 要插到第一行时用 `table.addTopTreeRow({ f_attr_sid: this.$generateUUID() })`。
197
+
198
+ 节点身份是 `treeConfig.rowField`(例如 `f_file_obj_id`)。新增时还没有正式编号,脚本里不要传这个字段,更不要写成 `0`。`0`、`"0"`、`null`、`""` 是根哨兵,只能出现在父字段(`parentField`,例如 `f_parent_file_obj_id`)上,表示没有父节点。写进节点身份会在入表时报「树节点 xxx 不能为空或根哨兵」。
199
+
200
+ `addTreeRows` 发现身份为空或是哨兵时,会生成 `row_时间戳_…` 临时键,并记到 `_X_TREE_TEMP_KEY`。父字段由方法写成 `rootParentValue`(默认 `0`)。表上开了 `serverGeneratesRowField` 时,提交会把临时键清成 `null`,正式编号由服务端回填。
201
+
202
+ 手里已经有真实、唯一、且不是哨兵的节点身份时,可以传给 `addTreeRows`,方法会按正式身份保留。
203
+
186
204
  ## 显隐和禁用
187
205
 
188
206
  参数可以是字段名,也可以是字段名数组。
@@ -131,6 +131,8 @@ import fieldMixin from "../../../../../components/xform/form-designer/form-widge
131
131
  import settingConfig from "@/settings.js";
132
132
 
133
133
  const BATCH_UPLOAD_API = "/api/v1.0/FileOperation/BatchUploadFilesFromPortal";
134
+ /** 全部处理完显示 100 后,再停一会儿关闭加载。 */
135
+ const HX_UPLOAD_DONE_DELAY = 200;
134
136
 
135
137
  function parseJsonValue(value) {
136
138
  if (value == null || value === "") return null;
@@ -342,6 +344,7 @@ export default {
342
344
 
343
345
  beforeDestroy() {
344
346
  this.componentDestroyed = true;
347
+ this.closeHxUploadLoading();
345
348
  this.revokeOwnedBlobUrls();
346
349
  this.unregisterFromRefList();
347
350
  },
@@ -644,14 +647,22 @@ export default {
644
647
  }
645
648
  target.clearFiles();
646
649
  if (uploadUrl) {
650
+ let fileOrder = 0;
647
651
  if (!isCustom) {
652
+ if (this.uploadingCount === 0) {
653
+ this.hxUploadTotal = 0;
654
+ this.openHxUploadLoading();
655
+ }
648
656
  this.uploadingCount++;
657
+ this.hxUploadTotal++;
658
+ fileOrder = this.hxUploadTotal;
649
659
  }
650
660
  var abort;
651
661
 
652
662
  let config = {
653
663
  useToken: false,
654
- isLoading: true,
664
+ // 串行时每个请求单独 isLoading,上一个的延迟关闭会把后一个的遮罩关掉,中间空一截
665
+ isLoading: false,
655
666
  headers: {
656
667
  "Content-Type": "multipart/form-data",
657
668
  Authorization: `Bearer ${this.token}`,
@@ -663,12 +674,14 @@ export default {
663
674
  }
664
675
  }), */
665
676
  onUploadProgress: (progressEvent) => {
677
+ const percent = progressEvent.total
678
+ ? Math.floor((progressEvent.loaded * 100) / progressEvent.total)
679
+ : 0;
666
680
  if (isCustom || file) {
667
- // progressEvent.loaded:已上传文件大小
668
- // progressEvent.total:被上传文件的总大小
669
- progressEvent.percent = Math.floor(
670
- (progressEvent.loaded * 100) / progressEvent.total
671
- );
681
+ progressEvent.percent = percent;
682
+ }
683
+ if (!isCustom) {
684
+ this.setHxUploadProgress(fileOrder, percent);
672
685
  }
673
686
  },
674
687
  failMsg: false,
@@ -678,36 +691,111 @@ export default {
678
691
  config = extendDeeply(config, config.httpConfig);
679
692
  }
680
693
 
681
- let req = this.getFormRef()
682
- .$http.post(uploadUrl, form, config)
683
- .then((res1) => {
684
- uploadConfig && uploadConfig.callback && uploadConfig.callback(res1, fileObj);
694
+ this.enqueueHxUpload(() => {
695
+ if (this.componentDestroyed || !this.getFormRef()) {
696
+ this.finishHxUpload(!isCustom);
697
+ return;
698
+ }
699
+ if (!isCustom) {
700
+ this.setHxUploadProgress(fileOrder, 0);
701
+ }
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);
685
712
 
686
- const adaptedResponse = this.responseAdapter(res1);
713
+ const adaptedResponse = this.responseAdapter(res1);
687
714
 
688
- if (!isCustom) {
689
- if (adaptedResponse.success) {
690
- // this.initShowImageUrl(adaptedResponse.data)
691
- if (adaptedResponse.data) {
692
- let fileInfo = {
693
- ...adaptedResponse.data,
694
- showUrl: null,
695
- };
696
- this.appendUploadedFile(fileInfo);
697
- // this.initShowUrl();
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 || '上传异常'));
732
+ this.$baseAlert(adaptedResponse.message);
698
733
  }
699
- } else {
700
- // param.onError(new Error(res1.content || '上传异常'));
701
- this.$baseAlert(adaptedResponse.message);
702
734
  }
703
- }
704
- })
705
- .finally(() => {
706
- if (!isCustom) {
707
- this.uploadingCount = Math.max(0, this.uploadingCount - 1);
708
- }
709
- });
735
+ })
736
+ .finally(() => {
737
+ return this.finishHxUpload(!isCustom, batchDone);
738
+ });
739
+ });
740
+ }
741
+ },
742
+ /**
743
+ * 同一控件内串行上传。上一次请求结束后立刻发下一次,
744
+ * 避免海信回写工单字段时后一次覆盖前一次。
745
+ */
746
+ enqueueHxUpload(task) {
747
+ if (!this.hxUploadChain) {
748
+ this.hxUploadChain = Promise.resolve();
710
749
  }
750
+ const scheduled = this.hxUploadChain.then(() => task());
751
+ this.hxUploadChain = scheduled.catch(() => {});
752
+ return scheduled;
753
+ },
754
+ openHxUploadLoading() {
755
+ if (this.hxUploadLoading) return;
756
+ this.hxUploadLoading = this.$baseLoading({
757
+ target: document.body,
758
+ background: "unset",
759
+ customClass: "hx-upload-loading",
760
+ text: "",
761
+ });
762
+ },
763
+ setHxUploadProgress(index, percent) {
764
+ if (!this.hxUploadLoading || typeof this.hxUploadLoading.setText !== "function") {
765
+ return;
766
+ }
767
+ const total = this.hxUploadTotal || 1;
768
+ const safePercent = Number.isFinite(percent) ? Math.min(percent, 98) : 0;
769
+ const text = total > 1 ? `${index}/${total}` : `${safePercent}%`;
770
+ this.hxUploadLoading.setText(text);
771
+ },
772
+ setHxUploadPercentText(percent) {
773
+ if (!this.hxUploadLoading || typeof this.hxUploadLoading.setText !== "function") {
774
+ return;
775
+ }
776
+ this.hxUploadLoading.setText(`${percent}%`);
777
+ },
778
+ closeHxUploadLoading() {
779
+ const loading = this.hxUploadLoading;
780
+ if (!loading) return;
781
+ this.hxUploadLoading = null;
782
+ loading.close();
783
+ },
784
+ finishHxUpload(counted, showDone) {
785
+ if (!counted) return;
786
+ this.uploadingCount = Math.max(0, this.uploadingCount - 1);
787
+ if (this.uploadingCount !== 0) return;
788
+ if (!showDone) {
789
+ this.closeHxUploadLoading();
790
+ return;
791
+ }
792
+ this.setHxUploadPercentText(100);
793
+ return new Promise((resolve) => {
794
+ setTimeout(() => {
795
+ this.closeHxUploadLoading();
796
+ resolve();
797
+ }, HX_UPLOAD_DONE_DELAY);
798
+ });
711
799
  },
712
800
  handleUploadExceed(files) {
713
801
  let limit = this.pickLimit || this.uploadLimit;
@@ -923,3 +1011,33 @@ export default {
923
1011
  }
924
1012
  }
925
1013
  </style>
1014
+
1015
+ <style lang="scss">
1016
+ /* 进度写在转圈中间。全局 spinner 被 zoom:2 放大,这里单独收回来,避免文字掉到圈外。 */
1017
+ body .el-loading-mask.hx-upload-loading .el-loading-spinner {
1018
+ zoom: 1;
1019
+ margin-top: -42px;
1020
+
1021
+ .circular {
1022
+ width: 84px;
1023
+ height: 84px;
1024
+ }
1025
+
1026
+ .el-loading-text {
1027
+ zoom: 1;
1028
+ position: absolute;
1029
+ left: 50%;
1030
+ top: 42px;
1031
+ width: 52px;
1032
+ margin: 0;
1033
+ padding: 0;
1034
+ transform: translate(-50%, -50%);
1035
+ font-size: 14px;
1036
+ line-height: 1;
1037
+ text-align: center;
1038
+ white-space: nowrap;
1039
+ overflow: hidden;
1040
+ color: #409eff;
1041
+ }
1042
+ }
1043
+ </style>