138 lines
13 KiB
JavaScript
138 lines
13 KiB
JavaScript
|
"use strict";
|
||
|
const common_vendor = require("../../common/vendor.js");
|
||
|
const sheep_store_index = require("../store/index.js");
|
||
|
const sheep_hooks_useModal = require("../hooks/useModal.js");
|
||
|
const sheep_helper_throttle = require("../helper/throttle.js");
|
||
|
var define_ROUTES_MAP_default = { "/pages/index/index": { path: "/pages/index/index", aliasPath: "/" }, "/pages/address/index": { path: "/pages/address/index" }, "/pages/ai/ai-interactive-space": { path: "/pages/ai/ai-interactive-space" }, "/pages/certification/index": { path: "/pages/certification/index" }, "/pages/certification/pet-sitter": { path: "/pages/certification/pet-sitter" }, "/pages/extended/index": { path: "/pages/extended/index" }, "/pages/h5mall/index": { path: "/pages/h5mall/index" }, "/pages/login/index": { path: "/pages/login/index" }, "/pages/login/phone": { path: "/pages/login/phone" }, "/pages/map/index": { path: "/pages/map/index" }, "/pages/message/chat": { path: "/pages/message/chat" }, "/pages/message/index": { path: "/pages/message/index" }, "/pages/message/message-list": { path: "/pages/message/message-list" }, "/pages/message/privatechat": { path: "/pages/message/privatechat" }, "/pages/my/index": { path: "/pages/my/index" }, "/pages/order/index": { path: "/pages/order/index" }, "/pages/order/order-detail": { path: "/pages/order/order-detail" }, "/pages/order/take": { path: "/pages/order/take" }, "/pages/others/agreement": { path: "/pages/others/agreement" }, "/pages/others/null": { path: "/pages/others/null" }, "/pages/others/official-account": { path: "/pages/others/official-account" }, "/pages/permission/bind-phone": { path: "/pages/permission/bind-phone" }, "/pages/permission/real-name-auth": { path: "/pages/permission/real-name-auth" }, "/pages/pet/index": { path: "/pages/pet/index" }, "/pages/pet/pet-add-page": { path: "/pages/pet/pet-add-page" }, "/pages/pet/pet-detail-page": { path: "/pages/pet/pet-detail-page" }, "/pages/push/door": { path: "/pages/push/door" }, "/pages/push/goods": { path: "/pages/push/goods" }, "/pages/push/index": { path: "/pages/push/index" }, "/pages/push/share": { path: "/pages/push/share" }, "/pages/service/accompany": { path: "/pages/service/accompany" }, "/pages/service/detail": { path: "/pages/service/detail" }, "/pages/service/door": { path: "/pages/service/door" }, "/pages/service/index": { path: "/pages/service/index" }, "/pages/service/knowledge": { path: "/pages/service/knowledge" }, "/pages/service/my-service": { path: "/pages/service/my-service" }, "/pages/service/search": { path: "/pages/service/search" }, "/pages/service/shop": { path: "/pages/service/shop" }, "/pages/service/slippery": { path: "/pages/service/slippery" }, "/pages/service/store": { path: "/pages/service/store" }, "/pages/settings/index": { path: "/pages/settings/index" }, "/pages/space/index": { path: "/pages/space/index" }, "/pages/webview/webview": { path: "/pages/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: "自定义页面", group: "商城" } }, "/modules/mall/goods/index": { path: "/modules/mall/goods/index", meta: { sync: true, title: "普通商品", group: "商品" } }, "/modules/mall/goods/groupon": { path: "/modules/mall/goods/groupon", meta: { sync: true, title: "拼团商品", group: "商品" } }, "/modules/mall/goods/seckill": { path: "/modules/mall/goods/seckill", meta: { sync: true, title: "秒杀商品", group: "商品" } }, "/modules/mall/goods/list": { path: "/modules/mall/goods/list", meta: { sync: true, title: "商品列表", group: "商品" } }, "/modul
|
||
|
var define_TABBAR_default = ["/pages/index/index", "/pages/space/index", "/pages/push/index", "/pages/message/index", "/pages/my/index"];
|
||
|
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) && !sheep_store_index.$store("user").isLogin) {
|
||
|
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) {
|
||
|
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":
|
||
|
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;
|
||
|
//# sourceMappingURL=index.js.map
|