crud.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, UserPageQuery } from '@fast-crud/fast-crud';
  2. import * as api from './api';
  3. import { auth } from '/@/utils/authFunction';
  4. export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  5. const pageRequest = async (query: UserPageQuery) => {
  6. return await api.GetList(query);
  7. };
  8. // const editRequest = async ({ form, row }: EditReq) => {
  9. // form.id = row.id;
  10. // return await api.UpdateObj(form);
  11. // };
  12. // const delRequest = async ({ row }: DelReq) => {
  13. // return await api.DelObj(row.id);
  14. // };
  15. const addRequest = async ({ form }: AddReq) => {
  16. return await api.AddObj(form);
  17. };
  18. /**
  19. * 懒加载
  20. * @param row
  21. * @returns {Promise<unknown>}
  22. */
  23. // const loadContentMethod = (tree: any, treeNode: any, resolve: Function) => {
  24. // pageRequest({ pcode: tree.code }).then((res: APIResponseData) => {
  25. // resolve(res.data);
  26. // });
  27. // };
  28. return {
  29. crudOptions: {
  30. request: {
  31. pageRequest,
  32. addRequest,
  33. },
  34. actionbar: {
  35. buttons: {
  36. add: {
  37. show: auth('area:Create'),
  38. },
  39. },
  40. },
  41. pagination: {
  42. show: false,
  43. },
  44. columns: {
  45. _index: {
  46. title: '序号',
  47. form: { show: false },
  48. column: {
  49. type: 'index',
  50. align: 'center',
  51. width: '70px',
  52. columnSetDisabled: true, //禁止在列设置中选择
  53. },
  54. },
  55. name: {
  56. title: '名称',
  57. search: {
  58. show: true,
  59. },
  60. treeNode: true,
  61. type: 'input',
  62. column: {
  63. minWidth: 120,
  64. },
  65. form: {
  66. rules: [
  67. // 表单校验规则
  68. { required: true, message: '名称必填项' },
  69. ],
  70. component: {
  71. placeholder: '请输入名称',
  72. },
  73. },
  74. },
  75. color:{
  76. title: '颜色',
  77. type: 'input',
  78. column: {
  79. minWidth: 120,
  80. },
  81. form: {
  82. component: { placeholder: '请填写标签颜色' },
  83. rules: [{ required: true, message: '请填写标签颜色' }],
  84. },
  85. },
  86. description:{
  87. title: '标签描述',
  88. type: 'input',
  89. column: {
  90. minWidth: 120,
  91. },
  92. form: {
  93. component: { placeholder: '请填写标签描述' },
  94. rules: [{ required: true, message: '请填写标签描述' }],
  95. },
  96. },
  97. sort:{
  98. title: '排序',
  99. type: 'input',
  100. column: {
  101. minWidth: 120,
  102. },
  103. form: {
  104. component: { placeholder: '请填写排序' },
  105. rules: [{ required: true, message: '请填写排序' }],
  106. },
  107. },
  108. },
  109. },
  110. };
  111. };