crud.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import type { CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
  2. import { dict } from '@fast-crud/fast-crud';
  3. import importStudent from '@/public/学员导入.xlsx';
  4. import { addRequest, delRequest, editRequest, pageRequest } from './api';
  5. function curd({ context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  6. return {
  7. crudOptions: {
  8. container: {
  9. is: 'fs-layout-card'
  10. },
  11. request: {
  12. pageRequest: async ({ page, query }) => {
  13. const { total, data } = await pageRequest(page.offset + 1, page.limit, query);
  14. return { records: data, total, currentPage: page.offset, pageSize: page.limit };
  15. },
  16. addRequest: ({ form }) => {
  17. return addRequest(form);
  18. },
  19. editRequest: ({ form }) => {
  20. editRequest(form);
  21. },
  22. delRequest: ({ row }) => {
  23. return delRequest(row.id);
  24. }
  25. },
  26. toolbar: {
  27. show: true
  28. },
  29. actionbar: {
  30. show: true,
  31. buttons: {
  32. add: {
  33. text: '新增学员',
  34. title: '使用表单新增学员',
  35. circle: false,
  36. tooltip: {
  37. slots: {
  38. default() {
  39. return '使用表单新增学员';
  40. }
  41. }
  42. }
  43. },
  44. importAdd: {
  45. text: 'Excel文件导入',
  46. title: '上传Excel文件批量导入学员',
  47. icon: '',
  48. iconRight: '',
  49. circle: false,
  50. style: {},
  51. disabled: false,
  52. tooltip: {
  53. slots: {
  54. default() {
  55. return '上传Excel文件,支持xlsx 格式';
  56. }
  57. }
  58. },
  59. show: true,
  60. click: () => {
  61. context?.openModal();
  62. },
  63. order: 1
  64. },
  65. exportAdd: {
  66. text: '下载导入模板',
  67. circle: false,
  68. disabled: false,
  69. tooltip: {
  70. slots: {
  71. default() {
  72. return '下载导入学员的 Excel 模板';
  73. }
  74. }
  75. },
  76. show: true,
  77. click: () => {
  78. window.location.href = importStudent;
  79. },
  80. order: 1
  81. }
  82. }
  83. },
  84. columns: {
  85. studentName: {
  86. title: '姓名',
  87. type: 'text',
  88. search: { show: true },
  89. column: {
  90. resizable: true,
  91. width: 60,
  92. align: 'center',
  93. fixed: 'left'
  94. }
  95. },
  96. phone: {
  97. title: '手机',
  98. type: 'text',
  99. search: { show: true },
  100. column: {
  101. resizable: true,
  102. width: 120,
  103. align: 'center',
  104. fixed: 'left'
  105. }
  106. },
  107. studentIdnumber: {
  108. title: '身份证号',
  109. type: 'text',
  110. search: { show: true },
  111. column: {
  112. resizable: true,
  113. width: 180,
  114. align: 'center',
  115. fixed: 'left'
  116. }
  117. },
  118. university: {
  119. title: '学校',
  120. type: 'text',
  121. search: { show: true },
  122. column: {
  123. resizable: true,
  124. width: 120,
  125. align: 'center',
  126. fixed: 'left'
  127. }
  128. },
  129. address: {
  130. title: '住址',
  131. type: 'text',
  132. search: { show: true },
  133. column: {
  134. resizable: true,
  135. width: 180,
  136. align: 'center',
  137. fixed: 'left'
  138. }
  139. },
  140. email: {
  141. title: '邮箱',
  142. type: 'text',
  143. search: { show: true },
  144. column: {
  145. resizable: true,
  146. width: 180,
  147. align: 'center',
  148. fixed: 'left'
  149. }
  150. },
  151. birthdate: {
  152. title: '生日',
  153. type: 'easDate',
  154. search: { show: true },
  155. column: {
  156. resizable: true,
  157. align: 'center',
  158. width: 120
  159. }
  160. },
  161. studentNumber: {
  162. title: '学生档案号',
  163. type: 'text',
  164. search: { show: true },
  165. column: {
  166. resizable: true,
  167. align: 'center',
  168. width: 200
  169. },
  170. form: {
  171. show: false
  172. }
  173. },
  174. enrollmentDate: {
  175. title: '入学时间',
  176. type: 'easDate',
  177. search: { show: true },
  178. column: {
  179. resizable: true,
  180. width: 100
  181. }
  182. },
  183. graduationDate: {
  184. title: '毕业时间',
  185. type: 'easDate',
  186. search: { show: true },
  187. column: {
  188. resizable: true,
  189. width: 100
  190. }
  191. },
  192. gender: {
  193. title: '性别',
  194. type: 'dict-select',
  195. dict: dict({
  196. data: [
  197. { value: 'M', label: '男' },
  198. { value: 'F', label: '女' }
  199. ]
  200. }),
  201. column: {
  202. resizable: true,
  203. width: 40
  204. }
  205. }
  206. }
  207. }
  208. };
  209. }
  210. export default curd;