form.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { last } from 'lodash';
  2. import { ref } from 'vue';
  3. import { useRoute } from 'vue-router';
  4. import { getGoafSelectOption } from '../monitor.api';
  5. import { useMineDepartmentStore } from '/@/store/modules/mine';
  6. import { historicalFormSchema, searchFormSchema } from '../monitor.data';
  7. import { FormSchema } from '/@/components/Form';
  8. export function useInitForm() {
  9. const mineStore = useMineDepartmentStore();
  10. const route = useRoute();
  11. const id = last(route.fullPath.split('/'));
  12. // 采空区选择器
  13. const goafId = ref('');
  14. const goafOptions = ref<any[]>([]);
  15. function initGoafOptions() {
  16. getGoafSelectOption({ mineCode: mineStore.getMineCode }).then(({ options, defaultValue }) => {
  17. goafOptions.value = options;
  18. goafId.value = defaultValue;
  19. });
  20. }
  21. initGoafOptions();
  22. const realtimeSchemas: FormSchema[] = [
  23. {
  24. field: 'mineCodeList',
  25. label: '煤矿名称',
  26. component: 'MineCascader',
  27. colProps: { span: 6 },
  28. componentProps: {
  29. resetOnDestroy: true,
  30. rootId: id,
  31. },
  32. },
  33. ...searchFormSchema,
  34. ];
  35. const historySchemas: FormSchema[] = [
  36. {
  37. field: 'mineCodeList',
  38. label: '煤矿名称',
  39. component: 'MineCascader',
  40. colProps: { span: 6 },
  41. required: true,
  42. componentProps: {
  43. resetOnDestroy: true,
  44. rootId: id,
  45. onChange() {
  46. initGoafOptions();
  47. },
  48. },
  49. },
  50. ...historicalFormSchema,
  51. ];
  52. return {
  53. historySchemas,
  54. realtimeSchemas,
  55. goafOptions,
  56. goafId,
  57. initGoafOptions,
  58. };
  59. }