Files
ebiz-h5/src/assets/js/utils/permission.js
2023-09-06 21:32:56 +08:00

44 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//权限控制
import router from '@/router'
import CacheUtils from '@/assets/js/utils/cacheUtils'
// import NProgress from 'nprogress' // Progress 进度条
// import 'nprogress/nprogress.css' // Progress 进度条样式
export function permission() {
router.beforeEach((to, from, next) => {
//修改title
const title = to.meta && to.meta.title
if (title) {
document.title = title
}
if(from.path == '/sale/signatureConfirmation' && to.path == '/sale/attachmentManagement'){
window.location.href = window.location.origin + '#' + from.path + '?orderNo=' + from.query.orderNo
}
//判断是否登录
let token = CacheUtils.getLocItem('token')
if (!token) {
CacheUtils.setLocItem('token','')
//无token判断是否需要登录
if (to.meta.auth) {
if (window.WebViewJavascriptBridge) {
//eslint-disable-next-line
EWebBridge.webCallAppInJs('bridge', { flag: 'login' })
} else {
next(`/login?redirect=${to.path}`)
}
} else {
next()
}
} else {
if (to.path == '/login') {
next({ path: '/' })
} else {
next()
}
}
})
// 结束Progress
router.afterEach(() => {
// NProgress.done()
})
}