role.data.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { FormSchema } from '/@/components/Table';
  2. import { isRoleExist } from './role.api';
  3. export const columns = [
  4. {
  5. title: '角色名称',
  6. dataIndex: 'roleName',
  7. width: 100,
  8. },
  9. {
  10. title: '角色编码',
  11. dataIndex: 'roleCode',
  12. width: 100,
  13. },
  14. {
  15. title: '创建时间',
  16. dataIndex: 'createTime',
  17. width: 100,
  18. sorter: true,
  19. },
  20. ];
  21. /**
  22. * 角色用户Columns
  23. */
  24. export const userColumns = [
  25. {
  26. title: '用户账号',
  27. dataIndex: 'username',
  28. },
  29. {
  30. title: '用户姓名',
  31. dataIndex: 'realname',
  32. },
  33. {
  34. title: '状态',
  35. dataIndex: 'status_dictText',
  36. width: 80,
  37. },
  38. ];
  39. export const searchFormSchema: FormSchema[] = [
  40. {
  41. field: 'roleName',
  42. label: '角色名称',
  43. component: 'Input',
  44. colProps: { span: 6 },
  45. },
  46. {
  47. field: 'roleCode',
  48. label: '角色编码',
  49. component: 'Input',
  50. colProps: { span: 6 },
  51. },
  52. ];
  53. /**
  54. * 角色用户搜索form
  55. */
  56. export const searchUserFormSchema: FormSchema[] = [
  57. {
  58. field: 'username',
  59. label: '用户账号',
  60. component: 'Input',
  61. colProps: { span: 12 },
  62. },
  63. ];
  64. export const formSchema: FormSchema[] = [
  65. {
  66. field: 'id',
  67. label: '',
  68. component: 'Input',
  69. show: false,
  70. },
  71. {
  72. field: 'roleName',
  73. label: '角色名称',
  74. required: true,
  75. component: 'Input',
  76. },
  77. {
  78. field: 'roleCode',
  79. label: '角色编码',
  80. required: true,
  81. component: 'Input',
  82. dynamicDisabled: ({ values }) => {
  83. return !!values.id;
  84. },
  85. dynamicRules: ({ values, model }) => {
  86. console.log('values:', values);
  87. return [
  88. {
  89. required: true,
  90. validator: (_, value) => {
  91. if (!value) {
  92. return Promise.reject('请输入角色编码');
  93. }
  94. if (values) {
  95. return new Promise((resolve, reject) => {
  96. isRoleExist({ id: model.id, roleCode: value })
  97. .then((res) => {
  98. res.success ? resolve() : reject(res.message || '校验失败');
  99. })
  100. .catch((err) => {
  101. reject(err.message || '验证失败');
  102. });
  103. });
  104. }
  105. return Promise.resolve();
  106. },
  107. },
  108. ];
  109. },
  110. },
  111. {
  112. label: '备注',
  113. field: 'description',
  114. component: 'InputTextArea',
  115. },
  116. ];
  117. export const formDescSchema = [
  118. {
  119. field: 'roleName',
  120. label: '角色名称',
  121. },
  122. {
  123. field: 'roleCode',
  124. label: '角色编码',
  125. },
  126. {
  127. label: '备注',
  128. field: 'description',
  129. },
  130. ];
  131. export const roleIndexFormSchema: FormSchema[] = [
  132. {
  133. field: 'id',
  134. label: '',
  135. component: 'Input',
  136. show: false,
  137. },
  138. {
  139. label: '角色编码',
  140. field: 'roleCode',
  141. component: 'Input',
  142. dynamicDisabled: true,
  143. },
  144. {
  145. label: '首页路由',
  146. field: 'url',
  147. component: 'Input',
  148. required: true,
  149. helpMessage: '首页路由的访问地址',
  150. },
  151. {
  152. label: '组件地址',
  153. field: 'component',
  154. component: 'Input',
  155. helpMessage: '首页路由的组件地址',
  156. componentProps: {
  157. placeholder: '请输入前端组件',
  158. },
  159. required: true,
  160. },
  161. {
  162. field: 'route',
  163. label: '是否路由菜单',
  164. helpMessage: '非路由菜单设置成首页,需开启',
  165. component: 'Switch',
  166. defaultValue: true,
  167. },
  168. {
  169. label: '优先级',
  170. field: 'priority',
  171. component: 'InputNumber',
  172. },
  173. {
  174. label: '是否开启',
  175. field: 'status',
  176. component: 'JSwitch',
  177. componentProps: {
  178. options: ['1', '0'],
  179. },
  180. },
  181. ];