urlRoute.js
4.75 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import jumpToMiniapp from '../router/jump-to-miniapp';
import queryString from '../vendors/query-string';
const GO_LIST = 'go.list';
const GO_PRODUCTPOOL = 'go.poollist';
const GO_SHOP = 'go.shop';
const GO_BRAND = 'go.brand';
const GO_CATEGORY = 'go.category';
const GO_DETAIL = 'go.productDetail';
const GO_COUPON = 'go.coupon';
const GO_MINE = 'go.mine';
const GO_NEW = 'go.new';
const GO_SHOPCART = 'go.shopcart';
const GO_H5 = 'go.h5';
const GO_ACTIVITY = 'go.activitytemplate';
const GO_MINIAPP = 'go.miniapp';
const GO_ZEROSELL = 'go.zerosell';
const GO_COLLAGEHOME = 'go.collagehome';//拼团购首页
const GO_LIMITPURCHASE = 'go.limitpurchase';//限定首页
const GO_MYREDPAC = "go.mineredpackage";//我的红包页面
const MINI_APP_DOMAIN = 'miniapp.yohobuy.com';
const router = global.router;
function jumpByUrl(jumpUrl,pageName){
if (!jumpUrl) {
return;
}
// 跳小程序
if (jumpUrl.indexOf(MINI_APP_DOMAIN)>=0) {
router.goUrl(jumpUrl);
return;
}
let url = "";
let startIndex = jumpUrl.indexOf('openby:yohobuy=');
if (startIndex < 0) {
return;
}
let jsonRule = jumpUrl.substring(startIndex+'openby:yohobuy='.length);
let json = JSON.parse(jsonRule);
let action = json.action;
let path = '';
if (GO_LIST === action) {
let actionType = json.params.actiontype || 1;
if (1 == actionType) {
path = "../goodsList/goodsList";
} else if (2 == actionType) {
path = "../goodsList/activtyDetail";
}
} else if (GO_BRAND === action) {
path = "../goodsList/brand";
} else if (GO_PRODUCTPOOL === action) {
path = "../goodsList/productPool";
} else if (GO_SHOP === action) {
path = "../goodsList/brandStore";
} else if (GO_DETAIL === action) {
let actionType = '';
if (json.params && json.params.activity_type){
actionType = json.params.activity_type;
}
if (actionType && actionType == 'groupPurchase'){
path = "/pages/groupPurchase/groupPurchaseDetail"
}else{
path = "../goodsDetail/goodsDetail";
}
} else if (GO_COUPON === action) {
path = "../page/subPackage/pages/couponList/couponList";
}else if (GO_NEW === action) {
path = "../goodsList/newArrival";
} else if (GO_ZEROSELL == action) {
path = "/page/subPackage/pages/zeroSell/index";
} else if (GO_SHOPCART === action) {
wx.switchTab({
url: "/pages/shopCart/shopCart"
})
return;
}else if (GO_CATEGORY === action) {
wx.switchTab({
url: "/pages/classify/category"
})
return;
}else if (GO_MINE === action) {
wx.switchTab({
url: "/pages/userCenter/userCenter"
})
return;
} else if (GO_H5 === action) {
path = "/pages/webview/webview";
//处理go.h5 url参数
if (json.params && json.params.param) {
if (json.params.url) {
let urltemp = json.params.url;
let urlparams = queryString.stringify(json.params.param, { encode: false });
if (urltemp.indexOf('?') > -1) {
urltemp = urltemp + "&" + encodeURIComponent(urlparams);
} else {
urltemp = urltemp + "?" + encodeURIComponent(urlparams);
}
json.params.url = encodeURIComponent(urltemp);
}
}
} else if (GO_ACTIVITY === action) {
let actionType;
if (json.params && json.params.type){
actionType = json.params.type;
}
if (actionType == 2) {
path = "../groupPurchase/groupPurchase";
} else if (actionType == 3) {
path = "../assist/assist";
}
}else if (GO_MINIAPP === action){
//跳转到小程序必须有appid和path
if(!json.params||!json.params.appId||!json.params.path ||json.params.appId.length===0 ||json.params.path.length===0){return}
let app_id = json.params.appId;
let target_path = json.params.path;
//如果appid的值为miniapp则表示要跳转到当前小程序中给定的path界面
if (app_id && 'miniapp' == app_id && target_path){
if (target_path.indexOf(0) != '/'){
target_path = '/' + target_path;
}
wx.navigateTo({
url: target_path,
})
return;
}
let navigateToMiniParams = {
appId: json.params.appId,
path: json.params.path
};
wx.navigateToMiniProgram(navigateToMiniParams);
return
} else if (GO_COLLAGEHOME == action){
return jumpToMiniapp({app: 'groupBuy', page: 'home'});
} else if (GO_LIMITPURCHASE == action) {
return jumpToMiniapp({ app: 'yohobuyLimitChannel', page: 'limitProductList' });
}
else if (GO_MYREDPAC == action){
path = "/page/subPackage/pages/allowance/allowance"
}
let params = queryString.stringify(json.params, { encode: false });
url = path + "?page_name=" + pageName + "&" + params;
if (!path) {
return;
}
if (url) {
wx.navigateTo({
url: url,
})
}
}
export {
jumpByUrl,
}