@longhongguo/form-create-ant-design-vue 3.3.21 → 3.3.23

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.3.21",
3
+ "version": "3.3.23",
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",
@@ -85,6 +85,14 @@ export default defineComponent({
85
85
  beforeFetch: {
86
86
  type: Function,
87
87
  default: null
88
+ },
89
+ // 数据类型:json 或 formData
90
+ dataType: {
91
+ type: String,
92
+ default: 'json',
93
+ validator(value) {
94
+ return ['json', 'formData'].includes(value)
95
+ }
88
96
  }
89
97
  },
90
98
  data() {
@@ -113,7 +121,8 @@ export default defineComponent({
113
121
  data: this.data,
114
122
  query: this.query,
115
123
  headers: this.headers,
116
- withCredentials: this.withCredentials
124
+ withCredentials: this.withCredentials,
125
+ dataType: this.dataType
117
126
  }
118
127
 
119
128
  // 如果有 beforeFetch,先调用它来修改配置
@@ -132,6 +141,9 @@ export default defineComponent({
132
141
  // 如果返回 false,取消请求
133
142
  this.loading = false
134
143
  return
144
+ } else if (result && typeof result === 'object') {
145
+ // 如果返回了新的配置对象,使用它
146
+ config = result
135
147
  }
136
148
 
137
149
  // beforeFetch 可能直接修改了 config,或者返回了新的 config
@@ -294,12 +306,33 @@ export default defineComponent({
294
306
  }
295
307
 
296
308
  // 处理请求体
297
- if (config.data) {
298
- const formData = new FormData()
299
- Object.keys(config.data).forEach((key) => {
300
- formData.append(key, config.data[key])
301
- })
302
- xhr.send(formData)
309
+ const dataType = config.dataType || 'json'
310
+ if (config.data && Object.keys(config.data).length > 0) {
311
+ if (dataType === 'formData') {
312
+ // 使用 FormData
313
+ const formData = new FormData()
314
+ Object.keys(config.data).forEach((key) => {
315
+ const value = config.data[key]
316
+ if (value !== null && value !== undefined) {
317
+ if (Array.isArray(value)) {
318
+ // 如果是数组,需要特殊处理
319
+ value.forEach((item) => {
320
+ formData.append(key, item)
321
+ })
322
+ } else {
323
+ formData.append(key, value)
324
+ }
325
+ }
326
+ })
327
+ xhr.send(formData)
328
+ } else {
329
+ // 使用 JSON
330
+ xhr.setRequestHeader(
331
+ 'Content-Type',
332
+ 'application/json;charset=UTF-8'
333
+ )
334
+ xhr.send(JSON.stringify(config.data))
335
+ }
303
336
  } else {
304
337
  xhr.send()
305
338
  }