role.data.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { BasicColumn, FormSchema } from '/@/components/Table';
  2. import { h } from 'vue';
  3. import { Switch } from 'ant-design-vue';
  4. import { setRoleStatus } from '/@/api/demo/system';
  5. import { useMessage } from '/@/hooks/web/useMessage';
  6. export const columns: BasicColumn[] = [
  7. {
  8. title: '角色名称',
  9. dataIndex: 'roleName',
  10. width: 200,
  11. },
  12. {
  13. title: '角色值',
  14. dataIndex: 'roleValue',
  15. width: 180,
  16. },
  17. {
  18. title: '排序',
  19. dataIndex: 'orderNo',
  20. width: 50,
  21. },
  22. {
  23. title: '状态',
  24. dataIndex: 'status',
  25. width: 120,
  26. customRender: ({ record }) => {
  27. if (!Reflect.has(record, 'pendingStatus')) {
  28. record.pendingStatus = false;
  29. }
  30. return h(Switch, {
  31. checked: record.status === '1',
  32. checkedChildren: '停用',
  33. unCheckedChildren: '启用',
  34. loading: record.pendingStatus,
  35. onChange(checked: boolean) {
  36. record.pendingStatus = true;
  37. const newStatus = checked ? '1' : '0';
  38. const { createMessage } = useMessage();
  39. setRoleStatus(record.id, newStatus)
  40. .then(() => {
  41. record.status = newStatus;
  42. createMessage.success(`已成功修改角色状态`);
  43. })
  44. .catch(() => {
  45. createMessage.error('修改角色状态失败');
  46. })
  47. .finally(() => {
  48. record.pendingStatus = false;
  49. });
  50. },
  51. });
  52. },
  53. },
  54. {
  55. title: '创建时间',
  56. dataIndex: 'createTime',
  57. width: 180,
  58. },
  59. {
  60. title: '备注',
  61. dataIndex: 'remark',
  62. },
  63. ];
  64. export const searchFormSchema: FormSchema[] = [
  65. {
  66. field: 'roleNme',
  67. label: '角色名称',
  68. component: 'Input',
  69. colProps: { span: 8 },
  70. },
  71. {
  72. field: 'status',
  73. label: '状态',
  74. component: 'Select',
  75. componentProps: {
  76. options: [
  77. { label: '启用', value: '1' },
  78. { label: '停用', value: '0' },
  79. ],
  80. },
  81. colProps: { span: 8 },
  82. },
  83. ];
  84. export const formSchema: FormSchema[] = [
  85. {
  86. field: 'roleName',
  87. label: '角色名称',
  88. required: true,
  89. component: 'Input',
  90. },
  91. {
  92. field: 'roleValue',
  93. label: '角色值',
  94. required: true,
  95. component: 'Input',
  96. },
  97. {
  98. field: 'status',
  99. label: '状态',
  100. component: 'RadioButtonGroup',
  101. defaultValue: '0',
  102. componentProps: {
  103. options: [
  104. { label: '启用', value: '1' },
  105. { label: '停用', value: '0' },
  106. ],
  107. },
  108. },
  109. {
  110. label: '备注',
  111. field: 'remark',
  112. component: 'InputTextArea',
  113. },
  114. {
  115. label: ' ',
  116. field: 'menu',
  117. slot: 'menu',
  118. component: 'Input',
  119. },
  120. ];