This commit is contained in:
steven
2022-12-19 15:05:20 +08:00
parent f240a6e78c
commit f97dc21d0f

View File

@@ -429,11 +429,12 @@ const router = createRouter({
history: createWebHashHistory(), history: createWebHashHistory(),
routes: constantRoutes routes: constantRoutes
}) })
router.beforeEach((to, from, next) => { router.beforeEach(async (to, from, next) => {
// token // token
if (!router.options.history.state.back) { if (!router.options.history.state.back) {
getToken(); await getToken();
} }
console.log(2);
if (!to.meta.noRedirectLogin) { if (!to.meta.noRedirectLogin) {
if (window.self === window.top) { if (window.self === window.top) {
// window.parent.location.href = 'https://yip-uat.dctest.digitalyili.com/login'; // window.parent.location.href = 'https://yip-uat.dctest.digitalyili.com/login';
@@ -452,20 +453,19 @@ router.beforeEach((to, from, next) => {
next() next()
}) })
const getToken = () => { const getToken = async () => {
jsonp(jsonpUrl, { try {
appId: "yip", const res = await jsonp(jsonpUrl, {
remoteIp: window.returnCitySN?window.returnCitySN["cip"]:"127.0.0.1", appId: "yip",
callbackQuery: "jsonpCallback", remoteIp: window.returnCitySN?window.returnCitySN["cip"]:"127.0.0.1",
}) callbackQuery: "jsonpCallback",
.then((res) => {
localStorage.setItem("plantToken", res.data.tokenid);
store.commit("common/M_COMMON_SET_TOKEN", res.data.tokenid);
console.log("成功");
}) })
.catch(() => { localStorage.setItem("plantToken", res.data.tokenid);
console.log("错误"); store.commit("common/M_COMMON_SET_TOKEN", res.data.tokenid);
}); console.log("成功");
} catch (error) {
console.log("错误");
}
}; };
export default router export default router