// 需要登录的界面
let needLogin = [
	"/pages/my/mySetting"
];
// 拦截类型
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];

const install = (Vue,vm) => {
	list.forEach(item => {
		uni.addInterceptor(item, {
			invoke(e) {
				const token = vm.$store.state.vuex_token;
				console.log(token)
				const url = e.url.split('?')[0];
				if (needLogin.includes(url) && !token) {
					console.log(url)
					uni.showToast({
						title: '该页面需要登录才能访问，请先登录',
						icon: 'none'
					});
					uni.navigateTo({
						url: "/pages/my/wxLogin?nextUrl="+e.url
					});
					return false;
				}
				return true;
			}
		});
	});
}

export default {
	install
}