crud.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. import * as api from './api';
  2. import {
  3. dict,
  4. UserPageQuery,
  5. AddReq,
  6. DelReq,
  7. EditReq,
  8. compute,
  9. CreateCrudOptionsProps,
  10. CreateCrudOptionsRet,
  11. } from '@fast-crud/fast-crud';
  12. import { request } from '/@/utils/service';
  13. import { dictionary } from '/@/utils/dictionary';
  14. import { successMessage } from '/@/utils/message';
  15. import { inject, ref } from 'vue';
  16. import resetPassword from './resetPassword';
  17. export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  18. const pageRequest = async (query: UserPageQuery) => {
  19. return await api.GetList(query);
  20. };
  21. const editRequest = async ({ form, row }: EditReq) => {
  22. form.id = row.id;
  23. return await api.UpdateObj(form);
  24. };
  25. const delRequest = async ({ row }: DelReq) => {
  26. return await api.DelObj(row.id);
  27. };
  28. const addRequest = async ({ form }: AddReq) => {
  29. return await api.AddObj(form);
  30. };
  31. const exportRequest = async (query: UserPageQuery) => {
  32. return await api.exportData(query);
  33. };
  34. //权限判定
  35. const hasPermissions: any = inject('$hasPermissions');
  36. const { dialogVisible, isShowDialog, resetId } = resetPassword();
  37. return {
  38. dialogVisible,
  39. resetId,
  40. crudOptions: {
  41. table: {
  42. remove: {
  43. confirmMessage: '是否删除该用户?',
  44. },
  45. border: false,
  46. },
  47. request: {
  48. pageRequest,
  49. addRequest,
  50. editRequest,
  51. delRequest,
  52. },
  53. actionbar: {
  54. buttons: {
  55. add: {
  56. show: hasPermissions('user:Create'),
  57. // show:true
  58. },
  59. export: {
  60. text: '导出', //按钮文字
  61. title: '导出', //鼠标停留显示的信息
  62. click() {
  63. return exportRequest(crudExpose!.getSearchFormData());
  64. },
  65. },
  66. },
  67. },
  68. rowHandle: {
  69. //固定右侧
  70. fixed: 'right',
  71. width: 200,
  72. buttons: {
  73. view: {
  74. show: false,
  75. },
  76. edit: {
  77. iconRight: 'Edit',
  78. type: 'text',
  79. show: hasPermissions('user:Update'),
  80. },
  81. remove: {
  82. iconRight: 'Delete',
  83. type: 'text',
  84. show: hasPermissions('user:Delete'),
  85. },
  86. custom: {
  87. text: '重设密码',
  88. type: 'text',
  89. show: hasPermissions('user:ResetPassword'),
  90. tooltip: {
  91. placement: 'top',
  92. content: '重设密码',
  93. },
  94. //@ts-ignore
  95. click: (ctx: any) => {
  96. const { row } = ctx;
  97. console.log('row', row);
  98. isShowDialog(row.id);
  99. },
  100. },
  101. },
  102. },
  103. columns: {
  104. _index: {
  105. title: '序号',
  106. form: { show: false },
  107. column: {
  108. type: 'index',
  109. align: 'center',
  110. width: '70px',
  111. columnSetDisabled: true, //禁止在列设置中选择
  112. },
  113. },
  114. username: {
  115. title: '账号',
  116. search: {
  117. show: true,
  118. },
  119. type: 'input',
  120. column: {
  121. minWidth: 100, //最小列宽
  122. },
  123. form: {
  124. rules: [
  125. // 表单校验规则
  126. {
  127. required: true,
  128. message: '账号必填项',
  129. },
  130. ],
  131. component: {
  132. placeholder: '请输入账号',
  133. },
  134. },
  135. },
  136. password: {
  137. title: '密码',
  138. type: 'input',
  139. column: {
  140. show: false,
  141. },
  142. editForm: {
  143. show: false,
  144. },
  145. form: {
  146. rules: [
  147. // 表单校验规则
  148. {
  149. required: true,
  150. message: '密码必填项',
  151. },
  152. ],
  153. component: {
  154. span: 12,
  155. showPassword: true,
  156. placeholder: '请输入密码',
  157. },
  158. // value: vm.systemConfig('base.default_password'),
  159. },
  160. /* valueResolve(row, key) {
  161. if (row.password) {
  162. row.password = vm.$md5(row.password)
  163. }
  164. } */
  165. },
  166. name: {
  167. title: '姓名',
  168. search: {
  169. show: true,
  170. },
  171. type: 'input',
  172. column: {
  173. minWidth: 100, //最小列宽
  174. },
  175. form: {
  176. rules: [
  177. // 表单校验规则
  178. {
  179. required: true,
  180. message: '姓名必填项',
  181. },
  182. ],
  183. component: {
  184. span: 12,
  185. placeholder: '请输入姓名',
  186. },
  187. },
  188. },
  189. gender: {
  190. title: '性别',
  191. type: 'dict-select',
  192. dict: dict({
  193. data: dictionary('gender'),
  194. }),
  195. column: {
  196. minWidth: 50, //最小列宽
  197. },
  198. form: {
  199. value: 1,
  200. component: {
  201. span: 12,
  202. },
  203. },
  204. component: { props: { color: 'auto' } }, // 自动染色
  205. },
  206. dept: {
  207. title: '部门',
  208. search: {
  209. disabled: true,
  210. },
  211. type: 'dict-tree',
  212. dict: dict({
  213. isTree: true,
  214. url: '/api/system/dept/all_dept/',
  215. value: 'id',
  216. label: 'name',
  217. getData: async ({ url }: { url: string }) => {
  218. return request({
  219. url: url,
  220. }).then((ret: any) => {
  221. return ret.data;
  222. });
  223. },
  224. }),
  225. column: {
  226. minWidth: 100, //最小列宽
  227. },
  228. form: {
  229. rules: [
  230. // 表单校验规则
  231. {
  232. required: true,
  233. message: '必填项',
  234. },
  235. ],
  236. component: {
  237. filterable: true,
  238. placeholder: '请选择',
  239. props: {
  240. props: {
  241. value: 'id',
  242. label: 'name',
  243. },
  244. },
  245. },
  246. },
  247. },
  248. role: {
  249. title: '角色',
  250. search: {
  251. disabled: true,
  252. },
  253. type: 'dict-select',
  254. dict: dict({
  255. url: '/api/system/role/',
  256. value: 'id',
  257. label: 'name',
  258. isTree: true,
  259. getData: async ({ url }: { url: string }) => {
  260. return request({
  261. url: url,
  262. params: {
  263. page: 1,
  264. limit: 10,
  265. },
  266. }).then((ret: any) => {
  267. return ret.data;
  268. });
  269. },
  270. }),
  271. column: {
  272. minWidth: 100, //最小列宽
  273. },
  274. form: {
  275. rules: [
  276. // 表单校验规则
  277. {
  278. required: true,
  279. message: '必填项',
  280. },
  281. ],
  282. component: {
  283. multiple: true,
  284. filterable: true,
  285. placeholder: '请选择角色',
  286. },
  287. },
  288. },
  289. mobile: {
  290. title: '手机号码',
  291. search: {
  292. show: true,
  293. },
  294. type: 'input',
  295. column: {
  296. minWidth: 120, //最小列宽
  297. },
  298. form: {
  299. rules: [
  300. {
  301. max: 20,
  302. message: '请输入正确的手机号码',
  303. trigger: 'blur',
  304. },
  305. {
  306. pattern: /^1[3-9]\d{9}$/,
  307. message: '请输入正确的手机号码',
  308. },
  309. ],
  310. component: {
  311. placeholder: '请输入手机号码',
  312. },
  313. },
  314. },
  315. email: {
  316. title: '邮箱',
  317. column: {
  318. width: 260,
  319. },
  320. form: {
  321. rules: [
  322. {
  323. type: 'email',
  324. message: '请输入正确的邮箱地址',
  325. trigger: ['blur', 'change'],
  326. },
  327. ],
  328. component: {
  329. placeholder: '请输入邮箱',
  330. },
  331. },
  332. },
  333. user_type: {
  334. title: '用户类型',
  335. search: {
  336. show: true,
  337. },
  338. type: 'dict-select',
  339. dict: dict({
  340. data: dictionary('user_type'),
  341. }),
  342. column: {
  343. minWidth: 100, //最小列宽
  344. },
  345. form: {
  346. show: false,
  347. value: 0,
  348. component: {
  349. span: 12,
  350. },
  351. },
  352. },
  353. is_active: {
  354. title: '锁定',
  355. search: {
  356. show: true,
  357. },
  358. type: 'dict-radio',
  359. column: {
  360. component: {
  361. name: 'fs-dict-switch',
  362. activeText: '',
  363. inactiveText: '',
  364. style: '--el-switch-on-color: var(--el-color-primary); --el-switch-off-color: #dcdfe6',
  365. onChange: compute((context) => {
  366. return () => {
  367. api.UpdateObj(context.row).then((res: APIResponseData) => {
  368. successMessage(res.msg as string);
  369. });
  370. };
  371. }),
  372. },
  373. },
  374. dict: dict({
  375. data: dictionary('button_status_bool'),
  376. }),
  377. },
  378. avatar: {
  379. title: '头像',
  380. type: 'avatar-cropper',
  381. column: {
  382. show: false,
  383. },
  384. form: {
  385. show: false,
  386. },
  387. },
  388. },
  389. },
  390. };
  391. };