data.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
  2. import type { VbenFormSchema } from '#/adapter/form';
  3. import type { OnActionClickFn } from '#/adapter/vxe-table';
  4. import type { SystemModel } from '#/api/method/system';
  5. import { listOrganizationsMethodAll } from '#/api/method/system';
  6. import { $t } from '#/locales';
  7. export function useUserSearchFormSchema(): VbenFormSchema[] {
  8. return [
  9. {
  10. component: 'Input',
  11. fieldName: 'name',
  12. label: $t('system.organization.name'),
  13. },
  14. ];
  15. }
  16. export function useUserTableColumns<T = SystemModel.Organization>(
  17. onActionClick?: OnActionClickFn<T>,
  18. ): VxeTableGridOptions<T>['columns'] {
  19. return [
  20. { type: 'seq', title: $t('table.column.seq'), width: 50 },
  21. {
  22. field: 'name',
  23. title: $t('system.organization.name'),
  24. minWidth: 100,
  25. },
  26. {
  27. field: 'code',
  28. title: $t('system.organization.code'),
  29. minWidth: 100,
  30. },
  31. {
  32. field: 'parentinstitutionSelsourceName',
  33. title: $t('system.organization.superior'),
  34. minWidth: 100,
  35. },
  36. {
  37. field: 'createTime',
  38. title: $t('system.organization.createTime'),
  39. minWidth: 100,
  40. },
  41. {
  42. field: 'createUser',
  43. title: $t('system.organization.createUser'),
  44. minWidth: 100,
  45. },
  46. {
  47. align: 'center',
  48. cellRender: {
  49. attrs: {
  50. nameField: 'name',
  51. nameTitle: $t('system.user._'),
  52. onClick: onActionClick,
  53. },
  54. name: 'CellOperation',
  55. },
  56. field: 'operation',
  57. fixed: 'right',
  58. title: $t('table.column.operation'),
  59. width: 130,
  60. },
  61. ];
  62. }
  63. export function useUserFormSchema(
  64. current?: Pick<SystemModel.Organization, 'id' | 'name'>,
  65. ): VbenFormSchema[] {
  66. return [
  67. {
  68. component: 'Input',
  69. fieldName: 'name',
  70. label: $t('system.organization.name'),
  71. rules: 'required',
  72. },
  73. {
  74. component: 'Input',
  75. componentProps: {
  76. placeholder: $t('system.organization.input'),
  77. },
  78. fieldName: 'code',
  79. label: $t('system.organization.code'),
  80. rules: 'required',
  81. },
  82. {
  83. component: 'ApiSelect',
  84. componentProps: {
  85. allowClear: true,
  86. api: listOrganizationsMethodAll,
  87. class: 'w-full',
  88. labelField: 'name',
  89. valueField: 'pid',
  90. childrenField: 'children',
  91. afterFetch: (res: SystemModel.Organization[]) => {
  92. if (!current) return res;
  93. return Array.isArray(res)
  94. ? res.filter(
  95. (item) => item.pid !== current.id && item.name !== current.name,
  96. )
  97. : res;
  98. },
  99. },
  100. fieldName: 'parentInstitutionId',
  101. label: $t('system.organization.superior'),
  102. // rules: 'selectRequired',
  103. },
  104. ];
  105. }