export function getActionPage() {
	let pages = getCurrentPages();
	return pages[pages.length - 1]
}
//登录拦截
export function interceptor() {
	let pages = getActionPage();
	// 获取当前页面
	let pageUrl = '/' + pages.route;
	let url = '/pages/public/login'
	// #ifdef H5
	// 判断是否为公众号调用微信授权登录
	let weichatBrowser = uni.getStorageSync('weichatBrowser');
	if (weichatBrowser) {
		url = '/pages/public/wxLogin';
	}
	// #endif
	
	// #ifdef MP-WEIXIN
	url = '/pages/public/wxLogin';
	// #endif
	
	// #ifdef APP-PLUS
	url = '/pages/public/login';
	// #endif
	if (pageUrl != url) {
		uni.navigateTo({
			url
		})
	}
}

// 保存页面
export function saveUrl() {
	console.log(111)
	// 获取当前页面
	let page = getActionPage();
	// 获取跳转前路由地址
	let path = '/' + page.route;
	// 判断是否在商品页
	if (path == '/pages/product/product') {
		if (page.spread) {
			if (page.type) {
				path = path + '?id=' + page.id +'&type='+page.goodsType+'&spread='+page.spread;
			}else{
				path = path + '?id=' + page.id+'&spread='+page.spread;
			}
		}else{
			if (page.type) {
				path = path + '?id=' + page.id +'&type=' + page.goodsType;
			}else{
				path = path + '?id=' + page.options.id;
			}
		}
	}
	//订单支付页面
	if (path == '/pages/order/createOrder') {
		// 判断是否为参团订单
		if (page.option.type == "pink") {
			const data = page.option;
			path = path + '?pinkid=' + data.pinkid + '&type=pink' + '&pid=' + data.pid + '&gid=' + data.gid;
		}
	}
	//邀请好友拼团页面
	if (path == '/pages/product/details') {
		if (page.spread) {
			path = path + '?pink_id=' + page.gp_id + '&spread=' + page.spread +'&teamid='+page.teamid;
		}else{
			path = path + '?pink_id=' + page.gp_id +'&teamid='+ page.teamid;
		}
	}
	//我的订单页面
	if (path == '/pages/order/order') {
		if (page.state) {
			path = path + '?state='+page.state;
		}
	}
	//我的订单页面
	if (path == '/pages/index/index') {
		if (page.bingding) {
			path = path + '?bingding='+page.bingding;
		}
			console.log(path)
	}
	//文章详情页面
	if (path == '/pages/moments/details') {
		if (page.spread) {
			path = path +'?id=' + page.id + '&spread='+ page.spread;
		}else{
			path = path +'?id=' + page.id;
		}
	}
	// 判断是否在登录页
	// 保存当前过去页面
	uni.setStorageSync('present', path);
}
