@longhongguo/form-create-ant-design-vue 3.2.57 → 3.2.60

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@longhongguo/form-create-ant-design-vue",
3
- "version": "3.2.57",
3
+ "version": "3.2.60",
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",
@@ -84,6 +84,25 @@ export default {
84
84
  )
85
85
  })
86
86
 
87
+ // 检查父容器是否是 flex 类型,如果是,自动设置 col: false 避免被 a-col 包装
88
+ // 需要在合并完 col 后再检查,确保能覆盖默认值
89
+ if (ctx.parent && ctx.parent.rule) {
90
+ const parentType = ctx.parent.rule.type
91
+ const parentMenu = ctx.parent.rule._menu
92
+ if (
93
+ parentType === 'flex' ||
94
+ parentType === 'a-flex' ||
95
+ parentMenu?.name === 'flex'
96
+ ) {
97
+ // 如果父容器是 flex,强制设置 col 为 false,禁用 col 包装
98
+ ctx.prop.col = false
99
+ // 同时设置 rule.col 以确保在 makeWrap 中也能识别
100
+ if (ctx.rule) {
101
+ ctx.rule.col = false
102
+ }
103
+ }
104
+ }
105
+
87
106
  // 为 upload 组件自动添加 onPreview,确保始终向父窗口发送预览通知
88
107
  if (ctx.rule.type === 'upload' && !ctx.prop.props.onPreview) {
89
108
  const sendPreviewMessage = function (file) {
@@ -205,6 +224,21 @@ export default {
205
224
  const cls = rule.wrap.class
206
225
  delete rule.wrap.class
207
226
  delete rule.wrap.title
227
+
228
+ // 检查父容器是否是 flex 类型,如果是,强制禁用 col 包装
229
+ let shouldDisableCol = false
230
+ if (ctx.parent && ctx.parent.rule) {
231
+ const parentType = ctx.parent.rule.type
232
+ const parentMenu = ctx.parent.rule._menu
233
+ if (
234
+ parentType === 'flex' ||
235
+ parentType === 'a-flex' ||
236
+ parentMenu?.name === 'flex'
237
+ ) {
238
+ shouldDisableCol = true
239
+ }
240
+ }
241
+
208
242
  const item = isFalse(rule.wrap.show)
209
243
  ? children
210
244
  : this.$r(
@@ -234,7 +268,11 @@ export default {
234
268
  ...(isTitle ? { label: () => this.makeInfo(rule, uni, ctx) } : {})
235
269
  }
236
270
  )
237
- return layout === 'inline' || isFalse(_col) || isFalse(col.show)
271
+ // 如果父容器是 flex,或者 layout inline,或者 col 被显式禁用,则不使用 col 包装
272
+ return layout === 'inline' ||
273
+ isFalse(_col) ||
274
+ isFalse(col.show) ||
275
+ shouldDisableCol
238
276
  ? item
239
277
  : this.makeCol(rule, uni, [item])
240
278
  },
@@ -8,6 +8,8 @@ export default {
8
8
  const justifyContent =
9
9
  props.justifyContent || ctx.rule.justifyContent || 'flex-start'
10
10
  const alignItems = props.alignItems || ctx.rule.alignItems || 'flex-start'
11
+ const alignContent =
12
+ props.alignContent || ctx.rule.alignContent || 'flex-start'
11
13
 
12
14
  // 映射 CSS flexbox 值到 Ant Design Vue Flex 组件的 props
13
15
  const vertical =
@@ -51,19 +53,55 @@ export default {
51
53
  ctx.prop.props.gap = props.gap
52
54
  }
53
55
 
54
- // 合并其他样式到 props.style(用于非 Flex 组件控制的样式,如 padding, margin 等)
55
- const existingStyle = ctx.rule.style || {}
56
- // 排除已经被 Flex 组件处理的样式
57
- const {
58
- display,
59
- flexDirection: _fd,
60
- flexWrap: _fw,
61
- justifyContent: _jc,
62
- alignItems: _ai,
63
- ...otherStyles
64
- } = existingStyle
65
- if (Object.keys(otherStyles).length > 0) {
66
- ctx.prop.props.style = otherStyles
56
+ // 直接修改 ctx.rule.style,确保样式能够正确应用
57
+ // 因为 form-create 会将 ctx.rule.style 合并到最终的样式对象中
58
+ if (!ctx.rule.style) {
59
+ ctx.rule.style = {}
60
+ }
61
+
62
+ // 保留用户设置的 display: 'flex'(如果存在)
63
+ const userDisplay = ctx.rule.style.display
64
+ const existingStyle = { ...ctx.rule.style }
65
+
66
+ // 构建样式对象,确保从 props 读取的配置能够应用到样式中
67
+ ctx.rule.style = {
68
+ // 保留用户设置的 display,如果没有则设置为 'flex'
69
+ display: userDisplay || 'flex',
70
+ // 确保 flex 容器占满整行
71
+ width: '100%',
72
+ // 在样式中设置 flexWrap,确保从 props 读取的配置能够生效
73
+ // 这是关键的:将 props.flexWrap 的值直接应用到 style 中
74
+ flexWrap: flexWrap,
75
+ // 保留其他用户自定义样式(排除 flex 相关的,避免冲突)
76
+ ...Object.keys(existingStyle).reduce((acc, key) => {
77
+ // 排除 flex 相关的样式属性,因为我们通过 props 或新的样式设置
78
+ if (
79
+ ![
80
+ 'flexDirection',
81
+ 'flexWrap',
82
+ 'justifyContent',
83
+ 'alignItems',
84
+ 'alignContent'
85
+ ].includes(key)
86
+ ) {
87
+ acc[key] = existingStyle[key]
88
+ }
89
+ return acc
90
+ }, {})
91
+ }
92
+
93
+ // 如果设置了 alignContent,添加到样式中
94
+ if (alignContent && alignContent !== 'flex-start') {
95
+ ctx.rule.style.alignContent = alignContent
96
+ }
97
+
98
+ // 同时也设置到 ctx.prop.props.style,作为备用
99
+ if (!ctx.prop.props.style) {
100
+ ctx.prop.props.style = {}
101
+ }
102
+ ctx.prop.props.style = {
103
+ ...ctx.prop.props.style,
104
+ ...ctx.rule.style
67
105
  }
68
106
 
69
107
  // 确保 children 存在
@@ -107,6 +145,13 @@ export default {
107
145
  // children 会通过 form-create 的机制自动渲染
108
146
  const childrenNodes = children || []
109
147
 
110
- return ctx.vNode.make('a-flex', prop, childrenNodes)
148
+ // flex 容器包装在 col 中,确保它占满整行(span: 24)
149
+ // 这样 flex 容器才能有足够的宽度,子项才能自适应展示
150
+ return ctx.vNode.col(
151
+ { props: { span: 24 } },
152
+ {
153
+ default: () => [ctx.vNode.make('a-flex', prop, childrenNodes)]
154
+ }
155
+ )
111
156
  }
112
157
  }