1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
| <script lang="ts" setup>
| import type { VbenFormProps } from '#/adapter/form';
| import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
| import { Page } from '@vben/common-ui';
|
| import { message } from 'ant-design-vue';
| import dayjs from 'dayjs';
|
| import { useVbenVxeGrid } from '#/adapter/vxe-table';
| import { getExampleTableApi } from '#/api';
|
| interface RowType {
| category: string;
| color: string;
| id: string;
| price: string;
| productName: string;
| releaseDate: string;
| }
|
| const formOptions: VbenFormProps = {
| // 默认展开
| collapsed: false,
| fieldMappingTime: [['date', ['start', 'end']]],
| schema: [
| {
| component: 'Input',
| defaultValue: '1',
| fieldName: 'category',
| label: 'Category',
| },
| {
| component: 'Input',
| fieldName: 'productName',
| label: 'ProductName',
| },
| {
| component: 'Input',
| fieldName: 'price',
| label: 'Price',
| },
| {
| component: 'Select',
| componentProps: {
| allowClear: true,
| options: [
| {
| label: 'Color1',
| value: '1',
| },
| {
| label: 'Color2',
| value: '2',
| },
| ],
| placeholder: '请选择',
| },
| fieldName: 'color',
| label: 'Color',
| },
| {
| component: 'RangePicker',
| defaultValue: [dayjs().subtract(7, 'days'), dayjs()],
| fieldName: 'date',
| label: 'Date',
| },
| ],
| // 控制表单是否显示折叠按钮
| showCollapseButton: true,
| // 是否在字段值改变时提交表单
| submitOnChange: true,
| // 按下回车时是否提交表单
| submitOnEnter: false,
| };
|
| const gridOptions: VxeTableGridOptions<RowType> = {
| checkboxConfig: {
| highlight: true,
| labelField: 'name',
| },
| columns: [
| { title: '序号', type: 'seq', width: 50 },
| { align: 'left', title: 'Name', type: 'checkbox', width: 100 },
| { field: 'category', title: 'Category' },
| { field: 'color', title: 'Color' },
| { field: 'productName', title: 'Product Name' },
| { field: 'price', title: 'Price' },
| { field: 'releaseDate', formatter: 'formatDateTime', title: 'Date' },
| ],
| exportConfig: {},
| height: 'auto',
| keepSource: true,
| pagerConfig: {},
| proxyConfig: {
| ajax: {
| query: async ({ page }, formValues) => {
| message.success(`Query params: ${JSON.stringify(formValues)}`);
| return await getExampleTableApi({
| page: page.currentPage,
| pageSize: page.pageSize,
| ...formValues,
| });
| },
| },
| },
| toolbarConfig: {
| custom: true,
| export: true,
| refresh: true,
| resizable: true,
| search: true,
| zoom: true,
| },
| };
|
| const [Grid] = useVbenVxeGrid({
| formOptions,
| gridOptions,
| });
| </script>
|
| <template>
| <Page auto-content-height>
| <Grid />
| </Page>
| </template>
|
|