WholeProcessPlatform/frontend/src/store/modules/shuJuTianBao.ts

116 lines
3.1 KiB
TypeScript
Raw Normal View History

2026-04-24 15:31:32 +08:00
import { defineStore } from 'pinia';
import { ref } from 'vue'; // 使用 ref 更简单直观
import {
getBaseDropdown,
getSelectForDropdown,
getEngInfoDropdown,
getFpssDropdown
} from '@/api/select';
2026-04-24 15:31:32 +08:00
export const useShuJuTianBaoStore = defineStore('shuJuTianBao', () => {
// 水电基地下拉列表
const baseLoading = ref(false);
const baseOption = ref<any[]>([]);
// 流域下拉列表
const lyLoading = ref(false);
const lyOption = ref<any[]>([]);
// 电站下拉列表
2026-04-24 15:31:32 +08:00
const engOption = ref<any[]>([]);
const engLoading = ref(false);
// 流域下拉列表
const fpssOption = ref<any[]>([]);
const fpssLoading = ref(false);
// 鱼类名称下拉列表
const fishOption = ref([]);
// 获取水电基地列表
2026-04-24 15:31:32 +08:00
const getBaseOption = async () => {
try {
baseLoading.value = true;
2026-04-24 15:31:32 +08:00
const res = await getBaseDropdown({});
if (res.data && Array.isArray(res.data)) {
const list = [...res.data];
// 直接赋值给 ref触发响应式更新
baseOption.value = list;
}
} catch (error) {
console.error('获取水电基地列表失败:', error);
} finally {
baseLoading.value = false;
2026-04-24 15:31:32 +08:00
}
};
// 获取流域列表
const getSelectForOption = async () => {
try {
lyLoading.value = true;
const res = await getSelectForDropdown({});
if (res.data && Array.isArray(res.data)) {
const list = [
{ rvcd: 'all', rvnm: '当前全部', baseid: '01' },
...res.data
];
// 直接赋值给 ref触发响应式更新
lyOption.value = list;
}
} catch (error) {
console.error('获取流域列表失败:', error);
} finally {
lyLoading.value = false;
}
};
// 获取电站列表
const getEngOption = async (rvcd: string) => {
2026-04-24 15:31:32 +08:00
try {
engLoading.value = true;
const param = rvcd === 'all' ? {} : { reachcd: rvcd };
2026-04-24 15:31:32 +08:00
const res = await getEngInfoDropdown(param);
if (res.data && Array.isArray(res.data)) {
// 直接赋值给 ref
engOption.value = res.data;
getFpssOption(rvcd, '');
2026-04-24 15:31:32 +08:00
}
} catch (error) {
console.error('获取电站列表失败:', error);
} finally {
engLoading.value = false;
2026-04-24 15:31:32 +08:00
}
};
// 获取过鱼设施列表
const getFpssOption = async (rvcd: string, rstcd: string) => {
2026-04-24 15:31:32 +08:00
try {
fpssLoading.value = true;
const param = rvcd === 'all' ? {} : { rvcd };
const res = await getFpssDropdown({ ...param, rstcd: rstcd });
2026-04-24 15:31:32 +08:00
fpssOption.value = res.data;
} catch (error) {
console.log(error);
} finally {
// fpssLoading.value = false;
2026-04-24 15:31:32 +08:00
}
};
const getFishOption = () => {
return fishOption.value;
};
const setFishOption = (data: any[]) => {
fishOption.value = data;
};
2026-04-24 15:31:32 +08:00
// 3. 直接返回 ref 和方法
// 在组件中使用时store.baseOption 会自动解包为数组
return {
fpssOption,
lyOption,
2026-04-24 15:31:32 +08:00
baseOption,
engOption,
fishOption,
fpssLoading,
baseLoading,
lyLoading,
engLoading,
2026-04-24 15:31:32 +08:00
getBaseOption,
getSelectForOption,
2026-04-24 15:31:32 +08:00
getEngOption,
getFpssOption,
getFishOption,
setFishOption
2026-04-24 15:31:32 +08:00
};
});