useVxeGrid.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { reactive } from 'vue'
  2. import { VxeGridProps } from 'vxe-table'
  3. export const useVxeGrid = (allSchemas, getPageApi) => {
  4. const gridOptions = reactive<VxeGridProps>({
  5. loading: false,
  6. height: 800,
  7. rowConfig: {
  8. keyField: 'id',
  9. isHover: true
  10. },
  11. toolbarConfig: {
  12. custom: true,
  13. slots: { buttons: 'toolbar_buttons' }
  14. },
  15. printConfig: {
  16. columns: allSchemas.printSchema
  17. },
  18. formConfig: {
  19. titleWidth: 100,
  20. titleAlign: 'right',
  21. items: allSchemas.searchSchema
  22. },
  23. columns: allSchemas.tableSchema,
  24. pagerConfig: {
  25. border: false,
  26. background: false,
  27. perfect: true,
  28. pageSize: 10,
  29. pagerCount: 7,
  30. pageSizes: [5, 10, 15, 20, 50, 100, 200, 500],
  31. layouts: [
  32. 'PrevJump',
  33. 'PrevPage',
  34. 'Jump',
  35. 'PageCount',
  36. 'NextPage',
  37. 'NextJump',
  38. 'Sizes',
  39. 'Total'
  40. ]
  41. },
  42. proxyConfig: {
  43. seq: true, // 启用动态序号代理(分页之后索引自动计算为当前页的起始序号)
  44. form: true, // 启用表单代理,当点击表单提交按钮时会自动触发 reload 行为
  45. props: { result: 'list', total: 'total' },
  46. ajax: {
  47. query: ({ page, form }) => {
  48. const queryParams = Object.assign({}, form)
  49. queryParams.pageSize = page.pageSize
  50. queryParams.pageNo = page.currentPage
  51. return new Promise(async (resolve) => {
  52. resolve(await getPageApi(queryParams))
  53. })
  54. }
  55. }
  56. }
  57. })
  58. return gridOptions
  59. }