form.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { last } from 'lodash';
  2. import { ref, computed } from 'vue';
  3. import { useRoute } from 'vue-router';
  4. import { getGoafSelectOption } from '../monitor.api';
  5. import { useMineStore } from '/@/store/modules/mine';
  6. import { findNodeAll, findPath } from '/@/utils/helper/treeHelper';
  7. export function useInitForm() {
  8. const config = {
  9. id: 'id',
  10. pid: 'parentId',
  11. children: 'childDepart',
  12. };
  13. const route = useRoute();
  14. const mineStroe = useMineStore();
  15. const mineCodes = ref<string[]>([]);
  16. const getMineTree = computed(() => {
  17. const id = last(route.fullPath.split('/'));
  18. return findNodeAll(mineStroe.mineTree, (item) => item.id === id, config);
  19. });
  20. const paths = findPath(getMineTree.value, (item) => item.isLeaf, config);
  21. mineCodes.value = paths.map((e) => e.id);
  22. // 采空区选择器
  23. const goafId = ref('');
  24. const goafOptions = ref<any[]>([]);
  25. function initGoafOptions() {
  26. getGoafSelectOption({ mineCode: last(mineCodes.value) }).then(({ options, defaultValue }) => {
  27. goafOptions.value = options;
  28. goafId.value = defaultValue;
  29. });
  30. }
  31. initGoafOptions();
  32. return {
  33. goafId,
  34. goafOptions,
  35. mineCodes,
  36. getMineTree,
  37. initGoafOptions,
  38. };
  39. }