xianyu.js
3.86 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
/**
* Xianyu-SDK
*
* 与原生 APP 交互的代码
*
*/
import queryString from 'querystring';
const xianyu = {
/**
* 判断是否是 APP
*/
isAliApp: /AliApp/i.test(navigator.userAgent || ''),
isiOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(navigator.userAgent || ''),
isAndroid: /Android/i.test(navigator.userAgent || ''),
setXianyuWebview() {
if (this.isAliApp && window.WindVane) {
window.WindVane.call('WVIdleFishApi', 'setNavigationBarVisible', { visible: false }, () => {
console.log('set ok');
}, () => {
});
}
},
finishXianyuPage() {
if (this.isAliApp && window.WindVane) {
window.WindVane.call('WVIdleFishApi', 'finish', {}, () => {
console.log('set ok');
}, () => {
});
}
},
backXianyuPage() {
if (this.isAliApp && window.WindVane) {
window.WindVane.call('WVIdleFishApi', 'nativeBack', {}, () => {
console.log('set ok');
}, () => {
});
}
},
setXianyuTitle(args) {
if (this.isAliApp && window.WindVane) {
window.WindVane.call('WVIdleFishApi', 'setTitle', args, () => {
console.log('set ok');
}, () => {
});
}
},
setXianyuNav() {
if (this.isAliApp && window.WindVane) {
window.WindVane.call('WVIdleFishApi', 'setHideNavigatorRightItem', {}, () => {
console.log('set ok');
}, () => {
});
}
},
/**
*
* @param args payURL
* @param okAction
* @param errorAction
*/
setXianyuPay(args, okAction, errorAction) {
if (this.isAliApp && window.WindVane) {
window.WindVane.call('WVIdleFishApi', 'payAlipay', args, (data) => {
okAction && okAction(data);
}, (error) => {
errorAction && errorAction(error);
});
}
},
goXianyuNewPage(args) {
if (!args.url) {
return;
}
let urlSplit = args.url.split('?');
if (urlSplit[1]) {
let pageName = '';
let pageParams = {};
try {
pageParams = queryString.parse(urlSplit[1]);
let arr = [];
if (Object.keys(pageParams)[0] === 'openby:yohobuy') {
for (let key in pageParams) {
arr.push(pageParams[key]);
}
pageParams = JSON.parse(arr[0]).params;
pageParams.owner = pageParams.logisticsType;
pageParams.code = pageParams.ordercode;
}
if (pageParams.pagename) {
switch (pageParams.pagename) {
case 'productList':
pageName = 'List';
break;
case 'productDetail':
pageName = 'ProductDetail';
break;
case 'logisticsInfo':
pageName = 'orderLogisticsInfo';
break;
case 'productListNew':
pageName = 'List';
break;
default:
break;
}
delete pageParams.pagename;
}
} catch (error) {
console.log(error);
}
if (pageName) {
let paramsV = {};
if (pageName === 'List') {
paramsV.query = pageParams;
} else {
paramsV.params = pageParams;
}
console.log(paramsV);
return this.$router.push({
name: pageName,
...paramsV,
});
}
}
if (this.isAliApp && window.WindVane) {
window.WindVane.call('Base', 'openWindow', args, () => {
console.log('open new window success');
}, () => {
window.open(args.url, '_blank');
});
} else {
if (args.url) {
window.open(args.url, '_blank');
}
}
},
copyToClipboard(args, okAction, errorAction) {
if (this.isAliApp && window.WindVane) {
window.WindVane.call('Base', 'copyToClipboard', args, data => {
okAction && okAction(data);
}, error => {
errorAction && errorAction(error);
});
}
}
};
export default xianyu;