zhou zhou
1 天以前 0a1d91e42e6c5af96e1108e9ebcc37e99eb3b22c
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { h } from 'vue'
import ArtButtonMore from '@/components/core/forms/art-button-more/index.vue'
import { ElTag } from 'element-plus'
import { get@{ENTITYNAME}StatusMeta } from './@{SIMPLEENTITYNAME}Page.helpers'
 
const MORE_ACTIONS = [
  {
    key: 'edit',
    label: '编辑',
    icon: 'ri:edit-2-line',
    auth: 'edit'
  },
  {
    key: 'delete',
    label: '删除',
    icon: 'ri:delete-bin-4-line',
    color: '#f56c6c',
    auth: 'delete'
  }
]
 
function resolveCellValue(row, prop) {
  const value = row?.[prop]
  return value === '' || value === void 0 || value === null ? '-' : value
}
 
function createTextColumn(prop, label, minWidth, extra = {}) {
  return {
    prop,
    label,
    minWidth,
    showOverflowTooltip: true,
    formatter: (row) => resolveCellValue(row, prop),
    ...extra
  }
}
 
function createNumberColumn(prop, label, width, extra = {}) {
  return {
    prop,
    label,
    width,
    formatter: (row) => resolveCellValue(row, prop),
    ...extra
  }
}
 
function createTagColumn(prop, label, width, resolveMeta) {
  return {
    prop,
    label,
    width,
    formatter: (row) => {
      const statusMeta = resolveMeta(row)
      return h(ElTag, { type: statusMeta.type, effect: 'light' }, () => statusMeta.text)
    }
  }
}
 
function buildMoreActions(handleEdit, handleDelete) {
  return MORE_ACTIONS.filter((item) => {
    if (item.key === 'edit') {
      return typeof handleEdit === 'function'
    }
    if (item.key === 'delete') {
      return typeof handleDelete === 'function'
    }
    return true
  })
}
 
export function create@{ENTITYNAME}TableColumns({ handleEdit, handleDelete } = {}) {
  return [
    { type: 'selection', width: 52, fixed: 'left' },
@{TABLECOLUMNSCONTENT}
    {
      prop: 'operation',
      label: '操作',
      width: 120,
      align: 'center',
      fixed: 'right',
      formatter: (row) =>
        h(ArtButtonMore, {
          list: buildMoreActions(handleEdit, handleDelete),
          onClick: (item) => {
            if (item.key === 'edit') {
              handleEdit?.(row)
            }
            if (item.key === 'delete') {
              handleDelete?.(row)
            }
          }
        })
    }
  ]
}