"use strict";const common_vendor=require("../../../../common/vendor.js");const uni_modules_uviewPlus_libs_function_index=require("../function/index.js");class Router{constructor(){this.config={type:"navigateTo",url:"",delta:1,params:{},animationType:"pop-in",animationDuration:300,intercept:false};this.route=this.route.bind(this)}addRootPath(url){return url[0]==="/"?url:`/${url}`}mixinParam(url,params){url=url&&this.addRootPath(url);let query="";if(/.*\/.*\?.*=.*/.test(url)){query=uni_modules_uviewPlus_libs_function_index.queryParams(params,false);return url+=`&${query}`}query=uni_modules_uviewPlus_libs_function_index.queryParams(params);return url+=query}async route(options={},params={}){let mergeConfig={};if(typeof options==="string"){mergeConfig.url=this.mixinParam(options,params);mergeConfig.type="navigateTo"}else{mergeConfig=uni_modules_uviewPlus_libs_function_index.deepMerge(this.config,options);mergeConfig.url=this.mixinParam(options.url,options.params)}if(mergeConfig.url===uni_modules_uviewPlus_libs_function_index.page())return;if(params.intercept){this.config.intercept=params.intercept}mergeConfig.params=params;mergeConfig=uni_modules_uviewPlus_libs_function_index.deepMerge(this.config,mergeConfig);if(typeof common_vendor.index.$u.routeIntercept==="function"){const isNext=await new Promise(((resolve,reject)=>{common_vendor.index.$u.routeIntercept(mergeConfig,resolve)}));isNext&&this.openPage(mergeConfig)}else{this.openPage(mergeConfig)}}openPage(config){const{url:url,type:type,delta:delta,animationType:animationType,animationDuration:animationDuration}=config;if(config.type=="navigateTo"||config.type=="to"){common_vendor.index.navigateTo({url:url,animationType:animationType,animationDuration:animationDuration})}if(config.type=="redirectTo"||config.type=="redirect"){common_vendor.index.redirectTo({url:url})}if(config.type=="switchTab"||config.type=="tab"){common_vendor.index.switchTab({url:url})}if(config.type=="reLaunch"||config.type=="launch"){common_vendor.index.reLaunch({url:url})}if(config.type=="navigateBack"||config.type=="back"){common_vendor.index.navigateBack({delta:delta})}}}const route=(new Router).route;exports.route=route;
