tableData.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { BasicColumn } from '/@/components/Table/src/types/table'
  2. import { Popconfirm } from 'ant-design-vue'
  3. import { Icon } from '/@/components/Icon/index'
  4. import { deletePermGroup } from '/@/api/sys/manager'
  5. import { computed } from 'vue'
  6. import { FormSchema } from '/@/components/Form'
  7. enum PermMap {
  8. showProject = '项目',
  9. showStaff = '用户列表',
  10. showPermission = '权限组'
  11. }
  12. export function getTableColumns(fn1: () => Promise<void>, fn2: (item) => void): BasicColumn[] {
  13. async function delConfirm(id: string) {
  14. await deletePermGroup(id)
  15. await fn1()
  16. }
  17. return [
  18. {
  19. dataIndex: 'Id',
  20. title: 'ID',
  21. width: '5%'
  22. },
  23. {
  24. dataIndex: 'name',
  25. title: '组名称',
  26. width: '15%'
  27. },
  28. {
  29. dataIndex: 'permission',
  30. title: '拥有权限',
  31. customRender: ({ record }) => {
  32. const text = record.permission.reduce((prev, curr) => {
  33. if (prev && PermMap[curr]) {
  34. prev += '、'
  35. }
  36. if (PermMap[curr]) {
  37. prev += PermMap[curr]
  38. }
  39. return prev
  40. }, '')
  41. return <span>{text}</span>
  42. }
  43. },
  44. {
  45. dataIndex: 'createTime',
  46. title: '创建时间'
  47. },
  48. {
  49. dataIndex: 'remark',
  50. title: '备注'
  51. },
  52. {
  53. dataIndex: 'opreate',
  54. title: '操作',
  55. customRender: ({ record }) => (
  56. <div class="text-primary divide-x">
  57. <span class="cursor-pointer mr-2" onClick={() => fn2(record)}>
  58. <Icon icon="ant-design:edit-filled"></Icon>
  59. </span>
  60. <span class="pl-2">
  61. <Popconfirm title="确定删除吗?" okText="确认" cancelText="取消" onConfirm={() => delConfirm(record.id)}>
  62. <span class="text-red-500 hover:text-red-600 cursor-pointer">
  63. <Icon icon="fluent:delete-20-filled"></Icon>
  64. </span>
  65. </Popconfirm>
  66. </span>
  67. </div>
  68. )
  69. }
  70. ]
  71. }
  72. export function getPermSchemas() {
  73. const schemas = computed<FormSchema[]>(() => [
  74. {
  75. field: 'id',
  76. required: false,
  77. component: 'Input',
  78. label: 'ID',
  79. show: false
  80. },
  81. {
  82. field: 'name',
  83. component: 'Input',
  84. required: true,
  85. componentProps: {
  86. placeholder: '输入用户组名称'
  87. },
  88. label: '用户组名称'
  89. },
  90. {
  91. field: 'permission',
  92. component: 'CheckboxGroup',
  93. required: true,
  94. label: '权限设置',
  95. componentProps: {
  96. options: [
  97. { label: '项目', value: 'showProject' },
  98. { label: '用户列表', value: 'showStaff' },
  99. { label: '权限组', value: 'showPermission' }
  100. ]
  101. }
  102. },
  103. {
  104. field: 'remark',
  105. component: 'InputTextArea',
  106. label: '备注'
  107. }
  108. ])
  109. return schemas
  110. }