data.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import type { VbenFormSchema } from '#/adapter/form';
  2. import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
  3. import type { SystemModel } from '#/api';
  4. import { $t } from '#/locales';
  5. export function useRoleSearchFormSchema(): VbenFormSchema[] {
  6. return [
  7. { component: 'Input', fieldName: 'name', label: $t('system.role.name') },
  8. {
  9. component: 'Select',
  10. componentProps: {
  11. allowClear: true,
  12. options: [
  13. { label: $t('common.enabled'), value: 1 },
  14. { label: $t('common.disabled'), value: 0 },
  15. ],
  16. },
  17. fieldName: 'status',
  18. label: $t('system.role.status'),
  19. },
  20. ];
  21. }
  22. export function useRoleTableColumns<T = SystemModel.Role>(
  23. onActionClick: OnActionClickFn<T>,
  24. onStatusChange?: (newStatus: any, row: T) => PromiseLike<boolean | undefined>,
  25. ): VxeTableGridOptions['columns'] {
  26. return [
  27. {
  28. field: 'name',
  29. title: $t('system.role.name'),
  30. width: 200,
  31. },
  32. {
  33. field: 'code',
  34. title: $t('system.role.code'),
  35. width: 200,
  36. },
  37. {
  38. cellRender: {
  39. attrs: { beforeChange: onStatusChange },
  40. // props: { accessRole: '超级管理员' },
  41. name: onStatusChange ? 'CellSwitch' : 'CellTag',
  42. },
  43. field: 'status',
  44. title: $t('system.role.status'),
  45. width: 100,
  46. },
  47. {
  48. field: 'remark',
  49. minWidth: 100,
  50. title: $t('system.role.remark'),
  51. },
  52. {
  53. field: 'lastTime',
  54. title: $t('table.column.lastTime'),
  55. },
  56. {
  57. field: 'lastUser',
  58. title: $t('table.column.lastUser'),
  59. },
  60. {
  61. field: 'createUser',
  62. title: $t('table.column.createUser'),
  63. },
  64. {
  65. field: 'createTime',
  66. title: $t('table.column.createTime'),
  67. },
  68. {
  69. align: 'center',
  70. cellRender: {
  71. attrs: {
  72. nameField: 'name',
  73. nameTitle: $t('system.role.name'),
  74. onClick: onActionClick,
  75. },
  76. name: 'CellOperation',
  77. },
  78. field: 'operation',
  79. fixed: 'right',
  80. title: $t('table.column.operation'),
  81. width: 130,
  82. },
  83. ];
  84. }
  85. export function useRoleFormSchema(): VbenFormSchema[] {
  86. return [
  87. {
  88. component: 'Input',
  89. fieldName: 'name',
  90. label: $t('system.role.name'),
  91. rules: 'required',
  92. },
  93. {
  94. component: 'RadioGroup',
  95. componentProps: {
  96. buttonStyle: 'solid',
  97. options: [
  98. { label: $t('common.enabled'), value: 1 },
  99. { label: $t('common.disabled'), value: 0 },
  100. ],
  101. optionType: 'button',
  102. },
  103. defaultValue: 1,
  104. fieldName: 'status',
  105. label: $t('system.role.status'),
  106. },
  107. {
  108. component: 'Textarea',
  109. fieldName: 'remark',
  110. label: $t('system.role.remark'),
  111. },
  112. {
  113. component: 'Input',
  114. fieldName: 'permissions',
  115. formItemClass: 'items-start',
  116. label: $t('system.role.setPermissions'),
  117. modelPropName: 'modelValue',
  118. },
  119. ];
  120. }