crud.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import type { CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
  2. import { dict } from '@fast-crud/fast-crud';
  3. import _ from 'lodash';
  4. import { isString } from '~/src/utils';
  5. import type { UserList } from './api';
  6. import { addRequest, delRequest, editRequest, pageRequest, queryAll } from './api';
  7. const userList: UserList = await queryAll();
  8. const dictOpt = {
  9. url: '/userinfo/queryAll',
  10. label: 'relname',
  11. value: 'id'
  12. };
  13. function curd({ context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  14. const openModel = context?.openModel;
  15. return {
  16. crudOptions: {
  17. request: {
  18. pageRequest: async ({ page, query }) => {
  19. const { total, data } = await pageRequest(page.offset + 1, page.limit, query);
  20. return { records: data, total, currentPage: page.offset, pageSize: page.limit };
  21. },
  22. addRequest: ({ form }) => {
  23. return addRequest(form);
  24. },
  25. editRequest: ({ form }) => {
  26. editRequest(form);
  27. },
  28. delRequest: ({ row }) => {
  29. return delRequest(row.id);
  30. }
  31. },
  32. toolbar: {
  33. show: true
  34. },
  35. actionbar: {
  36. show: true,
  37. buttons: {
  38. add: {
  39. text: '新增班级',
  40. title: '使用表单新增班级',
  41. circle: false,
  42. tooltip: {
  43. slots: {
  44. default() {
  45. return '使用表单新增班级';
  46. }
  47. }
  48. }
  49. }
  50. }
  51. },
  52. form: {
  53. beforeSubmit: localContext => {
  54. if (isString(localContext.form.createUid)) {
  55. localContext.form.createUid = null;
  56. }
  57. if (isString(localContext.form.manageId)) {
  58. localContext.form.manageId = null;
  59. }
  60. return true;
  61. }
  62. },
  63. columns: {
  64. id: {
  65. title: '班级ID',
  66. type: 'text',
  67. search: { show: true },
  68. form: {
  69. show: false
  70. },
  71. column: {
  72. resizable: true,
  73. width: 120,
  74. align: 'center',
  75. fixed: 'left'
  76. }
  77. },
  78. name: {
  79. title: '班级名称',
  80. type: 'text',
  81. search: {
  82. title: '名称',
  83. show: true
  84. },
  85. column: {
  86. resizable: true,
  87. width: 60,
  88. align: 'center',
  89. fixed: 'left'
  90. }
  91. },
  92. createUid: {
  93. title: '创建用户',
  94. type: 'text',
  95. valueBuilder(localContext) {
  96. if (userList[localContext.row.createUid]) {
  97. localContext.row.createUid = userList[localContext.row.createUid];
  98. }
  99. },
  100. form: {
  101. component: {
  102. name: 'fs-dict-select',
  103. dict: dict(dictOpt)
  104. }
  105. },
  106. search: { show: false },
  107. column: {
  108. resizable: true,
  109. width: 90,
  110. align: 'center',
  111. fixed: 'left'
  112. }
  113. },
  114. manageId: {
  115. title: '负责人',
  116. type: 'text',
  117. valueBuilder(localContext) {
  118. if (userList[localContext.row.manageId]) {
  119. localContext.row.manageId = userList[localContext.row.manageId];
  120. }
  121. },
  122. form: {
  123. component: {
  124. name: 'fs-dict-select',
  125. dict: dict(dictOpt)
  126. }
  127. },
  128. search: { show: false },
  129. column: {
  130. resizable: true,
  131. width: 90,
  132. align: 'center',
  133. fixed: 'left'
  134. }
  135. },
  136. modifyTime: {
  137. title: '更新时间',
  138. type: 'easDateTime',
  139. search: { show: false },
  140. form: { show: false },
  141. column: {
  142. resizable: true,
  143. width: 110,
  144. align: 'center',
  145. fixed: 'left'
  146. }
  147. },
  148. createTime: {
  149. title: '创建时间',
  150. type: 'easDateTime',
  151. search: { show: true },
  152. form: { show: false },
  153. column: {
  154. resizable: true,
  155. width: 110,
  156. align: 'center',
  157. fixed: 'left'
  158. }
  159. },
  160. disabled: {
  161. title: '状态',
  162. type: 'dict-select',
  163. dict: dict({
  164. data: [
  165. { value: 'N', label: '启用中' },
  166. { value: 'Y', label: '已禁用' }
  167. ]
  168. }),
  169. column: {
  170. resizable: true,
  171. width: 80
  172. }
  173. }
  174. },
  175. rowHandle: {
  176. buttons: {
  177. studentManager: {
  178. text: null,
  179. size: 'small',
  180. icon: 'raphael:people',
  181. tooltip: {
  182. slots: {
  183. default() {
  184. return '管理学员';
  185. }
  186. }
  187. },
  188. click: ({ row }) => {
  189. openModel(row.id);
  190. }
  191. },
  192. schedule: {
  193. text: null,
  194. size: 'small',
  195. icon: 'uil:schedule',
  196. tooltip: {
  197. slots: {
  198. default() {
  199. return '查看排课计划';
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. };
  208. }
  209. export default curd;