/**
 * uniapp 页面跳转通用函数（将参数自动转换）
 * @author terrfly
 * @site https://www.jeequan.com
 * @date 2021/12/17 18:49
 */
let result = {
	
	convertCondition: (params) =>{
		
		if(!params){
			return '';
		}
		
		let result = '';
		Object.keys(params).forEach(function(key){
			result += key + '=' + encodeURIComponent(params[key]) + '&'
		});
		
		return result.substring(0, result.length - 1)
	},
	
	// 跳转页面
	to: (page, params) => {
		
		uni.navigateTo({
			url: params ? page + '?' + result.convertCondition(params) : page
		})
	},
	
	// 关闭当前页面并跳转页面
	redirectTo: (page, params) => {
		
		uni.redirectTo({
			url: params ? page + '?' + result.convertCondition(params) : page
		})
	},
	
}



export default result
