index.js
3.33 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
import rules from './rules';
import router from './router';
// const urlParse = require('url');
// const queryString = require('querystring');
const ACTION_TYPE = {
h5: 'go.h5',
productList: 'go.list',
brandStore: 'go.shop',
}
const OPEN_BY_TYPE = {
GO_LIST: 'productList',
GO_ORDER_LIST: 'orderList',
GO_DETAIL: 'productDetail',
GO_ORDER_DETAIL: 'BuyerOrderDetail',
GO_HOME: 'home',
GO_YOLUCK: 'yoluck',
};
export default {
go(name, query, jumpType) {
const jump = jumpType ? jumpType : 'navigateTo';
const rule = rules[name];
if (!rule) {
return Promise.reject(`路由规则未匹配到: ${name}`);
}
query = query || {};
const routerFn = router[jump] || router.navigateTo;
return routerFn({
url: rule.path,
query
});
},
goUrl(jumpUrl) {
if (!jumpUrl) {
return;
}
let url = "";
let startIndex = jumpUrl.indexOf('openby:yohobuy=');
if (startIndex < 0) {
return;
}
let jsonRule = jumpUrl.substring(startIndex+'openby:yohobuy='.length);
let yoho = JSON.parse(jsonRule);
console.log('===============router===============');
console.log(jsonRule);
console.log(yoho);
console.log('====================================');
switch(yoho.action) {
case ACTION_TYPE.h5: {
let yohobuy = {
...yoho.params.param,
url: yoho.params.url,
action: yoho.action
}
this.go('webview', yohobuy);
break;
}
case ACTION_TYPE.productList: {
let yohobuy = {
...yoho.params,
url: yoho.params.url,
action: yoho.action
}
this.go('productList', yohobuy);
break;
}
case ACTION_TYPE.brandStore: {
let yohobuy = {
...yoho.params,
url: yoho.params.url,
action: yoho.action
}
this.go('brandStore', yohobuy);
break;
}
case ACTION_TYPE.ufo: {
this.handleUFOJumpPage(yoho);
break;
}
default:
break;
}
},
handleUFOJumpPage(yoho) {
const params = yoho.params
switch(params.pagename) {
case OPEN_BY_TYPE.GO_LIST: {
console.log(yoho);
this.go(OPEN_BY_TYPE.GO_LIST, params);
break;
}
case OPEN_BY_TYPE.GO_HOME: {
this.go(OPEN_BY_TYPE.GO_HOME);
break;
}
case OPEN_BY_TYPE.GO_DETAIL: {
this.go(OPEN_BY_TYPE.GO_DETAIL, params);
break;
}
case OPEN_BY_TYPE.GO_ORDER_DETAIL: {
let userInfo = tt.getStorageSync('userInfo');
if (userInfo && userInfo.uid && userInfo.session_key) {
this.go('orderDetail', params);
} else {
this.go('nativeLogin');
}
break;
}
case OPEN_BY_TYPE.GO_ORDER_LIST: {
let userInfo = tt.getStorageSync('userInfo');
if (userInfo && userInfo.uid && userInfo.session_key) {
this.go(OPEN_BY_TYPE.GO_ORDER_LIST, params);
} else {
this.go('nativeLogin');
}
break;
}
case OPEN_BY_TYPE.GO_YOLUCK: {
let userInfo = tt.getStorageSync('userInfo');
if (userInfo && userInfo.uid && userInfo.session_key) {
this.go('yoLuck', params);
} else {
this.go('nativeLogin');
}
}
break;
default: break;
}
}
}