crud.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, dict, UserPageQuery,compute } 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 getDetail = async ({ row }: InfoReq) => {
  9. return await api.GetObj(row.id);
  10. };
  11. const editRequest = async ({ form, row }: EditReq) => {
  12. form.id = row.id;
  13. return await api.UpdateObj(form);
  14. };
  15. const delRequest = async ({ row }: DelReq) => {
  16. return await api.DelObj(row.id);
  17. };
  18. const addRequest = async ({ form }: AddReq) => {
  19. return await api.AddObj(form);
  20. };
  21. return {
  22. crudOptions: {
  23. request: {
  24. pageRequest,
  25. editRequest,
  26. delRequest,
  27. addRequest,
  28. getDetail,
  29. },
  30. form:{
  31. wrapper: {
  32. buttons: {
  33. ok:{
  34. text:'提交',
  35. show:compute((row) => {
  36. return row.mode !=='view'
  37. })
  38. }
  39. }
  40. }
  41. },
  42. actionbar: {
  43. buttons: {
  44. add: {
  45. show: auth('area:Create'),
  46. },
  47. },
  48. },
  49. pagination: {
  50. show: true,
  51. },
  52. columns: {
  53. _index: {
  54. title: '序号',
  55. form: { show: false },
  56. column: {
  57. type: 'index',
  58. align: 'center',
  59. width: '70px',
  60. columnSetDisabled: true, //禁止在列设置中选择
  61. },
  62. },
  63. user_code:{
  64. title:'工号',
  65. type:'input',
  66. column: {
  67. minWidth: 120,
  68. },
  69. form: {
  70. component: { placeholder: '请填写工号' },
  71. rules: [{ required: true, message: '请填写工号' }],
  72. },
  73. },
  74. username:{
  75. title:'账号名',
  76. type:'input',
  77. column: {
  78. show: false,
  79. minWidth: 120,
  80. },
  81. form: {
  82. component: { placeholder: '请填写账号名' },
  83. rules: [{ required: true, message: '请填写账号名' }],
  84. },
  85. viewForm:{
  86. component: { placeholder: '' },
  87. }
  88. },
  89. name: {
  90. title: '名称',
  91. search: {
  92. show: true,
  93. },
  94. treeNode: true,
  95. type: 'input',
  96. column: {
  97. minWidth: 120,
  98. },
  99. form: {
  100. rules: [
  101. // 表单校验规则
  102. { required: true, message: '名称必填项' },
  103. ],
  104. component: {
  105. placeholder: '请输入名称',
  106. },
  107. },
  108. },
  109. password:{
  110. title: '密码',
  111. type: 'input',
  112. column: {
  113. minWidth: 120,
  114. show: false,
  115. },
  116. form: {
  117. component: { placeholder: '请填写密码' },
  118. },
  119. addForm:{
  120. component:{placeholder: '请填写密码'} ,
  121. rules: [{ required: true, message: '请填写密码' }],},
  122. editForm:{
  123. show:true,
  124. },
  125. viewForm:{
  126. show:false,
  127. }
  128. },
  129. email:{
  130. title: '邮箱',
  131. type: 'input',
  132. column: {
  133. show: false,
  134. minWidth: 120,
  135. },
  136. form: {
  137. component: { placeholder: '请填写邮箱' },
  138. rules: [{ required: false, message: '请填写邮箱' }],
  139. },
  140. viewForm:{
  141. component: { placeholder: '' },
  142. }
  143. },
  144. mobile:{
  145. title: '手机号',
  146. type: 'input',
  147. column: {
  148. show: false,
  149. minWidth: 120,
  150. },
  151. form: {
  152. component: { placeholder: '请填写手机号' },
  153. rules: [{ required: true, message: '请填写手机号' }],
  154. },
  155. viewForm:{
  156. component: { placeholder: '' },
  157. }
  158. },
  159. gender:{
  160. title: '性别',
  161. type: 'dict-select',
  162. column: {
  163. show: false,
  164. minWidth: 120,
  165. },
  166. dict: dict({
  167. data: [
  168. { label: '男', value: 1 },
  169. { label: '女', value: 2 },
  170. ],
  171. }),
  172. form: {
  173. component: { placeholder: '请选择性别' },
  174. rules: [{ required: true, message: '请选择性别' }],
  175. },
  176. viewForm:{
  177. component: { placeholder: '' },
  178. }
  179. },
  180. user_type:{
  181. title: '用户类型',
  182. type: 'dict-select',
  183. search: {
  184. show: true,
  185. },
  186. column: {
  187. minWidth: 120,
  188. },
  189. dict: dict({
  190. data: [
  191. /* { label: '学生', value: 0 }, */
  192. { label: '教师', value: 1 },
  193. { label: '校外团体', value: 2 },
  194. { label: '学院领导', value: 3 },
  195. ],
  196. }),
  197. form: {
  198. value:1,
  199. component: { placeholder: '请选择用户类型' },
  200. rules: [{ required: false, message: '请选择用户类型' }],
  201. },
  202. },
  203. organization:{
  204. title: '学院',
  205. type: 'input',
  206. column: {
  207. show: true,
  208. minWidth: 120,
  209. },
  210. form: {
  211. component: { placeholder: '请填写学院' },
  212. rules: [{ required: false, message: '请填写学院' }],
  213. },
  214. viewForm:{
  215. component: { placeholder: '' },
  216. }
  217. },
  218. sub_organization:{
  219. title: '专业',
  220. type: 'input',
  221. column: {
  222. show: true,
  223. minWidth: 120,
  224. },
  225. form: {
  226. component: { placeholder: '请填写专业' },
  227. rules: [{ required: false, message: '请填写专业' }],
  228. },
  229. viewForm:{
  230. component: { placeholder: '' },
  231. }
  232. },
  233. grade_or_level:{
  234. title: '年级',
  235. type: 'input',
  236. column: {
  237. show: false,
  238. minWidth: 120,
  239. },
  240. form: {
  241. show:false,
  242. component: { placeholder: '请填写年级' },
  243. rules: [{ required: false, message: '请填写年级' }],
  244. },
  245. viewForm:{
  246. component: { placeholder: '' },
  247. }
  248. },
  249. class_or_group:{
  250. title: '班级',
  251. type: 'input',
  252. column: {
  253. show: false,
  254. minWidth: 120,
  255. },
  256. form: {
  257. show: false,
  258. component: { placeholder: '请填写班级' },
  259. rules: [{ required: false, message: '请填写班级' }],
  260. },
  261. viewForm:{
  262. component: { placeholder: '' },
  263. }
  264. },
  265. },
  266. },
  267. };
  268. };