crud.tsx 7.8 KB

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