index.js
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"use strict";
const common_vendor = require("../../common/vendor.js");
const store_index = require("../../store/index.js");
const ty_helper_throttle = require("../helper/throttle.js");
const _go = (path, params = {}, options = {
redirect: false
}) => {
var _a;
let page = "";
let query = "";
let url = "";
if (common_vendor.lodashExports.isString(path)) {
if (common_vendor.lodashExports.startsWith(path, "http")) {
page = `/pages/public/webview`;
query = `url=${encodeURIComponent(path)}`;
} else {
[page, query] = path.split("?");
}
if (!common_vendor.lodashExports.isEmpty(params)) {
let query2 = paramsToQuery(params);
if (common_vendor.lodashExports.isEmpty(query)) {
query = query2;
} else {
query += "&" + query2;
}
}
}
if (common_vendor.lodashExports.isObject(path)) {
page = path.url;
if (!common_vendor.lodashExports.isNil(path.params)) {
query = paramsToQuery(path.params);
}
}
const nextRoute = { "/pages/index/index": { "path": "/pages/index/index", "aliasPath": "/", "meta": { "auth": false, "sync": true, "title": "首页", "group": "模板" } }, "/pages/me/index": { "path": "/pages/me/index", "meta": { "auth": true, "sync": true, "title": "我的", "group": "模板" } }, "/pages/myOrder/myOrder": { "path": "/pages/myOrder/myOrder" }, "/pages/activity/activity": { "path": "/pages/activity/activity", "meta": { "auth": false, "sync": true, "title": "举办活动" } }, "/pages/me/apply/apply": { "path": "/pages/me/apply/apply" }, "/pages/orderDetail/orderDetail": { "path": "/pages/orderDetail/orderDetail" }, "/pages/achievement/achievement": { "path": "/pages/achievement/achievement" }, "/pages/achievement/searchachievement": { "path": "/pages/achievement/searchachievement" }, "/pages/map/map": { "path": "/pages/map/map" }, "/pages/myGift/myGift": { "path": "/pages/myGift/myGift" }, "/pages/useCoupon/useCoupon": { "path": "/pages/useCoupon/useCoupon" }, "/pages/me/envelope/envelope": { "path": "/pages/me/envelope/envelope" }, "/pages/me/order/order": { "path": "/pages/me/order/order" }, "/pages/me/order/orderdetail": { "path": "/pages/me/order/orderdetail" }, "/pages/verification/verification": { "path": "/pages/verification/verification" }, "/pages/verification/allverification": { "path": "/pages/verification/allverification" }, "/pages/me/user/user": { "path": "/pages/me/user/user" }, "/pages/login/login": { "path": "/pages/login/login", "aliasPath": "/" } }[page];
if (!nextRoute) {
console.log(`%c跳转路径参数错误<${page || "EMPTY"}>`, "color:red;background:yellow");
return;
}
if (((_a = nextRoute.meta) == null ? void 0 : _a.auth) && !store_index.$store("user").isLogin) {
common_vendor.index.navigateTo({
url: "/pages/login/login"
});
return;
}
url = page;
if (!common_vendor.lodashExports.isEmpty(query)) {
url += `?${query}`;
}
if (["/pages/index/index", "/pages/myOrder/myOrder", "/pages/me/index"].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) {
ty_helper_throttle.throttle(() => {
_go(...args);
});
}
function paramsToQuery(params) {
if (common_vendor.lodashExports.isEmpty(params)) {
return "";
}
let query = [];
for (let 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 = "") {
let currentPage = getCurrentPage();
currentPage.$page["route"] = currentPage.route;
currentPage.$page["options"] = currentPage.options;
if (field !== "") {
return currentPage.$page[field];
} else {
return currentPage.$page;
}
}
function getCurrentPage() {
let pages = getCurrentPages();
return pages[pages.length - 1];
}
function getCur() {
let a = getCurrentPages();
let pages = common_vendor.lodashExports.clone(a);
return pages;
}
function error(errCode, errMsg = "") {
redirect("/pages/public/error", {
errCode,
errMsg
});
}
const $router = {
go,
back,
hasHistory,
redirect,
getCurrentPage,
getCurrentRoute,
getCur,
error
};
exports.$router = $router;