cloud-web-corejs 1.0.324 → 1.0.327

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.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Vue 页面自动完成的展示。取数由页面的 load 回调完成。
3
+ */
4
+
5
+ export function hasValue(val) {
6
+ return val !== null && val !== undefined && val !== "";
7
+ }
8
+
9
+ export function trimText(value) {
10
+ if (value == null) return "";
11
+ return String(value).trim();
12
+ }
13
+
14
+ export function escapeHtml(str) {
15
+ const map = {
16
+ "&": "&",
17
+ "<": "&lt;",
18
+ ">": "&gt;",
19
+ '"': "&quot;",
20
+ "'": "&#39;",
21
+ };
22
+ return String(str == null ? "" : str).replace(/[&<>"']/g, (ch) => map[ch]);
23
+ }
24
+
25
+ export function highlightKeyword(text, keyword) {
26
+ const escaped = escapeHtml(text);
27
+ const raw = keyword == null ? "" : String(keyword);
28
+ if (!trimText(raw)) return escaped;
29
+ const kw = escapeHtml(raw).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
30
+ if (!kw) return escaped;
31
+ const re = new RegExp("(" + kw + ")", "gi");
32
+ return escaped.replace(
33
+ re,
34
+ '<span class="base-autocomplete-highlight">$1</span>'
35
+ );
36
+ }
@@ -11,7 +11,7 @@
11
11
  :disabled="field.options.disabled"
12
12
  :readonly="field.options.readonly"
13
13
  :size="field.options.size"
14
- :placeholder="getI18nLabel(field.options.placeholder || '请输入关键词搜索')"
14
+ :placeholder="getI18nLabel(field.options.placeholder || $t1('请输入关键词搜索'))"
15
15
  :clearable="field.options.clearable"
16
16
  :fetch-suggestions="querySearchAsync"
17
17
  :trigger-on-focus="false"
@@ -13,7 +13,8 @@
13
13
  >
14
14
  <el-cascader
15
15
  ref="fieldEditor"
16
- :options="field.options.optionItems"
16
+ :key="lazyRenderKey"
17
+ :options="cascaderOptions"
17
18
  v-model="fieldModel"
18
19
  v-show="!isReadMode"
19
20
  class="full-width-input"
@@ -25,20 +26,13 @@
25
26
  field.options.placeholder || i18nt('render.hint.selectPlaceholder')
26
27
  "
27
28
  :show-all-levels="showFullPath"
28
- :props="{
29
- checkStrictly: field.options.checkStrictly,
30
- multiple: field.options.multiple,
31
- expandTrigger: 'hover',
32
- value: valueKey,
33
- label: labelKey,
34
- children: childrenKey,
35
- }"
29
+ :props="cascaderProps"
36
30
  @visible-change="hideDropDownOnClick"
37
31
  @expand-change="hideDropDownOnClick"
38
32
  @focus="handleFocusCustomEvent"
39
33
  @blur="handleBlurCustomEvent"
40
34
  @clear="handleClearEvent"
41
- @change="onFieldChangeEvent"
35
+ @change="handleCascaderChange"
42
36
  >
43
37
  </el-cascader>
44
38
  <template v-if="isReadMode">
@@ -91,9 +85,37 @@ export default {
91
85
  oldFieldValue: null, //field组件change之前的值
92
86
  fieldModel: null,
93
87
  rules: [],
88
+ lazyEmptyOptions: [],
89
+ lazyRenderKey: 0,
90
+ lazyLabelMap: {},
91
+ cascaderSyncing: false,
94
92
  };
95
93
  },
