137 lines
14 KiB
JavaScript
137 lines
14 KiB
JavaScript
|
"use strict";
|
||
|
const common_vendor = require("../../../../common/vendor.js");
|
||
|
const modules_mall_sheep_store_index = require("../store/index.js");
|
||
|
const modules_mall_sheep_hooks_useModal = require("../hooks/useModal.js");
|
||
|
const modules_mall_sheep_helper_throttle = require("../helper/throttle.js");
|
||
|
var define_ROUTES_MAP_default = { "/pages/index/index": { path: "/pages/index/index", aliasPath: "/" }, "/pages/index/404": { path: "/pages/index/404" }, "/modules/pet/address/index": { path: "/modules/pet/address/index" }, "/modules/pet/ai/ai-interactive-space": { path: "/modules/pet/ai/ai-interactive-space" }, "/modules/pet/certification/index": { path: "/modules/pet/certification/index" }, "/modules/pet/certification/pet-sitter": { path: "/modules/pet/certification/pet-sitter" }, "/modules/pet/extended/index": { path: "/modules/pet/extended/index" }, "/modules/pet/h5mall/index": { path: "/modules/pet/h5mall/index" }, "/modules/pet/login/index": { path: "/modules/pet/login/index" }, "/modules/pet/login/phone": { path: "/modules/pet/login/phone" }, "/modules/pet/map/index": { path: "/modules/pet/map/index" }, "/modules/pet/message/chat": { path: "/modules/pet/message/chat" }, "/modules/pet/message/index": { path: "/modules/pet/message/index" }, "/modules/pet/message/message-list": { path: "/modules/pet/message/message-list" }, "/modules/pet/message/privatechat": { path: "/modules/pet/message/privatechat" }, "/modules/pet/my/index": { path: "/modules/pet/my/index" }, "/modules/pet/order/index": { path: "/modules/pet/order/index" }, "/modules/pet/order/order-detail": { path: "/modules/pet/order/order-detail" }, "/modules/pet/order/take": { path: "/modules/pet/order/take" }, "/modules/pet/others/agreement": { path: "/modules/pet/others/agreement" }, "/modules/pet/others/null": { path: "/modules/pet/others/null" }, "/modules/pet/others/official-account": { path: "/modules/pet/others/official-account" }, "/modules/pet/permission/bind-phone": { path: "/modules/pet/permission/bind-phone" }, "/modules/pet/permission/real-name-auth": { path: "/modules/pet/permission/real-name-auth" }, "/modules/pet/pet/index": { path: "/modules/pet/pet/index" }, "/modules/pet/pet/pet-add-page": { path: "/modules/pet/pet/pet-add-page" }, "/modules/pet/pet/pet-detail-page": { path: "/modules/pet/pet/pet-detail-page" }, "/modules/pet/push/door": { path: "/modules/pet/push/door" }, "/modules/pet/push/goods": { path: "/modules/pet/push/goods" }, "/modules/pet/push/index": { path: "/modules/pet/push/index" }, "/modules/pet/push/share": { path: "/modules/pet/push/share" }, "/modules/pet/service/accompany": { path: "/modules/pet/service/accompany" }, "/modules/pet/service/detail": { path: "/modules/pet/service/detail" }, "/modules/pet/service/door": { path: "/modules/pet/service/door" }, "/modules/pet/service/index": { path: "/modules/pet/service/index" }, "/modules/pet/service/knowledge": { path: "/modules/pet/service/knowledge" }, "/modules/pet/service/my-service": { path: "/modules/pet/service/my-service" }, "/modules/pet/service/search": { path: "/modules/pet/service/search" }, "/modules/pet/service/shop": { path: "/modules/pet/service/shop" }, "/modules/pet/service/slippery": { path: "/modules/pet/service/slippery" }, "/modules/pet/service/store": { path: "/modules/pet/service/store" }, "/modules/pet/settings/index": { path: "/modules/pet/settings/index" }, "/modules/pet/space/index": { path: "/modules/pet/space/index" }, "/modules/pet/webview/webview": { path: "/modules/pet/webview/webview" }, "/modules/mall/index/index": { path: "/modules/mall/index/index", aliasPath: "/mall", meta: { auth: false, sync: true, title: "宠物商城", group: "商城" } }, "/modules/mall/index/user": { path: "/modules/mall/index/user", meta: { sync: true, title: "个人中心", group: "商城" } }, "/modules/mall/index/category": { path: "/modules/mall/index/category", meta: { sync: true, title: "商品分类", group: "商城" } }, "/modules/mall/index/cart": { path: "/modules/mall/index/cart", meta: { sync: true, title: "购物车", group: "商城" } }, "/modules/mall/index/login": { path: "/modules/mall/index/login" }, "/modules/mall/index/search": { path: "/modules/mall/index/search", meta: { sync: true, title: "搜索", group: "商城" } }, "/modules/mall/index/page": { path: "/modules/mall/index/page", meta: { auth: false, sync: true, title: "自定义页面",
|
||
|
var define_TABBAR_default = ["/pages/index/index", "/pages/index/404"];
|
||
|
const _go = (path, params = {}, options = {
|
||
|
redirect: false
|
||
|
}) => {
|
||
|
var _a;
|
||
|
let page = "";
|
||
|
let query = "";
|
||
|
let url = "";
|
||
|
if (common_vendor.isString(path)) {
|
||
|
if (common_vendor.startsWith(path, "http")) {
|
||
|
page = `/modules/mall/public/webview`;
|
||
|
query = `url=${encodeURIComponent(path)}`;
|
||
|
} else if (common_vendor.startsWith(path, "action:")) {
|
||
|
handleAction(path);
|
||
|
return;
|
||
|
} else {
|
||
|
[page, query] = path.split("?");
|
||
|
}
|
||
|
if (!common_vendor.isEmpty(params)) {
|
||
|
const query2 = paramsToQuery(params);
|
||
|
if (common_vendor.isEmpty(query)) {
|
||
|
query = query2;
|
||
|
} else {
|
||
|
query += "&" + query2;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (common_vendor.isObject(path)) {
|
||
|
page = path.url;
|
||
|
if (!common_vendor.isNil(path.params)) {
|
||
|
query = paramsToQuery(path.params);
|
||
|
}
|
||
|
}
|
||
|
const nextRoute = define_ROUTES_MAP_default[page];
|
||
|
if (!nextRoute) {
|
||
|
console.log(`%c跳转路径参数错误<${page || "EMPTY"}>`, "color:red;background:yellow");
|
||
|
return;
|
||
|
}
|
||
|
if (((_a = nextRoute.meta) == null ? void 0 : _a.auth) && !modules_mall_sheep_store_index.$store("user").isLogin) {
|
||
|
modules_mall_sheep_hooks_useModal.showAuthModal();
|
||
|
return;
|
||
|
}
|
||
|
url = page;
|
||
|
if (!common_vendor.isEmpty(query)) {
|
||
|
url += `?${query}`;
|
||
|
}
|
||
|
if (define_TABBAR_default.includes(page)) {
|
||
|
common_vendor.index.switchTab({
|
||
|
url
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
if (options.redirect) {
|
||
|
common_vendor.index.redirectTo({
|
||
|
url
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
common_vendor.index.navigateTo({
|
||
|
url
|
||
|
});
|
||
|
};
|
||
|
function go(...args) {
|
||
|
modules_mall_sheep_helper_throttle.throttle(() => {
|
||
|
_go(...args);
|
||
|
});
|
||
|
}
|
||
|
function paramsToQuery(params) {
|
||
|
if (common_vendor.isEmpty(params)) {
|
||
|
return "";
|
||
|
}
|
||
|
const query = [];
|
||
|
for (const key in params) {
|
||
|
query.push(key + "=" + params[key]);
|
||
|
}
|
||
|
return query.join("&");
|
||
|
}
|
||
|
function back() {
|
||
|
common_vendor.index.navigateBack();
|
||
|
}
|
||
|
function redirect(path, params = {}) {
|
||
|
go(path, params, {
|
||
|
redirect: true
|
||
|
});
|
||
|
}
|
||
|
function hasHistory() {
|
||
|
const pages = getCurrentPages();
|
||
|
if (pages.length > 1) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
function getCurrentRoute(field = "") {
|
||
|
const currentPage = getCurrentPage();
|
||
|
currentPage.$page.route = currentPage.route;
|
||
|
currentPage.$page.options = currentPage.options;
|
||
|
if (field !== "") {
|
||
|
return currentPage.$page[field];
|
||
|
} else {
|
||
|
return currentPage.$page;
|
||
|
}
|
||
|
}
|
||
|
function getCurrentPage() {
|
||
|
const pages = getCurrentPages();
|
||
|
return pages[pages.length - 1];
|
||
|
}
|
||
|
function handleAction(path) {
|
||
|
const action = path.split(":");
|
||
|
switch (action[1]) {
|
||
|
case "showShareModal":
|
||
|
modules_mall_sheep_hooks_useModal.showShareModal();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
function error(errCode, errMsg = "") {
|
||
|
redirect("/modules/mall/public/error", {
|
||
|
errCode,
|
||
|
errMsg
|
||
|
});
|
||
|
}
|
||
|
const $router = {
|
||
|
go,
|
||
|
back,
|
||
|
hasHistory,
|
||
|
redirect,
|
||
|
getCurrentPage,
|
||
|
getCurrentRoute,
|
||
|
error
|
||
|
};
|
||
|
exports.$router = $router;
|