el-form-renderer-vue3 1.0.7 → 1.0.9

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/README.md CHANGED
@@ -1,409 +1,413 @@
1
- ## 遗留问题 :待解决
2
-
3
- select multiple 多选时 必须初始化空数组(在 elementplus v-model 初始化 updateValue 时 为空数组会触发校验)
4
-
5
- ## Introduction
6
-
7
- ### WHAT
8
-
9
- form-renderer 基于元素 element-plus,但不限于元素 element-plus 组件。在完全继承 element-plus 元素的 form 属性的基础上,进行了扩展。一些非表单组件或自定义组件,因此,用户可以使用一段 json 来呈现完整的表单。
10
-
11
- ### WHY
12
-
13
- 在我们的日常开发中,有很多有表单的页面,通常表单结构相似,逻辑重复。el 表单呈现器没有复杂的逻辑。它只转换 JSON 来呈现表单项,节省了编写业务逻辑的时间和精力,并减少了重复代码。
14
-
15
- ## Features
16
-
17
- - json 呈现表单
18
- - 支持与自定义组件集成
19
- - 支持 updateForm 方法批量更新表单数据
20
- - 支持 setOptions 方法,动态更改选择选项
21
- - 内容支持 inputFormat、outputFormat、trim 以处理组件的输入和输出值
22
- - 支持 v-model
23
-
24
- ## Links
25
-
26
- - [$attrs 和 $listeners (vue2&&vue3)](https://blog.csdn.net/qq_63358859/article/details/133699476?spm=1001.2014.3001.5501)
27
- - [vue2 与 vue3 函数式组件](https://blog.csdn.net/qq_63358859/article/details/133635120?spm=1001.2014.3001.5501)
28
- - [vue 2 与 vue3 获取模版引用 (ref)的区别](https://blog.csdn.net/qq_63358859/article/details/133532229?spm=1001.2014.3001.5501)
29
- - [vue2 与 vue3 v-model 的区别](https://blog.csdn.net/qq_63358859/article/details/133484380?spm=1001.2014.3001.5501)
30
- - [vue2 版本](https://blog.csdn.net/qq_63358859/article/details/130442636?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169684271816800180612618%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=169684271816800180612618&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-7-130442636-null-null.nonecase&utm_term=render&spm=1018.2226.3001.4450)
31
- - [中文文档](https://gitee.com/childe-jia/form-render/wikis/%E6%96%87%E6%A1%A3/%E4%BB%8B%E7%BB%8D)
32
- - [element-plus table 的封装](https://gitee.com/childe-jia/table-vue3)
33
-
34
- ## Quick Start
35
-
36
- ```ts
37
- pnpm i el-form-renderer-vue3
38
- ```
39
-
40
- ```ts
41
- import elFormRenderer from "el-form-renderer-vue3";
42
- app.use(elFormRenderer);
43
- ```
44
-
45
- ```ts
46
- <template>
47
- <el-form-renderer
48
- label-width="100px"
49
- :content="content"
50
- v-model:FormData="FormData"
51
- ref="form"
52
- >
53
- <el-button @click="resetForm">reset</el-button>
54
- <el-button @click="setValue">设置名字为小明</el-button>
55
- <pre>{{ FormData }}</pre>
56
- </el-form-renderer>
57
- </template>
58
-
59
- <script setup>
60
- import { reactive, ref } from "vue";
61
-
62
- const form = ref();
63
- let FormData = reactive({
64
- name: "",
65
- type: [],
66
- startDate: "2019-01-01",
67
- endDate: "2019-01-02",
68
- region: [],
69
- date: ["2019-01-01", "2019-01-02"],
70
- });
71
- const content = reactive([
72
- {
73
- type: "input",
74
- id: "name",
75
- label: "name",
76
- attrs: { "data-name": "form1" },
77
- el: {
78
- size: "default",
79
- placeholder: "test placeholder",
80
- },
81
- rules: [
82
- { required: true, message: "miss name", trigger: "blur" },
83
- { min: 3, max: 5, message: "length between 3 to 5", trigger: "blur" },
84
- ],
85
- },
86
- {
87
- type: "select",
88
- id: "region",
89
- label: "region",
90
- options: [
91
- {
92
- label: "shanghai",
93
- value: "shanghai",
94
- },
95
- {
96
- label: "beijing",
97
- value: "beijing",
98
- },
99
- {
100
- label: "guangzhou",
101
- value: "guangzhou",
102
- },
103
- ],
104
- el: { filterable: true, multiple: true, multipleLimit: 2 },
105
- rules: [{ required: true, message: "miss area", trigger: "change" }],
106
- },
107
- {
108
- type: "date-picker",
109
- id: "date",
110
- label: "date",
111
- el: {
112
- type: "daterange",
113
- valueFormat: "yyyy-MM-dd",
114
- },
115
- rules: [{ required: true, message: "miss date", trigger: "change" }],
116
- inputFormat: (row) => {
117
- if (row.startDate && row.endDate) {
118
- return [row.startDate, row.endDate];
119
- }
120
- },
121
- outputFormat: (val) => {
122
- if (!val) {
123
- return { startDate: "", endDate: "" };
124
- }
125
- return {
126
- startDate: val[0],
127
- endDate: val[1],
128
- };
129
- },
130
- },
131
- {
132
- type: "switch",
133
- id: "delivery",
134
- label: "delivery",
135
- },
136
- {
137
- type: "checkbox-group",
138
- id: "type",
139
- label: "type",
140
- default: [],
141
- options: [
142
- {
143
- label: "typeA",
144
- },
145
- {
146
- label: "typeB",
147
- },
148
- {
149
- label: "typeC",
150
- },
151
- ],
152
- rules: [{ type: "array", required: true, message: "miss type", trigger: "change" }],
153
- },
154
- {
155
- type: "radio-group",
156
- id: "resource",
157
- label: "resource",
158
- options: [
159
- {
160
- label: "resourceA",
161
- value: "A",
162
- },
163
- {
164
- label: "resourceB",
165
- value: "B",
166
- },
167
- ],
168
- rules: [{ required: true, message: "miss resource", trigger: "change" }],
169
- },
170
- {
171
- type: "input",
172
- id: "desc",
173
- label: "desc",
174
- el: {
175
- type: "textarea",
176
- },
177
- rules: [{ required: true, message: "miss desc", trigger: "blur" }],
178
- },
179
- ]);
180
- const resetForm = () => {
181
- form.value.methods.resetFields();
182
- };
183
- const setValue = () => {
184
- FormData.name = "小明";
185
- };
186
- </script>
187
-
188
- ```
189
-
190
- ## Props
191
-
192
- ```ts
193
- export default {
194
- // ...
195
- props: {
196
- /**
197
- * support all el-form's props
198
- * @see: https://element.eleme.io/#/zh-CN/component/form#form-attributes
199
- */
200
-
201
- /**
202
- * 表单项的配置数组,每个表单项代表一个原子表单项
203
- * the form config's array, each item represents a form-item
204
- */
205
- content: {
206
- type: Array, // type:Content[], check Content's definition below
207
- required: true
208
- },
209
-
210
- /**
211
- * disable all form-items
212
- */
213
- disabled: {
214
- type: Boolean,
215
- default: false
216
- }
217
- }
218
- }
219
-
220
- /**
221
- * 表单项的typescript定义
222
- * 支持所有el-form-item's props。表单项组件本身的props定义在el上
223
- * definition of form-item written in typescript.
224
- * support all el-form-item's props. The component's props need to be set at prop el
225
- */
226
- interface Content {
227
- // 每一个原子都存在 id,用于存储该原子的值,不能重复
228
- // key of form-item value in form value. Must be unique
229
- id: string
230
-
231
- /**
232
- * 可以是element提供的所有表单组件类型,如传入'input',则渲染出'el-input'
233
- * 当type="group"时,可以创造复杂对象类型的表单数据,配合items使用。此时getFormValue()返回的是对象类型的数据,对象的每个属性对应items里的每一项
234
- * support all element's form component, e.g., type 'input' will render as 'el-input'.
235
- * you can create nested form value with type 'group' and use items to define that form value's shape. The type of this form value will be 'object'
236
- */
237
- type: string
238
-
239
- /**
240
- * 当type="group"时使用
241
- * items内依然遵循同一层级的id不重复的原则
242
- * using with type 'group'
243
- * the `id` in each item of items must be unique
244
- */
245
- items: Content[]
246
-
247
- /**
248
- * 默认值
249
- * FIXME: 别用关键字做 key
250
- */
251
- default?: any
252
-
253
- /**
254
- * 当 type === 'input' 时展示文本值
255
- * 当 type === 'select' 时展示对应 label
256
- * 对于其他组件等同于 disabled = true
257
- */
258
- readonly = false
259
-
260
- /**
261
- * @deprecated
262
- */
263
- enableWhen?: object | string
264
-
265
- /**
266
- * 传入一个方法,并返回 boolean,返回 true 时则隐藏该表单项
267
- * formValue 为当前 form 的值,item 为当前表单项的定义
268
- * hide the form-item when return true
269
- * formValue is same as what getFormValue returns, and item is the config of this form-item
270
- */
271
- hidden?: (formValue: Object, item: Content) => boolean
272
-
273
- /**
274
- * 具有选择功能的原子表单可用此定义可选项
275
- * use with type: select, radio-group, radio-button, checkbox-group, checkbox-button
276
- */
277
- options?: {label: string; value?: any}[]
278
-
279
- /**
280
- * 配置remote.url,即可远程配置组件的某个prop!
281
- * remote接受以下属性:
282
- * url: 远程接口的地址
283
- * prop: 要注入的 prop 的名称,默认为 options
284
- * request: 可选,请求方法
285
- * dataPath: 可选,data在响应体中的路径
286
- * onResponse: 可选,处理请求回来的数据
287
- * onError: 可选,处理请求出错的情况
288
- * 另外,针对 select、radio-group、checkbox-group,远程数据能自动映射成 el-option 选项!以下属性仅在此情况使用
289
- * label: 可选,可直接配置远程数据中用作 label 的key
290
- * value: 可选,可直接配置远程数据中用作 value 的key
291
- * @see https://zhuanlan.zhihu.com/p/97827063
292
- *
293
- * use remote to set one prop! remote accept following props:
294
- * url: remote api address
295
- * prop: prop name that data inject
296
- * request: optional, customize how to get your options
297
- * dataPath: optional, data's path in response
298
- * onResponse: optional, deal with your response
299
- * onError: optional, deal with request error
300
- * and, we treat select、radio-group、checkbox-group specially and the resp will be map as an el-option's group! following props only suitable for this case
301
- * label: optional, label key in resp
302
- * value: optional, value key in resp
303
- */
304
- remote?: {
305
- url: string
306
- request = () => this.$axios.get(url).then(resp => resp.data)
307
- prop = 'options'
308
- dataPath = ''
309
- onResponse = resp => {
310
- if (dataPath) resp = _get(resp, dataPath)
311
- switch (this.data.type) {
312
- case 'select':
313
- case 'checkbox-group':
314
- case 'radio-group':
315
- return resp.map(item => ({
316
- label: item[label],
317
- value: item[value]
318
- }))
319
- default:
320
- return resp
321
- }
322
- }
323
- onError = error => console.error(error.message)
324
- label = 'label'
325
- value = 'value'
326
- }
327
-
328
- attrs?: object // html attributes
329
- /**
330
- * 用于定义具体原子表单(如el-input)的属性,比如定义el-input的placeholder
331
- * use to define props of the actual component of this form-item, such as placeholder of el-input
332
- */
333
- el?: object
334
-
335
- /**
336
- * 使用自定义组件
337
- * component适用于渲染局部注册组件和自定义组件,而type适用于带el-前缀的全局组件
338
- * custom component
339
- * use it when element's form components are not enough
340
- */
341
- component?: Vue
342
-
343
- /**
344
- * 是否覆盖自定义组件内置的校验规则
345
- * `true` 为覆盖, 默认为 `false`
346
- * whether to override the validation rules written in custom components
347
- * `true` to override, default `false`
348
- */
349
- overrideRules: boolean
350
-
351
- label?: string //set el-form-item's label
352
- trim = true // trim value at change event
353
-
354
- // 用于处理输入值,输入的值包括:1. default;2. v-model;3. updateForm。参数为整个表单的值对象或 updateForm 传入的对象
355
- // 如果 inputFormat 返回 undefined,则不会更新此表单项
356
- // obj is param you passed to updateForm. You can use this function to hijack this process and customize the form value
357
- inputFormat?: (obj: any) => any
358
-
359
- // 用于处理输出值,参数为对应组件返回值
360
- // 如果处理后的值是对象类型,会覆盖(Object.assign)到整个表单的值上
361
- // used to hijack the getFormValue's process and customize the return value
362
- outputFormat?: (val: any) => any
363
-
364
- // set el-form-item's rules
365
- rules?: object
366
-
367
- // @deprecated
368
- atChange?: (id: string, value: any) => void
369
-
370
- /**
371
- * 监听表单项发出的事件
372
- * listen to any events emitted by component of form item
373
- * @param {any[]} args - what that event emits
374
- * @param {function} updateForm - same as methods.updateForm
375
- */
376
- on?: {
377
- [eventName: string]: (args: any[], updateForm: function) => void
378
- }
379
- }
380
-
381
- /**
382
- * a tour of typescript
383
- */
384
- interface obj {
385
- a: string // type string
386
- b?: string // type string, optional
387
- c = true // type boolean, optional, default true
388
- d: string[] // type array, each item must be string
389
- e: any // could be any valid js type
390
- f: (a: number) => void // type function, which receives a param 'a' as number and return nothing
391
- h: Vue // instance of Vue
392
- i: {[a: string]: number} // type object, whose key is type string, and value is type number
393
- }
394
- ```
395
-
396
- ## Methods
397
-
398
- support all [el-form's methods](https://element.eleme.io/#/zh-CN/component/form#form-methods)
399
-
400
- ## Slots
401
-
402
- | Slot | Description |
403
- | -------- | ------------------------------------------- |
404
- | default | insert at bottom |
405
- | id:hello | insert before form-item whose id is 'hello' |
406
-
407
- ## Inspiration
408
-
409
- thanks to [el-form-renderer](https://github.com/femessage/el-form-renderer/)
1
+ ## 技术交流群 711368818
2
+
3
+ <img src="./src/assets/qq.jpg" width="200" />
4
+
5
+ ## 遗留问题 :待解决
6
+
7
+ select 为 multiple 多选时 必须初始化空数组(在 elementplus v-model 初始化 updateValue 时 为空数组会触发校验)
8
+
9
+ ## Introduction
10
+
11
+ ### WHAT
12
+
13
+ form-renderer 基于元素 element-plus,但不限于元素 element-plus 组件。在完全继承 element-plus 元素的 form 属性的基础上,进行了扩展。一些非表单组件或自定义组件,因此,用户可以使用一段 json 来呈现完整的表单。
14
+
15
+ ### WHY
16
+
17
+ 在我们的日常开发中,有很多有表单的页面,通常表单结构相似,逻辑重复。el 表单呈现器没有复杂的逻辑。它只转换 JSON 来呈现表单项,节省了编写业务逻辑的时间和精力,并减少了重复代码。
18
+
19
+ ## Features
20
+
21
+ - json 呈现表单
22
+ - 支持与自定义组件集成
23
+ - 支持 updateForm 方法批量更新表单数据
24
+ - 支持 setOptions 方法,动态更改选择选项
25
+ - 内容支持 inputFormat、outputFormat、trim 以处理组件的输入和输出值
26
+ - 支持 v-model
27
+
28
+ ## Links
29
+
30
+ - [$attrs 和 $listeners (vue2&&vue3)](https://blog.csdn.net/qq_63358859/article/details/133699476?spm=1001.2014.3001.5501)
31
+ - [vue2 与 vue3 函数式组件](https://blog.csdn.net/qq_63358859/article/details/133635120?spm=1001.2014.3001.5501)
32
+ - [vue 2 与 vue3 获取模版引用 (ref)的区别](https://blog.csdn.net/qq_63358859/article/details/133532229?spm=1001.2014.3001.5501)
33
+ - [vue2 与 vue3 v-model 的区别](https://blog.csdn.net/qq_63358859/article/details/133484380?spm=1001.2014.3001.5501)
34
+ - [vue2 版本](https://blog.csdn.net/qq_63358859/article/details/130442636?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169684271816800180612618%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=169684271816800180612618&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-7-130442636-null-null.nonecase&utm_term=render&spm=1018.2226.3001.4450)
35
+ - [中文文档](https://gitee.com/childe-jia/form-render/wikis/%E6%96%87%E6%A1%A3/%E4%BB%8B%E7%BB%8D)
36
+ - [element-plus table 的封装](https://gitee.com/childe-jia/table-vue3)
37
+
38
+ ## Quick Start
39
+
40
+ ```ts
41
+ pnpm i el-form-renderer-vue3
42
+ ```
43
+
44
+ ```ts
45
+ import elFormRenderer from "el-form-renderer-vue3";
46
+ app.use(elFormRenderer);
47
+ ```
48
+
49
+ ```ts
50
+ <template>
51
+ <el-form-renderer
52
+ label-width="100px"
53
+ :content="content"
54
+ v-model:FormData="FormData"
55
+ ref="form"
56
+ >
57
+ <el-button @click="resetForm">reset</el-button>
58
+ <el-button @click="setValue">设置名字为小明</el-button>
59
+ <pre>{{ FormData }}</pre>
60
+ </el-form-renderer>
61
+ </template>
62
+
63
+ <script setup>
64
+ import { reactive, ref } from "vue";
65
+
66
+ const form = ref();
67
+ let FormData = reactive({
68
+ name: "",
69
+ type: [],
70
+ startDate: "2019-01-01",
71
+ endDate: "2019-01-02",
72
+ region: [],
73
+ date: ["2019-01-01", "2019-01-02"],
74
+ });
75
+ const content = reactive([
76
+ {
77
+ type: "input",
78
+ id: "name",
79
+ label: "name",
80
+ attrs: { "data-name": "form1" },
81
+ el: {
82
+ size: "default",
83
+ placeholder: "test placeholder",
84
+ },
85
+ rules: [
86
+ { required: true, message: "miss name", trigger: "blur" },
87
+ { min: 3, max: 5, message: "length between 3 to 5", trigger: "blur" },
88
+ ],
89
+ },
90
+ {
91
+ type: "select",
92
+ id: "region",
93
+ label: "region",
94
+ options: [
95
+ {
96
+ label: "shanghai",
97
+ value: "shanghai",
98
+ },
99
+ {
100
+ label: "beijing",
101
+ value: "beijing",
102
+ },
103
+ {
104
+ label: "guangzhou",
105
+ value: "guangzhou",
106
+ },
107
+ ],
108
+ el: { filterable: true, multiple: true, multipleLimit: 2 },
109
+ rules: [{ required: true, message: "miss area", trigger: "change" }],
110
+ },
111
+ {
112
+ type: "date-picker",
113
+ id: "date",
114
+ label: "date",
115
+ el: {
116
+ type: "daterange",
117
+ valueFormat: "yyyy-MM-dd",
118
+ },
119
+ rules: [{ required: true, message: "miss date", trigger: "change" }],
120
+ inputFormat: (row) => {
121
+ if (row.startDate && row.endDate) {
122
+ return [row.startDate, row.endDate];
123
+ }
124
+ },
125
+ outputFormat: (val) => {
126
+ if (!val) {
127
+ return { startDate: "", endDate: "" };
128
+ }
129
+ return {
130
+ startDate: val[0],
131
+ endDate: val[1],
132
+ };
133
+ },
134
+ },
135
+ {
136
+ type: "switch",
137
+ id: "delivery",
138
+ label: "delivery",
139
+ },
140
+ {
141
+ type: "checkbox-group",
142
+ id: "type",
143
+ label: "type",
144
+ default: [],
145
+ options: [
146
+ {
147
+ label: "typeA",
148
+ },
149
+ {
150
+ label: "typeB",
151
+ },
152
+ {
153
+ label: "typeC",
154
+ },
155
+ ],
156
+ rules: [{ type: "array", required: true, message: "miss type", trigger: "change" }],
157
+ },
158
+ {
159
+ type: "radio-group",
160
+ id: "resource",
161
+ label: "resource",
162
+ options: [
163
+ {
164
+ label: "resourceA",
165
+ value: "A",
166
+ },
167
+ {
168
+ label: "resourceB",
169
+ value: "B",
170
+ },
171
+ ],
172
+ rules: [{ required: true, message: "miss resource", trigger: "change" }],
173
+ },
174
+ {
175
+ type: "input",
176
+ id: "desc",
177
+ label: "desc",
178
+ el: {
179
+ type: "textarea",
180
+ },
181
+ rules: [{ required: true, message: "miss desc", trigger: "blur" }],
182
+ },
183
+ ]);
184
+ const resetForm = () => {
185
+ form.value.methods.resetFields();
186
+ };
187
+ const setValue = () => {
188
+ FormData.name = "小明";
189
+ };
190
+ </script>
191
+
192
+ ```
193
+
194
+ ## Props
195
+
196
+ ```ts
197
+ export default {
198
+ // ...
199
+ props: {
200
+ /**
201
+ * support all el-form's props
202
+ * @see: https://element.eleme.io/#/zh-CN/component/form#form-attributes
203
+ */
204
+
205
+ /**
206
+ * 表单项的配置数组,每个表单项代表一个原子表单项
207
+ * the form config's array, each item represents a form-item
208
+ */
209
+ content: {
210
+ type: Array, // type:Content[], check Content's definition below
211
+ required: true
212
+ },
213
+
214
+ /**
215
+ * disable all form-items
216
+ */
217
+ disabled: {
218
+ type: Boolean,
219
+ default: false
220
+ }
221
+ }
222
+ }
223
+
224
+ /**
225
+ * 表单项的typescript定义
226
+ * 支持所有el-form-item's props。表单项组件本身的props定义在el上
227
+ * definition of form-item written in typescript.
228
+ * support all el-form-item's props. The component's props need to be set at prop el
229
+ */
230
+ interface Content {
231
+ // 每一个原子都存在 id,用于存储该原子的值,不能重复
232
+ // key of form-item value in form value. Must be unique
233
+ id: string
234
+
235
+ /**
236
+ * 可以是element提供的所有表单组件类型,如传入'input',则渲染出'el-input'
237
+ * 当type="group"时,可以创造复杂对象类型的表单数据,配合items使用。此时getFormValue()返回的是对象类型的数据,对象的每个属性对应items里的每一项
238
+ * support all element's form component, e.g., type 'input' will render as 'el-input'.
239
+ * you can create nested form value with type 'group' and use items to define that form value's shape. The type of this form value will be 'object'
240
+ */
241
+ type: string
242
+
243
+ /**
244
+ * 当type="group"时使用
245
+ * items内依然遵循同一层级的id不重复的原则
246
+ * using with type 'group'
247
+ * the `id` in each item of items must be unique
248
+ */
249
+ items: Content[]
250
+
251
+ /**
252
+ * 默认值
253
+ * FIXME: 别用关键字做 key
254
+ */
255
+ default?: any
256
+
257
+ /**
258
+ * type === 'input' 时展示文本值
259
+ * 当 type === 'select' 时展示对应 label
260
+ * 对于其他组件等同于 disabled = true
261
+ */
262
+ readonly = false
263
+
264
+ /**
265
+ * @deprecated
266
+ */
267
+ enableWhen?: object | string
268
+
269
+ /**
270
+ * 传入一个方法,并返回 boolean,返回 true 时则隐藏该表单项
271
+ * formValue 为当前 form 的值,item 为当前表单项的定义
272
+ * hide the form-item when return true
273
+ * formValue is same as what getFormValue returns, and item is the config of this form-item
274
+ */
275
+ hidden?: (formValue: Object, item: Content) => boolean
276
+
277
+ /**
278
+ * 具有选择功能的原子表单可用此定义可选项
279
+ * use with type: select, radio-group, radio-button, checkbox-group, checkbox-button
280
+ */
281
+ options?: {label: string; value?: any}[]
282
+
283
+ /**
284
+ * 配置remote.url,即可远程配置组件的某个prop!
285
+ * remote接受以下属性:
286
+ * url: 远程接口的地址
287
+ * prop: 要注入的 prop 的名称,默认为 options
288
+ * request: 可选,请求方法
289
+ * dataPath: 可选,data在响应体中的路径
290
+ * onResponse: 可选,处理请求回来的数据
291
+ * onError: 可选,处理请求出错的情况
292
+ * 另外,针对 select、radio-group、checkbox-group,远程数据能自动映射成 el-option 选项!以下属性仅在此情况使用
293
+ * label: 可选,可直接配置远程数据中用作 label 的key
294
+ * value: 可选,可直接配置远程数据中用作 value 的key
295
+ * @see https://zhuanlan.zhihu.com/p/97827063
296
+ *
297
+ * use remote to set one prop! remote accept following props:
298
+ * url: remote api address
299
+ * prop: prop name that data inject
300
+ * request: optional, customize how to get your options
301
+ * dataPath: optional, data's path in response
302
+ * onResponse: optional, deal with your response
303
+ * onError: optional, deal with request error
304
+ * and, we treat select、radio-group、checkbox-group specially and the resp will be map as an el-option's group! following props only suitable for this case
305
+ * label: optional, label key in resp
306
+ * value: optional, value key in resp
307
+ */
308
+ remote?: {
309
+ url: string
310
+ request = () => this.$axios.get(url).then(resp => resp.data)
311
+ prop = 'options'
312
+ dataPath = ''
313
+ onResponse = resp => {
314
+ if (dataPath) resp = _get(resp, dataPath)
315
+ switch (this.data.type) {
316
+ case 'select':
317
+ case 'checkbox-group':
318
+ case 'radio-group':
319
+ return resp.map(item => ({
320
+ label: item[label],
321
+ value: item[value]
322
+ }))
323
+ default:
324
+ return resp
325
+ }
326
+ }
327
+ onError = error => console.error(error.message)
328
+ label = 'label'
329
+ value = 'value'
330
+ }
331
+
332
+ attrs?: object // html attributes
333
+ /**
334
+ * 用于定义具体原子表单(如el-input)的属性,比如定义el-input的placeholder
335
+ * use to define props of the actual component of this form-item, such as placeholder of el-input
336
+ */
337
+ el?: object
338
+
339
+ /**
340
+ * 使用自定义组件
341
+ * component适用于渲染局部注册组件和自定义组件,而type适用于带el-前缀的全局组件
342
+ * custom component
343
+ * use it when element's form components are not enough
344
+ */
345
+ component?: Vue
346
+
347
+ /**
348
+ * 是否覆盖自定义组件内置的校验规则
349
+ * `true` 为覆盖, 默认为 `false`
350
+ * whether to override the validation rules written in custom components
351
+ * `true` to override, default `false`
352
+ */
353
+ overrideRules: boolean
354
+
355
+ label?: string //set el-form-item's label
356
+ trim = true // trim value at change event
357
+
358
+ // 用于处理输入值,输入的值包括:1. default;2. v-model;3. updateForm。参数为整个表单的值对象或 updateForm 传入的对象
359
+ // 如果 inputFormat 返回 undefined,则不会更新此表单项
360
+ // obj is param you passed to updateForm. You can use this function to hijack this process and customize the form value
361
+ inputFormat?: (obj: any) => any
362
+
363
+ // 用于处理输出值,参数为对应组件返回值
364
+ // 如果处理后的值是对象类型,会覆盖(Object.assign)到整个表单的值上
365
+ // used to hijack the getFormValue's process and customize the return value
366
+ outputFormat?: (val: any) => any
367
+
368
+ // set el-form-item's rules
369
+ rules?: object
370
+
371
+ // @deprecated
372
+ atChange?: (id: string, value: any) => void
373
+
374
+ /**
375
+ * 监听表单项发出的事件
376
+ * listen to any events emitted by component of form item
377
+ * @param {any[]} args - what that event emits
378
+ * @param {function} updateForm - same as methods.updateForm
379
+ */
380
+ on?: {
381
+ [eventName: string]: (args: any[], updateForm: function) => void
382
+ }
383
+ }
384
+
385
+ /**
386
+ * a tour of typescript
387
+ */
388
+ interface obj {
389
+ a: string // type string
390
+ b?: string // type string, optional
391
+ c = true // type boolean, optional, default true
392
+ d: string[] // type array, each item must be string
393
+ e: any // could be any valid js type
394
+ f: (a: number) => void // type function, which receives a param 'a' as number and return nothing
395
+ h: Vue // instance of Vue
396
+ i: {[a: string]: number} // type object, whose key is type string, and value is type number
397
+ }
398
+ ```
399
+
400
+ ## Methods
401
+
402
+ support all [el-form's methods](https://element.eleme.io/#/zh-CN/component/form#form-methods)
403
+
404
+ ## Slots
405
+
406
+ | Slot | Description |
407
+ | -------- | ------------------------------------------- |
408
+ | default | insert at bottom |
409
+ | id:hello | insert before form-item whose id is 'hello' |
410
+
411
+ ## Inspiration
412
+
413
+ thanks to [el-form-renderer](https://github.com/femessage/el-form-renderer/)