crud.tsx 5.8 KB

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