cloud-web-corejs 1.1.0-dev.20 → 1.1.0-dev.21

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.
@@ -1,133 +0,0 @@
1
- /**
2
- * 表单级「动态字段规则」运行时混入(挂载于 VFormRender 根组件)。
3
- *
4
- * 配置来源:formConfig.dynamicFieldEnabled / dynamicFieldSourceType / dynamicFieldRules /
5
- * dynamicFieldScriptCode / dynamicFieldScriptParam(额外参数) / dynamicFieldTriggerFields
6
- * 作用范围:整个表单内任意字段 / 命名容器的 显隐/必填/只读/禁用/取值。
7
- *
8
- * 依赖根组件(indexMixin)已提供:formConfig、widgetList、formModel、getWidgetRef、formHttp。
9
- */
10
- import {
11
- buildFormTargetMap,
12
- computeLocalStates,
13
- applyTargetState,
14
- } from "./container-item/dynamicFieldEngine";
15
-
16
- export default {
17
- created() {
18
- // 目标key -> { widget, refKey, isContainer }
19
- this._fdfMap = {};
20
- // 设计期基线,未命中规则时还原
21
- this._fdfBaseline = {};
22
- this._fdfWatcher = null;
23
- this._fdfTimer = null;
24
- this._fdfInited = false;
25
- },
26
- watch: {
27
- showFormContent(val) {
28
- // 表单内容渲染(字段ref注册)完成后再初始化
29
- if (val && !this._fdfInited) {
30
- this.$nextTick(() => this.initFormDynamicFields());
31
- }
32
- },
33
- },
34
- beforeDestroy() {
35
- if (this._fdfWatcher) {
36
- this._fdfWatcher();
37
- this._fdfWatcher = null;
38
- }
39
- if (this._fdfTimer) {
40
- clearTimeout(this._fdfTimer);
41
- this._fdfTimer = null;
42
- }
43
- },
44
- methods: {
45
- initFormDynamicFields() {
46
- if (this.isFieldControlV2 && this.isFieldControlV2()) return;
47
- const cfg = this.formConfig || {};
48
- if (!cfg.dynamicFieldEnabled) return;
49
- this._fdfInited = true;
50
- const { map, baseline } = buildFormTargetMap(this.widgetList);
51
- this._fdfMap = map;
52
- this._fdfBaseline = baseline;
53
- this.applyFormDynamicFields();
54
- this.setupFormDynamicWatcher();
55
- },
56
-
57
- applyFormDynamicFields() {
58
- if (this.isFieldControlV2 && this.isFieldControlV2()) return this.refreshFieldControl();
59
- const cfg = this.formConfig || {};
60
- if (!cfg.dynamicFieldEnabled) return;
61
- if (cfg.dynamicFieldSourceType === "script") {
62
- this.applyFormScriptStates();
63
- } else {
64
- const states = computeLocalStates(
65
- cfg.dynamicFieldRules || [],
66
- this._fdfBaseline,
67
- this.formModel
68
- );
69
- Object.keys(states).forEach((key) =>
70
- this.applyFormFieldState(key, states[key])
71
- );
72
- }
73
- },
74
-
75
- applyFormFieldState(targetKey, state) {
76
- const entry = this._fdfMap[targetKey];
77
- if (!entry) return;
78
- applyTargetState(entry, state, (name) => this.getWidgetRef(name));
79
- },
80
-
81
- setupFormDynamicWatcher() {
82
- const cfg = this.formConfig || {};
83
- if (cfg.dynamicFieldSourceType === "script") {
84
- const triggers = cfg.dynamicFieldTriggerFields || [];
85
- if (!triggers.length) return;
86
- this._fdfWatcher = this.$watch(
87
- () =>
88
- triggers
89
- .map((f) => this.formModel && this.formModel[f])
90
- .join("\u0001"),
91
- () => this.debouncedFormApply()
92
- );
93
- } else {
94
- this._fdfWatcher = this.$watch(
95
- () => this.formModel,
96
- () => this.debouncedFormApply(),
97
- { deep: true }
98
- );
99
- }
100
- },
101
-
102
- debouncedFormApply() {
103
- if (this._fdfTimer) clearTimeout(this._fdfTimer);
104
- this._fdfTimer = setTimeout(() => this.applyFormDynamicFields(), 120);
105
- },
106
-
107
- applyFormScriptStates() {
108
- const cfg = this.formConfig || {};
109
- if (!cfg.dynamicFieldScriptCode) return;
110
- const extra = this.handleCustomEvent(cfg.dynamicFieldScriptParam) || {};
111
- this.formHttp({
112
- scriptCode: cfg.dynamicFieldScriptCode,
113
- isLoading: false,
114
- data: {
115
- formData: this.formModel,
116
- ...extra,
117
- },
118
- success: (res) => {
119
- const result = (res && res.objx) || {};
120
- const fieldStates = result.fieldStates || {};
121
- Object.keys(this._fdfBaseline).forEach((key) => {
122
- if (!fieldStates[key]) {
123
- this.applyFormFieldState(key, this._fdfBaseline[key]);
124
- }
125
- });
126
- Object.keys(fieldStates).forEach((key) =>
127
- this.applyFormFieldState(key, fieldStates[key])
128
- );
129
- },
130
- });
131
- },
132
- },
133
- };