crud.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery } 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. toolbar:{
  28. show:false,
  29. },
  30. actionbar: {
  31. buttons: {
  32. add: {
  33. show: auth('user:Create')
  34. }
  35. }
  36. },
  37. rowHandle: {
  38. fixed:'right',
  39. width: 100,
  40. buttons: {
  41. view: {
  42. type: 'text',
  43. },
  44. edit: {
  45. show: false,
  46. },
  47. remove: {
  48. show: false,
  49. },
  50. },
  51. },
  52. columns: {
  53. _index: {
  54. title: '序号',
  55. form: { show: false },
  56. column: {
  57. align: 'center',
  58. width: '70px',
  59. columnSetDisabled: true,
  60. formatter: (context) => {
  61. let index = context.index ?? 1;
  62. let pagination = crudExpose!.crudBinding.value.pagination;
  63. return ((pagination!.currentPage ?? 1) - 1) * pagination!.pageSize + index + 1;
  64. },
  65. },
  66. },
  67. code: {
  68. title: '供应商编号',
  69. search: { show: true },
  70. type: 'text',
  71. column: { minWidth: 120},
  72. form: {
  73. show: false,
  74. }
  75. },
  76. name: {
  77. title: '供应商名称',
  78. search: { show: false },
  79. type: 'input',
  80. column: { minWidth: 120 },
  81. form: {
  82. component: { placeholder: '请输入供应商名称' },
  83. rules: [{ required: true, message: '请输入供应商名称' }]
  84. }
  85. },
  86. contact_person: {
  87. title: '联系人',
  88. search: { show: true },
  89. type: 'input',
  90. column: { minWidth: 100 },
  91. form: {
  92. component: { placeholder: '请选择联系人' },
  93. rules: [{ required: true, message: '请选择联系人' }],
  94. },
  95. },
  96. contact_phone: {
  97. title: '联系手机号',
  98. search: { show: true },
  99. type: 'input',
  100. column: { minWidth: 100 },
  101. form: {
  102. component: { placeholder: '请选择联系手机号' },
  103. rules: [{ required: true, message: '请选择联系手机号' }],
  104. },
  105. },
  106. contact_email: {
  107. title: '联系邮箱',
  108. search: { show: true },
  109. type: 'input',
  110. column: { minWidth: 100 },
  111. form: {
  112. component: { placeholder: '请输入联系邮箱' },
  113. rules: [{ required: true, message: '请输入联系邮箱' }],
  114. },
  115. },
  116. address: {
  117. title: '地址',
  118. search: { show: false },
  119. type: 'input',
  120. column: { minWidth: 100 },
  121. form: {
  122. component: { placeholder: '请输入地址' },
  123. rules: [{ required: false, message: '请输入地址' }],
  124. },
  125. },
  126. website: {
  127. title: '网址',
  128. search: { show: false },
  129. type: 'input',
  130. column: { minWidth: 100 },
  131. form: {
  132. component: { placeholder: '请输入网址' },
  133. rules: [{ required: false, message: '请输入网址' }],
  134. },
  135. },
  136. business_license: {
  137. title: '营业执照',
  138. search: { show: false },
  139. type: 'input',
  140. column: { minWidth: 100 },
  141. form: {
  142. component: { placeholder: '请输入营业执照' },
  143. rules: [{ required: false, message: '请输入营业执照' }],
  144. },
  145. },
  146. tax_number: {
  147. title: '税号',
  148. search: { show: false },
  149. type: 'input',
  150. column: { minWidth: 100 },
  151. form: {
  152. component: { placeholder: '请输入税号' },
  153. rules: [{ required: false, message: '请输入税号' }],
  154. },
  155. },
  156. bank_account: {
  157. title: '银行卡号',
  158. search: { show: false },
  159. type: 'input',
  160. column: { minWidth: 100 },
  161. form: {
  162. component: { placeholder: '请输入银行卡号' },
  163. rules: [{ required: false, message: '请输入银行卡号' }],
  164. },
  165. },
  166. credit_rating: {
  167. title: '信用评级',
  168. search: { show: false },
  169. type: 'input',
  170. column: { minWidth: 100 },
  171. form: {
  172. component: { placeholder: '请输入信用评级' },
  173. rules: [{ required: false, message: '请输入信用评级' }],
  174. },
  175. },
  176. cooperation_years: {
  177. title: '合作年份',
  178. search: { show: false },
  179. type: 'input',
  180. column: { minWidth: 100 },
  181. form: {
  182. component: { placeholder: '请输入合作年份' },
  183. rules: [{ required: false, message: '请输入合作年份' }],
  184. },
  185. },
  186. remark: {
  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. },
  196. tenant_id:{
  197. title: '租户id',
  198. type: 'dict-select',
  199. tenant_id:1,
  200. column: {
  201. show:false,
  202. minWidth: 120,
  203. },
  204. dict: dict({
  205. url: '/api/system/tenant/list/',
  206. value: 'id',
  207. label: 'name',
  208. }),
  209. form: {
  210. show:false,
  211. value: 1,
  212. component: { placeholder: '请填租户id' },
  213. rules: [{ required: false, message: '请填租户id' }],
  214. },
  215. },
  216. status: {
  217. title: '状态',
  218. type: 'dict-select',
  219. status:true,
  220. search: { show: false },
  221. dict: dict({
  222. data: [
  223. { label: '启用', value: true },
  224. { label: '禁用', value: false },
  225. ],
  226. }),
  227. column: { minWidth: 100 },
  228. form: {
  229. show:true,
  230. value:true,
  231. component: { placeholder: '请选择状态' },
  232. rules: [{ required: true, message: '请选择状态' }],
  233. },
  234. },
  235. ...commonCrudConfig({
  236. create_datetime: { search: false },
  237. update_datetime: { search: false },
  238. }),
  239. },
  240. },
  241. };
  242. };