crud.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. import { CrudOptions, AddReq, DelReq, EditReq, dict, CrudExpose, compute } from '@fast-crud/fast-crud'
  2. import * as api from './api'
  3. import { dictionary } from '/@/utils/dictionary'
  4. import { columnPermission } from '../../../utils/columnPermission'
  5. import { successMessage } from '../../../utils/message'
  6. interface CreateCrudOptionsTypes {
  7. output: any
  8. crudOptions: CrudOptions
  9. }
  10. //此处为crudOptions配置
  11. export const createCrudOptions = function ({
  12. crudExpose,
  13. rolePermission,
  14. handleDrawerOpen,
  15. hasPermissions,
  16. }: {
  17. crudExpose: CrudExpose
  18. rolePermission: any
  19. handleDrawerOpen: Function
  20. hasPermissions: Function
  21. }): CreateCrudOptionsTypes {
  22. const pageRequest = async (query: any) => {
  23. return await api.GetList(query)
  24. }
  25. const editRequest = async ({ form, row }: EditReq) => {
  26. form.id = row.id
  27. return await api.UpdateObj(form)
  28. }
  29. const delRequest = async ({ row }: DelReq) => {
  30. return await api.DelObj(row.id)
  31. }
  32. const addRequest = async ({ form }: AddReq) => {
  33. return await api.AddObj(form)
  34. }
  35. //权限判定
  36. // @ts-ignore
  37. // @ts-ignore
  38. return {
  39. crudOptions: {
  40. request: {
  41. pageRequest,
  42. addRequest,
  43. editRequest,
  44. delRequest,
  45. },
  46. rowHandle: {
  47. //固定右侧
  48. fixed: 'right',
  49. width: 320,
  50. buttons: {
  51. view: {
  52. show: true,
  53. },
  54. edit: {
  55. show: hasPermissions('role:Update'),
  56. },
  57. remove: {
  58. show: hasPermissions('role:Delete'),
  59. },
  60. /* custom: {
  61. type: 'primary',
  62. text: '权限配置',
  63. show: hasPermissions('role:Update'),
  64. tooltip: {
  65. placement: 'top',
  66. content: '权限配置',
  67. },
  68. click: (context: any): void => {
  69. const { row } = context;
  70. // eslint-disable-next-line no-mixed-spaces-and-tabs
  71. rolePermission.value.drawer = true;
  72. rolePermission.value.editedRoleInfo = row;
  73. rolePermission.value.initGet();
  74. },
  75. }, */
  76. customNew: {
  77. type: 'primary',
  78. text: '权限配置',
  79. show: hasPermissions('role:Update'),
  80. tooltip: {
  81. placement: 'top',
  82. content: '权限配置',
  83. },
  84. click: (context: any): void => {
  85. const { row } = context
  86. handleDrawerOpen(row)
  87. },
  88. },
  89. },
  90. },
  91. form: {
  92. col: { span: 24 },
  93. labelWidth: '100px',
  94. wrapper: {
  95. is: 'el-dialog',
  96. width: '600px',
  97. },
  98. },
  99. columns: {
  100. _index: {
  101. title: '序号',
  102. form: { show: false },
  103. column: {
  104. type: 'index',
  105. align: 'center',
  106. width: '70px',
  107. columnSetDisabled: true, //禁止在列设置中选择
  108. },
  109. },
  110. id: {
  111. title: 'ID',
  112. type: 'text',
  113. column: { show: false },
  114. search: { show: false },
  115. form: { show: false },
  116. },
  117. name: {
  118. title: '角色名称',
  119. type: 'text',
  120. search: { show: true },
  121. column: {
  122. minWidth: 120,
  123. sortable: 'custom',
  124. show: columnPermission('name', 'is_query'),
  125. },
  126. // addForm: {
  127. // show: columnPermission('name', 'is_create'),
  128. // },
  129. // editForm: {
  130. // show: columnPermission('name', 'is_update'),
  131. // },
  132. // TODO: addForm 和 editForm 会合并到form中 但是columnPermission得到的永远都是false
  133. form: {
  134. show: true,
  135. rules: [{ required: true, message: '角色名称必填' }],
  136. component: {
  137. placeholder: '请输入角色名称',
  138. },
  139. },
  140. },
  141. key: {
  142. title: '权限标识',
  143. type: 'text',
  144. search: { show: false },
  145. column: {
  146. minWidth: 120,
  147. sortable: 'custom',
  148. show: columnPermission('key', 'is_query'),
  149. columnSetDisabled: true,
  150. },
  151. // addForm: {
  152. // show: columnPermission('key', 'is_create'),
  153. // },
  154. // editForm: {
  155. // show: columnPermission('key', 'is_update'),
  156. // },
  157. form: {
  158. show: true,
  159. rules: [{ required: true, message: '权限标识必填' }],
  160. component: {
  161. placeholder: '输入权限标识',
  162. },
  163. },
  164. },
  165. sort: {
  166. title: '排序',
  167. search: { show: false },
  168. type: 'number',
  169. column: {
  170. minWidth: 90,
  171. sortable: 'custom',
  172. show: columnPermission('sort', 'is_query'),
  173. },
  174. // addForm: {
  175. // show: columnPermission('sort', 'is_create'),
  176. // },
  177. // editForm: {
  178. // show: columnPermission('sort', 'is_update'),
  179. // },
  180. form: {
  181. show: true,
  182. rules: [{ required: true, message: '排序必填' }],
  183. value: 1,
  184. },
  185. },
  186. admin: {
  187. title: '是否管理员',
  188. search: { show: false },
  189. type: 'dict-radio',
  190. dict: dict({
  191. data: [
  192. {
  193. label: '是',
  194. value: true,
  195. color: 'success',
  196. },
  197. {
  198. label: '否',
  199. value: false,
  200. color: 'danger',
  201. },
  202. ],
  203. }),
  204. column: {
  205. minWidth: 130,
  206. sortable: 'custom',
  207. show: columnPermission('admin', 'is_query'),
  208. },
  209. addForm: {
  210. show: columnPermission('admin', 'is_create'),
  211. },
  212. editForm: {
  213. show: columnPermission('admin', 'is_update'),
  214. },
  215. form: {
  216. rules: [{ required: true, message: '是否管理员必填' }],
  217. value: false,
  218. },
  219. },
  220. status: {
  221. title: '状态',
  222. search: { show: true },
  223. type: 'dict-radio',
  224. column: {
  225. width: 100,
  226. component: {
  227. name: 'fs-dict-switch',
  228. activeText: '',
  229. inactiveText: '',
  230. style: '--el-switch-on-color: var(--el-color-primary); --el-switch-off-color: #dcdfe6',
  231. onChange: compute((context) => {
  232. return () => {
  233. api.UpdateObj(context.row).then((res: APIResponseData) => {
  234. successMessage(res.msg as string)
  235. })
  236. }
  237. }),
  238. },
  239. show: columnPermission('status', 'is_query'),
  240. },
  241. // addForm: {
  242. // show: columnPermission('status', 'is_create'),
  243. // },
  244. // editForm: {
  245. // show: columnPermission('status', 'is_update'),
  246. // },
  247. form: {
  248. show: true,
  249. // component: {
  250. // placeholder: '输入关键词搜索',
  251. // },
  252. },
  253. dict: dict({
  254. data: dictionary('button_status_bool'),
  255. }),
  256. },
  257. update_datetime: {
  258. title: '更新时间',
  259. type: 'text',
  260. search: { show: false },
  261. column: {
  262. minWidth: 170,
  263. sortable: 'custom',
  264. show: columnPermission('update_datetime', 'is_query'),
  265. },
  266. form: {
  267. show: false,
  268. component: {
  269. placeholder: '输入关键词搜索',
  270. },
  271. },
  272. },
  273. create_datetime: {
  274. title: '创建时间',
  275. type: 'text',
  276. search: { show: false },
  277. column: {
  278. sortable: 'custom',
  279. minWidth: 170,
  280. show: columnPermission('create_datetime', 'is_query'),
  281. },
  282. form: {
  283. show: false,
  284. component: {
  285. placeholder: '输入关键词搜索',
  286. },
  287. },
  288. },
  289. // description: {
  290. // title: '备注',
  291. // type: 'textarea',
  292. // search: {show: false},
  293. // form: {
  294. // component: {
  295. // maxlength: 200,
  296. // placeholder: '输入备注',
  297. // },
  298. // },
  299. // },
  300. },
  301. },
  302. }
  303. }