index.vue 2.7 KB

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