crud.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. import { AddReq, CreateCrudOptionsProps, dict,CreateCrudOptionsRet, UserPageQuery } from '@fast-crud/fast-crud';
  2. import * as api from './api';
  3. import { auth } from '/@/utils/authFunction';
  4. import dayjs from 'dayjs';
  5. export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  6. const pageRequest = async (query: UserPageQuery) => {
  7. return await api.GetList(query);
  8. };
  9. const editRequest = async ({ form, row }: EditReq) => {
  10. form.id = row.id;
  11. return await api.UpdateObj(form);
  12. };
  13. const delRequest = async ({ row }: DelReq) => {
  14. return await api.DelObj(row.id);
  15. };
  16. const addRequest = async ({ form }: AddReq) => {
  17. return await api.AddObj(form);
  18. };
  19. return {
  20. crudOptions: {
  21. request: {
  22. pageRequest,
  23. addRequest,
  24. editRequest,
  25. delRequest,
  26. },
  27. form:{
  28. wrapper: {
  29. buttons: {
  30. ok:{
  31. text:'提交'
  32. }
  33. }
  34. }
  35. },
  36. actionbar: {
  37. buttons: {
  38. add: {
  39. show: auth('area:Create'),
  40. },
  41. },
  42. },
  43. toolbar:{
  44. show:false,
  45. },
  46. rowHandle:{
  47. fixed: 'right',
  48. width: 220,
  49. buttons:{
  50. view:{
  51. show:true
  52. },
  53. remove:{
  54. show:true,
  55. },
  56. edit:{
  57. show:true,
  58. }
  59. }
  60. },
  61. pagination: {
  62. show: true,
  63. },
  64. columns: {
  65. _index: {
  66. title: '序号',
  67. form: { show: false },
  68. column: {
  69. type: 'index',
  70. align: 'center',
  71. width: '70px',
  72. columnSetDisabled: true, //禁止在列设置中选择
  73. },
  74. },
  75. plan_code: {
  76. title: '计划编码',
  77. search: {
  78. show: false,
  79. },
  80. treeNode: true,
  81. type: 'input',
  82. column: {
  83. minWidth: 120,
  84. },
  85. form: {
  86. show:false,
  87. rules: [
  88. // 表单校验规则
  89. { required: true, message: '名称必填项' },
  90. ],
  91. component: {
  92. placeholder: '请输入名称',
  93. },
  94. },
  95. viewForm:{
  96. component: { placeholder: '' },
  97. rules: [{ required: true, message: '' }],
  98. }
  99. },
  100. plan_name: {
  101. title: '计划名称',
  102. search: {
  103. show: true,
  104. },
  105. treeNode: true,
  106. type: 'input',
  107. column: {
  108. minWidth: 120,
  109. },
  110. form: {
  111. rules: [
  112. // 表单校验规则
  113. { required: true, message: '名称必填项' },
  114. ],
  115. component: {
  116. placeholder: '请输入计划名称',
  117. },
  118. },
  119. viewForm:{
  120. component: { placeholder: '' },
  121. rules: [{ required: true, message: '' }],
  122. }
  123. },
  124. description:{
  125. title: '计划描述',
  126. type: 'input',
  127. column: {
  128. show:true,
  129. minWidth: 120,
  130. },
  131. form: {
  132. component: { placeholder: '请填写计划描述' },
  133. rules: [{ required: false, message: '请填写计划描述' }],
  134. },
  135. viewForm:{
  136. component: { placeholder: '' },
  137. rules: [{ required: true, message: '' }],
  138. }
  139. },
  140. device:{
  141. title: '设备id',
  142. type: 'dict-select',
  143. column: {
  144. minWidth: 120,
  145. },
  146. dict: dict({
  147. url: '/api/system/device/',
  148. value: 'id',
  149. label: 'name',
  150. }),
  151. form: {
  152. show:true,
  153. component: { placeholder: '请选择设备id' },
  154. rules: [{ required: true, message: '请选择设备id' }],
  155. },
  156. viewForm:{
  157. component: { placeholder: '' },
  158. rules: [{ required: true, message: '' }],
  159. }
  160. },
  161. device_name:{
  162. title: '设备名称',
  163. type: 'input',
  164. column: {
  165. minWidth: 120,
  166. },
  167. form: {
  168. show:false,
  169. component: { placeholder: '请填写标签描述' },
  170. rules: [{ required: false, message: '请填写标签描述' }],
  171. },
  172. viewForm:{
  173. component: { placeholder: '' },
  174. rules: [{ required: true, message: '' }],
  175. }
  176. },
  177. device_code:{
  178. title: '设备编码',
  179. type: 'input',
  180. column: {
  181. minWidth: 120,
  182. },
  183. form: {
  184. show:false,
  185. component: { placeholder: '请填写设备编码' },
  186. rules: [{ required: false, message: '请填写设备编码' }],
  187. },
  188. viewForm:{
  189. component: { placeholder: '' },
  190. rules: [{ required: true, message: '' }],
  191. }
  192. },
  193. cycle_type:{
  194. title: '维护类型',
  195. type: 'dict-select',
  196. column: {
  197. show:false,
  198. minWidth: 120,
  199. },
  200. dict: dict({
  201. data: [
  202. { label: '每月', value: 2 },
  203. { label: '每季度', value: 3 },
  204. { label: '每年', value: 5 },
  205. ],
  206. }),
  207. form: {
  208. show:true,
  209. component: { placeholder: '请选择维护类型' },
  210. rules: [{ required: true, message: '请选择维护类型' }],
  211. },
  212. viewForm:{
  213. component: { placeholder: '' },
  214. rules: [{ required: true, message: '' }],
  215. }
  216. },
  217. cycle_type_display:{
  218. title: '维护类型',
  219. type: 'input',
  220. column: {
  221. minWidth: 120,
  222. },
  223. form: {
  224. show:false,
  225. component: { placeholder: '请填写排序' },
  226. rules: [{ required: false, message: '请填写排序' }],
  227. },
  228. viewForm:{
  229. component: { placeholder: '' },
  230. rules: [{ required: true, message: '' }],
  231. }
  232. },
  233. maintenance_content:{
  234. title: '维护内容',
  235. type: 'input',
  236. column: {
  237. minWidth: 120,
  238. },
  239. form: {
  240. show:true,
  241. component: { placeholder: '请填写维护内容' },
  242. rules: [{ required: true, message: '请填写维护内容' }],
  243. },
  244. viewForm:{
  245. component: { placeholder: '' },
  246. rules: [{ required: true, message: '' }],
  247. }
  248. },
  249. maintenance_person:{
  250. title: '维护人',
  251. type: 'input',
  252. column: {
  253. minWidth: 120,
  254. },
  255. form: {
  256. show:true,
  257. component: { placeholder: '请填写维护人' },
  258. rules: [{ required: true, message: '请填写维护人' }],
  259. },
  260. viewForm:{
  261. component: { placeholder: '' },
  262. rules: [{ required: true, message: '' }],
  263. }
  264. },
  265. start_date:{
  266. title: '维护开始时间',
  267. type: 'date',
  268. column: {
  269. minWidth: 120,
  270. // formatter: ({ value }) => (value ? dayjs(value).format('YYYY-MM-DD') : ''),
  271. },
  272. form: {
  273. show:true,
  274. component: { placeholder: '请填写维护开始时间' },
  275. rules: [{ required: true, message: '请填写维护开始时间' }],
  276. },
  277. viewForm:{
  278. component: { placeholder: '' },
  279. rules: [{ required: true, message: '' }],
  280. },
  281. valueResolve({ form, value }) {
  282. form.start_date = value ? dayjs(value).format('YYYY-MM-DD') : null;
  283. },
  284. valueBuilder({ form, value }) {
  285. form.start_date = value ;
  286. },
  287. },
  288. next_maintenance_date:{
  289. title: '下次维护开始时间',
  290. type: 'date',
  291. column: {
  292. minWidth: 120,
  293. formatter: ({ value }) => (value ? dayjs(value).format('YYYY-MM-DD') : ''),
  294. },
  295. form: {
  296. show:false,
  297. component: { placeholder: '请填写维护开始时间' },
  298. rules: [{ required: false, message: '请填写维护开始时间' }],
  299. },
  300. viewForm:{
  301. component: { placeholder: '' },
  302. rules: [{ required: true, message: '' }],
  303. },
  304. valueResolve({ form, value }) {
  305. form.purchase_date = value ? dayjs(value).format('YYYY-MM-DD') : null;
  306. },
  307. valueBuilder({ form, value }) {
  308. form.purchase_date = value;
  309. },
  310. },
  311. status_display:{
  312. title: '维护状态',
  313. type: 'input',
  314. column: {
  315. minWidth: 120,
  316. },
  317. form: {
  318. show:false,
  319. component: { placeholder: '请填写维护状态' },
  320. rules: [{ required: false, message: '请填写维护状态' }],
  321. },
  322. viewForm:{
  323. component: { placeholder: '' },
  324. rules: [{ required: true, message: '' }],
  325. }
  326. },
  327. },
  328. },
  329. };
  330. };