index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <script lang="ts" setup>
  2. import type { VxeGridProps } from '#/adapter/vxe-table';
  3. import { Button, Image, Switch, Tag } from 'ant-design-vue';
  4. import { useVbenVxeGrid } from '#/adapter/vxe-table';
  5. import { getExampleTableApi } from '../mock-api';
  6. interface RowType {
  7. category: string;
  8. color: string;
  9. id: string;
  10. imageUrl: string;
  11. open: boolean;
  12. price: string;
  13. productName: string;
  14. releaseDate: string;
  15. status: 'error' | 'success' | 'warning';
  16. }
  17. const gridOptions: VxeGridProps<RowType> = {
  18. checkboxConfig: {
  19. highlight: true,
  20. labelField: 'name',
  21. },
  22. columns: [
  23. { title: '序号', type: 'seq', width: 50 },
  24. { field: 'category', title: 'Category', width: 100 },
  25. {
  26. field: 'imageUrl',
  27. slots: { default: 'image-url' },
  28. title: 'Image',
  29. width: 100,
  30. },
  31. {
  32. cellRender: { name: 'CellImage' },
  33. field: 'imageUrl2',
  34. title: 'Render Image',
  35. width: 130,
  36. },
  37. {
  38. field: 'open',
  39. slots: { default: 'open' },
  40. title: 'Open',
  41. width: 100,
  42. },
  43. {
  44. field: 'status',
  45. slots: { default: 'status' },
  46. title: 'Status',
  47. width: 100,
  48. },
  49. { field: 'color', title: 'Color', width: 100 },
  50. { field: 'productName', title: 'Product Name', width: 200 },
  51. { field: 'price', title: 'Price', width: 100 },
  52. {
  53. field: 'releaseDate',
  54. formatter: 'formatDateTime',
  55. title: 'Date',
  56. width: 200,
  57. },
  58. {
  59. cellRender: { name: 'CellLink', props: { text: '编辑' } },
  60. field: 'action',
  61. fixed: 'right',
  62. title: '操作',
  63. width: 120,
  64. },
  65. ],
  66. keepSource: true,
  67. pagerConfig: {},
  68. proxyConfig: {
  69. ajax: {
  70. query: async ({ page }) => {
  71. return await getExampleTableApi({
  72. page: page.currentPage,
  73. pageSize: page.pageSize,
  74. });
  75. },
  76. },
  77. },
  78. };
  79. const [Grid] = useVbenVxeGrid({ gridOptions });
  80. </script>
  81. <template>
  82. <div class="vp-raw w-full">
  83. <Grid>
  84. <template #image-url="{ row }">
  85. <Image :src="row.imageUrl" height="30" width="30" />
  86. </template>
  87. <template #open="{ row }">
  88. <Switch v-model:checked="row.open" />
  89. </template>
  90. <template #status="{ row }">
  91. <Tag :color="row.color">{{ row.status }}</Tag>
  92. </template>
  93. <template #action>
  94. <Button type="link">编辑</Button>
  95. </template>
  96. </Grid>
  97. </div>
  98. </template>