Blame view

src/views/demo/table/CustomerCell.vue 2.77 KB
1
2
3
<template>
  <div class="p-4">
    <BasicTable @register="registerTable">
4
5
6
7
8
9
10
11
12
13
14
15
16
17
      <template #bodyCell="{ column, record, text }">
        <template v-if="column.key === 'id'"> ID: {{ record.id }} </template>
        <template v-if="column.key === 'no'">
          <Tag color="green">
            {{ record.no }}
          </Tag>
        </template>
        <template v-if="column.key === 'avatar'">
          <Avatar :size="60" :src="record.avatar" />
        </template>
        <template v-if="column.key === 'imgArr'">
          <TableImg :size="60" :simpleShow="true" :imgList="text" />
        </template>
        <template v-if="column.key === 'imgs'"> <TableImg :size="60" :imgList="text" /> </template>
18
19
20
21
22
23
        <template v-if="column.key === 'category'">
          <Tag color="green">
            {{ record.no }}
          </Tag>
        </template>
24
      </template>
25
26
27
28
29
30
    </BasicTable>
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, BasicColumn, TableImg } from '/@/components/Table';
31
  import { Tag, Avatar } from 'ant-design-vue';
32
33
34
35
36
  import { demoListApi } from '/@/api/demo/table';
  const columns: BasicColumn[] = [
    {
      title: 'ID',
      dataIndex: 'id',
37
      // slots: { customRender: 'id' },
38
39
    },
    {
40
41
42
      title: '头像',
      dataIndex: 'avatar',
      width: 100,
43
      // slots: { customRender: 'avatar' },
44
45
    },
    {
46
47
48
49
      title: '分类',
      dataIndex: 'category',
      width: 80,
      align: 'center',
50
      defaultHidden: true,
51
      // slots: { customRender: 'category' },
52
53
    },
    {
54
55
56
57
58
      title: '姓名',
      dataIndex: 'name',
      width: 120,
    },
    {
59
      title: '图片列表1',
60
      dataIndex: 'imgArr',
61
62
      helpMessage: ['这是简单模式的图片列表', '只会显示一张在表格中', '但点击可预览多张图片'],
      width: 140,
63
      // slots: { customRender: 'img' },
64
65
    },
    {
66
67
68
      title: '照片列表2',
      dataIndex: 'imgs',
      width: 160,
69
      // slots: { customRender: 'imgs' },
70
71
    },
    {
72
73
74
75
76
77
      title: '地址',
      dataIndex: 'address',
    },
    {
      title: '编号',
      dataIndex: 'no',
78
      // slots: { customRender: 'no' },
79
80
81
82
83
84
85
86
87
88
89
    },
    {
      title: '开始时间',
      dataIndex: 'beginTime',
    },
    {
      title: '结束时间',
      dataIndex: 'endTime',
    },
  ];
  export default defineComponent({
90
    components: { BasicTable, TableImg, Tag, Avatar },
91
92
93
    setup() {
      const [registerTable] = useTable({
        title: '自定义列内容',
94
        titleHelpMessage: '表格中所有头像、图片均为mock生成,仅用于演示图片占位',
95
96
        api: demoListApi,
        columns: columns,
97
        bordered: true,
98
        showTableSetting: true,
99
100
101
102
103
104
105
106
      });

      return {
        registerTable,
      };
    },
  });
</script>