@qin-ui/antd-vue-pro 1.0.0 → 1.0.1
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 +332 -0
- package/es/component-provider/index.js +23 -0
- package/es/form/index.js +11837 -0
- package/es/index.d.ts +42 -27
- package/es/index.js +11 -11826
- package/es/style.css +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,336 @@
|
|
|
1
1
|
## antd-vue-pro
|
|
2
2
|
|
|
3
|
+
- [x] pro-component-provider
|
|
3
4
|
- [x] pro-form
|
|
4
5
|
- [ ] pro-table
|
|
6
|
+
|
|
7
|
+
#### 安装
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
npm i @qin-ui/antd-vue-pro
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
#### 1. pro-component-provider
|
|
16
|
+
|
|
17
|
+
组件接收参数名为component-vars的props,内部provide所接收的props供所有被包裹的组件inject
|
|
18
|
+
|
|
19
|
+
##### API
|
|
20
|
+
|
|
21
|
+
+ Props
|
|
22
|
+
|
|
23
|
+
| 参数名 | 说明 | 类型 | 默认值 |
|
|
24
|
+
| -------------- | ----------------- | ------------- | ------ |
|
|
25
|
+
| component-vars | 需要provide的配置 | ComponentVars | |
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#### 2. pro-form
|
|
30
|
+
|
|
31
|
+
ant-design-vue ui组件库form组件的二次封装
|
|
32
|
+
|
|
33
|
+
##### API
|
|
34
|
+
|
|
35
|
+
+ Props
|
|
36
|
+
|
|
37
|
+
| 参数名 | 说明 | 类型 | 默认值 |
|
|
38
|
+
| ------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------ |
|
|
39
|
+
| form | proform useForm返回对象,传递此参数后formData和fields参数将失效(推荐使用配套hook) | Form | |
|
|
40
|
+
| formData | 表单数据(推荐使用form) | object | |
|
|
41
|
+
| fields | 表单字段(推荐使用form) | Fields | |
|
|
42
|
+
| grid | 是否启用栅格布局 | boolean \| GridProps同[antdv Grid的RowProps](https://antdv.com/components/grid-cn/#api) | |
|
|
43
|
+
| autoCommandDisabled | 是否禁用字段规则 | boolean | false |
|
|
44
|
+
| 继承ant-design-vue form组件的所有参数 | [查看文档](https://antdv.com/components/form-cn#api) | ... | |
|
|
45
|
+
|
|
46
|
+
- Emits
|
|
47
|
+
|
|
48
|
+
| 事件参数名 | 说明 | 类型 | 默认值 |
|
|
49
|
+
| ------------------------------------- | ---------------------------------------------------- | --------------------- | ------ |
|
|
50
|
+
| update:formData | 更新props.formData表单数据(推荐使用form) | (val: object) => void | |
|
|
51
|
+
| 继承ant-design-vue form组件的所有事件 | [查看文档](https://antdv.com/components/form-cn#api) | ... | |
|
|
52
|
+
|
|
53
|
+
+ Expose
|
|
54
|
+
|
|
55
|
+
| 参数名 | 说明 | 类型 | 默认值 |
|
|
56
|
+
| ------------------------------------- | ------------------------------------------------------- | ---- | ------ |
|
|
57
|
+
| refs | 组件暴露的所有ref集合,包含formItems的ref以及field的ref | Refs | |
|
|
58
|
+
| 继承ant-design-vue form组件的所有方法 | [查看文档](https://antdv.com/components/form-cn#api) | ... | |
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
##### Types
|
|
63
|
+
|
|
64
|
+
+ Field
|
|
65
|
+
|
|
66
|
+
表单字段类型 由某一个输入项(如Input、Select组件)参数类型+表单项(FormItem组件)参数类型+Grid布局组件Col的参数类型+公共拓展类型Common
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
type Field = FieldType[keyof FieldType] & FormItemProps & GridItemProps & Common
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
+ 输入项参数类型FieldType
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
export type FieldType = {
|
|
76
|
+
/** 文本框 */
|
|
77
|
+
'input': { component: 'input', slots?: InputSlots } & InputProps;
|
|
78
|
+
/** 文本域 */
|
|
79
|
+
'textarea': { component: 'textarea', slots?: InputSlots } & TextAreaProps;
|
|
80
|
+
/** 文本框-密码 */
|
|
81
|
+
'input-password': { component: 'input-password', slots?: InputSlots } & InputProps;
|
|
82
|
+
/** 文本框-搜索 */
|
|
83
|
+
'input-search': { component: 'input-search', slots?: InputSlots } & InputProps;
|
|
84
|
+
/** 数字文本框 */
|
|
85
|
+
'input-number': { component: 'input-number', slots?: InputNumberSlots } & InputNumberProps;
|
|
86
|
+
/** 下拉选择器 */
|
|
87
|
+
'select': { component: 'select', slots?: SelectSlots } & SelectProps;
|
|
88
|
+
/** 级联选择器 */
|
|
89
|
+
'cascader': { component: 'cascader', slots?: CascaderSlots } & CascaderProps;
|
|
90
|
+
/** 日期选择器 */
|
|
91
|
+
'date-picker': { component: 'date-picker', slots?: DatePickerSlots } & DatePickerProps;
|
|
92
|
+
/** 日期选择器-范围 */
|
|
93
|
+
'range-picker': { component: 'range-picker', slots?: DatePickerSlots } & DatePickerProps;
|
|
94
|
+
/** 时间选择器 */
|
|
95
|
+
'time-picker': { component: 'time-picker', slots?: TimePickerSlots } & TimePickerProps;
|
|
96
|
+
/** 复选框组 */
|
|
97
|
+
'checkbox-group': { component: 'checkbox-group' } & CheckboxGroupProps;
|
|
98
|
+
/** 单选框组 */
|
|
99
|
+
'radio-group': { component: 'radio-group' } & RadioGroupProps;
|
|
100
|
+
/** 开关 */
|
|
101
|
+
'switch': { component: 'switch', slots?: SwitchSlots } & SwitchProps;
|
|
102
|
+
/** 滑块 */
|
|
103
|
+
'slider': { component: 'slider', slots?: SliderSlots } & SliderProps;
|
|
104
|
+
/** 树形选择器 */
|
|
105
|
+
'tree-select': { component: 'tree-select', slots?: TreeSelectSlots } & TreeSelectProps;
|
|
106
|
+
/** 穿梭框 */
|
|
107
|
+
'transfer': { component: 'transfer' } & TransferProps;
|
|
108
|
+
/** 自定义组件 */
|
|
109
|
+
'custom': { component?: RenderComponentType } & Record<string, any>;
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
[InputProps](https://antdv.com/components/input-cn/#input)
|
|
114
|
+
|
|
115
|
+
[TextAreaProps](https://antdv.com/components/input-cn/#textarea)
|
|
116
|
+
|
|
117
|
+
[InputNumberProps](https://antdv.com/components/input-number-cn#api)
|
|
118
|
+
|
|
119
|
+
[SelectProps](https://antdv.com/components/select-cn#select-props)
|
|
120
|
+
|
|
121
|
+
[CascaderProps](https://antdv.com/components/cascader-cn#api)
|
|
122
|
+
|
|
123
|
+
[DatePickerProps](https://antdv.com/components/date-picker-cn#%E5%85%B1%E5%90%8C%E7%9A%84-api)
|
|
124
|
+
|
|
125
|
+
[TimePickerProps](https://antdv.com/components/time-picker-cn#api)
|
|
126
|
+
|
|
127
|
+
[CheckboxGroupProps](https://antdv.com/components/checkbox-cn#checkbox-group)
|
|
128
|
+
|
|
129
|
+
[RadioGroupProps](https://antdv.com/components/radio-cn#radiogroup)
|
|
130
|
+
|
|
131
|
+
[SwitchProps](https://antdv.com/components/switch-cn#api)
|
|
132
|
+
|
|
133
|
+
[SliderProps](https://antdv.com/components/switch-cn#api)
|
|
134
|
+
|
|
135
|
+
[TreeSelectProps](https://antdv.com/components/tree-select-cn#tree-props)
|
|
136
|
+
|
|
137
|
+
[TransferProps](https://antdv.com/components/transfer-cn#api)
|
|
138
|
+
|
|
139
|
+
+ 表单项参数类型FormItemProps
|
|
140
|
+
|
|
141
|
+
同ant-design-vue FormItemProps, [查看文档](https://antdv.com/components/form-cn#form-item)
|
|
142
|
+
|
|
143
|
+
+ 栅格布局参数类型GridItemProps
|
|
144
|
+
|
|
145
|
+
同ant-design-vue ColProps, [查看文档](https://antdv.com/components/grid-cn/#col)
|
|
146
|
+
|
|
147
|
+
+ 公共拓展参数类型Common
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
interface Common {
|
|
151
|
+
/** 标识key */
|
|
152
|
+
key?: string;
|
|
153
|
+
/** 中文名称 */
|
|
154
|
+
label?: SlotComponentType;
|
|
155
|
+
/** 插槽,可包含formItem插槽和component插槽 */
|
|
156
|
+
slots?: Record<(typeof FORM_ITEM_SLOT_KEYS)[number], SlotComponentType>;
|
|
157
|
+
/** 网格布局属性 */
|
|
158
|
+
grid?: Grid;
|
|
159
|
+
/** 子字段 */
|
|
160
|
+
fields?: Array<Field>;
|
|
161
|
+
/** 是否隐藏 */
|
|
162
|
+
hidden?: boolean;
|
|
163
|
+
/** 自动化指令 */
|
|
164
|
+
autoCommand?: AutoCommand;
|
|
165
|
+
/** formItem样式属性 */
|
|
166
|
+
style?: CSSProperties;
|
|
167
|
+
/** formItem样式类名 */
|
|
168
|
+
className?: string;
|
|
169
|
+
/** formItem容器包裹组件 */
|
|
170
|
+
container?: ContainerComponent;
|
|
171
|
+
/** component样式属性 */
|
|
172
|
+
componentStyle?: CSSProperties;
|
|
173
|
+
/** component样式类名 */
|
|
174
|
+
componentClassName?: string;
|
|
175
|
+
/** component容器包裹组件 */
|
|
176
|
+
componentContainer?: ContainerComponent;
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
+ UseForm
|
|
181
|
+
|
|
182
|
+
自定义hook,由两个hook(useFormData、useFields)内聚产生。接收两个参数(initFormData, initFields)返回一个对象
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
type Form = ReturnType<UseFields> & ReturnType<UseFormData>;
|
|
186
|
+
|
|
187
|
+
type UseForm = <T extends FormData>(
|
|
188
|
+
initFormData?: T,
|
|
189
|
+
initFields?: Fields
|
|
190
|
+
) => Form;
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
/**
|
|
195
|
+
* @description useFields hook
|
|
196
|
+
* @param {Fields} initFields - 初始化表单字段
|
|
197
|
+
* @returns {Object} form
|
|
198
|
+
*/
|
|
199
|
+
type UseFields = (initFields: Fields) => {
|
|
200
|
+
/** 表单字段Ref */
|
|
201
|
+
fields: Ref<Fields>;
|
|
202
|
+
/** 获取指定字段数据路径的字段配置 */
|
|
203
|
+
getField: GetField;
|
|
204
|
+
/** 设置指定字段数据路径的字段配置 */
|
|
205
|
+
setField: SetField;
|
|
206
|
+
/** 删除指定字段数据路径的字段配置 */
|
|
207
|
+
deleteField: DeleteField;
|
|
208
|
+
/** 根据字段数据路径获取字段配置路径 */
|
|
209
|
+
getFieldPath: GetFieldPath;
|
|
210
|
+
/** 在指定字段数据路径的字段配置后添加新的字段配置 */
|
|
211
|
+
appendField: AppendField;
|
|
212
|
+
/** 在指定字段数据路径的字段配置前插入新的字段配置 */
|
|
213
|
+
prependField: PrependField;
|
|
214
|
+
/** 获取指定字段数据路径的字段所在分组字段的配置 */
|
|
215
|
+
getParentField: GetParentField;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @description useFormData hook
|
|
220
|
+
* @param {array} initFormData - 初始化表单数据
|
|
221
|
+
* @returns {Object}
|
|
222
|
+
*/
|
|
223
|
+
type UseFormData = (initFormData: FormData) => {
|
|
224
|
+
/** 表单数据Ref */
|
|
225
|
+
formData: Ref<FormData>;
|
|
226
|
+
/** 获取指定字段数据路径的值 */
|
|
227
|
+
getFormData: GetFormData;
|
|
228
|
+
/** 设置指定字段数据路径的值 */
|
|
229
|
+
setFormData: SetFormData;
|
|
230
|
+
};
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
##### Demo
|
|
236
|
+
|
|
237
|
+
```vue
|
|
238
|
+
<script lang="ts" setup>
|
|
239
|
+
import {
|
|
240
|
+
ProForm,
|
|
241
|
+
useForm,
|
|
242
|
+
ProComponentProvider,
|
|
243
|
+
type ComponentVars,
|
|
244
|
+
type ProFormInstance,
|
|
245
|
+
type Field,
|
|
246
|
+
type Fields,
|
|
247
|
+
} from '@qin-ui/antd-vue-pro';
|
|
248
|
+
import { h, ref } from 'vue';
|
|
249
|
+
|
|
250
|
+
const proFormRef = ref<ProFormInstance | null>(null);
|
|
251
|
+
|
|
252
|
+
const CodeContainer: Field['componentContainer'] = (p, ctx) => {
|
|
253
|
+
return h(
|
|
254
|
+
'div',
|
|
255
|
+
{
|
|
256
|
+
style: { display: 'flex', alignItems: 'center' },
|
|
257
|
+
},
|
|
258
|
+
[
|
|
259
|
+
ctx.slots.default?.(),
|
|
260
|
+
h(
|
|
261
|
+
'a',
|
|
262
|
+
{
|
|
263
|
+
style: { marginLeft: '10px', whiteSpace: 'nowrap' },
|
|
264
|
+
onClick: () => {
|
|
265
|
+
proFormRef.value?.validateFields('username');
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
'发送验证码'
|
|
269
|
+
),
|
|
270
|
+
]
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const initFields: Fields = [
|
|
275
|
+
{
|
|
276
|
+
label: '用户名',
|
|
277
|
+
key: 'username',
|
|
278
|
+
component: 'input',
|
|
279
|
+
maxlength: 20,
|
|
280
|
+
rules: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
label: '密码',
|
|
284
|
+
key: 'password',
|
|
285
|
+
component: 'input',
|
|
286
|
+
type: 'password',
|
|
287
|
+
rules: [
|
|
288
|
+
{ required: true, message: '请输入密码' },
|
|
289
|
+
{ min: 4, message: '密码最小长度为5个字符' },
|
|
290
|
+
{ max: 18, message: '密码最大长度为18个字符' },
|
|
291
|
+
],
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
label: '验证码',
|
|
295
|
+
key: 'code',
|
|
296
|
+
component: 'input-number',
|
|
297
|
+
rules: [{ required: true, message: '请输入密码' }],
|
|
298
|
+
componentContainer: CodeContainer,
|
|
299
|
+
},
|
|
300
|
+
];
|
|
301
|
+
|
|
302
|
+
const form = useForm({}, initFields);
|
|
303
|
+
|
|
304
|
+
const componentVars: ComponentVars = {
|
|
305
|
+
proFormField: {
|
|
306
|
+
input: { maxlength: 50 },
|
|
307
|
+
textarea: { maxlength: 1000 },
|
|
308
|
+
'input-number': { max: 10 ** 12 - 1 },
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const submit = () => {
|
|
313
|
+
proFormRef.value?.validate().then(() => {
|
|
314
|
+
console.log(form.formData.value);
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
</script>
|
|
318
|
+
|
|
319
|
+
<template>
|
|
320
|
+
<div style="max-width: 500px; margin: 0 auto">
|
|
321
|
+
<h1>hello world</h1>
|
|
322
|
+
|
|
323
|
+
<ProComponentProvider :component-vars="componentVars">
|
|
324
|
+
<ProForm ref="proFormRef" :form="form" />
|
|
325
|
+
</ProComponentProvider>
|
|
326
|
+
|
|
327
|
+
<button @click="submit">提交</button>
|
|
328
|
+
|
|
329
|
+
<pre>{{ form.formData }}</pre>
|
|
330
|
+
</div>
|
|
331
|
+
</template>
|
|
332
|
+
|
|
333
|
+
<style scoped lang="less"></style>
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineComponent, provide, renderSlot } from "vue";
|
|
2
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
3
|
+
__name: "index",
|
|
4
|
+
props: {
|
|
5
|
+
componentVars: {}
|
|
6
|
+
},
|
|
7
|
+
setup(__props) {
|
|
8
|
+
const props = __props;
|
|
9
|
+
if (props.componentVars) {
|
|
10
|
+
Object.values(props.componentVars).forEach((item) => {
|
|
11
|
+
Object.entries(item).forEach(([key, value]) => {
|
|
12
|
+
provide(key, value);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return (_ctx, _cache) => {
|
|
17
|
+
return renderSlot(_ctx.$slots, "default");
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export {
|
|
22
|
+
_sfc_main as default
|
|
23
|
+
};
|