intercept-click.js
6.59 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/**
* 拦截跳转, 在这里给将要打开的页面设置一下 header 样式
* @return {[type]}
*/
const yoho = require('yoho');
const parse = require('yoho-qs/parse'); // 提供解析函数
const origin = location.origin;
console.log('定义拦截跳转');
/**
* TODO: 结构优化
*/
/**
* 跳转 App 头部参数
* 文档 http://git.yoho.cn/mobile/AppJSBridge/blob/master/HeaderType.md
* @type {Object}
*/
const defaultTitleMap = {
1: {
headerid: '1',
left: {
action: ''
},
title: {
des: '',
action: ''
}
},
2: {
headerid: '2',
left: {
action: ''
},
title: {
des: '',
action: ''
},
right: {
icon: 'chat',
action: 'goToService'
}
},
3: {
headerid: '3',
left: {
action: ''
},
title: {
des: '',
action: ''
},
right: {
des: '提交',
action: 'test'
}
},
4: {
headerid: '4',
ltitle: {
des: '品牌',
action: origin + '/brands'
},
rtitle: {
des: '品类',
action: origin + '/cate'
}
},
5: {
headerid: '5',
left: {
action: ''
},
ltitle: {
des: '商品',
action: origin + '/me/collection'
},
rtitle: {
des: '品牌',
action: origin + '/me/collection?tab=brand'
},
right: {
des: '编辑',
action: 'editModel'
},
defaultSelectedIndex: '0'
},
6: {
headerid: '6',
title: {
des: '资讯',
action: ''
}
}
};
const matchHeader = (path, qs, titleMap) => {
let header = {
headerid: '-1'
};
if (/\/cate-all$/.test(path)) {
header = titleMap[1];
header.title.des = '全部分类';
return header;
}
if (/\/me\/mydetails$/.test(path)) {
header = titleMap[1];
header.title.des = '个人信息';
return header;
}
if (/\/me\/order$/.test(path)) {
let des = '';
if (qs.type === '1') {
des = '我的订单';
} else if (qs.type === '2') {
des = '待付款';
} else if (qs.type === '3') {
des = '待发货';
} else if (qs.type === '4') {
des = '待收货';
}
header = titleMap[1];
header.title.des = des;
return header;
}
if (/\/me\/return\/refund$/.test(path)) {
header = titleMap[3];
header.title.des = '退货申请';
header.right.action = 'submitForm';
return header;
}
if (/\/me\/return\/exchange$/.test(path)) {
header = titleMap[3];
header.title.des = '换货申请';
header.right.action = 'submitForm';
return header;
}
if (/\/me\/return\/refund\/detail/.test(path)) {
header = titleMap[1];
header.title.des = '退货状态';
return header;
}
if (/\/me\/return\/exchange\/detail/.test(path)) {
header = titleMap[1];
header.title.des = '换货状态';
return header;
}
if (/\/me\/logistic$/.test(path)) {
header = titleMap[1];
header.title.des = '物流信息';
return header;
}
if (/\/me\/return\/logistics$/.test(path)) {
header = titleMap[1];
header.title.des = '商品寄回';
return header;
}
if (/\/me\/order\/detail$/.test(path)) {
header = titleMap[2];
header.title.des = '订单详情';
return header;
}
if (/\/me\/return$/.test(path)) {
header = titleMap[1];
header.title.des = '退/换货';
return header;
}
if (/\/me\/mycurrency$/.test(path)) {
header = titleMap[1];
header.title.des = '有货币';
return header;
}
if (/\/help$/.test(path)) {
header = titleMap[1];
header.title.des = '帮助中心';
return header;
}
if (/\/help-detail$/.test(path)) {
header = titleMap[1];
header.title.des = qs.title; // 帮助中心详细
return header;
}
if (/\/me\/service$/.test(path)) {
header = titleMap[1];
header.title.des = 'Yoho!Blk在线客服';
return header;
}
if (/\/me\/feedback$/.test(path)) {
header = titleMap[3];
header.title.des = '意见反馈';
header.right = {
des: '提交',
action: 'saveFeedback'
};
return header;
}
if (/\/me\/about$/.test(path)) {
header = titleMap[1];
header.title.des = '关于';
return header;
}
// 处理 feature.yoho.cn 等域名下的站外链接
if (/^(https?:)?\/\//i.test(path) && !/yohoblk\.com/.test(path)) {
header = titleMap[1];
header.title.des = qs.title || '';
return header;
}
return header;
};
const intercept = (url) => {
if (yoho.isApp) {
let titleMap = Object.assign({}, defaultTitleMap);
let [path, qs] = url.split('?');
qs = parse(qs);
// 个人中心收藏
if (/\/me\/collection$/.test(path)) {
let header = titleMap[5];
if (qs.tab === 'brand') {
header.defaultSelectedIndex = '1';
} else {
header.defaultSelectedIndex = '0';
}
return yoho.goPageView({
header: header
});
}
// 个人中心首页
if (/\/me$/.test(path)) {
return yoho.goTab({
index: 4
});
}
// 资讯
if (/\/editorial\/list$/.test(path)) {
return yoho.goTab({
index: 2
});
}
// 品牌 品类
if (/\/brand$/.test(path) || /\/cate$/.test(path)) {
return yoho.goTab({
index: 1,
headerIndex: /\/brand$/.test(path) ? 0 : 1
});
}
// 首页
if (/\/$/.test(path) || !path) {
return yoho.goTab({
index: 0,
url: /^(https?:)?\/\//i.test(url) ? url : origin + url
});
}
yoho.goNewPage({
header: matchHeader(path, qs, titleMap),
url: /^(https?:)?\/\//i.test(url) ? url : origin + url
});
} else {
location.href = url;
}
};
module.exports = {
defaultTitleMap,
intercept
};