crud.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery,compute } from '@fast-crud/fast-crud';
  2. import * as api from './api';
  3. import { auth } from '/@/utils/authFunction';
  4. import { commonCrudConfig } from '/@/utils/commonCrud';
  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. toolbar:{
  40. show:false,
  41. },
  42. actionbar: {
  43. buttons: {
  44. add: {
  45. show: auth('user:Create')
  46. }
  47. }
  48. },
  49. rowHandle: {
  50. fixed:'right',
  51. width: 230,
  52. buttons: {
  53. view: {
  54. show: true,
  55. },
  56. edit: {
  57. show: true,
  58. },
  59. remove: {
  60. show: true,
  61. },
  62. },
  63. },
  64. columns: {
  65. _index: {
  66. title: '序号',
  67. form: { show: false },
  68. column: {
  69. align: 'center',
  70. width: '70px',
  71. columnSetDisabled: true,
  72. formatter: (context) => {
  73. let index = context.index ?? 1;
  74. let pagination = crudExpose!.crudBinding.value.pagination;
  75. return ((pagination!.currentPage ?? 1) - 1) * pagination!.pageSize + index + 1;
  76. },
  77. },
  78. },
  79. code: {
  80. title: '供应商编号',
  81. search: { show: true },
  82. type: 'text',
  83. column: { minWidth: 120},
  84. form: {
  85. show: false,
  86. }
  87. },
  88. name: {
  89. title: '供应商名称',
  90. search: { show: false },
  91. type: 'input',
  92. column: { minWidth: 120 },
  93. form: {
  94. component: { placeholder: '请输入供应商名称' },
  95. rules: [{ required: true, message: '请输入供应商名称' }]
  96. },
  97. viewForm:{
  98. component: { placeholder: '' },
  99. rules: [{ required: true, message: '' }],
  100. }
  101. },
  102. contact_person: {
  103. title: '联系人',
  104. search: { show: true },
  105. type: 'input',
  106. column: { minWidth: 100 },
  107. form: {
  108. component: { placeholder: '请选择联系人' },
  109. rules: [{ required: true, message: '请选择联系人' }],
  110. },
  111. viewForm:{
  112. component: { placeholder: '' },
  113. rules: [{ required: true, message: '' }],
  114. }
  115. },
  116. contact_phone: {
  117. title: '联系手机号',
  118. search: { show: true },
  119. type: 'input',
  120. column: { minWidth: 100 },
  121. form: {
  122. component: { placeholder: '请选择联系手机号' },
  123. rules: [{ required: true, message: '请选择联系手机号' }],
  124. },
  125. viewForm:{
  126. component: { placeholder: '' },
  127. rules: [{ required: true, message: '' }],
  128. }
  129. },
  130. contact_email: {
  131. title: '联系邮箱',
  132. search: { show: true },
  133. type: 'input',
  134. column: { minWidth: 100 },
  135. form: {
  136. component: { placeholder: '请输入联系邮箱' },
  137. rules: [{ required: true, message: '请输入联系邮箱' }],
  138. },
  139. viewForm:{
  140. component: { placeholder: '' },
  141. rules: [{ required: true, message: '' }],
  142. }
  143. },
  144. address: {
  145. title: '地址',
  146. search: { show: false },
  147. type: 'input',
  148. column: { minWidth: 100 },
  149. form: {
  150. component: { placeholder: '请输入地址' },
  151. rules: [{ required: false, message: '请输入地址' }],
  152. },
  153. viewForm:{
  154. component: { placeholder: '' },
  155. rules: [{ required: true, message: '' }],
  156. }
  157. },
  158. website: {
  159. title: '网址',
  160. search: { show: false },
  161. type: 'input',
  162. column: { minWidth: 100 },
  163. form: {
  164. component: { placeholder: '请输入网址' },
  165. rules: [{ required: false, message: '请输入网址' }],
  166. },
  167. viewForm:{
  168. component: { placeholder: '' },
  169. rules: [{ required: true, message: '' }],
  170. }
  171. },
  172. business_license: {
  173. title: '营业执照',
  174. search: { show: false },
  175. type: 'input',
  176. column: { minWidth: 100 },
  177. form: {
  178. component: { placeholder: '请输入营业执照' },
  179. rules: [{ required: false, message: '请输入营业执照' }],
  180. },
  181. viewForm:{
  182. component: { placeholder: '' },
  183. rules: [{ required: true, message: '' }],
  184. }
  185. },
  186. tax_number: {
  187. title: '税号',
  188. search: { show: false },
  189. type: 'input',
  190. column: { minWidth: 100 },
  191. form: {
  192. component: { placeholder: '请输入税号' },
  193. rules: [{ required: false, message: '请输入税号' }],
  194. },
  195. viewForm:{
  196. component: { placeholder: '' },
  197. rules: [{ required: true, message: '' }],
  198. }
  199. },
  200. bank_account: {
  201. title: '银行卡号',
  202. search: { show: false },
  203. type: 'input',
  204. column: { minWidth: 100 },
  205. form: {
  206. component: { placeholder: '请输入银行卡号' },
  207. rules: [{ required: false, message: '请输入银行卡号' }],
  208. },
  209. viewForm:{
  210. component: { placeholder: '' },
  211. rules: [{ required: true, message: '' }],
  212. }
  213. },
  214. credit_rating: {
  215. title: '信用评级',
  216. search: { show: true },
  217. type: 'dict-select',
  218. column: { minWidth: 100 },
  219. dict: dict({
  220. data: [
  221. { label: 'A', value: 'A' },
  222. { label: 'B', value: 'B' },
  223. { label: 'C', value: 'C' },
  224. { label: 'D', value: 'D' },
  225. { label: 'E', value: 'E' },
  226. { label: 'F', value: 'F' },
  227. ],
  228. }),
  229. form: {
  230. component: { placeholder: '请输入信用评级' },
  231. rules: [{ required: false, message: '请输入信用评级' }],
  232. },
  233. viewForm:{
  234. component: { placeholder: '' },
  235. rules: [{ required: true, message: '' }],
  236. }
  237. },
  238. cooperation_years: {
  239. title: '合作年份',
  240. search: { show: false },
  241. type: 'input',
  242. column: { minWidth: 100 },
  243. form: {
  244. component: { placeholder: '请输入合作年份' },
  245. rules: [{ required: false, message: '请输入合作年份' }],
  246. },
  247. viewForm:{
  248. component: { placeholder: '' },
  249. rules: [{ required: true, message: '' }],
  250. }
  251. },
  252. remark: {
  253. title: '备注',
  254. search: { show: false },
  255. type: 'input',
  256. column: { minWidth: 100 },
  257. form: {
  258. component: { placeholder: '请输入备注' },
  259. rules: [{ required: false, message: '请输入备注' }],
  260. },
  261. viewForm:{
  262. component: { placeholder: '' },
  263. rules: [{ required: true, message: '' }],
  264. }
  265. },
  266. tenant_id:{
  267. title: '租户id',
  268. type: 'dict-select',
  269. tenant_id:1,
  270. column: {
  271. show:false,
  272. minWidth: 120,
  273. },
  274. dict: dict({
  275. url: '/api/system/tenant/list/',
  276. value: 'id',
  277. label: 'name',
  278. }),
  279. form: {
  280. show:false,
  281. value: 1,
  282. component: { placeholder: '请填租户id' },
  283. rules: [{ required: false, message: '请填租户id' }],
  284. },
  285. viewForm:{
  286. component: { placeholder: '' },
  287. rules: [{ required: true, message: '' }],
  288. }
  289. },
  290. status: {
  291. title: '状态',
  292. type: 'dict-select',
  293. status:true,
  294. search: { show: false },
  295. dict: dict({
  296. data: [
  297. { label: '启用', value: true },
  298. { label: '禁用', value: false },
  299. ],
  300. }),
  301. column: { minWidth: 100 },
  302. form: {
  303. show:true,
  304. value:true,
  305. component: { placeholder: '请选择状态' },
  306. rules: [{ required: true, message: '请选择状态' }],
  307. },
  308. viewForm:{
  309. component: { placeholder: '' },
  310. rules: [{ required: true, message: '' }],
  311. }
  312. },
  313. ...commonCrudConfig({
  314. create_datetime: { search: false },
  315. update_datetime: { search: false },
  316. }),
  317. },
  318. },
  319. };
  320. };