2026-04-24 15:31:32 +08:00
|
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
|
|
import { ref } from 'vue'; // 使用 ref 更简单直观
|
|
|
|
|
|
import { getBaseDropdown, getEngInfoDropdown, getFpssDropdown } from '@/api/select';
|
2026-04-27 09:28:16 +08:00
|
|
|
|
import { set } from 'lodash';
|
2026-04-24 15:31:32 +08:00
|
|
|
|
|
|
|
|
|
|
export const useShuJuTianBaoStore = defineStore('shuJuTianBao', () => {
|
|
|
|
|
|
// 1. 直接使用 ref 定义状态,确保响应式
|
2026-04-27 10:35:06 +08:00
|
|
|
|
const fpssOption = ref<any[]>([]);
|
|
|
|
|
|
const fpssLoading = ref(false);
|
2026-04-24 15:31:32 +08:00
|
|
|
|
const baseOption = ref<any[]>([]);
|
2026-04-27 10:35:06 +08:00
|
|
|
|
const baseLoading = ref(false);
|
2026-04-24 15:31:32 +08:00
|
|
|
|
const engOption = ref<any[]>([]);
|
2026-04-27 10:35:06 +08:00
|
|
|
|
const engLoading = ref(false);
|
2026-04-27 09:28:16 +08:00
|
|
|
|
const fishOption = ref([]);
|
2026-04-27 10:35:06 +08:00
|
|
|
|
// 获取水电基地列表
|
2026-04-24 15:31:32 +08:00
|
|
|
|
const getBaseOption = async () => {
|
|
|
|
|
|
try {
|
2026-04-27 10:35:06 +08:00
|
|
|
|
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];
|
|
|
|
|
|
list.unshift({
|
|
|
|
|
|
baseid: 'all',
|
|
|
|
|
|
basename: '当前全部'
|
|
|
|
|
|
});
|
|
|
|
|
|
// 直接赋值给 ref,触发响应式更新
|
|
|
|
|
|
baseOption.value = list;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('获取水电基地列表失败:', error);
|
2026-04-27 10:35:06 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
baseLoading.value = false;
|
2026-04-24 15:31:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2026-04-27 10:35:06 +08:00
|
|
|
|
// 获取电站列表
|
2026-04-24 15:31:32 +08:00
|
|
|
|
const getEngOption = async (baseId: string) => {
|
|
|
|
|
|
try {
|
2026-04-27 10:35:06 +08:00
|
|
|
|
engLoading.value = true;
|
2026-04-24 15:31:32 +08:00
|
|
|
|
const param = baseId === 'all' ? {} : { baseId };
|
|
|
|
|
|
const res = await getEngInfoDropdown(param);
|
|
|
|
|
|
if (res.data && Array.isArray(res.data)) {
|
|
|
|
|
|
// 直接赋值给 ref
|
|
|
|
|
|
engOption.value = res.data;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('获取电站列表失败:', error);
|
2026-04-27 10:35:06 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
engLoading.value = false;
|
2026-04-24 15:31:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2026-04-27 10:35:06 +08:00
|
|
|
|
// 获取过鱼设施列表
|
2026-04-24 15:31:32 +08:00
|
|
|
|
const getFpssOption = async (baseId: string, rstcd: string) => {
|
|
|
|
|
|
try {
|
2026-04-27 10:35:06 +08:00
|
|
|
|
fpssLoading.value = true;
|
2026-04-24 15:31:32 +08:00
|
|
|
|
const res = await getFpssDropdown({ baseId, rstcd });
|
|
|
|
|
|
fpssOption.value = res.data;
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.log(error);
|
2026-04-27 10:35:06 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
fpssLoading.value = false;
|
2026-04-24 15:31:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2026-04-27 09:28:16 +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,
|
|
|
|
|
|
baseOption,
|
|
|
|
|
|
engOption,
|
2026-04-27 09:28:16 +08:00
|
|
|
|
fishOption,
|
2026-04-27 10:35:06 +08:00
|
|
|
|
fpssLoading,
|
|
|
|
|
|
baseLoading,
|
|
|
|
|
|
engLoading,
|
2026-04-24 15:31:32 +08:00
|
|
|
|
getBaseOption,
|
|
|
|
|
|
getEngOption,
|
|
|
|
|
|
getFpssOption,
|
2026-04-27 09:28:16 +08:00
|
|
|
|
getFishOption,
|
|
|
|
|
|
setFishOption
|
2026-04-24 15:31:32 +08:00
|
|
|
|
};
|
|
|
|
|
|
});
|