chushih
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// 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 };
|
||||
Reference in New Issue
Block a user