Files
Portal/router.js
T
2026-01-17 17:39:51 +08:00

59 lines
1.2 KiB
JavaScript

// router.js
import { RouterMount, createRouter } from "uni-simple-router";
import $store from "@/store";
const router = createRouter({
platform: process.env.VUE_APP_PLATFORM,
routes: [...ROUTES],
});
// 权限逻辑处理
const inlet = (to, from, next) => {
const { api_token = null } = $store.state.app.userInfo;
if (
to.name != "Login" &&
to.name != "Register" &&
to.name != "Download" &&
!api_token
) {
uni.reLaunch({
url: "/pages/login",
});
next();
} else {
next();
}
};
//全局路由前置守卫
router.beforeEach((to, from, next) => {
const apiUrl = $store.state.app.apiUrl;
if (!apiUrl) {
// 入口配置
uni.request({
url: "./static/config.json",
method: "GET",
timeout: 10000,
success: (res) => {
if (res.data.title) {
$store.commit("app/setConfig", res.data);
inlet(to, from, next);
} else {
console.warn("配置文件不存在");
}
},
fail: (err) => {
console.log(err);
},
});
} else {
inlet(to, from, next);
}
});
// 全局路由后置守卫
router.afterEach((to, from) => {
// console.log('跳转结束')
});
export { router, RouterMount };