123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /********数据请求同时继承了文件上传(包括七牛云上传)************/
- import upload from "./upload/upload.js";
- export default upload;
- //路由拦截
- import store from '@/store';
- const whiteList = [
- "/pages/login/login",
- "/pages/register/register",
- ];
- //白名单 不需要登录的页面路径组成的数组
- function hasPermission(url) {
- // 在白名单中或有token,直接跳转
- if (whiteList.indexOf(url) !== -1 || store.state.token) {
- return true;
- }
- return false;
- }
- uni.addInterceptor("navigateTo", {
- // 页面跳转前进行拦截, invoke根据返回值进行判断是否继续执行跳转
- invoke(e) {
- if (!hasPermission(e.url)) {
- uni.reLaunch({
- url: "/pages/login/login",
- });
- return false;
- }
- return true;
- },
- success(e) {},
- });
- uni.addInterceptor("switchTab", {
- // tabbar页面跳转前进行拦截
- invoke(e) {
- if (!hasPermission(e.url)) {
- uni.reLaunch({
- url: "/pages/login/login",
- });
- return false;
- }
- return true;
- },
- success(e) {},
- });
- // #ifdef H5
- const needLoginList = [
- "/pages/index/index",
- ]
- let token = uni.getStorageSync("token")
- let locationUrl = window.location.href.split("#")[1]
- if (needLoginList.includes(locationUrl) && !token) {
- window.location.href = "/";
- } else {
- }
- // #endif
|