diff --git a/src/views/composables/useFetchData.ts b/src/views/composables/useFetchData.ts index 088ef57..613f54f 100644 --- a/src/views/composables/useFetchData.ts +++ b/src/views/composables/useFetchData.ts @@ -1,65 +1,67 @@ - -import {getRequest} from "@/api/customFetch"; +import { getRequest } from "@/api/customFetch"; import { getBigScreenRanking, getGainUrl, getPaymentUrl, getSegmentStatic, getSixStatisticsUrl } from "@/api/fetchUrl"; -import { usePolling,addRequest } from "@/composables/usePolling"; +import { usePolling, addRequest } from "@/composables/usePolling"; +import { useRouter } from "vue-router"; export const useFetchAllData = () => { - const paymentData = ref({}) - const getPaymentData = () => { - getRequest(getPaymentUrl(),{},{}).then(resp => { - if(resp.code == 200){ - paymentData.value = JSON.parse(JSON.stringify(resp.result)) - } - }) - }; - addRequest('paymentData',getPaymentData) - provide("paymentData",paymentData) + const router = useRouter(); + const paymentData = ref({}); + const getPaymentData = () => { + getRequest(getPaymentUrl(), {}, {}).then((resp) => { + if (resp.code == 200) { + paymentData.value = JSON.parse(JSON.stringify(resp.result)); + } else if (resp.code == 401) { + router.push("/login"); + } + }); + }; + addRequest("paymentData", getPaymentData); + provide("paymentData", paymentData); - const gainData = ref({}) - const getGainData = () => { - getRequest(getGainUrl(),null,{}).then(resp => { - if(resp.code === 200){ - gainData.value = resp.result - } - }) - } - addRequest("getGainData",getGainData) - provide("gainData",gainData) - - const askSectionData = ref({}) - const getAskSectionData = () => { - getRequest(getSegmentStatic(), {}, {}).then((resp) => { - if (resp.code === 200) { - askSectionData.value = resp.result; - } - }); - }; - addRequest("getAskSectionData",getAskSectionData) - provide("askSectionData",askSectionData) + const gainData = ref({}); + const getGainData = () => { + getRequest(getGainUrl(), null, {}).then((resp) => { + if (resp.code === 200) { + gainData.value = resp.result; + } + }); + }; + addRequest("getGainData", getGainData); + provide("gainData", gainData); - const chargingRankingData = ref({}) - const getChargingRankingData = () => { - getRequest(getBigScreenRanking(),{},{}).then(resp => { - if(resp.code === 200){ - chargingRankingData.value = resp.result - } - }) - } - addRequest("getChargingRankingData",getChargingRankingData) - provide("chargingRankingData",chargingRankingData) + const askSectionData = ref({}); + const getAskSectionData = () => { + getRequest(getSegmentStatic(), {}, {}).then((resp) => { + if (resp.code === 200) { + askSectionData.value = resp.result; + } + }); + }; + addRequest("getAskSectionData", getAskSectionData); + provide("askSectionData", askSectionData); - const sixStatisticsData = ref({}) - const getSixStaticsData = () => { - getRequest(getSixStatisticsUrl(),{},{}).then(resp => { - if(resp.code === 200){ - sixStatisticsData.value = resp.result - } - }) - } + const chargingRankingData = ref({}); + const getChargingRankingData = () => { + getRequest(getBigScreenRanking(), {}, {}).then((resp) => { + if (resp.code === 200) { + chargingRankingData.value = resp.result; + } + }); + }; + addRequest("getChargingRankingData", getChargingRankingData); + provide("chargingRankingData", chargingRankingData); - addRequest('getSixStaticsData',getSixStaticsData) - provide('sixStatisticsData',sixStatisticsData) + const sixStatisticsData = ref({}); + const getSixStaticsData = () => { + getRequest(getSixStatisticsUrl(), {}, {}).then((resp) => { + if (resp.code === 200) { + sixStatisticsData.value = resp.result; + } + }); + }; + addRequest("getSixStaticsData", getSixStaticsData); + provide("sixStatisticsData", sixStatisticsData); - usePolling(); -} \ No newline at end of file + usePolling(); +}; diff --git a/src/views/home.vue b/src/views/home.vue index 804df0a..1d880e8 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -154,6 +154,8 @@ getRequest(getUserInfoUrl(),{},{headers:{ Authorization: `Bearer ${accessToken}`}}).then(resp => { if(resp.code === 200){ username.value = (resp.result as {account:string}).account + }else if(resp.code === 401){ + router.push("/login") } }) }