@leiyin/v-form-renderer 0.1.3-alpha.3 → 1.0.0

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/dist/index.d.ts CHANGED
@@ -1,9 +1,229 @@
1
- declare const __VLS_export: any;
1
+ import * as vue from 'vue';
2
+ import { Component, PropType, ExtractPublicPropTypes } from 'vue';
3
+ import { FormItemRule } from 'element-plus';
4
+
5
+ /** 表单项类型 */
6
+ type Content = {
7
+ /**
8
+ * 每一个原子都存在 id,用于存储该原子的值,不能重复
9
+ */
10
+ id: string;
11
+ /**
12
+ * 对应el-form-item 的 label值
13
+ *
14
+ */
15
+ label?: string | Function;
16
+ /**
17
+ * 可以是element提供的所有表单组件类型,如传入'input',则渲染出'el-input'
18
+ * 当type="group"时,可以创造复杂对象类型的表单数据,配合items使用。此时getFormValue()返回的是对象类型的数据,对象的每个属性对应items里的每一项
19
+ */
20
+ type?: string;
21
+ /**
22
+ * 用于定义具体原子表单(如el-input)的属性,比如定义el-input的placeholder,
23
+ * tips: 原始属性,尽量不要传响应式数据
24
+ */
25
+ el?: Record<string, any>;
26
+ /**
27
+ * 当 type === 'input' 时展示文本值
28
+ * 当 type === 'select' 时展示对应 label
29
+ * 对于其他组件等同于 disabled = true
30
+ */
31
+ readonly?: boolean;
32
+ /**
33
+ * 输入时自动去掉前后空格
34
+ */
35
+ trim?: boolean;
36
+ /**
37
+ * 表单初始化时的默认值
38
+ */
39
+ default?: any;
40
+ /**
41
+ * 当type="group"时使用
42
+ * items内依然遵循同一层级的id不重复的原则
43
+ */
44
+ items?: Content[];
45
+ /**
46
+ * 传入一个方法,并返回 boolean,返回 true 时则隐藏该表单项
47
+ * formValue 为当前 form 的值,item 为当前表单项的定义
48
+ */
49
+ hidden?: (formValue: Record<string, any>, item: Content) => boolean;
50
+ /**
51
+ * 传入一个方法,并返回 boolean,返回 true 时则禁用该表单项
52
+ * formValue 为当前 form 的值,item 为当前表单项的定义
53
+ */
54
+ disabled?: (formValue: Record<string, any>, item: Content) => boolean;
55
+ /**
56
+ * 具有选择功能的原子表单可用此定义可选项
57
+ */
58
+ options?: {
59
+ label: string;
60
+ value?: any;
61
+ }[];
62
+ /**
63
+ * 使用自定义组件
64
+ * component适用于渲染局部注册组件和自定义组件,而type适用于带el-前缀的全局组件
65
+ */
66
+ component?: Component;
67
+ /**
68
+ * 用于处理输入值,输入的值包括:1. default;2. v-model;3. updateForm。参数为整个表单的值对象或 updateForm 传入的对象
69
+ * 如果 inputFormat 返回 undefined,则不会更新此表单项
70
+ */
71
+ inputFormat?: (obj: any) => any;
72
+ /**
73
+ * 用于处理输出值,参数为对应组件返回值
74
+ * 如果处理后的值是对象类型,会覆盖(Object.assign)到整个表单的值上
75
+ */
76
+ outputFormat?: (val: any, obj: any) => any;
77
+ /** 设置表单校验规则 */
78
+ rules?: FormItemRule[];
79
+ /**
80
+ * 配置remote.url,即可远程配置组件的某个prop!
81
+ * remote接受以下属性:
82
+ * url: 远程接口的地址
83
+ * prop: 要注入的 prop 的名称,默认为 options
84
+ * request: 可选,请求方法
85
+ * dataPath: 可选,data在响应体中的路径
86
+ * onResponse: 可选,处理请求回来的数据
87
+ * onError: 可选,处理请求出错的情况
88
+ * 另外,针对 select、radio-group、checkbox-group,远程数据能自动映射成 el-option 选项!以下属性仅在此情况使用
89
+ * label: 可选,可直接配置远程数据中用作 label 的key
90
+ * value: 可选,可直接配置远程数据中用作 value 的key
91
+ */
92
+ remote?: {
93
+ url?: (params: Record<string, any>) => Promise<any>;
94
+ request?: () => Promise<any>;
95
+ params?: Record<string, any>;
96
+ prop?: string;
97
+ dataPath?: string;
98
+ onResponse?: (resp: any) => any;
99
+ onError?: (error: any) => void;
100
+ label?: string | Function;
101
+ value?: string | Function;
102
+ children?: string;
103
+ };
104
+ /**
105
+ * 监听表单项发出的事件
106
+ * listen to any events emitted by component of form item
107
+ * @param {any[]} args - what that event emits
108
+ * @param {function} updateForm - same as methods.updateForm
109
+ */
110
+ on?: {
111
+ [eventName: string]: (args: any[], updateForm: Function, setOptions: Function) => void;
112
+ };
113
+ };
114
+
115
+ declare var __VLS_13: `id:${string}`;
116
+ declare var __VLS_14: {};
117
+ declare var __VLS_23: {};
118
+ type __VLS_Slots = {} & {
119
+ [K in NonNullable<typeof __VLS_13>]?: (props: typeof __VLS_14) => any;
120
+ } & {
121
+ default?: (props: typeof __VLS_23) => any;
122
+ };
123
+ declare const __VLS_base: vue.DefineComponent<vue.ExtractPropTypes<{
124
+ content: {
125
+ readonly type: vue.PropType<Content[]>;
126
+ readonly required: true;
127
+ readonly default: () => never[];
128
+ };
129
+ labelWidth: {
130
+ readonly type: StringConstructor;
131
+ readonly default: "98px";
132
+ };
133
+ disabled: {
134
+ readonly type: BooleanConstructor;
135
+ readonly default: false;
136
+ };
137
+ inline: {
138
+ readonly type: BooleanConstructor;
139
+ readonly default: true;
140
+ };
141
+ readonly: {
142
+ readonly type: BooleanConstructor;
143
+ readonly default: false;
144
+ };
145
+ model: {
146
+ type: vue.PropType<any>;
147
+ };
148
+ }>, {
149
+ getFormValue: () => Record<string, any>;
150
+ validate: () => Promise<boolean | undefined | void>;
151
+ resetFields: () => Promise<void>;
152
+ updateForm: (newValue: Record<string, any>) => void;
153
+ setOptions: (id: string, data: any[]) => void;
154
+ }, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
155
+ enter: (...args: any[]) => void;
156
+ "update:model": (value: any) => void;
157
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
158
+ content: {
159
+ readonly type: vue.PropType<Content[]>;
160
+ readonly required: true;
161
+ readonly default: () => never[];
162
+ };
163
+ labelWidth: {
164
+ readonly type: StringConstructor;
165
+ readonly default: "98px";
166
+ };
167
+ disabled: {
168
+ readonly type: BooleanConstructor;
169
+ readonly default: false;
170
+ };
171
+ inline: {
172
+ readonly type: BooleanConstructor;
173
+ readonly default: true;
174
+ };
175
+ readonly: {
176
+ readonly type: BooleanConstructor;
177
+ readonly default: false;
178
+ };
179
+ model: {
180
+ type: vue.PropType<any>;
181
+ };
182
+ }>> & Readonly<{
183
+ "onUpdate:model"?: ((value: any) => any) | undefined;
184
+ onEnter?: ((...args: any[]) => any) | undefined;
185
+ }>, {
186
+ content: Content[];
187
+ labelWidth: string;
188
+ disabled: boolean;
189
+ inline: boolean;
190
+ readonly: boolean;
191
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
192
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
2
193
  declare const _default: typeof __VLS_export;
3
194
 
4
- interface TFormProp {
5
- content: any[];
6
- }
195
+ type __VLS_WithSlots<T, S> = T & {
196
+ new (): {
197
+ $slots: S;
198
+ };
199
+ };
200
+
201
+ declare const vFormProps: {
202
+ readonly content: {
203
+ readonly type: PropType<Content[]>;
204
+ readonly required: true;
205
+ readonly default: () => never[];
206
+ };
207
+ /** 统一label宽度 */
208
+ readonly labelWidth: {
209
+ readonly type: StringConstructor;
210
+ readonly default: "98px";
211
+ };
212
+ readonly disabled: {
213
+ readonly type: BooleanConstructor;
214
+ readonly default: false;
215
+ };
216
+ readonly inline: {
217
+ readonly type: BooleanConstructor;
218
+ readonly default: true;
219
+ };
220
+ readonly readonly: {
221
+ readonly type: BooleanConstructor;
222
+ readonly default: false;
223
+ };
224
+ };
225
+ type VFormProps = ExtractPublicPropTypes<typeof vFormProps>;
226
+ type VFormRendererInstance = InstanceType<typeof _default>;
7
227
 
8
- export { _default as default };
9
- export type { TFormProp };
228
+ export { _default as default, vFormProps };
229
+ export type { Content, VFormProps, VFormRendererInstance };
@@ -1 +1 @@
1
- .red-text[data-v-3f4b8568]{color:red}
1
+ .el-form-renderer{.el-form-item{.el-form-item__content{&>.el-input{&>input[readonly][data-v-3f4b8568]{background-color:transparent;border:none;color:#606266}}&>.el-date-editor>input[disabled][data-v-3f4b8568],&>.el-textarea>textarea[readonly][data-v-3f4b8568]{background-color:transparent;border:none;color:#606266}}.no-label-form-item{.el-form-item__content[data-v-3f4b8568]{margin-left:0!important}}}}