import { last } from 'lodash'; import { ref } from 'vue'; import { useRoute } from 'vue-router'; import { getGoafSelectOption } from '../monitor.api'; import { useMineDepartmentStore } from '/@/store/modules/mine'; import { historicalFormSchema, searchFormSchema } from '../monitor.data'; import { FormSchema } from '/@/components/Form'; export function useInitForm() { const mineStore = useMineDepartmentStore(); const route = useRoute(); const id = last(route.fullPath.split('/')); // 采空区选择器 const goafId = ref(''); const goafOptions = ref([]); function initGoafOptions() { getGoafSelectOption({ mineCode: mineStore.getMineCode }).then(({ options, defaultValue }) => { goafOptions.value = options; goafId.value = defaultValue; }); } initGoafOptions(); const realtimeSchemas: FormSchema[] = [ { field: 'mineCodeList', label: '煤矿名称', component: 'MineCascader', colProps: { span: 6 }, componentProps: { resetOnDestroy: true, rootId: id, }, }, ...searchFormSchema, ]; const historySchemas: FormSchema[] = [ { field: 'mineCodeList', label: '煤矿名称', component: 'MineCascader', colProps: { span: 6 }, required: true, componentProps: { resetOnDestroy: true, rootId: id, onChange() { initGoafOptions(); }, }, }, ...historicalFormSchema, ]; return { historySchemas, realtimeSchemas, goafOptions, goafId, initGoafOptions, }; }