96
94
  computed: {
95
+ lazyEnabled() {
96
+ return !!this.field.options.lazy && !this.designState;
97
+ },
98
+
99
+ cascaderOptions() {
100
+ return this.lazyEnabled
101
+ ? this.lazyEmptyOptions
102
+ : this.field.options.optionItems;
103
+ },
104
+
105
+ cascaderProps() {
106
+ return {
107
+ checkStrictly: !!this.field.options.checkStrictly,
108
+ multiple: !!this.field.options.multiple,
109
+ expandTrigger: "hover",
110
+ value: this.valueKey,
111
+ label: this.labelKey,
112
+ children: this.childrenKey,
113
+ leaf: "leaf",
114
+ lazy: this.lazyEnabled,
115
+ lazyLoad: this.lazyLoadNode,
116
+ };
117
+ },
118
+
97
119
  labelKey() {
98
120
  return this.field.options.labelKey || "label";
99
121
  },
@@ -114,6 +136,37 @@ export default {
114
136
  },
115
137
 
116
138
  contentForReadMode() {
139
+ if (this.lazyEnabled) {
140
+ if (
141
+ this.fieldModel === null ||
142
+ this.fieldModel === undefined ||
143
+ this.fieldModel === ""
144
+ ) {
145
+ return "--";
146
+ }
147
+ const text = this.resolveDisplayValue(this.fieldModel);
148
+ if (text === null || text === undefined || text === "") return "--";
149
+ if (Array.isArray(text)) {
150
+ if (text.some((item) => Array.isArray(item))) {
151
+ return (
152
+ text
153
+ .map((item) => (Array.isArray(item) ? item.join(" / ") : item))
154
+ .join(", ") || "--"
155
+ );
156
+ }
157
+ return text.join(" / ") || "--";
158
+ }
159
+ if (!this.showFullPath && typeof text === "string") {
160
+ return (
161
+ text
162
+ .split(", ")
163
+ .map((item) => item.split(" / ").pop())
164
+ .filter(Boolean)
165
+ .join(", ") || "--"
166
+ );
167
+ }
168
+ return text;
169
+ }
117
170
  if (!!this.field.options.multiple) {
118
171
  //console.log('test======', this.$refs.fieldEditor.presentTags)
119
172
  const curTags = this.$refs.fieldEditor.presentTags;
@@ -152,11 +205,277 @@ export default {
152
205
  },
153
206
 
154
207
  methods: {
208
+ // 重新加载懒加载节点(上级条件变化后清空已展开数据)
209
+ reloadLazyNodes() {
210
+ this.lazyLabelMap = {};
211
+ this.lazyRenderKey += 1;
212
+ },
213
+ // 详情回显:用已有的各级 value/label 显示全称,不写入表单数据
214
+ initLazyChecked(levels) {
215
+ const path = [];
216
+ this.lazyLabelMap = {};
217
+ const list = Array.isArray(levels) ? levels : [];
218
+ for (let i = 0; i < list.length; i++) {
219
+ const item = list[i];
220
+ if (
221
+ !item ||
222
+ item.value === null ||
223
+ item.value === undefined ||
224
+ item.value === ""
225
+ ) {
226
+ break;
227
+ }
228
+ path.push(item.value);
229
+ this.$set(this.lazyLabelMap, this.lazyPathKey(path.slice()), {
230
+ path: path.slice(),
231
+ label: item.label == null ? "" : item.label,
232
+ });
233
+ }
234
+ this.cascaderSyncing = true;
235
+ this.fieldModel = path.length ? path.slice() : null;
236
+ this.$nextTick(() => {
237
+ this.cascaderSyncing = false;
238
+ this.$nextTick(() => {
239
+ const editor = this.$refs.fieldEditor;
240
+ const text = this.resolveLazyDisplayValue(this.fieldModel);
241
+ if (!editor || !text || Array.isArray(text)) return;
242
+ editor.presentText = text;
243
+ editor.inputValue = text;
244
+ });
245
+ });
246
+ },
247
+ lazyPathKey(path) {
248
+ return JSON.stringify(path);
249
+ },
250
+ rememberLazyNodes(parentNode, list) {
251
+ if (!Array.isArray(list)) return;
252
+ const valueKey = this.valueKey;
253
+ const labelKey = this.labelKey;
254
+ const basePath =
255
+ parentNode && parentNode.level > 0 && Array.isArray(parentNode.path)
256
+ ? parentNode.path.slice()
257
+ : [];
258
+ list.forEach((item) => {
259
+ if (!item || typeof item !== "object") return;
260
+ const value = item[valueKey];
261
+ if (value === undefined) return;
262
+ const path = basePath.concat(value);
263
+ this.$set(this.lazyLabelMap, this.lazyPathKey(path), {
264
+ path: path,
265
+ label: item[labelKey],
266
+ });
267
+ });
268
+ },
269
+ lazyLoadNode(node, resolve) {
270
+ if (!this.lazyEnabled) {
271
+ resolve([]);
272
+ return;
273
+ }
274
+ // 启用请求访问时,按级走表单脚本;否则才用 onLazyLoad 自定义请求
275
+ if (this.field.options.formScriptEnabled) {
276
+ this.loadLazyNodesByFormScript(node, resolve);
277
+ return;
278
+ }
279
+ const handler = this.field.options.onLazyLoad;
280
+ if (!handler) {
281
+ resolve([]);
282
+ return;
283
+ }
284
+ let settled = false;
285
+ const done = (list) => {
286
+ if (settled) return;
287
+ settled = true;
288
+ const nodes = this.normalizeLazyNodes(list);
289
+ this.rememberLazyNodes(node, nodes);
290
+ resolve(nodes);
291
+ };
292
+ const abortLazyLoad = () => {
293
+ if (settled) return;
294
+ settled = true;
295
+ if (node) {
296
+ node.loading = false;
297
+ node.loaded = false;
298
+ }
299
+ };
300
+ try {
301
+ this.handleCustomEvent(handler, ["node", "resolve"], [node, done]);
302
+ } catch (e) {
303
+ abortLazyLoad();
304
+ }
305
+ },
306
+ // 展开节点时复用「请求访问」的脚本编码。查询参数不参与懒加载
307
+ loadLazyNodesByFormScript(node, resolve) {
308
+ const formRef = this.getFormRef && this.getFormRef();
309
+ const reportTemplate = formRef && formRef.reportTemplate;
310
+ if (!reportTemplate) {
311
+ resolve([]);
312
+ return;
313
+ }
314
+ const rowParam = this.resolveLazyRowParam(node);
315
+ let settled = false;
316
+ const done = (list) => {
317
+ if (settled) return;
318
+ settled = true;
319
+ const nodes = this.normalizeLazyNodes(list);
320
+ this.rememberLazyNodes(node, nodes);
321
+ resolve(nodes);
322
+ };
323
+ // 请求失败不能 resolve([]):Element 会把 node.loaded 置 true,之后不再 lazyLoad
324
+ const abortLazyLoad = () => {
325
+ if (settled) return;
326
+ settled = true;
327
+ if (node) {
328
+ node.loading = false;
329
+ node.loaded = false;
330
+ }
331
+ };
332
+ this.formHttp({
333
+ scriptCode: this.field.options.formScriptCode || "getList",
334
+ ...this.getQueryConditionHttpOption(),
335
+ isLoading: false,
336
+ data: this.buildLazyFormScriptData(reportTemplate, node, rowParam),
337
+ callback: (res) => {
338
+ const objx = res.objx;
339
+ let rows = Array.isArray(objx) ? objx : [];
340
+ const handled = this.handleCustomEvent(
341
+ this.field.options.formScriptSuccess,
342
+ ["res", "rows"],
343
+ [res, rows]
344
+ );
345
+ if (Array.isArray(handled)) rows = handled;
346
+ done(rows);
347
+ },
348
+ fail: abortLazyLoad,
349
+ error: abortLazyLoad,
350
+ });
351
+ },
352
+ // 展开节点时的路径上下文(与 onSelect 的 item 字段含义一致)
353
+ buildCascaderNodePathContext(node) {
354
+ if (!node || node.root || node.level === 0) {
355
+ return {
356
+ row: null,
357
+ level: null,
358
+ path: [],
359
+ pathLabels: [],
360
+ pathRows: [],
361
+ levels: [],
362
+ };
363
+ }
364
+ const path = node.path ? node.path.slice() : [];
365
+ const pathNodes = node.pathNodes || [];
366
+ const levels = pathNodes.map((seg, index) => ({
367
+ level: index,
368
+ value: seg.value,
369
+ label: seg.label,
370
+ data: seg.data || null,
371
+ }));
372
+ return {
373
+ row: node.data || null,
374
+ level: path.length ? path.length - 1 : 0,
375
+ path: path,
376
+ pathLabels: node.pathLabels ? node.pathLabels.slice() : [],
377
+ pathRows: pathNodes.map((seg) => seg.data || null),
378
+ levels: levels,
379
+ };
380
+ },
381
+ // 传参脚本返回选中行上的其他字段。根节点没有选中行。
382
+ resolveLazyRowParam(node) {
383
+ const ctx = this.buildCascaderNodePathContext(node);
384
+ const rowParam = this.handleCustomEvent(
385
+ this.field.options.lazyParamScript,
386
+ ["row", "level", "path", "pathLabels", "pathRows", "levels"],
387
+ [
388
+ ctx.row,
389
+ ctx.level,
390
+ ctx.path,
391
+ ctx.pathLabels,
392
+ ctx.pathRows,
393
+ ctx.levels,
394
+ ]
395
+ );
396
+ if (!rowParam || typeof rowParam !== "object" || Array.isArray(rowParam)) {
397
+ return {};
398
+ }
399
+ return rowParam;
400
+ },
401
+ // 未维护父级字段时用 f_parent,不把默认值写回配置
402
+ buildLazyFormScriptData(reportTemplate, node, rowParam) {
403
+ const parentField =
404
+ (this.field.options.parentKey || "f_parent").trim() || "f_parent";
405
+ const data = { ...(rowParam || {}) };
406
+ data[parentField] = node && node.level > 0 ? node.value : null;
407
+ return this.buildFormScriptData(reportTemplate, data);
408
+ },
409
+ normalizeLazyNodes(list) {
410
+ if (!Array.isArray(list)) return [];
411
+ const hasChildKey =
412
+ (this.field.options.hasChildKey || "f_has_child").trim() ||
413
+ "f_has_child";
414
+ return list.map((item) => {
415
+ if (!item || typeof item !== "object") return item;
416
+ const row = { ...item };
417
+ if (item[hasChildKey] != null && item[hasChildKey] !== "") {
418
+ row.leaf = !this.isHasChildFlag(item[hasChildKey]);
419
+ } else if (item.leaf != null) {
420
+ row.leaf = !!item.leaf;
421
+ }
422
+ return row;
423
+ });
424
+ },
425
+ isHasChildFlag(value) {
426
+ if (value === false || value === 0 || value === "0" || value === "false") {
427
+ return false;
428
+ }
429
+ return !!value;
430
+ },
431
+ resolveLazyDisplayValue(rawValue) {
432
+ if (!this.lazyLabelMap || !Object.keys(this.lazyLabelMap).length) {
433
+ return null;
434
+ }
435
+ const labelOf = (path) => {
436
+ const labels = [];
437
+ for (let i = 0; i < path.length; i++) {
438
+ const seg = this.lazyLabelMap[this.lazyPathKey(path.slice(0, i + 1))];
439
+ if (!seg) return null;
440
+ labels.push(this.$t1 ? this.$t1(seg.label) : seg.label);
441
+ }
442
+ return labels.join(" / ");
443
+ };
444
+ const resolveOne = (value) => {
445
+ if (Array.isArray(value)) return labelOf(value);
446
+ let matched = null;
447
+ Object.keys(this.lazyLabelMap).forEach((key) => {
448
+ const seg = this.lazyLabelMap[key];
449
+ if (
450
+ seg &&
451
+ seg.path.length &&
452
+ seg.path[seg.path.length - 1] === value
453
+ ) {
454
+ matched = seg;
455
+ }
456
+ });
457
+ return matched ? labelOf(matched.path) : null;
458
+ };
459
+ if (
460
+ this.field.options.multiple &&
461
+ Array.isArray(rawValue) &&
462
+ rawValue.some((item) => Array.isArray(item))
463
+ ) {
464
+ const parts = rawValue.map(resolveOne);
465
+ if (parts.some((item) => !item)) return null;
466
+ return parts.join(", ");
467
+ }
468
+ return resolveOne(rawValue);
469
+ },
155
470
  // 对比展示:级联值(叶子value 或 value路径数组) → 逐级 label 路径
156
471
  resolveDisplayValue(rawValue) {
157
472
  if (rawValue === null || rawValue === undefined || rawValue === "") {
158
473
  return rawValue;
159
474
  }
475
+ if (this.lazyEnabled) {
476
+ const lazyText = this.resolveLazyDisplayValue(rawValue);
477
+ return lazyText == null || lazyText === "" ? rawValue : lazyText;
478
+ }
160
479
  let options = this.field.options.optionItems || [];
161
480
  let vk = this.valueKey;
162
481
  let lk = this.labelKey;
@@ -213,6 +532,80 @@ export default {
213
532
  }, 100);
214
533
  },
215
534
 
535
+ // 脚本赋值不视为用户选中,避免回写省市区镇
536
+ setValue(value) {
537
+ this.cascaderSyncing = true;
538
+ fieldMixin.methods.setValue.call(this, value);
539
+ this.$nextTick(() => {
540
+ this.cascaderSyncing = false;
541
+ });
542
+ },
543
+ handleCascaderChange(value) {
544
+ const userAction = !this.cascaderSyncing;
545
+ const oldValue = this.oldFieldValue;
546
+ this.onFieldChangeEvent(value);
547
+ if (!userAction) return;
548
+ if (this.isEmptyCascaderValue(value)) {
549
+ this.fireOnClear();
550
+ return;
551
+ }
552
+ this.fireOnSelect(value, oldValue);
553
+ },
554
+ isEmptyCascaderValue(value) {
555
+ if (value == null || value === "") return true;
556
+ return Array.isArray(value) && value.length === 0;
557
+ },
558
+ fireOnClear() {
559
+ if (!this.field.options.onClear) return;
560
+ const tableParam = this.tableParam;
561
+ this.handleCustomEvent(
562
+ this.field.options.onClear,
563
+ ["rowData", "rowIndex"],
564
+ [
565
+ tableParam ? tableParam.row : null,
566
+ tableParam ? tableParam.rowIndex : null,
567
+ ]
568
+ );
569
+ },
570
+ // 仅用户选中。item 为当前节点,多选为节点数组
571
+ fireOnSelect(value, oldValue) {
572
+ if (!this.field.options.onSelect) return;
573
+ const editor = this.$refs.fieldEditor;
574
+ const nodes =
575
+ editor && typeof editor.getCheckedNodes === "function"
576
+ ? (editor.getCheckedNodes(false) || []).filter(Boolean)
577
+ : [];
578
+ const toItem = (node) => {
579
+ const ctx = this.buildCascaderNodePathContext(node);
580
+ return {
581
+ value: node.value,
582
+ label: node.label,
583
+ level: ctx.level == null ? 0 : ctx.level,
584
+ path: ctx.path,
585
+ pathLabels: ctx.pathLabels,
586
+ data: ctx.row,
587
+ pathRows: ctx.pathRows,
588
+ levels: ctx.levels,
589
+ };
590
+ };
591
+ const item = this.field.options.multiple
592
+ ? nodes.map(toItem)
593
+ : nodes[0]
594
+ ? toItem(nodes[0])
595
+ : null;
596
+ const tableParam = this.tableParam;
597
+ this.handleCustomEvent(
598
+ this.field.options.onSelect,
599
+ ["value", "oldValue", "item", "rowData", "rowIndex"],
600
+ [
601
+ value,
602
+ oldValue,
603
+ item,
604
+ tableParam ? tableParam.row : null,
605
+ tableParam ? tableParam.rowIndex : null,
606
+ ]
607
+ );
608
+ },
216
609
  handleClearEvent() {
217
610
  if (!!this.designState) {
218
611
  //设计状态不触发事件
@@ -786,6 +786,9 @@ modules = {
786
786
  }
787
787
  }) */
788
788
 
789
+ if (this.field.type === "cascader" && this.field.options.lazy) {
790
+ return;
791
+ }
789
792
  let reportTemplate = this.getFormRef().reportTemplate;
790
793
  let formCode = reportTemplate.formCode;
791
794
  let formScriptEnabled = this.field.options.formScriptEnabled || false;
@@ -943,6 +946,9 @@ modules = {
943
946
  this.field.type === "select" ||
944
947
  this.field.type === "cascader"
945
948
  ) {
949
+ if (this.field.type === "cascader" && this.field.options.lazy) {
950
+ return;
951
+ }
946
952
  let reportTemplate = this.getFormRef().reportTemplate;
947
953
  let formCode = reportTemplate.formCode;
948
954
  let formScriptEnabled = this.field.options.formScriptEnabled || false;