form.vue 2.4 KB

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