account.data.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { getAllRoleList, isAccountExist } from '@/api/demo/system';
  2. import { BasicColumn, FormSchema } from '@/components/Table';
  3. /**
  4. * transform mock data
  5. * {
  6. * 0: '华东分部',
  7. * '0-0': '华东分部-研发部'
  8. * '0-1': '华东分部-市场部',
  9. * ...
  10. * }
  11. */
  12. export const deptMap = (() => {
  13. const pDept = ['华东分部', '华南分部', '西北分部'];
  14. const cDept = ['研发部', '市场部', '商务部', '财务部'];
  15. return pDept.reduce((map, p, pIdx) => {
  16. map[pIdx] = p;
  17. cDept.forEach((c, cIndex) => (map[`${pIdx}-${cIndex}`] = `${p}-${c}`));
  18. return map;
  19. }, {});
  20. })();
  21. export const columns: BasicColumn[] = [
  22. {
  23. title: '用户名',
  24. dataIndex: 'account',
  25. width: 120,
  26. },
  27. {
  28. title: '昵称',
  29. dataIndex: 'nickname',
  30. width: 120,
  31. },
  32. {
  33. title: '邮箱',
  34. dataIndex: 'email',
  35. width: 120,
  36. },
  37. {
  38. title: '创建时间',
  39. dataIndex: 'createTime',
  40. width: 180,
  41. },
  42. {
  43. title: '角色',
  44. dataIndex: 'role',
  45. width: 200,
  46. },
  47. {
  48. title: '所属部门',
  49. dataIndex: 'dept',
  50. customRender: ({ value }) => {
  51. return deptMap[value];
  52. },
  53. },
  54. {
  55. title: '备注',
  56. dataIndex: 'remark',
  57. },
  58. ];
  59. export const searchFormSchema: FormSchema[] = [
  60. {
  61. field: 'account',
  62. label: '用户名',
  63. component: 'Input',
  64. colProps: { span: 8 },
  65. },
  66. {
  67. field: 'nickname',
  68. label: '昵称',
  69. component: 'Input',
  70. colProps: { span: 8 },
  71. },
  72. ];
  73. export const accountFormSchema: FormSchema[] = [
  74. {
  75. field: 'account',
  76. label: '用户名',
  77. component: 'Input',
  78. helpMessage: ['本字段演示异步验证', '不能输入带有admin的用户名'],
  79. rules: [
  80. {
  81. required: true,
  82. message: '请输入用户名',
  83. },
  84. {
  85. trigger: 'blur',
  86. validator(_, value) {
  87. return new Promise((resolve, reject) => {
  88. if (!value) return resolve();
  89. isAccountExist(value)
  90. .then(resolve)
  91. .catch((err) => {
  92. reject(err.message || '验证失败');
  93. });
  94. });
  95. },
  96. },
  97. ],
  98. },
  99. {
  100. field: 'pwd',
  101. label: '密码',
  102. component: 'InputPassword',
  103. required: true,
  104. ifShow: false,
  105. },
  106. {
  107. label: '角色',
  108. field: 'role',
  109. component: 'ApiSelect',
  110. componentProps: {
  111. api: getAllRoleList,
  112. labelField: 'roleName',
  113. valueField: 'roleValue',
  114. },
  115. required: true,
  116. },
  117. {
  118. field: 'dept',
  119. label: '所属部门',
  120. component: 'TreeSelect',
  121. componentProps: {
  122. fieldNames: {
  123. label: 'deptName',
  124. value: 'id',
  125. },
  126. getPopupContainer: () => document.body,
  127. },
  128. required: true,
  129. },
  130. {
  131. field: 'nickname',
  132. label: '昵称',
  133. component: 'Input',
  134. required: true,
  135. },
  136. {
  137. label: '邮箱',
  138. field: 'email',
  139. component: 'Input',
  140. required: true,
  141. },
  142. {
  143. label: '备注',
  144. field: 'remark',
  145. component: 'InputTextArea',
  146. },
  147. ];