import { ref } from 'vue'; import { defineStore } from 'pinia'; import missionApi from '@/api/missionApi'; import { useFetchData } from '@/composables/fetchData'; // 走航任务 export const useMissionStore = defineStore('mission', () => { const missionList = ref([]); const { loading, fetchData } = useFetchData(); function fetchMission(type) { return fetchData((page, pageSize) => { return missionApi .fethchMission({ type: type, page, pageSize }) .then((res) => { missionList.value = res.data; return res; }); }); } function deleteMission(missionCode) { return fetchData(() => { return missionApi.deleteMission(missionCode).then((res) => { let index = -1; for (let i = 0; i < missionList.value.length; i++) { const e = missionList.value[i]; if (e.missionCode == missionCode) { index = i; break; } } if (index != -1) { missionList.value.splice(index, 1); } return res; }); }); } return { missionList, loading, fetchMission, deleteMission }; });