import tools from '@/common/tools.js'

let token
//页面黑名单
const blackList = [
	
]
//未登录黑名单 
const tokenList = [
]
//回调处理
function isNext(back,login) {
	console.log(back,login)
	if (!back) {//如果是黑名单中的路径
		tools.showtt('该功能暂未开放')
	}
	
	if (!login) {//如果是登录名单中的路径,并且没登陆
		uni.showModal({
			content: "请先授权登录再进行此操作",
			title: "未登录",
			success(res) {
				if (res.confirm) {
					tools.goNext('/pages/login/login')
				}
			}
		})
	}
}
//拦截器
// e.url == pagesOne/order/orderlist
uni.addInterceptor('navigateTo', {
	invoke(e) {
		console.log(e)
		token = uni.getStorageSync('token')
		//黑名单判断
		let back = blackList.every(val => val !== e.url)
		//登录名单判断
		let login = tokenList.every(val => e.url.indexOf(val) == -1 || token)
		//白名单
		// let back = !blackList.every(val => val !== e.url)
		//拦截回调
		isNext(back,login)
		return login && back
	},
	success(e) {
		console.log(e,'拦截器成功回调')
	},
	fail(e) {
		console.log(e,'拦截器失败回调')
	}
})
