crud.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import * as api from './api';
  2. import { dict, UserPageQuery, AddReq, DelReq, EditReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
  3. import * as companyApi from '../company/api';
  4. import { dictionary } from '/@/utils/dictionary';
  5. import { successMessage } from '/@/utils/message';
  6. import { auth } from '/@/utils/authFunction';
  7. import { Md5 } from 'ts-md5';
  8. export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  9. const pageRequest = async (query: any) => {
  10. console.log(query)
  11. return await api.GetList(query);
  12. };
  13. const editRequest = async ({ form, row }: EditReq) => {
  14. form.id = row.id;
  15. return await api.UpdateObj(form);
  16. };
  17. const delRequest = async ({ row }: DelReq) => {
  18. return await api.DelObj(row.id);
  19. };
  20. const addRequest = async ({ form }: AddReq) => {
  21. return await api.AddObj(form);
  22. };
  23. return {
  24. crudOptions: {
  25. toolbar:{
  26. buttons:{
  27. search:{show:false},
  28. // 刷新按钮
  29. refresh:{show:false},
  30. // 紧凑模式
  31. compact:{show:false},
  32. // 导出按钮
  33. export:{
  34. text: '导出',
  35. type: 'primary',
  36. size: 'small',
  37. icon: 'upload',
  38. circle: false,
  39. display: true,
  40. show:false
  41. },
  42. // 列设置按钮
  43. columns:{
  44. show:false
  45. },
  46. }
  47. },
  48. search: {
  49. col: { span: 3 },
  50. show: true,
  51. autoSearch:false,
  52. buttons: {
  53. search: {
  54. size: 'small', // 设置查询按钮大小为small
  55. },
  56. reset: {
  57. size: 'small', // 设置重置按钮大小为small
  58. }
  59. }
  60. },
  61. request: {
  62. pageRequest,
  63. addRequest,
  64. editRequest,
  65. delRequest,
  66. },
  67. actionbar: {
  68. buttons: {
  69. add: {
  70. show: true,//auth('account:Create'),
  71. },
  72. },
  73. },
  74. rowHandle: {
  75. fixed: 'right',
  76. width: 200,
  77. buttons: {
  78. view: { iconRight: 'View', type: 'text',show: true },
  79. edit: { iconRight: 'Edit', type: 'text', show: false },//auth('account:Update')
  80. remove: { iconRight: 'Delete', type: 'text', show: false },//auth('account:Delete')
  81. },
  82. },
  83. columns: {
  84. _index: {
  85. title: '序号',
  86. form: { show: false },
  87. column: { type: 'index', align: 'center', width: '70px', columnSetDisabled: true },
  88. },
  89. username: {
  90. title: '用户名',
  91. type: 'text',
  92. search: { show: true },
  93. form: {
  94. component: { placeholder: '请输入用户名' },
  95. rules: [{ required: true, message: '请输入用户名' }]
  96. },
  97. column: { minWidth: 120 },
  98. },
  99. password: {
  100. title: '密码',
  101. type: 'password',
  102. search: { show: false },
  103. column: { show: false },
  104. form: {
  105. component: { placeholder: '请输入密码' },
  106. rules: [{ required: true, message: '请输入密码' }],
  107. show: true,
  108. column: { show: false }
  109. },
  110. valueResolve({ form }) {
  111. if (form.password) {
  112. form.password = Md5.hashStr(form.password)
  113. }
  114. }
  115. },
  116. name: {
  117. title: '姓名',
  118. type: 'text',
  119. search: { show: false },
  120. form: {
  121. component: { placeholder: '请输入姓名' },
  122. rules: [{ required: true, message: '请输入姓名' }]
  123. },
  124. column: { minWidth: 120 },
  125. },
  126. mobile: {
  127. title: '手机号',
  128. type: 'text',
  129. search: { show: true },
  130. form: {
  131. component: { placeholder: '请输入手机号' },
  132. rules: [{ required: true, message: '请输入手机号' }]
  133. },
  134. column: { minWidth: 120 },
  135. },
  136. email: {
  137. title: '邮箱',
  138. type: 'text',
  139. search: { show: true },
  140. form: {
  141. component: { placeholder: '请输入邮箱' },
  142. rules: [{ required: true, message: '请输入邮箱' }]
  143. },
  144. column: { minWidth: 180 },
  145. },
  146. tenant_id: {
  147. title: '商户ID',
  148. search: { show: true },
  149. type: 'dict-select',
  150. dict: dict({
  151. url: '/api/platform/tenants/',
  152. value: 'tenant_id',
  153. label: 'name',
  154. getData: (url) => {
  155. return companyApi.GetList({ page: 1, limit: 20 }).then((res:any) => {
  156. return res.data.results;
  157. });
  158. }
  159. }),
  160. },
  161. is_active: {
  162. title: '账号状态',
  163. search: { show: true },
  164. type: 'dict-select',
  165. form: { show:false, component: { placeholder: '请选择账号状态' } },
  166. column: { minWidth: 120 },
  167. dict: dict({
  168. data: [
  169. { value: true, label: '启用' },
  170. { value: false, label: '禁用' }
  171. ]
  172. }),
  173. },
  174. date_joined: {
  175. title: '开通时间',
  176. type: 'datetime',
  177. search: { show: false },
  178. form: { component: { placeholder: '请选择开通时间' },show:false },
  179. column: { minWidth: 150 },
  180. },
  181. last_login: {
  182. title: '最后登录时间',
  183. type: 'datetime',
  184. search: { show: false },
  185. form: { component: { placeholder: '请选择最后登录时间' },show:false },
  186. column: { minWidth: 150 },
  187. },
  188. permission_level: {
  189. title: '权限等级',
  190. search: { show: false },
  191. type: 'dict-select',
  192. form: { component: { placeholder: '请选择权限等级' },show:false },
  193. column: { minWidth: 120 },
  194. dict: dict({
  195. data: [
  196. { value: 'admin', label: '管理员' },
  197. { value: 'user', label: '普通用户' },
  198. { value: 'guest', label: '访客' }
  199. ]
  200. }),
  201. },
  202. /* job_count: {
  203. title: '岗位数量',
  204. type: 'number',
  205. column: { minWidth: 100 },
  206. },
  207. report_count: {
  208. title: '报告数量',
  209. type: 'number',
  210. column: { minWidth: 100 },
  211. }, */
  212. },
  213. },
  214. };
  215. };