fix: 增加接口401处理

master
xjs 2025-06-03 10:07:33 +08:00
parent 3a2899295e
commit 28952fc52f
2 changed files with 60 additions and 56 deletions

View File

@ -1,65 +1,67 @@
import { getRequest } from "@/api/customFetch";
import {getRequest} from "@/api/customFetch";
import { getBigScreenRanking, getGainUrl, getPaymentUrl, getSegmentStatic, getSixStatisticsUrl } from "@/api/fetchUrl"; 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 = () => { export const useFetchAllData = () => {
const paymentData = ref<any>({}) const router = useRouter();
const getPaymentData = () => { const paymentData = ref<any>({});
getRequest(getPaymentUrl(),{},{}).then(resp => { const getPaymentData = () => {
if(resp.code == 200){ getRequest(getPaymentUrl(), {}, {}).then((resp) => {
paymentData.value = JSON.parse(JSON.stringify(resp.result)) 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) });
};
addRequest("paymentData", getPaymentData);
provide("paymentData", paymentData);
const gainData = ref<any>({}) const gainData = ref<any>({});
const getGainData = () => { const getGainData = () => {
getRequest(getGainUrl(),null,{}).then(resp => { getRequest(getGainUrl(), null, {}).then((resp) => {
if(resp.code === 200){ if (resp.code === 200) {
gainData.value = resp.result gainData.value = resp.result;
} }
}) });
} };
addRequest("getGainData",getGainData) addRequest("getGainData", getGainData);
provide("gainData",gainData) provide("gainData", gainData);
const askSectionData = ref<any>({})
const getAskSectionData = () => {
getRequest(getSegmentStatic(), {}, {}).then((resp) => {
if (resp.code === 200) {
askSectionData.value = resp.result;
}
});
};
addRequest("getAskSectionData",getAskSectionData)
provide("askSectionData",askSectionData)
const chargingRankingData = ref<any>({}) const askSectionData = ref<any>({});
const getChargingRankingData = () => { const getAskSectionData = () => {
getRequest(getBigScreenRanking(),{},{}).then(resp => { getRequest(getSegmentStatic(), {}, {}).then((resp) => {
if(resp.code === 200){ if (resp.code === 200) {
chargingRankingData.value = resp.result askSectionData.value = resp.result;
} }
}) });
} };
addRequest("getChargingRankingData",getChargingRankingData) addRequest("getAskSectionData", getAskSectionData);
provide("chargingRankingData",chargingRankingData) provide("askSectionData", askSectionData);
const sixStatisticsData = ref<any>({}) const chargingRankingData = ref<any>({});
const getSixStaticsData = () => { const getChargingRankingData = () => {
getRequest(getSixStatisticsUrl(),{},{}).then(resp => { getRequest(getBigScreenRanking(), {}, {}).then((resp) => {
if(resp.code === 200){ if (resp.code === 200) {
sixStatisticsData.value = resp.result chargingRankingData.value = resp.result;
} }
}) });
} };
addRequest("getChargingRankingData", getChargingRankingData);
provide("chargingRankingData", chargingRankingData);
addRequest('getSixStaticsData',getSixStaticsData) const sixStatisticsData = ref<any>({});
provide('sixStatisticsData',sixStatisticsData) const getSixStaticsData = () => {
getRequest(getSixStatisticsUrl(), {}, {}).then((resp) => {
if (resp.code === 200) {
sixStatisticsData.value = resp.result;
}
});
};
addRequest("getSixStaticsData", getSixStaticsData);
provide("sixStatisticsData", sixStatisticsData);
usePolling(); usePolling();
} };

View File

@ -154,6 +154,8 @@
getRequest(getUserInfoUrl(),{},{headers:{ Authorization: `Bearer ${accessToken}`}}).then(resp => { getRequest(getUserInfoUrl(),{},{headers:{ Authorization: `Bearer ${accessToken}`}}).then(resp => {
if(resp.code === 200){ if(resp.code === 200){
username.value = (resp.result as {account:string}).account username.value = (resp.result as {account:string}).account
}else if(resp.code === 401){
router.push("/login")
} }
}) })
} }