@longhongguo/form-create-ant-design-vue 3.2.66 → 3.2.68
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 -0
- 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/core/maker.js +5 -0
- package/src/parsers/cascader.js +141 -0
- package/src/parsers/index.js +3 -1
- package/src/parsers/spin.js +113 -0
- package/types/maker.d.ts +2 -1
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.68",
|
|
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/core/maker.js
CHANGED
|
@@ -106,6 +106,10 @@ function useSpace(maker) {
|
|
|
106
106
|
maker.space = creatorFactory('space')
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
function useSpin(maker) {
|
|
110
|
+
maker.spin = creatorFactory('spin')
|
|
111
|
+
}
|
|
112
|
+
|
|
109
113
|
useAlias(maker)
|
|
110
114
|
useSlider(maker)
|
|
111
115
|
useFrame(maker)
|
|
@@ -116,5 +120,6 @@ useCusUserSelect(maker)
|
|
|
116
120
|
useText(maker)
|
|
117
121
|
useFlex(maker)
|
|
118
122
|
useSpace(maker)
|
|
123
|
+
useSpin(maker)
|
|
119
124
|
|
|
120
125
|
export default maker
|
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,144 @@ 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
|
+
if (!selectedOptions || selectedOptions.length === 0) return
|
|
60
|
+
|
|
61
|
+
const targetOption = selectedOptions[selectedOptions.length - 1]
|
|
62
|
+
|
|
63
|
+
if (targetOption?.isLeaf === true) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const options = props.options || []
|
|
68
|
+
|
|
69
|
+
// 创建 updateOptions 函数,完全按照 effect.fetch 的方式
|
|
70
|
+
// 关键:effect.fetch 使用 deepSet(inject.getProp(), 'props.options', val) 然后 api.sync(rule)
|
|
71
|
+
const updateOptions = () => {
|
|
72
|
+
// 关键:创建新数组时,同时创建新对象,确保引用完全改变
|
|
73
|
+
// 这样可以触发 Vue 的响应式更新,即使对象属性被修改了
|
|
74
|
+
const currentOptions = props.options || []
|
|
75
|
+
|
|
76
|
+
// 找到 targetOption 在数组中的索引
|
|
77
|
+
let targetIndex = -1
|
|
78
|
+
if (targetOption) {
|
|
79
|
+
targetIndex = currentOptions.findIndex(
|
|
80
|
+
(item) =>
|
|
81
|
+
item.value === targetOption.value ||
|
|
82
|
+
item.id === targetOption.id ||
|
|
83
|
+
item === targetOption
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const newOptions = currentOptions.map((item, index) => {
|
|
88
|
+
// 如果是 targetOption,创建包含所有修改的新对象
|
|
89
|
+
if (index === targetIndex && targetOption) {
|
|
90
|
+
const newTarget = { ...targetOption }
|
|
91
|
+
return newTarget
|
|
92
|
+
}
|
|
93
|
+
// 其他对象创建新引用(浅拷贝即可)
|
|
94
|
+
return { ...item }
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// 完全按照 effect.fetch 的方式:使用 deepSet 在响应式对象上设置值
|
|
98
|
+
// effect.fetch 使用: deepSet(inject.getProp(), 'props.options', val)
|
|
99
|
+
// inject.getProp() 返回 ctx.effectData('fetch')
|
|
100
|
+
// 所以我们应该在同一个位置设置:ctxRef.effectData('fetch')
|
|
101
|
+
const fetchData = ctxRef.effectData('fetch')
|
|
102
|
+
if (fetchData) {
|
|
103
|
+
// 关键:在 fetchData 上设置,就像 effect.fetch 那样
|
|
104
|
+
deepSet(fetchData, 'props.options', newOptions)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 同时直接更新 props.options(这是最终传递给组件的值)
|
|
108
|
+
props.options = newOptions
|
|
109
|
+
|
|
110
|
+
// 同步到 ctx.prop.props.options(确保 mergeRule 能获取到最新值)
|
|
111
|
+
if (ctxRef.prop?.props) {
|
|
112
|
+
ctxRef.prop.props.options = newOptions
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 同步到 rule.props.options
|
|
116
|
+
if (ctxRef.rule?.props) {
|
|
117
|
+
ctxRef.rule.props.options = newOptions
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 调用 api.sync 触发更新,就像 effect.fetch 那样
|
|
121
|
+
if (api && rule) {
|
|
122
|
+
api.sync(rule)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 刷新组件
|
|
126
|
+
if (ctxRef.$handle) {
|
|
127
|
+
ctxRef.$handle.refresh()
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 关键:在调用用户函数之前,立即设置 loading 并更新
|
|
132
|
+
// 这样确保 loading 状态能立即显示
|
|
133
|
+
if (targetOption) {
|
|
134
|
+
targetOption.loading = true
|
|
135
|
+
updateOptions()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 调用用户函数
|
|
139
|
+
const result = parsedFn.call(
|
|
140
|
+
this,
|
|
141
|
+
selectedOptions,
|
|
142
|
+
options,
|
|
143
|
+
updateOptions,
|
|
144
|
+
api,
|
|
145
|
+
rule
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
// 如果用户函数返回 Promise,等待完成
|
|
149
|
+
if (result && typeof result.then === 'function') {
|
|
150
|
+
return result.finally(() => {
|
|
151
|
+
updateOptions()
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return result
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
18
159
|
},
|
|
19
160
|
render(children, ctx) {
|
|
20
161
|
// 检测 loading 状态(与 mergeProp 中的逻辑保持一致)
|
package/src/parsers/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import cusStoreSelect from './cusStoreSelect'
|
|
|
15
15
|
import cusUserSelect from './cusUserSelect'
|
|
16
16
|
import flex from './flex'
|
|
17
17
|
import space from './space'
|
|
18
|
+
import spin from './spin'
|
|
18
19
|
|
|
19
20
|
export default [
|
|
20
21
|
checkbox,
|
|
@@ -33,5 +34,6 @@ export default [
|
|
|
33
34
|
cusStoreSelect,
|
|
34
35
|
cusUserSelect,
|
|
35
36
|
flex,
|
|
36
|
-
space
|
|
37
|
+
space,
|
|
38
|
+
spin
|
|
37
39
|
]
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { hasProperty } from '@form-create/utils/lib/type'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: 'spin',
|
|
5
|
+
mergeProp(ctx) {
|
|
6
|
+
// 确保不显示标题
|
|
7
|
+
if (!ctx.rule.wrap) {
|
|
8
|
+
ctx.rule.wrap = {}
|
|
9
|
+
}
|
|
10
|
+
ctx.rule.wrap.title = false
|
|
11
|
+
|
|
12
|
+
const props = ctx.prop.props || {}
|
|
13
|
+
if (!hasProperty(props, 'spinning')) {
|
|
14
|
+
props.spinning = ctx.prop.props?.spinning ?? ctx.rule.props?.spinning ?? false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 支持从多个位置读取配置
|
|
18
|
+
const bindField =
|
|
19
|
+
ctx.rule.bindField || ctx.rule.props?.bindField || ctx.prop.props?.bindField
|
|
20
|
+
let bindMode =
|
|
21
|
+
ctx.rule.bindMode || ctx.rule.props?.bindMode || ctx.prop.props?.bindMode
|
|
22
|
+
|
|
23
|
+
// 如果没有设置 bindMode,根据是否有 bindField 自动判断
|
|
24
|
+
if (!bindMode) {
|
|
25
|
+
if (bindField) {
|
|
26
|
+
bindMode = 'field'
|
|
27
|
+
} else {
|
|
28
|
+
bindMode = 'static'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 如果配置了 bindField(绑定单个字段),使用 loadData 来实现动态绑定
|
|
33
|
+
if (bindMode === 'field' && bindField) {
|
|
34
|
+
const loadDataConfig = {
|
|
35
|
+
attr: bindField,
|
|
36
|
+
to: 'props.spinning',
|
|
37
|
+
modify: true,
|
|
38
|
+
wait: 300,
|
|
39
|
+
watch: true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 添加到 effect 中(避免重复添加)
|
|
43
|
+
if (!ctx.rule.effect) {
|
|
44
|
+
ctx.rule.effect = {}
|
|
45
|
+
}
|
|
46
|
+
if (!ctx.rule.effect.loadData) {
|
|
47
|
+
ctx.rule.effect.loadData = []
|
|
48
|
+
}
|
|
49
|
+
// 检查是否已存在相同的配置,避免重复添加
|
|
50
|
+
const exists = ctx.rule.effect.loadData.some(
|
|
51
|
+
(item) => item.attr === bindField && item.to === 'props.spinning'
|
|
52
|
+
)
|
|
53
|
+
if (!exists) {
|
|
54
|
+
ctx.rule.effect.loadData.push(loadDataConfig)
|
|
55
|
+
// 手动触发 effect 来确保 loadData provider 被调用
|
|
56
|
+
if (ctx.$handle && ctx.$handle.effect) {
|
|
57
|
+
ctx.$handle.effect(ctx, 'loaded')
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 确保子组件不被 a-col 包装
|
|
63
|
+
if (ctx.rule.children && Array.isArray(ctx.rule.children)) {
|
|
64
|
+
ctx.rule.children.forEach((child) => {
|
|
65
|
+
if (child && typeof child === 'object' && child.col !== false) {
|
|
66
|
+
child.col = false
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
render(children, ctx) {
|
|
72
|
+
// 获取 spinning 状态
|
|
73
|
+
const props = ctx.prop.props || {}
|
|
74
|
+
const spinning = props.spinning || false
|
|
75
|
+
|
|
76
|
+
// 设置组件类型为 a-spin
|
|
77
|
+
if (!ctx.prop.props) {
|
|
78
|
+
ctx.prop.props = {}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 映射 props
|
|
82
|
+
ctx.prop.props.spinning = spinning
|
|
83
|
+
|
|
84
|
+
// 如果有 tip,设置 tip prop
|
|
85
|
+
const tip = ctx.rule.tip || ctx.rule.props?.tip || ctx.prop.props?.tip
|
|
86
|
+
if (tip) {
|
|
87
|
+
ctx.prop.props.tip = tip
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 如果有 delay,设置 delay prop
|
|
91
|
+
const delay = ctx.rule.delay || ctx.rule.props?.delay || ctx.prop.props?.delay
|
|
92
|
+
if (delay != null) {
|
|
93
|
+
ctx.prop.props.delay = delay
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 如果有 size,设置 size prop
|
|
97
|
+
const size = ctx.rule.size || ctx.rule.props?.size || ctx.prop.props?.size
|
|
98
|
+
if (size) {
|
|
99
|
+
ctx.prop.props.size = size
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 设置类型为 a-spin
|
|
103
|
+
ctx.prop.type = 'a-spin'
|
|
104
|
+
|
|
105
|
+
// 如果有子组件,渲染子组件,否则渲染默认内容
|
|
106
|
+
const childrenNodes = children && Array.isArray(children) && children.length > 0
|
|
107
|
+
? children
|
|
108
|
+
: null
|
|
109
|
+
|
|
110
|
+
return ctx.vNode.make('a-spin', ctx.prop, childrenNodes)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|