123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- "use strict";
- var common_vendor = require("../../../../common/vendor.js");
- var 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,
- type,
- delta,
- animationType,
- animationDuration
- } = config;
- if (config.type == "navigateTo" || config.type == "to") {
- common_vendor.index.navigateTo({
- url,
- animationType,
- animationDuration
- });
- }
- if (config.type == "redirectTo" || config.type == "redirect") {
- common_vendor.index.redirectTo({
- url
- });
- }
- if (config.type == "switchTab" || config.type == "tab") {
- common_vendor.index.switchTab({
- url
- });
- }
- if (config.type == "reLaunch" || config.type == "launch") {
- common_vendor.index.reLaunch({
- url
- });
- }
- if (config.type == "navigateBack" || config.type == "back") {
- common_vendor.index.navigateBack({
- delta
- });
- }
- }
- }
- var route = new Router().route;
- exports.route = route;
|