@vue-ui-kit/ant 1.8.6 → 1.9.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/README.md +480 -503
- package/dist/cjs/index.js +1 -1
- package/dist/declarations/antProxy.d.ts +3 -4
- package/dist/es/index.js +147 -147
- package/dist/index.d.ts +1 -1
- package/dist/packages/components/PFormGroup.vue.d.ts +1 -1
- package/dist/packages/components/PGroupBlock.vue.d.ts +3 -1
- package/dist/packages/store/renderStore.d.ts +4 -4
- package/package.json +1 -1
- package/src/declarations/antProxy.ts +15 -10
- package/src/index.ts +2 -17
- package/src/packages/components/PFormGroup.vue +2 -2
- package/src/packages/components/PGroupBlock.vue +8 -3
- package/src/packages/store/renderStore.tsx +126 -119
- package/src/packages/utils/treeHelper.ts +62 -72
package/README.md
CHANGED
|
@@ -50,14 +50,14 @@ import '@vue-ui-kit/ant/style.scss';
|
|
|
50
50
|
// Configure global defaults
|
|
51
51
|
setup({
|
|
52
52
|
form: {
|
|
53
|
-
labelCol: { span: 8 },
|
|
53
|
+
labelCol: { span: 8 }, // Modify form label column width
|
|
54
54
|
wrapperCol: { span: 14 }, // Modify form input column width
|
|
55
55
|
},
|
|
56
56
|
grid: {
|
|
57
|
-
align: 'center',
|
|
58
|
-
lazyReset: true,
|
|
59
|
-
fitHeight: 200,
|
|
60
|
-
}
|
|
57
|
+
align: 'center', // Set default table alignment
|
|
58
|
+
lazyReset: true, // Don't auto-submit after reset
|
|
59
|
+
fitHeight: 200, // Set adaptive height
|
|
60
|
+
},
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
createApp(App).use(Antd).use(UIKit).mount('#app');
|
|
@@ -78,6 +78,7 @@ require('@vue-ui-kit/ant/style.css');
|
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
### 4. For Vite users
|
|
81
|
+
|
|
81
82
|
If using Vite, make sure your vite.config.js includes sass support:
|
|
82
83
|
|
|
83
84
|
```js
|
|
@@ -86,11 +87,11 @@ export default {
|
|
|
86
87
|
css: {
|
|
87
88
|
preprocessorOptions: {
|
|
88
89
|
scss: {
|
|
89
|
-
additionalData: `@import '@vue-ui-kit/ant/dist/style.scss'
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
90
|
+
additionalData: `@import '@vue-ui-kit/ant/dist/style.scss';`,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
94
95
|
```
|
|
95
96
|
|
|
96
97
|
## 🎯 样式文件导入 - 故障排除指南
|
|
@@ -98,6 +99,7 @@ export default {
|
|
|
98
99
|
如果遇到样式文件导入问题,请按顺序尝试以下方法:
|
|
99
100
|
|
|
100
101
|
### 方法1: 标准导入(推荐)
|
|
102
|
+
|
|
101
103
|
```typescript
|
|
102
104
|
import '@vue-ui-kit/ant/style.scss';
|
|
103
105
|
// 或
|
|
@@ -105,13 +107,15 @@ import '@vue-ui-kit/ant/style.css';
|
|
|
105
107
|
```
|
|
106
108
|
|
|
107
109
|
### 方法2: 完整路径导入
|
|
108
|
-
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
109
112
|
import '@vue-ui-kit/ant/dist/style.scss';
|
|
110
113
|
// 或
|
|
111
114
|
import '@vue-ui-kit/ant/dist/style.css';
|
|
112
115
|
```
|
|
113
116
|
|
|
114
117
|
### 方法3: SCSS @use 语法
|
|
118
|
+
|
|
115
119
|
```scss
|
|
116
120
|
@use '@vue-ui-kit/ant/style.scss';
|
|
117
121
|
// 或者使用完整路径
|
|
@@ -119,38 +123,41 @@ import '@vue-ui-kit/ant/dist/style.css';
|
|
|
119
123
|
```
|
|
120
124
|
|
|
121
125
|
### 方法4: 在 style 标签中
|
|
126
|
+
|
|
122
127
|
```vue
|
|
123
128
|
<style lang="scss">
|
|
124
|
-
@import '@vue-ui-kit/ant/style.scss';
|
|
129
|
+
@import '@vue-ui-kit/ant/style.scss';
|
|
125
130
|
</style>
|
|
126
131
|
```
|
|
127
132
|
|
|
128
133
|
### 方法5: Vite 配置导入
|
|
134
|
+
|
|
129
135
|
```javascript
|
|
130
136
|
// vite.config.js
|
|
131
137
|
export default defineConfig({
|
|
132
138
|
css: {
|
|
133
139
|
preprocessorOptions: {
|
|
134
140
|
scss: {
|
|
135
|
-
additionalData: `@import '@vue-ui-kit/ant/dist/style.scss'
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
})
|
|
141
|
+
additionalData: `@import '@vue-ui-kit/ant/dist/style.scss';`,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
});
|
|
140
146
|
```
|
|
141
147
|
|
|
142
148
|
### 方法6: Webpack 配置
|
|
149
|
+
|
|
143
150
|
```javascript
|
|
144
151
|
// webpack.config.js 或 vue.config.js
|
|
145
152
|
module.exports = {
|
|
146
153
|
css: {
|
|
147
154
|
loaderOptions: {
|
|
148
155
|
sass: {
|
|
149
|
-
additionalData: `@import '@vue-ui-kit/ant/dist/style.scss'
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
156
|
+
additionalData: `@import '@vue-ui-kit/ant/dist/style.scss';`,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
};
|
|
154
161
|
```
|
|
155
162
|
|
|
156
163
|
### 🔧 调试步骤
|
|
@@ -161,7 +168,9 @@ module.exports = {
|
|
|
161
168
|
4. **清除缓存**: 删除 `node_modules` 和 lock 文件后重新安装
|
|
162
169
|
|
|
163
170
|
### 📦 包内容确认
|
|
171
|
+
|
|
164
172
|
安装后可以在以下位置找到样式文件:
|
|
173
|
+
|
|
165
174
|
```
|
|
166
175
|
node_modules/@vue-ui-kit/ant/
|
|
167
176
|
├── dist/
|
|
@@ -253,34 +262,34 @@ Enhanced data table component with integrated search form, pagination, and toolb
|
|
|
253
262
|
|
|
254
263
|
```vue
|
|
255
264
|
<script setup lang="ts">
|
|
256
|
-
import { computed } from 'vue';
|
|
257
|
-
import { PGridProps, labelColDict } from '@vue-ui-kit/ant';
|
|
258
|
-
|
|
259
|
-
const gridSetting = computed<PGridProps<Student, { keyword?: string }>>(() => ({
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
265
|
+
import { computed } from 'vue';
|
|
266
|
+
import { PGridProps, labelColDict } from '@vue-ui-kit/ant';
|
|
267
|
+
|
|
268
|
+
const gridSetting = computed<PGridProps<Student, { keyword?: string }>>(() => ({
|
|
269
|
+
columns: [
|
|
270
|
+
{ field: 'name', title: 'Name', width: 200 },
|
|
271
|
+
{ field: 'email', title: 'Email', width: 200 },
|
|
272
|
+
{ field: 'age', title: 'Age', width: 100 },
|
|
273
|
+
],
|
|
274
|
+
formConfig: {
|
|
275
|
+
items: [
|
|
276
|
+
{
|
|
277
|
+
field: 'keyword',
|
|
278
|
+
title: 'Keyword',
|
|
279
|
+
labelCol: labelColDict[3],
|
|
280
|
+
itemRender: {
|
|
281
|
+
name: '$input',
|
|
282
|
+
props: { placeholder: 'Search...' },
|
|
283
|
+
},
|
|
274
284
|
},
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
proxyConfig: {
|
|
288
|
+
ajax: {
|
|
289
|
+
query: ({ form, page }) => api.getStudents({ ...form, ...page }),
|
|
275
290
|
},
|
|
276
|
-
],
|
|
277
|
-
},
|
|
278
|
-
proxyConfig: {
|
|
279
|
-
ajax: {
|
|
280
|
-
query: ({ form, page }) => api.getStudents({ ...form, ...page }),
|
|
281
291
|
},
|
|
282
|
-
}
|
|
283
|
-
}));
|
|
292
|
+
}));
|
|
284
293
|
</script>
|
|
285
294
|
|
|
286
295
|
<template>
|
|
@@ -294,44 +303,44 @@ Enhanced Form component with simplified configuration and dynamic fields.
|
|
|
294
303
|
|
|
295
304
|
#### Props
|
|
296
305
|
|
|
297
|
-
| Prop
|
|
298
|
-
|
|
|
299
|
-
| items
|
|
300
|
-
| data
|
|
301
|
-
| customReset | `() => void`
|
|
302
|
-
| labelCol
|
|
303
|
-
| wrapperCol
|
|
304
|
-
| ...others
|
|
306
|
+
| Prop | Type | Description | Default |
|
|
307
|
+
| ----------- | ------------------ | ------------------------------ | -------------- |
|
|
308
|
+
| items | `PFormItemProps[]` | Form items configuration array | - |
|
|
309
|
+
| data | `T` | Form data object | - |
|
|
310
|
+
| customReset | `() => void` | Custom reset function | - |
|
|
311
|
+
| labelCol | `ColProps` | Label column layout | `{ span: 6 }` |
|
|
312
|
+
| wrapperCol | `ColProps` | Wrapper column layout | `{ span: 16 }` |
|
|
313
|
+
| ...others | `FormProps` | All ant-design-vue Form props | - |
|
|
305
314
|
|
|
306
315
|
#### Events
|
|
307
316
|
|
|
308
|
-
| Event | Description
|
|
309
|
-
|
|
|
317
|
+
| Event | Description | Parameters |
|
|
318
|
+
| ----- | -------------------------------- | ----------------------- |
|
|
310
319
|
| apply | Triggered when form is submitted | `(formData: T) => void` |
|
|
311
|
-
| reset | Triggered when form is reset
|
|
320
|
+
| reset | Triggered when form is reset | `() => void` |
|
|
312
321
|
|
|
313
322
|
#### PFormItemProps
|
|
314
323
|
|
|
315
|
-
| Prop
|
|
316
|
-
|
|
|
317
|
-
| field
|
|
318
|
-
| title
|
|
319
|
-
| span
|
|
320
|
-
| colon
|
|
321
|
-
| labelCol
|
|
322
|
-
| wrapperCol
|
|
323
|
-
| forceRequired | `boolean`
|
|
324
|
-
| align
|
|
325
|
-
| col
|
|
326
|
-
| rule
|
|
327
|
-
| itemRender
|
|
328
|
-
| tooltipConfig | `TooltipConfig`
|
|
329
|
-
| slots
|
|
324
|
+
| Prop | Type | Description | Default |
|
|
325
|
+
| ------------- | ------------------------------- | -------------------------------- | -------- |
|
|
326
|
+
| field | `string` | Form field name | - |
|
|
327
|
+
| title | `string` | Field label | - |
|
|
328
|
+
| span | `number` | Grid span (1-24) | - |
|
|
329
|
+
| colon | `boolean` | Show colon after label | `true` |
|
|
330
|
+
| labelCol | `ColProps` | Label column layout | - |
|
|
331
|
+
| wrapperCol | `ColProps` | Wrapper column layout | - |
|
|
332
|
+
| forceRequired | `boolean` | Show required mark (visual only) | `false` |
|
|
333
|
+
| align | `'left' \| 'right' \| 'center'` | Text alignment | `'left'` |
|
|
334
|
+
| col | `ColProps` | Grid column properties | - |
|
|
335
|
+
| rule | `Rule[]` | Validation rules | - |
|
|
336
|
+
| itemRender | `ItemRender` | Field renderer configuration | - |
|
|
337
|
+
| tooltipConfig | `TooltipConfig` | Tooltip configuration | - |
|
|
338
|
+
| slots | `object` | Custom slot renderers | - |
|
|
330
339
|
|
|
331
340
|
#### Built-in Renderers
|
|
332
341
|
|
|
333
342
|
- `$input`: Input field
|
|
334
|
-
- `$textarea`: Textarea field
|
|
343
|
+
- `$textarea`: Textarea field
|
|
335
344
|
- `$number`: Number input
|
|
336
345
|
- `$select`: Select dropdown
|
|
337
346
|
- `$date`: Date picker
|
|
@@ -346,97 +355,93 @@ Enhanced Form component with simplified configuration and dynamic fields.
|
|
|
346
355
|
|
|
347
356
|
```vue
|
|
348
357
|
<script setup lang="ts">
|
|
349
|
-
import { ref, computed } from 'vue';
|
|
350
|
-
import { PFormProps } from '@vue-ui-kit/ant';
|
|
351
|
-
|
|
352
|
-
interface UserForm {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
358
|
+
import { ref, computed } from 'vue';
|
|
359
|
+
import { PFormProps } from '@vue-ui-kit/ant';
|
|
360
|
+
|
|
361
|
+
interface UserForm {
|
|
362
|
+
name: string;
|
|
363
|
+
email: string;
|
|
364
|
+
age?: number;
|
|
365
|
+
gender: string;
|
|
366
|
+
skills: string[];
|
|
367
|
+
}
|
|
359
368
|
|
|
360
|
-
const formData = ref<UserForm>({
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
});
|
|
369
|
+
const formData = ref<UserForm>({
|
|
370
|
+
name: '',
|
|
371
|
+
email: '',
|
|
372
|
+
age: undefined,
|
|
373
|
+
gender: '',
|
|
374
|
+
skills: [],
|
|
375
|
+
});
|
|
367
376
|
|
|
368
|
-
const formSetting = computed<PFormProps<UserForm>>(() => ({
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
377
|
+
const formSetting = computed<PFormProps<UserForm>>(() => ({
|
|
378
|
+
items: [
|
|
379
|
+
{
|
|
380
|
+
field: 'name',
|
|
381
|
+
title: 'Name',
|
|
382
|
+
span: 12,
|
|
383
|
+
rule: [{ required: true, message: 'Please enter name' }],
|
|
384
|
+
itemRender: {
|
|
385
|
+
name: '$input',
|
|
386
|
+
props: { placeholder: 'Enter name' },
|
|
387
|
+
},
|
|
378
388
|
},
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
{
|
|
390
|
+
field: 'email',
|
|
391
|
+
title: 'Email',
|
|
392
|
+
span: 12,
|
|
393
|
+
rule: [
|
|
394
|
+
{ required: true, message: 'Please enter email' },
|
|
395
|
+
{ type: 'email', message: 'Invalid email format' },
|
|
396
|
+
],
|
|
397
|
+
itemRender: {
|
|
398
|
+
name: '$input',
|
|
399
|
+
props: { placeholder: 'Enter email' },
|
|
400
|
+
},
|
|
391
401
|
},
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
402
|
+
{
|
|
403
|
+
field: 'gender',
|
|
404
|
+
title: 'Gender',
|
|
405
|
+
span: 12,
|
|
406
|
+
rule: [{ required: true, message: 'Please select gender' }],
|
|
407
|
+
itemRender: {
|
|
408
|
+
name: '$select',
|
|
409
|
+
props: {
|
|
410
|
+
placeholder: 'Select gender',
|
|
411
|
+
options: [
|
|
412
|
+
{ label: 'Male', value: 'male' },
|
|
413
|
+
{ label: 'Female', value: 'female' },
|
|
414
|
+
],
|
|
415
|
+
},
|
|
406
416
|
},
|
|
407
417
|
},
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
418
|
+
{
|
|
419
|
+
field: 'skills',
|
|
420
|
+
title: 'Skills',
|
|
421
|
+
span: 24,
|
|
422
|
+
itemRender: {
|
|
423
|
+
name: '$select',
|
|
424
|
+
props: {
|
|
425
|
+
mode: 'multiple',
|
|
426
|
+
placeholder: 'Select skills',
|
|
427
|
+
options: [
|
|
428
|
+
{ label: 'Vue.js', value: 'vue' },
|
|
429
|
+
{ label: 'React', value: 'react' },
|
|
430
|
+
{ label: 'Angular', value: 'angular' },
|
|
431
|
+
],
|
|
432
|
+
},
|
|
423
433
|
},
|
|
424
434
|
},
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
}));
|
|
435
|
+
],
|
|
436
|
+
}));
|
|
428
437
|
|
|
429
|
-
const handleSubmit = (data: UserForm) => {
|
|
430
|
-
|
|
431
|
-
};
|
|
438
|
+
const handleSubmit = (data: UserForm) => {
|
|
439
|
+
console.log('Form submitted:', data);
|
|
440
|
+
};
|
|
432
441
|
</script>
|
|
433
442
|
|
|
434
443
|
<template>
|
|
435
|
-
<p-form
|
|
436
|
-
v-bind="formSetting"
|
|
437
|
-
:data="formData"
|
|
438
|
-
@apply="handleSubmit"
|
|
439
|
-
/>
|
|
444
|
+
<p-form v-bind="formSetting" :data="formData" @apply="handleSubmit" />
|
|
440
445
|
</template>
|
|
441
446
|
```
|
|
442
447
|
|
|
@@ -444,31 +449,31 @@ const handleSubmit = (data: UserForm) => {
|
|
|
444
449
|
|
|
445
450
|
```vue
|
|
446
451
|
<script setup lang="tsx">
|
|
447
|
-
import { ref, computed } from 'vue';
|
|
452
|
+
import { ref, computed } from 'vue';
|
|
448
453
|
|
|
449
|
-
const formData = ref({
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
});
|
|
454
|
+
const formData = ref({
|
|
455
|
+
name: '',
|
|
456
|
+
isActive: false,
|
|
457
|
+
});
|
|
453
458
|
|
|
454
|
-
const formSetting = computed(() => ({
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
459
|
+
const formSetting = computed(() => ({
|
|
460
|
+
items: [
|
|
461
|
+
{
|
|
462
|
+
field: 'isActive',
|
|
463
|
+
title: 'Status',
|
|
464
|
+
span: 24,
|
|
465
|
+
slots: {
|
|
466
|
+
default: ({ data }) => (
|
|
467
|
+
<a-switch
|
|
468
|
+
v-model:checked={data.isActive}
|
|
469
|
+
checkedChildren="Active"
|
|
470
|
+
unCheckedChildren="Inactive"
|
|
471
|
+
/>
|
|
472
|
+
),
|
|
473
|
+
},
|
|
468
474
|
},
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}));
|
|
475
|
+
],
|
|
476
|
+
}));
|
|
472
477
|
</script>
|
|
473
478
|
```
|
|
474
479
|
|
|
@@ -497,113 +502,107 @@ Dynamic form group component for managing multiple form instances with add/remov
|
|
|
497
502
|
|
|
498
503
|
#### Exposed Methods
|
|
499
504
|
|
|
500
|
-
| Method
|
|
501
|
-
|
|
|
502
|
-
| validateAll
|
|
503
|
-
| validate
|
|
504
|
-
| setActiveKey | Set active tab
|
|
505
|
+
| Method | Description | Parameters | Returns |
|
|
506
|
+
| ------------ | ------------------------------- | ----------------- | --------------- |
|
|
507
|
+
| validateAll | Validate all form instances | - | `Promise<void>` |
|
|
508
|
+
| validate | Validate specific form instance | `__index: number` | `Promise<void>` |
|
|
509
|
+
| setActiveKey | Set active tab | `key: number` | `void` |
|
|
505
510
|
|
|
506
511
|
#### Basic Example
|
|
507
512
|
|
|
508
513
|
```vue
|
|
509
514
|
<script setup lang="ts">
|
|
510
|
-
import { ref, computed } from 'vue';
|
|
511
|
-
import { PFormGroupProps } from '@vue-ui-kit/ant';
|
|
512
|
-
|
|
513
|
-
interface Project {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const projects = ref<Project[]>([
|
|
522
|
-
{
|
|
523
|
-
__index: 0,
|
|
524
|
-
name: 'Project A',
|
|
525
|
-
startDate: '',
|
|
526
|
-
endDate: '',
|
|
527
|
-
budget: undefined,
|
|
515
|
+
import { ref, computed } from 'vue';
|
|
516
|
+
import { PFormGroupProps } from '@vue-ui-kit/ant';
|
|
517
|
+
|
|
518
|
+
interface Project {
|
|
519
|
+
__index: number;
|
|
520
|
+
name: string;
|
|
521
|
+
startDate: string;
|
|
522
|
+
endDate: string;
|
|
523
|
+
budget?: number;
|
|
528
524
|
}
|
|
529
|
-
]);
|
|
530
525
|
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
526
|
+
const projects = ref<Project[]>([
|
|
527
|
+
{
|
|
528
|
+
__index: 0,
|
|
529
|
+
name: 'Project A',
|
|
530
|
+
startDate: '',
|
|
531
|
+
endDate: '',
|
|
532
|
+
budget: undefined,
|
|
533
|
+
},
|
|
534
|
+
]);
|
|
535
|
+
|
|
536
|
+
const groupSetting = computed<PFormGroupProps<Project>>(() => ({
|
|
537
|
+
title: 'Project Management',
|
|
538
|
+
showAdd: true,
|
|
539
|
+
max: 10,
|
|
540
|
+
getFormSetting: (data) => ({
|
|
541
|
+
items: [
|
|
542
|
+
{
|
|
543
|
+
field: 'name',
|
|
544
|
+
title: 'Project Name',
|
|
545
|
+
span: 24,
|
|
546
|
+
rule: [{ required: true, message: 'Please enter project name' }],
|
|
547
|
+
itemRender: {
|
|
548
|
+
name: '$input',
|
|
549
|
+
props: { placeholder: 'Enter project name' },
|
|
550
|
+
},
|
|
545
551
|
},
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
552
|
+
{
|
|
553
|
+
field: 'startDate',
|
|
554
|
+
title: 'Start Date',
|
|
555
|
+
span: 12,
|
|
556
|
+
rule: [{ required: true, message: 'Please select start date' }],
|
|
557
|
+
itemRender: {
|
|
558
|
+
name: '$date',
|
|
559
|
+
props: { placeholder: 'Select start date' },
|
|
560
|
+
},
|
|
555
561
|
},
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
562
|
+
{
|
|
563
|
+
field: 'endDate',
|
|
564
|
+
title: 'End Date',
|
|
565
|
+
span: 12,
|
|
566
|
+
rule: [{ required: true, message: 'Please select end date' }],
|
|
567
|
+
itemRender: {
|
|
568
|
+
name: '$date',
|
|
569
|
+
props: { placeholder: 'Select end date' },
|
|
570
|
+
},
|
|
565
571
|
},
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
572
|
+
{
|
|
573
|
+
field: 'budget',
|
|
574
|
+
title: 'Budget',
|
|
575
|
+
span: 24,
|
|
576
|
+
itemRender: {
|
|
577
|
+
name: '$number',
|
|
578
|
+
props: {
|
|
579
|
+
min: 0,
|
|
580
|
+
placeholder: 'Enter budget',
|
|
581
|
+
formatter: (value) => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ','),
|
|
582
|
+
parser: (value) => value.replace(/\$\s?|(,*)/g, ''),
|
|
583
|
+
},
|
|
578
584
|
},
|
|
579
585
|
},
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
})
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
};
|
|
586
|
+
],
|
|
587
|
+
}),
|
|
588
|
+
}));
|
|
589
|
+
|
|
590
|
+
const handleSave = async () => {
|
|
591
|
+
try {
|
|
592
|
+
await groupRef.value?.validateAll();
|
|
593
|
+
console.log('All projects saved:', projects.value);
|
|
594
|
+
} catch (error) {
|
|
595
|
+
console.error('Validation failed:', error);
|
|
596
|
+
}
|
|
597
|
+
};
|
|
593
598
|
|
|
594
|
-
const groupRef = ref();
|
|
599
|
+
const groupRef = ref();
|
|
595
600
|
</script>
|
|
596
601
|
|
|
597
602
|
<template>
|
|
598
603
|
<div>
|
|
599
|
-
<p-form-group
|
|
600
|
-
|
|
601
|
-
v-model="projects"
|
|
602
|
-
v-bind="groupSetting"
|
|
603
|
-
/>
|
|
604
|
-
<a-button type="primary" @click="handleSave">
|
|
605
|
-
Save All Projects
|
|
606
|
-
</a-button>
|
|
604
|
+
<p-form-group ref="groupRef" v-model="projects" v-bind="groupSetting" />
|
|
605
|
+
<a-button type="primary" @click="handleSave"> Save All Projects </a-button>
|
|
607
606
|
</div>
|
|
608
607
|
</template>
|
|
609
608
|
```
|
|
@@ -612,43 +611,43 @@ const groupRef = ref();
|
|
|
612
611
|
|
|
613
612
|
```vue
|
|
614
613
|
<script setup lang="ts">
|
|
615
|
-
import { ref, computed } from 'vue';
|
|
614
|
+
import { ref, computed } from 'vue';
|
|
616
615
|
|
|
617
|
-
const projects = ref([]);
|
|
618
|
-
|
|
619
|
-
const groupSetting = computed(() => ({
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
616
|
+
const projects = ref([]);
|
|
617
|
+
|
|
618
|
+
const groupSetting = computed(() => ({
|
|
619
|
+
title: 'Advanced Project Management',
|
|
620
|
+
itemMenus: [
|
|
621
|
+
{ content: 'Copy', code: 'copy' },
|
|
622
|
+
{ content: 'Delete', code: 'delete' },
|
|
623
|
+
{ content: 'Export', code: 'export' },
|
|
624
|
+
{
|
|
625
|
+
content: 'Archive',
|
|
626
|
+
code: 'archive',
|
|
627
|
+
visibleMethod: ({ data }) => data.status !== 'archived',
|
|
628
|
+
},
|
|
629
|
+
],
|
|
630
|
+
createItem: async ({ list }) => {
|
|
631
|
+
return {
|
|
632
|
+
name: `Project ${list.length + 1}`,
|
|
633
|
+
status: 'active',
|
|
634
|
+
startDate: new Date().toISOString().split('T')[0],
|
|
635
|
+
};
|
|
629
636
|
},
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
archiveProject(data, index);
|
|
645
|
-
break;
|
|
646
|
-
}
|
|
647
|
-
},
|
|
648
|
-
getFormSetting: (data) => ({
|
|
649
|
-
// ... form configuration
|
|
650
|
-
}),
|
|
651
|
-
}));
|
|
637
|
+
menuHandler: ({ code, data, index }) => {
|
|
638
|
+
switch (code) {
|
|
639
|
+
case 'export':
|
|
640
|
+
exportProject(data);
|
|
641
|
+
break;
|
|
642
|
+
case 'archive':
|
|
643
|
+
archiveProject(data, index);
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
getFormSetting: (data) => ({
|
|
648
|
+
// ... form configuration
|
|
649
|
+
}),
|
|
650
|
+
}));
|
|
652
651
|
</script>
|
|
653
652
|
```
|
|
654
653
|
|
|
@@ -669,7 +668,7 @@ import { labelColDict } from '@vue-ui-kit/ant';
|
|
|
669
668
|
}
|
|
670
669
|
|
|
671
670
|
{
|
|
672
|
-
field: 'longerField',
|
|
671
|
+
field: 'longerField',
|
|
673
672
|
title: 'Description', // 4+ characters
|
|
674
673
|
labelCol: labelColDict[4],
|
|
675
674
|
}
|
|
@@ -684,10 +683,7 @@ import UIKit from '@vue-ui-kit/ant';
|
|
|
684
683
|
import { Switch } from 'ant-design-vue';
|
|
685
684
|
|
|
686
685
|
UIKit.addRender('$switch', {
|
|
687
|
-
renderItemContent(
|
|
688
|
-
{ props = {}, events = {} },
|
|
689
|
-
{ data, field }
|
|
690
|
-
) {
|
|
686
|
+
renderItemContent({ props = {}, events = {} }, { data, field }) {
|
|
691
687
|
return (
|
|
692
688
|
<Switch
|
|
693
689
|
v-model:checked={data[field]}
|
|
@@ -746,13 +742,13 @@ Answer: It simplifies all dynamic logic. For complex scenarios, you can try usin
|
|
|
746
742
|
### 基本类型导入
|
|
747
743
|
|
|
748
744
|
```typescript
|
|
749
|
-
import {
|
|
750
|
-
PGridProps,
|
|
751
|
-
PFormProps,
|
|
745
|
+
import {
|
|
746
|
+
PGridProps,
|
|
747
|
+
PFormProps,
|
|
752
748
|
PFormItemProps,
|
|
753
749
|
ColumnProps,
|
|
754
750
|
ToolbarConfig,
|
|
755
|
-
UIKitConfig
|
|
751
|
+
UIKitConfig,
|
|
756
752
|
} from '@vue-ui-kit/ant';
|
|
757
753
|
```
|
|
758
754
|
|
|
@@ -770,7 +766,7 @@ interface Student {
|
|
|
770
766
|
age: number;
|
|
771
767
|
}
|
|
772
768
|
|
|
773
|
-
// 定义查询表单类型
|
|
769
|
+
// 定义查询表单类型
|
|
774
770
|
interface StudentQuery {
|
|
775
771
|
keyword?: string;
|
|
776
772
|
age?: number;
|
|
@@ -837,7 +833,7 @@ const formSetting = computed<PFormProps<UserForm>>(() => ({
|
|
|
837
833
|
},
|
|
838
834
|
},
|
|
839
835
|
{
|
|
840
|
-
field: 'email',
|
|
836
|
+
field: 'email',
|
|
841
837
|
title: '邮箱',
|
|
842
838
|
rule: [
|
|
843
839
|
{ required: true, message: '请输入邮箱' },
|
|
@@ -937,12 +933,12 @@ formRef.value?.$form.validateFields();
|
|
|
937
933
|
This library is fully written in TypeScript and provides comprehensive type definitions:
|
|
938
934
|
|
|
939
935
|
```ts
|
|
940
|
-
import type {
|
|
941
|
-
PFormProps,
|
|
936
|
+
import type {
|
|
937
|
+
PFormProps,
|
|
942
938
|
PFormItemProps,
|
|
943
939
|
PFormGroupProps,
|
|
944
940
|
PGridProps,
|
|
945
|
-
ColumnProps
|
|
941
|
+
ColumnProps,
|
|
946
942
|
} from '@vue-ui-kit/ant';
|
|
947
943
|
```
|
|
948
944
|
|
|
@@ -955,20 +951,20 @@ MIT
|
|
|
955
951
|
#### 从npm包导入工具方法
|
|
956
952
|
|
|
957
953
|
```typescript
|
|
958
|
-
import {
|
|
954
|
+
import {
|
|
959
955
|
// 响应式布局工具
|
|
960
956
|
getButtonResponsive,
|
|
961
|
-
defaultItemResponsive,
|
|
957
|
+
defaultItemResponsive,
|
|
962
958
|
defaultLabelCol,
|
|
963
959
|
labelColDict,
|
|
964
960
|
get24rest,
|
|
965
|
-
|
|
961
|
+
|
|
966
962
|
// 表格工具
|
|
967
963
|
cleanCol,
|
|
968
|
-
|
|
969
|
-
// 其他工具
|
|
964
|
+
|
|
965
|
+
// 其他工具
|
|
970
966
|
UIKitConfig,
|
|
971
|
-
setup
|
|
967
|
+
setup,
|
|
972
968
|
} from '@vue-ui-kit/ant';
|
|
973
969
|
```
|
|
974
970
|
|
|
@@ -979,7 +975,7 @@ import { getButtonResponsive, defaultItemResponsive } from '@vue-ui-kit/ant';
|
|
|
979
975
|
|
|
980
976
|
// 方式1: 根据表单项数量自动计算按钮响应式布局
|
|
981
977
|
const buttonSpan1 = getButtonResponsive(3); // 3个表单项
|
|
982
|
-
console.log(buttonSpan1);
|
|
978
|
+
console.log(buttonSpan1);
|
|
983
979
|
// 结果: { xs: 24, sm: 24, md: 24, lg: 0, xl: 0, xxl: 6 }
|
|
984
980
|
|
|
985
981
|
// 方式2: 传入自定义响应式配置数组
|
|
@@ -1021,33 +1017,25 @@ const formSetting = computed(() => ({
|
|
|
1021
1017
|
#### 响应式布局工具完整示例
|
|
1022
1018
|
|
|
1023
1019
|
```typescript
|
|
1024
|
-
import {
|
|
1025
|
-
getButtonResponsive,
|
|
1026
|
-
defaultItemResponsive,
|
|
1027
|
-
labelColDict
|
|
1028
|
-
} from '@vue-ui-kit/ant';
|
|
1020
|
+
import { getButtonResponsive, defaultItemResponsive, labelColDict } from '@vue-ui-kit/ant';
|
|
1029
1021
|
|
|
1030
1022
|
// 创建一个动态表单布局计算器
|
|
1031
1023
|
function createFormLayout(items: Array<{ title: string }>) {
|
|
1032
1024
|
return {
|
|
1033
1025
|
// 表单项布局
|
|
1034
|
-
items: items.map(item => ({
|
|
1026
|
+
items: items.map((item) => ({
|
|
1035
1027
|
...item,
|
|
1036
1028
|
col: defaultItemResponsive, // 使用默认响应式布局
|
|
1037
1029
|
labelCol: labelColDict[item.title.length] || labelColDict[4], // 根据标题长度选择
|
|
1038
1030
|
})),
|
|
1039
|
-
|
|
1031
|
+
|
|
1040
1032
|
// 按钮区域布局
|
|
1041
1033
|
buttonCol: getButtonResponsive(items.length),
|
|
1042
1034
|
};
|
|
1043
1035
|
}
|
|
1044
1036
|
|
|
1045
1037
|
// 使用示例
|
|
1046
|
-
const layout = createFormLayout([
|
|
1047
|
-
{ title: '姓名' },
|
|
1048
|
-
{ title: '邮箱地址' },
|
|
1049
|
-
{ title: '手机号码' },
|
|
1050
|
-
]);
|
|
1038
|
+
const layout = createFormLayout([{ title: '姓名' }, { title: '邮箱地址' }, { title: '手机号码' }]);
|
|
1051
1039
|
|
|
1052
1040
|
console.log('按钮布局:', layout.buttonCol);
|
|
1053
1041
|
// 自动计算最后一行剩余空间给按钮使用
|
|
@@ -1092,10 +1080,10 @@ console.log(restSpan); // 结果: 6 (24 - 6 - 8 - 4 = 6)
|
|
|
1092
1080
|
// 在表单中动态计算按钮位置
|
|
1093
1081
|
const formItems = [
|
|
1094
1082
|
{ span: 8 }, // 表单项1
|
|
1095
|
-
{ span: 8 }, // 表单项2
|
|
1083
|
+
{ span: 8 }, // 表单项2
|
|
1096
1084
|
{ span: 6 }, // 表单项3
|
|
1097
1085
|
];
|
|
1098
|
-
const buttonSpan = get24rest(formItems.map(item => item.span));
|
|
1086
|
+
const buttonSpan = get24rest(formItems.map((item) => item.span));
|
|
1099
1087
|
// 按钮将占据剩余的2格空间,如果小于等于1则占满整行(24格)
|
|
1100
1088
|
```
|
|
1101
1089
|
|
|
@@ -1106,16 +1094,12 @@ const buttonSpan = get24rest(formItems.map(item => item.span));
|
|
|
1106
1094
|
<div>
|
|
1107
1095
|
<a-row :gutter="[16, 16]">
|
|
1108
1096
|
<!-- 动态表单项 -->
|
|
1109
|
-
<a-col
|
|
1110
|
-
v-for="(item, index) in formItems"
|
|
1111
|
-
:key="index"
|
|
1112
|
-
v-bind="defaultItemResponsive"
|
|
1113
|
-
>
|
|
1097
|
+
<a-col v-for="(item, index) in formItems" :key="index" v-bind="defaultItemResponsive">
|
|
1114
1098
|
<a-form-item :label="item.label" :label-col="getLabelCol(item.label)">
|
|
1115
1099
|
<a-input v-model:value="item.value" />
|
|
1116
1100
|
</a-form-item>
|
|
1117
1101
|
</a-col>
|
|
1118
|
-
|
|
1102
|
+
|
|
1119
1103
|
<!-- 动态按钮区域 -->
|
|
1120
1104
|
<a-col v-bind="buttonLayout">
|
|
1121
1105
|
<a-button type="primary">提交</a-button>
|
|
@@ -1126,27 +1110,20 @@ const buttonSpan = get24rest(formItems.map(item => item.span));
|
|
|
1126
1110
|
</template>
|
|
1127
1111
|
|
|
1128
1112
|
<script setup lang="ts">
|
|
1129
|
-
import { computed } from 'vue';
|
|
1130
|
-
import {
|
|
1131
|
-
getButtonResponsive,
|
|
1132
|
-
defaultItemResponsive,
|
|
1133
|
-
labelColDict
|
|
1134
|
-
} from '@vue-ui-kit/ant';
|
|
1113
|
+
import { computed } from 'vue';
|
|
1114
|
+
import { getButtonResponsive, defaultItemResponsive, labelColDict } from '@vue-ui-kit/ant';
|
|
1135
1115
|
|
|
1136
|
-
const formItems = ref([
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
]);
|
|
1116
|
+
const formItems = ref([
|
|
1117
|
+
{ label: '姓名', value: '' },
|
|
1118
|
+
{ label: '电子邮箱', value: '' },
|
|
1119
|
+
{ label: '联系电话', value: '' },
|
|
1120
|
+
]);
|
|
1141
1121
|
|
|
1142
|
-
// 动态计算按钮布局
|
|
1143
|
-
const buttonLayout = computed(() =>
|
|
1144
|
-
getButtonResponsive(formItems.value.length)
|
|
1145
|
-
);
|
|
1122
|
+
// 动态计算按钮布局
|
|
1123
|
+
const buttonLayout = computed(() => getButtonResponsive(formItems.value.length));
|
|
1146
1124
|
|
|
1147
|
-
// 根据标签长度获取合适的labelCol
|
|
1148
|
-
const getLabelCol = (label: string) =>
|
|
1149
|
-
labelColDict[label.length] || labelColDict[4];
|
|
1125
|
+
// 根据标签长度获取合适的labelCol
|
|
1126
|
+
const getLabelCol = (label: string) => labelColDict[label.length] || labelColDict[4];
|
|
1150
1127
|
</script>
|
|
1151
1128
|
```
|
|
1152
1129
|
|
|
@@ -1156,28 +1133,28 @@ const getLabelCol = (label: string) =>
|
|
|
1156
1133
|
|
|
1157
1134
|
```typescript
|
|
1158
1135
|
// 方式1: 分别导入 (推荐)
|
|
1159
|
-
import {
|
|
1136
|
+
import {
|
|
1160
1137
|
// 组件
|
|
1161
|
-
PForm,
|
|
1162
|
-
PGrid,
|
|
1138
|
+
PForm,
|
|
1139
|
+
PGrid,
|
|
1163
1140
|
PFormGroup,
|
|
1164
1141
|
PGroupBlock,
|
|
1165
1142
|
PromisePicker,
|
|
1166
|
-
|
|
1143
|
+
|
|
1167
1144
|
// 类型
|
|
1168
|
-
PGridProps,
|
|
1169
|
-
PFormProps,
|
|
1145
|
+
PGridProps,
|
|
1146
|
+
PFormProps,
|
|
1170
1147
|
PFormItemProps,
|
|
1171
1148
|
ColumnProps,
|
|
1172
1149
|
UIKitConfig,
|
|
1173
|
-
|
|
1150
|
+
|
|
1174
1151
|
// 工具方法
|
|
1175
1152
|
getButtonResponsive,
|
|
1176
1153
|
labelColDict,
|
|
1177
1154
|
defaultItemResponsive,
|
|
1178
1155
|
get24rest,
|
|
1179
1156
|
cleanCol,
|
|
1180
|
-
|
|
1157
|
+
|
|
1181
1158
|
// 配置方法
|
|
1182
1159
|
setup,
|
|
1183
1160
|
addFormatter,
|
|
@@ -1194,167 +1171,163 @@ import UIKit, { PForm, PGrid, setup } from '@vue-ui-kit/ant';
|
|
|
1194
1171
|
<template>
|
|
1195
1172
|
<div class="demo-page">
|
|
1196
1173
|
<!-- PForm 组件 -->
|
|
1197
|
-
<PForm
|
|
1174
|
+
<PForm
|
|
1198
1175
|
ref="formRef"
|
|
1199
|
-
v-bind="formSetting"
|
|
1176
|
+
v-bind="formSetting"
|
|
1200
1177
|
:data="formData"
|
|
1201
1178
|
@apply="handleFormSubmit"
|
|
1202
1179
|
@reset="handleFormReset"
|
|
1203
1180
|
/>
|
|
1204
|
-
|
|
1181
|
+
|
|
1205
1182
|
<!-- PGrid 组件 -->
|
|
1206
|
-
<PGrid
|
|
1207
|
-
ref="gridRef"
|
|
1208
|
-
v-bind="gridSetting"
|
|
1209
|
-
@toolbar-button-click="handleToolbarClick"
|
|
1210
|
-
/>
|
|
1183
|
+
<PGrid ref="gridRef" v-bind="gridSetting" @toolbar-button-click="handleToolbarClick" />
|
|
1211
1184
|
</div>
|
|
1212
1185
|
</template>
|
|
1213
1186
|
|
|
1214
1187
|
<script setup lang="ts">
|
|
1215
|
-
import { ref, computed } from 'vue';
|
|
1216
|
-
import {
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
} from '@vue-ui-kit/ant';
|
|
1188
|
+
import { ref, computed } from 'vue';
|
|
1189
|
+
import {
|
|
1190
|
+
// 直接导入组件
|
|
1191
|
+
PForm,
|
|
1192
|
+
PGrid,
|
|
1193
|
+
|
|
1194
|
+
// 导入类型
|
|
1195
|
+
PFormProps,
|
|
1196
|
+
PGridProps,
|
|
1197
|
+
PFormInstance,
|
|
1198
|
+
PGridInstance,
|
|
1199
|
+
|
|
1200
|
+
// 导入工具方法
|
|
1201
|
+
getButtonResponsive,
|
|
1202
|
+
labelColDict,
|
|
1203
|
+
|
|
1204
|
+
// 导入配置方法
|
|
1205
|
+
setup,
|
|
1206
|
+
} from '@vue-ui-kit/ant';
|
|
1207
|
+
|
|
1208
|
+
// 配置全局默认值
|
|
1209
|
+
setup({
|
|
1210
|
+
grid: {
|
|
1211
|
+
align: 'center',
|
|
1212
|
+
fitHeight: 180,
|
|
1213
|
+
},
|
|
1214
|
+
form: {
|
|
1215
|
+
labelCol: labelColDict[4],
|
|
1216
|
+
},
|
|
1217
|
+
});
|
|
1234
1218
|
|
|
1235
|
-
//
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
},
|
|
1241
|
-
form: {
|
|
1242
|
-
labelCol: labelColDict[4],
|
|
1219
|
+
// 类型定义
|
|
1220
|
+
interface User {
|
|
1221
|
+
id: number;
|
|
1222
|
+
name: string;
|
|
1223
|
+
email: string;
|
|
1243
1224
|
}
|
|
1244
|
-
});
|
|
1245
1225
|
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
email: string;
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
interface UserForm {
|
|
1254
|
-
name: string;
|
|
1255
|
-
email: string;
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
interface UserQuery {
|
|
1259
|
-
keyword?: string;
|
|
1260
|
-
}
|
|
1226
|
+
interface UserForm {
|
|
1227
|
+
name: string;
|
|
1228
|
+
email: string;
|
|
1229
|
+
}
|
|
1261
1230
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1231
|
+
interface UserQuery {
|
|
1232
|
+
keyword?: string;
|
|
1233
|
+
}
|
|
1265
1234
|
|
|
1266
|
-
//
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
email: '',
|
|
1270
|
-
});
|
|
1235
|
+
// 组件引用
|
|
1236
|
+
const formRef = ref<PFormInstance>();
|
|
1237
|
+
const gridRef = ref<PGridInstance<User, UserQuery>>();
|
|
1271
1238
|
|
|
1272
|
-
//
|
|
1273
|
-
const
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
title: '用户名',
|
|
1278
|
-
labelCol: labelColDict[3], // 3个字符的标签
|
|
1279
|
-
rule: [{ required: true, message: '请输入用户名' }],
|
|
1280
|
-
itemRender: {
|
|
1281
|
-
name: '$input',
|
|
1282
|
-
props: { placeholder: '请输入用户名' },
|
|
1283
|
-
},
|
|
1284
|
-
},
|
|
1285
|
-
{
|
|
1286
|
-
field: 'email',
|
|
1287
|
-
title: '邮箱地址',
|
|
1288
|
-
labelCol: labelColDict[4], // 4个字符的标签
|
|
1289
|
-
rule: [
|
|
1290
|
-
{ required: true, message: '请输入邮箱' },
|
|
1291
|
-
{ type: 'email', message: '邮箱格式不正确' },
|
|
1292
|
-
],
|
|
1293
|
-
itemRender: {
|
|
1294
|
-
name: '$input',
|
|
1295
|
-
props: { placeholder: '请输入邮箱地址' },
|
|
1296
|
-
},
|
|
1297
|
-
},
|
|
1298
|
-
],
|
|
1299
|
-
}));
|
|
1239
|
+
// 表单数据
|
|
1240
|
+
const formData = ref<UserForm>({
|
|
1241
|
+
name: '',
|
|
1242
|
+
email: '',
|
|
1243
|
+
});
|
|
1300
1244
|
|
|
1301
|
-
//
|
|
1302
|
-
const
|
|
1303
|
-
columns: [
|
|
1304
|
-
{ field: 'name', title: '用户名', width: 200 },
|
|
1305
|
-
{ field: 'email', title: '邮箱', width: 200 },
|
|
1306
|
-
],
|
|
1307
|
-
formConfig: {
|
|
1245
|
+
// 表单配置
|
|
1246
|
+
const formSetting = computed<PFormProps<UserForm>>(() => ({
|
|
1308
1247
|
items: [
|
|
1309
1248
|
{
|
|
1310
|
-
field: '
|
|
1311
|
-
title: '
|
|
1312
|
-
labelCol: labelColDict[3],
|
|
1249
|
+
field: 'name',
|
|
1250
|
+
title: '用户名',
|
|
1251
|
+
labelCol: labelColDict[3], // 3个字符的标签
|
|
1252
|
+
rule: [{ required: true, message: '请输入用户名' }],
|
|
1313
1253
|
itemRender: {
|
|
1314
1254
|
name: '$input',
|
|
1315
|
-
props: { placeholder: '
|
|
1255
|
+
props: { placeholder: '请输入用户名' },
|
|
1316
1256
|
},
|
|
1317
1257
|
},
|
|
1318
|
-
],
|
|
1319
|
-
},
|
|
1320
|
-
toolbarConfig: {
|
|
1321
|
-
buttons: [
|
|
1322
1258
|
{
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1259
|
+
field: 'email',
|
|
1260
|
+
title: '邮箱地址',
|
|
1261
|
+
labelCol: labelColDict[4], // 4个字符的标签
|
|
1262
|
+
rule: [
|
|
1263
|
+
{ required: true, message: '请输入邮箱' },
|
|
1264
|
+
{ type: 'email', message: '邮箱格式不正确' },
|
|
1265
|
+
],
|
|
1266
|
+
itemRender: {
|
|
1267
|
+
name: '$input',
|
|
1268
|
+
props: { placeholder: '请输入邮箱地址' },
|
|
1269
|
+
},
|
|
1327
1270
|
},
|
|
1328
1271
|
],
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1272
|
+
}));
|
|
1273
|
+
|
|
1274
|
+
// 网格配置
|
|
1275
|
+
const gridSetting = computed<PGridProps<User, UserQuery>>(() => ({
|
|
1276
|
+
columns: [
|
|
1277
|
+
{ field: 'name', title: '用户名', width: 200 },
|
|
1278
|
+
{ field: 'email', title: '邮箱', width: 200 },
|
|
1279
|
+
],
|
|
1280
|
+
formConfig: {
|
|
1281
|
+
items: [
|
|
1282
|
+
{
|
|
1283
|
+
field: 'keyword',
|
|
1284
|
+
title: '关键字',
|
|
1285
|
+
labelCol: labelColDict[3],
|
|
1286
|
+
itemRender: {
|
|
1287
|
+
name: '$input',
|
|
1288
|
+
props: { placeholder: '请输入关键字' },
|
|
1289
|
+
},
|
|
1290
|
+
},
|
|
1291
|
+
],
|
|
1333
1292
|
},
|
|
1334
|
-
|
|
1335
|
-
|
|
1293
|
+
toolbarConfig: {
|
|
1294
|
+
buttons: [
|
|
1295
|
+
{
|
|
1296
|
+
code: 'add',
|
|
1297
|
+
content: '新增',
|
|
1298
|
+
type: 'primary',
|
|
1299
|
+
icon: 'PlusOutlined',
|
|
1300
|
+
},
|
|
1301
|
+
],
|
|
1302
|
+
},
|
|
1303
|
+
proxyConfig: {
|
|
1304
|
+
ajax: {
|
|
1305
|
+
query: ({ form, page }) => api.getUsers({ ...form, ...page }),
|
|
1306
|
+
},
|
|
1307
|
+
},
|
|
1308
|
+
}));
|
|
1336
1309
|
|
|
1337
|
-
// 事件处理
|
|
1338
|
-
const handleFormSubmit = (data: UserForm) => {
|
|
1339
|
-
|
|
1340
|
-
};
|
|
1310
|
+
// 事件处理
|
|
1311
|
+
const handleFormSubmit = (data: UserForm) => {
|
|
1312
|
+
console.log('表单提交:', data);
|
|
1313
|
+
};
|
|
1341
1314
|
|
|
1342
|
-
const handleFormReset = () => {
|
|
1343
|
-
|
|
1344
|
-
};
|
|
1315
|
+
const handleFormReset = () => {
|
|
1316
|
+
console.log('表单重置');
|
|
1317
|
+
};
|
|
1345
1318
|
|
|
1346
|
-
const handleToolbarClick = ({ code, data, selectedKeys }) => {
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
if (code === 'add') {
|
|
1350
|
-
// 处理新增逻辑
|
|
1351
|
-
}
|
|
1352
|
-
};
|
|
1319
|
+
const handleToolbarClick = ({ code, data, selectedKeys }) => {
|
|
1320
|
+
console.log('工具栏点击:', { code, data, selectedKeys });
|
|
1353
1321
|
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1322
|
+
if (code === 'add') {
|
|
1323
|
+
// 处理新增逻辑
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
// 使用工具方法
|
|
1328
|
+
const buttonLayout = computed(
|
|
1329
|
+
() => getButtonResponsive(2), // 根据表单项数量计算按钮布局
|
|
1330
|
+
);
|
|
1358
1331
|
</script>
|
|
1359
1332
|
```
|
|
1360
1333
|
|
|
@@ -1371,24 +1344,26 @@ import { PForm } from '@vue-ui-kit/ant/utils';
|
|
|
1371
1344
|
import UIKit, PForm from '@vue-ui-kit/ant'; // 语法错误
|
|
1372
1345
|
|
|
1373
1346
|
// ✅ 正确:从主包路径导入所有内容
|
|
1374
|
-
import {
|
|
1375
|
-
PForm,
|
|
1376
|
-
PGrid,
|
|
1377
|
-
getButtonResponsive,
|
|
1378
|
-
labelColDict
|
|
1347
|
+
import {
|
|
1348
|
+
PForm,
|
|
1349
|
+
PGrid,
|
|
1350
|
+
getButtonResponsive,
|
|
1351
|
+
labelColDict
|
|
1379
1352
|
} from '@vue-ui-kit/ant';
|
|
1380
1353
|
```
|
|
1381
1354
|
|
|
1382
1355
|
### 📋 可导入的完整列表
|
|
1383
1356
|
|
|
1384
1357
|
#### 组件
|
|
1358
|
+
|
|
1385
1359
|
- `PForm` - 增强表单组件
|
|
1386
|
-
- `PGrid` - 增强数据表格组件
|
|
1360
|
+
- `PGrid` - 增强数据表格组件
|
|
1387
1361
|
- `PFormGroup` - 动态表单组组件
|
|
1388
1362
|
- `PGroupBlock` - 表单块组件
|
|
1389
1363
|
- `PromisePicker` - 数据选择器组件
|
|
1390
1364
|
|
|
1391
1365
|
#### 类型定义
|
|
1366
|
+
|
|
1392
1367
|
- `PFormProps<T>` - 表单属性类型
|
|
1393
1368
|
- `PGridProps<D, F>` - 网格属性类型
|
|
1394
1369
|
- `PFormInstance` - 表单实例类型
|
|
@@ -1397,6 +1372,7 @@ import {
|
|
|
1397
1372
|
- `UIKitConfig` - 全局配置类型
|
|
1398
1373
|
|
|
1399
1374
|
#### 工具方法
|
|
1375
|
+
|
|
1400
1376
|
- `getButtonResponsive()` - 计算按钮响应式布局
|
|
1401
1377
|
- `labelColDict` - 标签宽度配置字典
|
|
1402
1378
|
- `defaultItemResponsive` - 默认响应式配置
|
|
@@ -1404,6 +1380,7 @@ import {
|
|
|
1404
1380
|
- `cleanCol()` - 清理列配置
|
|
1405
1381
|
|
|
1406
1382
|
#### 配置方法
|
|
1383
|
+
|
|
1407
1384
|
- `setup()` - 全局配置设置
|
|
1408
1385
|
- `addFormatter()` - 添加格式化器
|
|
1409
1386
|
- `addRender()` - 添加渲染器
|