import pageUrl from './pageUrl'
import BASE_URL from './config.js';

function navTo(obj) {
	let token = '';
	if(process.env.UNI_PLATFORM =="h5"){
		if(window.location.href.indexOf('//casedata.igandan.com')>-1){
			token = uni.getStorageSync('AUTH_TOKEN_App');
		}else{
			token = uni.getStorageSync('DEV_AUTH_TOKEN_App');
		}
	}else if(process.env.UNI_PLATFORM == "mp-weixin") {
		const { envVersion } = uni.getAccountInfoSync().miniProgram;
		if (envVersion == "release") {
		  token = uni.getStorageSync('AUTH_TOKEN_App');
		}else{
		  token = uni.getStorageSync('DEV_AUTH_TOKEN_App');
		}
	}else{
		token = uni.getStorageSync('AUTH_TOKEN_App');
	}
	if (!token) {
		// let page_url = pageUrl();
		// uni.setStorageSync('redirectUrl', page_url);
		uni.navigateTo({
			url: '/pages_app/login/login'
		});
	} else {
		if(process.env.UNI_PLATFORM =="h5"){
				uni.navigateTo(obj)
		}else if(process.env.UNI_PLATFORM =="mp-weixin"){
			const pages = getCurrentPages();
			let len = pages.length;
			console.log(len)
			if (len >=10) {
				uni.redirectTo(obj)
			} else {
				uni.navigateTo(obj)
				
			}
		}else{
			uni.navigateTo(obj)
		}
	}
	

}

export default navTo