custom-cell.vue 2.4 KB

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