zhuoyuan.wang
2024-06-19 15ebe96f28cadec6a726c5324593a40bbf56205f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
  <template v-for="column in columns" :key="column.id">
    <el-table-column
      v-if="column.isShow && !otherType.includes(column.type)"
      :prop="column.prop"
      :label="column.label"
      v-bind="column.table"
    >
      <template #default="scope">
        {{ formatData(column.format, getProperty(scope.row, column.prop)) }}
      </template>
    </el-table-column>
 
    <el-table-column
      v-if="column.isShow && column.type === 'dict'"
      :prop="column.prop"
      :label="column.label"
      v-bind="column.table"
    >
      <template #default="scope">
        {{ formatData(column.format, column.options.dict[getProperty(scope.row, column.prop)]) }}
      </template>
    </el-table-column>
 
    <el-table-column
      v-if="column.isShow && column.type === 'select'"
      :prop="column.prop"
      :label="column.label"
      v-bind="column.table"
    >
      <template #default="scope">
        {{ formatData(column.format, column.options.select[getProperty(scope.row, column.prop)]) }}
      </template>
    </el-table-column>
 
    <el-table-column
      v-if="column.isShow && column.type === 'slot'"
      :prop="column.prop"
      :label="column.label"
      v-bind="column.table"
    >
      <template #default="scope">
        <slot :name="`table-${column.prop}`" v-bind="scope"/>
      </template>
    </el-table-column>
  </template>
</template>
 
<script setup>
 
import {getProperty} from "@/utils/tools.js";
 
const props = defineProps({
  columns: {
    type: Array,
    default: []
  },
});
 
const otherType = ['slot', 'dict', 'select'];
 
const formatData = (format, data) => {
  return format ? format(data) : (data || '')
}
 
</script>
 
<style lang='scss' scoped>
</style>