2024-11-06 21:44:02 +08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import type { VbenFormProps } from '#/adapter/form';
|
2024-11-06 23:03:33 +08:00
|
|
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
2024-11-06 21:44:02 +08:00
|
|
|
|
|
|
|
import { message } from 'ant-design-vue';
|
|
|
|
|
2024-11-06 23:03:33 +08:00
|
|
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
|
|
|
2024-11-06 21:44:02 +08:00
|
|
|
import { getExampleTableApi } from '../mock-api';
|
|
|
|
|
|
|
|
interface RowType {
|
|
|
|
category: string;
|
|
|
|
color: string;
|
|
|
|
id: string;
|
|
|
|
price: string;
|
|
|
|
productName: string;
|
|
|
|
releaseDate: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const formOptions: VbenFormProps = {
|
|
|
|
// 默认展开
|
|
|
|
collapsed: false,
|
|
|
|
schema: [
|
|
|
|
{
|
|
|
|
component: 'Input',
|
|
|
|
componentProps: {
|
|
|
|
placeholder: 'Please enter category',
|
|
|
|
},
|
|
|
|
defaultValue: '1',
|
|
|
|
fieldName: 'category',
|
|
|
|
label: 'Category',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: 'Input',
|
|
|
|
componentProps: {
|
|
|
|
placeholder: 'Please enter productName',
|
|
|
|
},
|
|
|
|
fieldName: 'productName',
|
|
|
|
label: 'ProductName',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: 'Input',
|
|
|
|
componentProps: {
|
|
|
|
placeholder: 'Please enter price',
|
|
|
|
},
|
|
|
|
fieldName: 'price',
|
|
|
|
label: 'Price',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: 'Select',
|
|
|
|
componentProps: {
|
|
|
|
allowClear: true,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: 'Color1',
|
|
|
|
value: '1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Color2',
|
|
|
|
value: '2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
placeholder: '请选择',
|
|
|
|
},
|
|
|
|
fieldName: 'color',
|
|
|
|
label: 'Color',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: 'DatePicker',
|
|
|
|
fieldName: 'datePicker',
|
|
|
|
label: 'Date',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
// 控制表单是否显示折叠按钮
|
|
|
|
showCollapseButton: true,
|
|
|
|
submitButtonOptions: {
|
|
|
|
content: '查询',
|
|
|
|
},
|
2024-12-05 11:23:21 +08:00
|
|
|
// 是否在字段值改变时提交表单
|
|
|
|
submitOnChange: false,
|
2024-11-06 21:44:02 +08:00
|
|
|
// 按下回车时是否提交表单
|
|
|
|
submitOnEnter: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const gridOptions: VxeGridProps<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' },
|
|
|
|
],
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-01-20 03:43:19 +00:00
|
|
|
toolbarConfig: {
|
|
|
|
// 是否显示搜索表单控制按钮
|
|
|
|
// @ts-ignore 正式环境时有完整的类型声明
|
|
|
|
search: true,
|
|
|
|
},
|
2024-11-06 21:44:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const [Grid] = useVbenVxeGrid({ formOptions, gridOptions });
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="vp-raw w-full">
|
|
|
|
<Grid />
|
|
|
|
</div>
|
|
|
|
</template>
|