OfficeApp/router/router.js
2023-08-26 14:07:17 +08:00

57 lines
1.6 KiB
JavaScript
Raw Permalink 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 { Toast } from "../libs/uniApi";
const functionList = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
const whiteList = ['/','/pages/oaHome/oaHome', '/pages/oaExamine/oaExamine', '/pages/oaTask/oaTask', '/pages/oaMy/oaMy',
'/pages/oaLogin/oaLogin', '/pages/business/business'
]
const hasPermission = (url) => {
try{
if (whiteList.indexOf(url) !== -1 || whiteList.indexOf(url.split('?')[0]) || uni.getStorageSync("TOKEN")) {
return true;
}
return false;
}catch(e){
console.log(e);
return false;
}
}
const initRouter = () => {
functionList.forEach(item => {
uni.addInterceptor(item, {
invoke(args) {
uni.getSystemInfo({
success: function(res) {
console.log('系统信息', res)
// 获取内存相关指标
var totalMem = res.totalMem // 总内存大小单位MB
var usedMem = res.usedMem // 已使用内存大小单位MB
var availableMem = res.availableMem // 可用内存大小单位MB
// 输出结果
console.log('总内存大小MB:', totalMem)
console.log('已使用内存大小MB:', usedMem)
console.log('可用内存大小MB:', availableMem)
}
})
if (!hasPermission(args.url)) {
Toast('登录后查看更多')
return false;
}
return true;
},
success(args) {
},
fail(err) {
console.log('拦截失败', err)
},
complete(res) {
}
})
})
}
export default initRouter;