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 { usePolling,addRequest } from "@/composables/usePolling";
import { usePolling, addRequest } from "@/composables/usePolling";
import { useRouter } from "vue-router";
export const useFetchAllData = () => {
const paymentData = ref<any>({})
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<any>({});
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<any>({})
const getGainData = () => {
getRequest(getGainUrl(),null,{}).then(resp => {
if(resp.code === 200){
gainData.value = resp.result
}
})
}
addRequest("getGainData",getGainData)
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 gainData = ref<any>({});
const getGainData = () => {
getRequest(getGainUrl(), null, {}).then((resp) => {
if (resp.code === 200) {
gainData.value = resp.result;
}
});
};
addRequest("getGainData", getGainData);
provide("gainData", gainData);
const chargingRankingData = ref<any>({})
const getChargingRankingData = () => {
getRequest(getBigScreenRanking(),{},{}).then(resp => {
if(resp.code === 200){
chargingRankingData.value = resp.result
}
})
}
addRequest("getChargingRankingData",getChargingRankingData)
provide("chargingRankingData",chargingRankingData)
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 sixStatisticsData = ref<any>({})
const getSixStaticsData = () => {
getRequest(getSixStatisticsUrl(),{},{}).then(resp => {
if(resp.code === 200){
sixStatisticsData.value = resp.result
}
})
}
const chargingRankingData = ref<any>({});
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<any>({});
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 => {
if(resp.code === 200){
username.value = (resp.result as {account:string}).account
}else if(resp.code === 401){
router.push("/login")
}
})
}