xianyu-share-demo.js
4.22 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
import goldlog from '@ali/universal-goldlog';
import { isWeex } from '@ali/universal-env';
import { isFM, isWechat, isDD, isUC, isWB, isYK } from '../env';
import { obj2qs } from '../index';
import confirm from '../confirm/index';
import Windvane from '@weex-module/windvane';
import Navigator from '@weex-module/navigator';
import showGuideMaskInWechat from './showGuideMaskInWechat';
// h5 详情页定制逻辑,增加 itemPvid
const searchParams = new URLSearchParams(location.search);
let lxTrackParam;
if (searchParams.get('lxTrackParam')) {
try {
lxTrackParam = JSON.parse(searchParams.get('lxTrackParam'));
} catch(e) {
console.log(e);
}
}
export default function (url, success, error, cancel, noConfirm) {
if (typeof url === 'object') {
let opts = url;
url = opts.url;
success = opts.success;
error = opts.error;
cancel = opts.cancel;
noConfirm = opts.noConfirm;
lxTrackParam = opts.lxTrackParam;
}
if (isWeex) {
if (isFM) {
Windvane.call2(
'Base.openWindow', {
url,
popBeforeOpen: true
},
() => {},
() => {}
);
return false;
}
Windvane.call2(
'Base.isInstall',
{
ios: 'fleamarket://',
android: 'com.taobao.idlefish'
},
() => {
if (noConfirm) {
callappByWindvaneWhenInstalled(url, success, error);
} else {
goldlog.record('/xyzz.5.17', 'CLK', '', 'GET');
confirm({
titles: ['即将离开手机淘宝', '打开“闲鱼App”'],
cancelCallback: () => {
goldlog.record('/xyzz.5.18', 'CLK', '', 'GET');
cancel && cancel();
},
okCallback: () => {
goldlog.record('/xyzz.5.19', 'CLK', '', 'GET');
callappByWindvaneWhenInstalled(url, success, error);
}
});
}
},
() => {
error && error();
}
);
} else {
if (window.AlipayJSBridge) {
AlipayJSBridge.call('openInBrowser', {
url: getCallappUrl(url)
});
let startTime = Date.now();
let timer = setTimeout(() => {
if (Date.now() - startTime < 3000) {
error && error();
}
}, 2000);
document.addEventListener('visibilitychange', function () {
if (timer) {
clearTimeout(timer);
}
success && success();
});
return;
} else if (isWechat) {
showGuideMaskInWechat();
} else if (isDD || isUC || isYK) {
window.location.href = getCallappUrl(url);
error && error();
} else if (isWB) {
url = `fleamarket://home?forward_url=${encodeURIComponent(url)}`;
new lib.idle.callapp({
iosNativeUrl: url,
androidNativeUrl: url,
lauchFailCallback: function() {
error && error();
}
});
} else if (typeof lib !== 'undefined' && lib.idle && lib.idle.callapp) {
new lib.idle.callapp({
iosNativeUrl: url,
androidNativeUrl: url,
lauchFailCallback: function() {
error && error();
}
});
}
}
}
function getCallappUrl(url = '') {
if (/^http/.test(url)) {
return `fleamarket://weex?url=${encodeURIComponent(url)}`
} else {
return url;
}
}
function callappByWindvaneWhenInstalled(url, success, error) {
goldlog.record('/widle.tbMiniApp.h5detailinstall', 'CLK', '', 'GET');
const gokey = obj2qs(lxTrackParam);
if (weex.config.env.appName == 'TM') {
Navigator.open(
{
url: url || 'fleamarket://home'
},
() => {
goldlog.record('/widle.tbMiniApp.h5detailcallappsuccess', 'CLK', gokey, 'GET')
success && success();
},
() => {
goldlog.record('/widle.tbMiniApp.h5detailcallapperror', 'CLK', '', 'GET')
error && error();
}
);
} else {
Windvane.call2(
'WVClient.open',
{
url: getCallappUrl(url) || 'fleamarket://home'
},
() => {
goldlog.record('/widle.tbMiniApp.h5detailcallappsuccess', 'CLK', gokey, 'GET')
success && success();
},
() => {
goldlog.record('/widle.tbMiniApp.h5detailcallapperror', 'CLK', '', 'GET')
error && error();
}
);
}
}