data.ts 2.9 KB

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