@longhongguo/form-create-ant-design-vue 3.2.65 → 3.2.67
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/auto-import.js +2 -1
- package/dist/form-create.esm.js +2 -2
- package/dist/form-create.esm.js.map +1 -1
- package/dist/form-create.js +2 -2
- package/dist/form-create.js.map +1 -1
- package/package.json +1 -1
- package/src/core/alias.js +1 -0
- package/src/parsers/cascader.js +194 -0
- package/src/parsers/space.js +14 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longhongguo/form-create-ant-design-vue",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.67",
|
|
4
4
|
"description": "AntDesignVue版本低代码表单|FormCreate 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单生成组件。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。",
|
|
5
5
|
"main": "./dist/form-create.min.js",
|
|
6
6
|
"module": "./dist/form-create.esm.js",
|
package/src/core/alias.js
CHANGED
package/src/parsers/cascader.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { hasProperty } from '@form-create/utils/lib/type'
|
|
2
|
+
import { parseFn } from '@form-create/utils/lib/json'
|
|
3
|
+
import is from '@form-create/utils/lib/type'
|
|
4
|
+
import deepSet from '@form-create/utils/lib/deepset'
|
|
2
5
|
|
|
3
6
|
export default {
|
|
4
7
|
name: 'cascader',
|
|
@@ -15,6 +18,197 @@ export default {
|
|
|
15
18
|
props.disabled = true
|
|
16
19
|
props.loading = true
|
|
17
20
|
}
|
|
21
|
+
|
|
22
|
+
// 处理 loadData 函数
|
|
23
|
+
if (props.loadData) {
|
|
24
|
+
const api = ctx.$handle?.api
|
|
25
|
+
const rule = ctx.rule
|
|
26
|
+
const ctxRef = ctx
|
|
27
|
+
|
|
28
|
+
// 解析函数(如果是字符串)
|
|
29
|
+
let parsedFn = is.String(props.loadData)
|
|
30
|
+
? parseFn(props.loadData)
|
|
31
|
+
: props.loadData
|
|
32
|
+
|
|
33
|
+
// 如果不是函数,尝试包装
|
|
34
|
+
if (!is.Function(parsedFn) && is.String(props.loadData)) {
|
|
35
|
+
try {
|
|
36
|
+
const code = props.loadData.trim()
|
|
37
|
+
if (
|
|
38
|
+
!code.startsWith('function') &&
|
|
39
|
+
!code.startsWith('[[FORM-CREATE-PREFIX-function') &&
|
|
40
|
+
!code.startsWith('$FNX:')
|
|
41
|
+
) {
|
|
42
|
+
parsedFn = new Function(
|
|
43
|
+
'selectedOptions',
|
|
44
|
+
'options',
|
|
45
|
+
'updateOptions',
|
|
46
|
+
'api',
|
|
47
|
+
'rule',
|
|
48
|
+
code
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error('Failed to parse loadData:', e)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (is.Function(parsedFn)) {
|
|
57
|
+
// 包装 loadData 函数
|
|
58
|
+
props.loadData = function (selectedOptions) {
|
|
59
|
+
console.log('[Cascader loadData] ========== 开始 ==========')
|
|
60
|
+
console.log('[Cascader loadData] selectedOptions:', selectedOptions)
|
|
61
|
+
|
|
62
|
+
if (!selectedOptions || selectedOptions.length === 0) return
|
|
63
|
+
|
|
64
|
+
const targetOption = selectedOptions[selectedOptions.length - 1]
|
|
65
|
+
console.log('[Cascader loadData] targetOption:', targetOption)
|
|
66
|
+
|
|
67
|
+
if (targetOption?.isLeaf === true) {
|
|
68
|
+
console.log('[Cascader loadData] 是叶子节点,直接返回')
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const options = props.options || []
|
|
73
|
+
console.log('[Cascader loadData] 当前 options:', options)
|
|
74
|
+
console.log('[Cascader loadData] props.options:', props.options)
|
|
75
|
+
|
|
76
|
+
// 创建 updateOptions 函数,完全按照 effect.fetch 的方式
|
|
77
|
+
// 关键:effect.fetch 使用 deepSet(inject.getProp(), 'props.options', val) 然后 api.sync(rule)
|
|
78
|
+
const updateOptions = () => {
|
|
79
|
+
console.log(
|
|
80
|
+
'[Cascader updateOptions] ========== 开始更新 =========='
|
|
81
|
+
)
|
|
82
|
+
// 关键:创建新数组时,同时创建新对象,确保引用完全改变
|
|
83
|
+
// 这样可以触发 Vue 的响应式更新,即使对象属性被修改了
|
|
84
|
+
const currentOptions = props.options || []
|
|
85
|
+
|
|
86
|
+
// 找到 targetOption 在数组中的索引
|
|
87
|
+
let targetIndex = -1
|
|
88
|
+
if (targetOption) {
|
|
89
|
+
targetIndex = currentOptions.findIndex(
|
|
90
|
+
(item) =>
|
|
91
|
+
item.value === targetOption.value ||
|
|
92
|
+
item.id === targetOption.id ||
|
|
93
|
+
item === targetOption
|
|
94
|
+
)
|
|
95
|
+
console.log('[Cascader updateOptions] targetIndex:', targetIndex)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const newOptions = currentOptions.map((item, index) => {
|
|
99
|
+
// 如果是 targetOption,创建包含所有修改的新对象
|
|
100
|
+
if (index === targetIndex && targetOption) {
|
|
101
|
+
const newTarget = { ...targetOption }
|
|
102
|
+
console.log('[Cascader updateOptions] 创建新对象:', newTarget)
|
|
103
|
+
console.log(
|
|
104
|
+
'[Cascader updateOptions] newTarget.loading:',
|
|
105
|
+
newTarget.loading
|
|
106
|
+
)
|
|
107
|
+
console.log(
|
|
108
|
+
'[Cascader updateOptions] newTarget.children:',
|
|
109
|
+
newTarget.children
|
|
110
|
+
)
|
|
111
|
+
return newTarget
|
|
112
|
+
}
|
|
113
|
+
// 其他对象创建新引用(浅拷贝即可)
|
|
114
|
+
return { ...item }
|
|
115
|
+
})
|
|
116
|
+
console.log('[Cascader updateOptions] 新数组:', newOptions)
|
|
117
|
+
if (targetIndex >= 0 && newOptions[targetIndex]) {
|
|
118
|
+
console.log(
|
|
119
|
+
'[Cascader updateOptions] 新数组[targetIndex]:',
|
|
120
|
+
newOptions[targetIndex]
|
|
121
|
+
)
|
|
122
|
+
console.log(
|
|
123
|
+
'[Cascader updateOptions] 新数组[targetIndex].loading:',
|
|
124
|
+
newOptions[targetIndex].loading
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 完全按照 effect.fetch 的方式:使用 deepSet 在响应式对象上设置值
|
|
129
|
+
// effect.fetch 使用: deepSet(inject.getProp(), 'props.options', val)
|
|
130
|
+
// inject.getProp() 返回 ctx.effectData('fetch')
|
|
131
|
+
// 所以我们应该在同一个位置设置:ctxRef.effectData('fetch')
|
|
132
|
+
const fetchData = ctxRef.effectData('fetch')
|
|
133
|
+
if (fetchData) {
|
|
134
|
+
// 关键:在 fetchData 上设置,就像 effect.fetch 那样
|
|
135
|
+
deepSet(fetchData, 'props.options', newOptions)
|
|
136
|
+
console.log(
|
|
137
|
+
'[Cascader updateOptions] deepSet(fetchData, props.options) 完成'
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 同时直接更新 props.options(这是最终传递给组件的值)
|
|
142
|
+
props.options = newOptions
|
|
143
|
+
|
|
144
|
+
// 同步到 ctx.prop.props.options(确保 mergeRule 能获取到最新值)
|
|
145
|
+
if (ctxRef.prop?.props) {
|
|
146
|
+
ctxRef.prop.props.options = newOptions
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 同步到 rule.props.options
|
|
150
|
+
if (ctxRef.rule?.props) {
|
|
151
|
+
ctxRef.rule.props.options = newOptions
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
console.log(
|
|
155
|
+
'[Cascader updateOptions] 所有位置已同步,props.options:',
|
|
156
|
+
props.options
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
// 调用 api.sync 触发更新,就像 effect.fetch 那样
|
|
160
|
+
if (api && rule) {
|
|
161
|
+
console.log('[Cascader updateOptions] 调用 api.sync')
|
|
162
|
+
api.sync(rule)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 刷新组件
|
|
166
|
+
if (ctxRef.$handle) {
|
|
167
|
+
console.log('[Cascader updateOptions] 调用 refresh')
|
|
168
|
+
ctxRef.$handle.refresh()
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
console.log(
|
|
172
|
+
'[Cascader updateOptions] ========== 更新完成 =========='
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 关键:在调用用户函数之前,立即设置 loading 并更新
|
|
177
|
+
// 这样确保 loading 状态能立即显示
|
|
178
|
+
if (targetOption) {
|
|
179
|
+
console.log('[Cascader loadData] 设置 loading = true')
|
|
180
|
+
targetOption.loading = true
|
|
181
|
+
updateOptions()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 调用用户函数
|
|
185
|
+
console.log('[Cascader loadData] 调用用户函数')
|
|
186
|
+
const result = parsedFn.call(
|
|
187
|
+
this,
|
|
188
|
+
selectedOptions,
|
|
189
|
+
options,
|
|
190
|
+
updateOptions,
|
|
191
|
+
api,
|
|
192
|
+
rule
|
|
193
|
+
)
|
|
194
|
+
console.log('[Cascader loadData] 用户函数返回值:', result)
|
|
195
|
+
|
|
196
|
+
// 如果用户函数返回 Promise,等待完成
|
|
197
|
+
if (result && typeof result.then === 'function') {
|
|
198
|
+
console.log('[Cascader loadData] 用户函数返回 Promise')
|
|
199
|
+
return result.finally(() => {
|
|
200
|
+
console.log(
|
|
201
|
+
'[Cascader loadData] Promise 完成,调用 updateOptions'
|
|
202
|
+
)
|
|
203
|
+
updateOptions()
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
console.log('[Cascader loadData] ========== 结束 ==========')
|
|
208
|
+
return result
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
18
212
|
},
|
|
19
213
|
render(children, ctx) {
|
|
20
214
|
// 检测 loading 状态(与 mergeProp 中的逻辑保持一致)
|
package/src/parsers/space.js
CHANGED
|
@@ -72,9 +72,19 @@ export default {
|
|
|
72
72
|
// 使用 Ant Design Vue 的 Space 组件
|
|
73
73
|
const prop = { ...ctx.prop }
|
|
74
74
|
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
// 读取 compact 配置,决定使用 Space 还是 Space.Compact
|
|
76
|
+
const props = ctx.rule.props || {}
|
|
77
|
+
const compact = props.compact || ctx.rule.compact || false
|
|
78
|
+
|
|
79
|
+
// 根据 compact 属性决定使用哪个组件
|
|
80
|
+
if (compact) {
|
|
81
|
+
// 使用 Space.Compact 紧凑布局
|
|
82
|
+
prop.type = 'a-space-compact'
|
|
83
|
+
} else {
|
|
84
|
+
// 使用普通 Space 组件
|
|
85
|
+
if (prop.type === 'space') {
|
|
86
|
+
prop.type = 'a-space'
|
|
87
|
+
}
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
// children 会通过 form-create 的机制自动渲染
|
|
@@ -85,7 +95,7 @@ export default {
|
|
|
85
95
|
return ctx.vNode.col(
|
|
86
96
|
{ props: { span: 24 } },
|
|
87
97
|
{
|
|
88
|
-
default: () => [ctx.vNode.make(
|
|
98
|
+
default: () => [ctx.vNode.make(prop.type, prop, childrenNodes)]
|
|
89
99
|
}
|
|
90
100
|
)
|
|
91
101
|
}
|