crh-jssdk 0.10.24 → 0.10.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/business/assets/cx_share.png +0 -0
- package/business/base/crh-app-sdk-cxzq.ts +468 -0
- package/business/base/crh-app-sdk-lczq.ts +212 -0
- package/business/base/index.ts +47 -0
- package/business/index.ts +249 -0
- package/business/profession/crh-app-sdk-cxzq.ts +351 -0
- package/business/profession/crh-app-sdk-lczq.ts +18 -0
- package/business/profession/index.ts +53 -0
- package/business/user/crh-app-sdk-cxzq.ts +192 -0
- package/business/user/crh-app-sdk-cy.ts +46 -0
- package/business/user/crh-app-sdk-lczq.ts +152 -0
- package/business/user/index.ts +45 -0
- package/business/utils/bridge.ts +153 -0
- package/business/utils/index.ts +125 -0
- package/dist/business/assets/cx_share.png +0 -0
- package/dist/package.json +20 -0
- package/package.json +2 -2
- package/index.js +0 -34
|
Binary file
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { ios, checkIsHarmonyOS } from "../utils";
|
|
2
|
+
import ShareImg from "../assets/cx_share.png";
|
|
3
|
+
import ProfessionModel from "../profession/crh-app-sdk-cxzq";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @name 版本号比较
|
|
7
|
+
* @param {string} version1 版本号1
|
|
8
|
+
* @param {string} version2 版本号2
|
|
9
|
+
* @returns 1: 版本1大于版本2 | -1: 版本1小于版本2 | 0: 版本相等
|
|
10
|
+
*/
|
|
11
|
+
const compareVersion = (version1: any, version2: any) => {
|
|
12
|
+
version1 = version1.split(".");
|
|
13
|
+
version2 = version2.split(".");
|
|
14
|
+
const n = Math.max(version1.length, version2.length);
|
|
15
|
+
for (let i = 0; i < n; i++) {
|
|
16
|
+
const code1 = version1[i] === undefined ? 0 : parseInt(version1[i], 10);
|
|
17
|
+
const code2 = version2[i] === undefined ? 0 : parseInt(version2[i], 10);
|
|
18
|
+
if (code1 > code2) {
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
if (code1 < code2) {
|
|
22
|
+
return -1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return 0;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// webview类型
|
|
29
|
+
const webviewType = (() => {
|
|
30
|
+
const ua = navigator.userAgent;
|
|
31
|
+
const isWTSDK = ua.includes("cxzqwtsdk");
|
|
32
|
+
return {
|
|
33
|
+
isWTSDK,
|
|
34
|
+
// 新乐赚
|
|
35
|
+
isNewLeZhuan: !isWTSDK && ua.toLowerCase().includes("lezhuan"),
|
|
36
|
+
// 新聚财
|
|
37
|
+
isNewJuCai:
|
|
38
|
+
!isWTSDK &&
|
|
39
|
+
!ua.includes("crhsdk") &&
|
|
40
|
+
(ua.includes("Android_CFZQ_JUCAI") || ua.includes("iOS_CFZQ_JUCAI")),
|
|
41
|
+
// 老聚财
|
|
42
|
+
isOldJuCai: ua.includes("crhsdk") && !ua.includes("cfzqsdk"),
|
|
43
|
+
isLeZhuan:
|
|
44
|
+
(!isWTSDK && ua.toLowerCase().includes("lezhuan")) ||
|
|
45
|
+
ua.includes("cfzqsdk"),
|
|
46
|
+
isCRH: ua.includes("crhsdk") || ua.includes("crhapp"),
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
|
|
50
|
+
const actionMap = {
|
|
51
|
+
// 财信处理action地址方法
|
|
52
|
+
onJsOverrideUrlLoading(str: string) {
|
|
53
|
+
if (ios && window.webkit?.messageHandlers?.lzforward) {
|
|
54
|
+
window.webkit.messageHandlers.lzforward?.postMessage(str);
|
|
55
|
+
} else if (window.MyWebView && window.MyWebView.onJsOverrideUrlLoading) {
|
|
56
|
+
window.MyWebView.onJsOverrideUrlLoading(str);
|
|
57
|
+
} else if (window.HarmonyOS && window.HarmonyOS.onJsOverrideUrlLoading) {
|
|
58
|
+
window.HarmonyOS.onJsOverrideUrlLoading(str);
|
|
59
|
+
} else {
|
|
60
|
+
window.location.href = str;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
// 财信调用action路径
|
|
64
|
+
callAction(actionId: string | number, param?: any, cbFunName?: any) {
|
|
65
|
+
let url = `http://action:${actionId}/?target=2`;
|
|
66
|
+
if (param) {
|
|
67
|
+
const paramStr = JSON.stringify(param);
|
|
68
|
+
url += `¶m=${encodeURIComponent(paramStr)}`;
|
|
69
|
+
}
|
|
70
|
+
if (cbFunName) {
|
|
71
|
+
url += `&callback=${cbFunName}`;
|
|
72
|
+
}
|
|
73
|
+
console.log("callAction:", url);
|
|
74
|
+
this.onJsOverrideUrlLoading(url);
|
|
75
|
+
},
|
|
76
|
+
// 财信聚财通过js bridge调用app接口
|
|
77
|
+
setupWebViewJavascriptBridge(callback: any) {
|
|
78
|
+
if (window.WebViewJavascriptBridge) {
|
|
79
|
+
callback(window.WebViewJavascriptBridge);
|
|
80
|
+
} else {
|
|
81
|
+
document.addEventListener(
|
|
82
|
+
"WebViewJavascriptBridgeReady",
|
|
83
|
+
() => {
|
|
84
|
+
callback(window.WebViewJavascriptBridge);
|
|
85
|
+
},
|
|
86
|
+
false
|
|
87
|
+
);
|
|
88
|
+
if (!/android/gi.test(navigator.userAgent)) {
|
|
89
|
+
if (window.WebViewJavascriptBridge) {
|
|
90
|
+
callback(window.WebViewJavascriptBridge);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (window.WVJBCallbacks) {
|
|
94
|
+
window.WVJBCallbacks.push(callback);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
window.WVJBCallbacks = [callback];
|
|
98
|
+
const WVJBIframe = document.createElement("iframe");
|
|
99
|
+
WVJBIframe.style.display = "none";
|
|
100
|
+
WVJBIframe.src = "wvjbscheme://__BRIDGE_LOADED__";
|
|
101
|
+
document.documentElement.appendChild(WVJBIframe);
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
document.documentElement.removeChild(WVJBIframe);
|
|
104
|
+
}, 0);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
// 聚财Android调用app接口
|
|
109
|
+
callAndroidActionOfJvCai(param: any) {
|
|
110
|
+
const paramStr = JSON.stringify(param);
|
|
111
|
+
if (window.mobile) {
|
|
112
|
+
window.mobile.onActionEvent(paramStr);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
// 财信调用聚财方法
|
|
116
|
+
callJuCaiAction(funName: any, data?: any, callback?: any) {
|
|
117
|
+
console.log("callJuCaiAction:", funName, data, callback);
|
|
118
|
+
if (ios) {
|
|
119
|
+
this.setupWebViewJavascriptBridge((bridge: any) => {
|
|
120
|
+
bridge.callHandler(funName, data, window[callback]);
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
const param: any = {
|
|
124
|
+
funName,
|
|
125
|
+
callbackFunName: callback,
|
|
126
|
+
};
|
|
127
|
+
if (data) {
|
|
128
|
+
param.data = data;
|
|
129
|
+
}
|
|
130
|
+
this.callAndroidActionOfJvCai(param);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* iOS客户端方法加载函数(老乐赚老聚财)
|
|
135
|
+
* @param {string} url
|
|
136
|
+
*/
|
|
137
|
+
loadIOSNative(url: string) {
|
|
138
|
+
let iFrame: any = "";
|
|
139
|
+
iFrame = document.createElement("iframe");
|
|
140
|
+
iFrame.setAttribute("src", url);
|
|
141
|
+
iFrame.setAttribute("style", "display:none;");
|
|
142
|
+
iFrame.setAttribute("height", "0px");
|
|
143
|
+
iFrame.setAttribute("width", "0px");
|
|
144
|
+
iFrame.setAttribute("frameborder", "0");
|
|
145
|
+
document.body.appendChild(iFrame);
|
|
146
|
+
iFrame.parentNode.removeChild(iFrame);
|
|
147
|
+
iFrame = null;
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
if (!ios && webviewType.isNewJuCai) {
|
|
153
|
+
actionMap.setupWebViewJavascriptBridge((bridge: any) => {
|
|
154
|
+
bridge.init();
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
} catch (e) {
|
|
158
|
+
console.log("初始化失败");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default {
|
|
162
|
+
compareVersion,
|
|
163
|
+
actionMap,
|
|
164
|
+
webviewType() {
|
|
165
|
+
return webviewType;
|
|
166
|
+
},
|
|
167
|
+
//是否在app内
|
|
168
|
+
isApp() {
|
|
169
|
+
const ua = navigator.userAgent;
|
|
170
|
+
const isAppFlags = [
|
|
171
|
+
"crhsdk",
|
|
172
|
+
"crhapp",
|
|
173
|
+
"cfzqsdk",
|
|
174
|
+
"LeZhuan",
|
|
175
|
+
"LEZHUAN",
|
|
176
|
+
"lezhuan",
|
|
177
|
+
"Android_CFZQ_JUCAI",
|
|
178
|
+
"iOS_CFZQ_JUCAI",
|
|
179
|
+
];
|
|
180
|
+
return isAppFlags.some((flag) => ua.includes(flag));
|
|
181
|
+
},
|
|
182
|
+
// 拦截Android物理返回键事件,并回调给前端 --- 仅安卓
|
|
183
|
+
interceptBack(callback: Function) {
|
|
184
|
+
window.jtoJHandle.interceptBack("interceptBackCallBack");
|
|
185
|
+
window.interceptBackCallBack = function (e: any) {
|
|
186
|
+
callback && callback(e);
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
// 关闭页面 closeSJKH
|
|
191
|
+
closeSJKH() {
|
|
192
|
+
if (webviewType.isNewLeZhuan) {
|
|
193
|
+
actionMap.callAction(3);
|
|
194
|
+
} else if (webviewType.isNewJuCai) {
|
|
195
|
+
// iphone
|
|
196
|
+
actionMap.callJuCaiAction("closePage", {});
|
|
197
|
+
} else if (ios) {
|
|
198
|
+
// iphone
|
|
199
|
+
window.location.href = "objc://callIOSQuit/";
|
|
200
|
+
} else {
|
|
201
|
+
window.jtoJHandle.closeSJKH();
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
/**
|
|
205
|
+
* 跳转个股详情页
|
|
206
|
+
*/
|
|
207
|
+
goStockDetail(params: {
|
|
208
|
+
code?: string,
|
|
209
|
+
market?:string
|
|
210
|
+
}) {
|
|
211
|
+
const { code, market } = params;
|
|
212
|
+
if (webviewType.isNewLeZhuan) {
|
|
213
|
+
actionMap.callAction(923, {
|
|
214
|
+
code,
|
|
215
|
+
market,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
/**
|
|
220
|
+
* 通过pageId打开新的webview打开外部链接
|
|
221
|
+
*/
|
|
222
|
+
goWebview(params: {
|
|
223
|
+
sdk?: string;
|
|
224
|
+
h5?: string;
|
|
225
|
+
h5url?: string;
|
|
226
|
+
token_sn?: string;
|
|
227
|
+
thirdChannel?: string;
|
|
228
|
+
productCode?: string;
|
|
229
|
+
}) {
|
|
230
|
+
const { sdk, h5, h5url = "", productCode } = params;
|
|
231
|
+
const jsonObj = {
|
|
232
|
+
indexUrl: h5,
|
|
233
|
+
uploadPicUrl: "",
|
|
234
|
+
cookieDomain: "",
|
|
235
|
+
closeBusiness: "closeCallBack",
|
|
236
|
+
module: "",
|
|
237
|
+
identifier: "zt",
|
|
238
|
+
};
|
|
239
|
+
const jsonStr = JSON.stringify(jsonObj);
|
|
240
|
+
if (!this.isApp()) {
|
|
241
|
+
window.location.href = h5url;
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (webviewType.isNewLeZhuan) {
|
|
245
|
+
actionMap.callAction(207, {
|
|
246
|
+
pageId: sdk || "1",
|
|
247
|
+
needLogin: "0",
|
|
248
|
+
...(productCode ? { param: { productCode } } : {}),
|
|
249
|
+
});
|
|
250
|
+
} else if (webviewType.isNewJuCai) {
|
|
251
|
+
actionMap.callJuCaiAction("gotoClientPage", {
|
|
252
|
+
pageId: ios ? String(sdk) : sdk,
|
|
253
|
+
needLogin: "0",
|
|
254
|
+
...(productCode ? { param: { productCode } } : {}),
|
|
255
|
+
});
|
|
256
|
+
} else if (ios) {
|
|
257
|
+
// iphone
|
|
258
|
+
actionMap.loadIOSNative(`objc://openNewBusiness/$?${jsonStr}`);
|
|
259
|
+
} else {
|
|
260
|
+
window.jtoJHandle.openNewBusiness(jsonStr);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
/**
|
|
264
|
+
* 通过打开新的webview打开外部链接
|
|
265
|
+
* @param {string} url 跳转地址
|
|
266
|
+
* @param {boolean} needTitle 打开新webview是否需要页头1需要0不需要
|
|
267
|
+
*/
|
|
268
|
+
goWebview2({ url = "", needTitle = false, noNewWebView = false }) {
|
|
269
|
+
let targetUrl = url?.trim();
|
|
270
|
+
if (!targetUrl) {
|
|
271
|
+
console.log("targetUrl不能为空");
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const urlParams: {
|
|
275
|
+
[key: string]: string;
|
|
276
|
+
} = {};
|
|
277
|
+
let prefix = "";
|
|
278
|
+
if (targetUrl.includes("#")) {
|
|
279
|
+
prefix = targetUrl.split("#")[1].includes("?") ? "&" : "?";
|
|
280
|
+
} else {
|
|
281
|
+
prefix = targetUrl.includes("?") ? "&" : "?";
|
|
282
|
+
}
|
|
283
|
+
let from = "";
|
|
284
|
+
if (!targetUrl.includes("from=")) {
|
|
285
|
+
from = "from=newMall";
|
|
286
|
+
urlParams.from = "newMall";
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const currentPage: any = window.location.hash
|
|
290
|
+
? window.location.hash.match(/#([^?]*)/)?.[1]
|
|
291
|
+
: "/";
|
|
292
|
+
urlParams.fromPage = currentPage;
|
|
293
|
+
if (!noNewWebView) {
|
|
294
|
+
// 新开webview
|
|
295
|
+
urlParams.opentype = "newpage";
|
|
296
|
+
}
|
|
297
|
+
if (webviewType.isNewJuCai) {
|
|
298
|
+
delete urlParams.opentype;
|
|
299
|
+
}
|
|
300
|
+
if (!needTitle && !targetUrl.includes("needtitle=")) {
|
|
301
|
+
// 不显示原生标题栏
|
|
302
|
+
urlParams.needtitle = "0";
|
|
303
|
+
}
|
|
304
|
+
if (
|
|
305
|
+
targetUrl.includes("#") &&
|
|
306
|
+
(urlParams.opentype || urlParams.needtitle)
|
|
307
|
+
) {
|
|
308
|
+
// opentype和needtitle处理,需在#号前加
|
|
309
|
+
const tempUrl = targetUrl.split("#");
|
|
310
|
+
const preParams: {
|
|
311
|
+
[key: string]: string;
|
|
312
|
+
} = {};
|
|
313
|
+
if (urlParams.opentype && !tempUrl[0].includes("opentype=")) {
|
|
314
|
+
preParams.opentype = urlParams.opentype;
|
|
315
|
+
}
|
|
316
|
+
if (urlParams.needtitle && !tempUrl[0].includes("needtitle=")) {
|
|
317
|
+
preParams.needtitle = urlParams.needtitle;
|
|
318
|
+
}
|
|
319
|
+
const fromAppTab = sessionStorage.getItem("fromAppTab") || "";
|
|
320
|
+
if (+fromAppTab === 1 && !tempUrl[0].includes("fromAppTab=")) {
|
|
321
|
+
preParams.fromAppTab = "1";
|
|
322
|
+
}
|
|
323
|
+
const urlParamsStr = new URLSearchParams(preParams).toString();
|
|
324
|
+
targetUrl = `${tempUrl[0]}${
|
|
325
|
+
tempUrl[0].includes("?") ? "&" : "?"
|
|
326
|
+
}${urlParamsStr}#${tempUrl[1]}`;
|
|
327
|
+
}
|
|
328
|
+
if (urlParams.opentype) {
|
|
329
|
+
// 新开标识
|
|
330
|
+
urlParams.isInNewWebView = "1";
|
|
331
|
+
}
|
|
332
|
+
/* if (+getSessionStore('fromAppTab') === 1) {
|
|
333
|
+
urlParams.fromAppTab = '1';
|
|
334
|
+
} */
|
|
335
|
+
const urlParamsStr = new URLSearchParams(urlParams).toString();
|
|
336
|
+
const mregeUrl = `${targetUrl}${prefix}${urlParamsStr}`;
|
|
337
|
+
console.log("goWebView:", mregeUrl);
|
|
338
|
+
if (webviewType.isNewLeZhuan) {
|
|
339
|
+
window.location.href = mregeUrl;
|
|
340
|
+
} else if (webviewType.isNewJuCai) {
|
|
341
|
+
if (urlParams.opentype) {
|
|
342
|
+
if (ios) {
|
|
343
|
+
actionMap.setupWebViewJavascriptBridge((bridge: any) => {
|
|
344
|
+
bridge.callHandler(
|
|
345
|
+
"gotoNextPage",
|
|
346
|
+
{
|
|
347
|
+
needtitle: needTitle ? "1" : "0",
|
|
348
|
+
url,
|
|
349
|
+
},
|
|
350
|
+
(data: any) => {
|
|
351
|
+
console.log("goWebview:", data);
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
} else {
|
|
356
|
+
// {“pageId”: “2804”, “needLogin”: “true”, “title”: “网页标题”, “url”: “http://www.baidu.com”}
|
|
357
|
+
// pageId=2804表示跳转客户端默认webview,pageId=5002跳转客户端无标题webview;needLogin=1表示需要先登录委托,未登录委托情况下会先跳转客户端委托登录
|
|
358
|
+
actionMap.callJuCaiAction("goWebViewPage", {
|
|
359
|
+
pageId: needTitle ? "2804" : "5002",
|
|
360
|
+
url,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
// 聚财新开webview体验有问题,因此统一走location.href
|
|
365
|
+
window.location.href = url;
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
let paramsObj: any = {
|
|
369
|
+
indexUrl: url,
|
|
370
|
+
};
|
|
371
|
+
paramsObj = JSON.stringify(paramsObj);
|
|
372
|
+
if (ios) {
|
|
373
|
+
actionMap.loadIOSNative(`objc://openNewBusiness/$?${paramsObj}`);
|
|
374
|
+
} else {
|
|
375
|
+
window.jtoJHandle?.openNewBusiness(paramsObj);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* 获取客户端版本号
|
|
382
|
+
*/
|
|
383
|
+
getVersion() {
|
|
384
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
385
|
+
let regex: any = "";
|
|
386
|
+
if (webviewType.isNewLeZhuan) {
|
|
387
|
+
regex = ios || checkIsHarmonyOS() ? /cfzq_lezhuan_([\d.]+)/ : /cfzq_lezhuan([\d.]+)/;
|
|
388
|
+
} else if (webviewType.isNewJuCai) {
|
|
389
|
+
regex = /cfzq_jucai_([\d.]+)/;
|
|
390
|
+
}
|
|
391
|
+
const match = ua.match(regex);
|
|
392
|
+
console.log(match, "===match===");
|
|
393
|
+
if (match) {
|
|
394
|
+
const version = match[1];
|
|
395
|
+
return version;
|
|
396
|
+
} else {
|
|
397
|
+
console.warn("version没有找到匹配项");
|
|
398
|
+
return "0.0.0";
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
/**
|
|
402
|
+
* 设置原生状态栏颜色(乐赚客户端)
|
|
403
|
+
* @param {object} params
|
|
404
|
+
* @param {string} params.color 状态栏背景颜色,如#ff0000
|
|
405
|
+
* @param {string} params.wordColorStyle 状态栏文字颜色,0 白色,1 黑色
|
|
406
|
+
*/
|
|
407
|
+
async setStatusBar(params: any) {
|
|
408
|
+
if (webviewType.isNewLeZhuan) {
|
|
409
|
+
if (compareVersion("6.1.0", this.getVersion()) === 1) {
|
|
410
|
+
console.log("---版本号低,无法设置状态栏颜色---");
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
let data = {
|
|
414
|
+
statusColor: params.color,
|
|
415
|
+
isDark: params.wordColorStyle === "1",
|
|
416
|
+
};
|
|
417
|
+
actionMap.callAction(933, data);
|
|
418
|
+
} else if (webviewType.isCRH) {
|
|
419
|
+
if (ios) {
|
|
420
|
+
actionMap.loadIOSNative(
|
|
421
|
+
`objc://setAppBackgroundColor/$?${params.color}`
|
|
422
|
+
);
|
|
423
|
+
} else if (window.jtoJHandle) {
|
|
424
|
+
window.jtoJHandle.setAppBackgroundColor(params.color);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* 分享
|
|
431
|
+
* @param {object} params
|
|
432
|
+
* @param {string} params.img_url 分享展示的图片
|
|
433
|
+
* @param {string} params.url 分享链接
|
|
434
|
+
* @param {string} params.title 标题
|
|
435
|
+
* @param {string} params.message 内容
|
|
436
|
+
*/
|
|
437
|
+
share(params: {
|
|
438
|
+
img_url?: any;
|
|
439
|
+
url?: string;
|
|
440
|
+
title?: string;
|
|
441
|
+
message?: string;
|
|
442
|
+
}) {
|
|
443
|
+
if (webviewType.isLeZhuan) {
|
|
444
|
+
const shareParam = {
|
|
445
|
+
img_url: params.img_url || ShareImg,
|
|
446
|
+
url: params.url,
|
|
447
|
+
title: params.title,
|
|
448
|
+
message: params.message,
|
|
449
|
+
};
|
|
450
|
+
if (webviewType.isNewLeZhuan) {
|
|
451
|
+
actionMap.callAction(900, shareParam, "");
|
|
452
|
+
} else {
|
|
453
|
+
ProfessionModel.businessAlertView(
|
|
454
|
+
`http://action:900/?target=2¶m=${encodeURIComponent(
|
|
455
|
+
JSON.stringify(shareParam)
|
|
456
|
+
)}`
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
return new Promise(async (resolve) => {
|
|
461
|
+
resolve({
|
|
462
|
+
error_no: "-3",
|
|
463
|
+
error_info: "当前APP不支持分享",
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
};
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 联储证券基础模块 - Bridge版本
|
|
3
|
+
* 基于WebViewJavascriptBridge实现基础功能
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { globalBridge, ios } from "../utils";
|
|
7
|
+
export default {
|
|
8
|
+
/**
|
|
9
|
+
* 检查是否在App环境中
|
|
10
|
+
*/
|
|
11
|
+
isApp(): boolean {
|
|
12
|
+
const ua = navigator.userAgent;
|
|
13
|
+
console.log(ua);
|
|
14
|
+
return (
|
|
15
|
+
ua.includes("lczq")
|
|
16
|
+
);
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 获取webview类型
|
|
21
|
+
*/
|
|
22
|
+
webviewType() {
|
|
23
|
+
const ua = navigator.userAgent;
|
|
24
|
+
return {
|
|
25
|
+
isLCZQ: ua.includes("lczq"),
|
|
26
|
+
isIOS: ios,
|
|
27
|
+
isAndroid: /Android/i.test(ua),
|
|
28
|
+
ua: ua,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 返回到App
|
|
34
|
+
* @param params 返回参数
|
|
35
|
+
*/
|
|
36
|
+
async goBack(params: any = {}): Promise<void> {
|
|
37
|
+
try {
|
|
38
|
+
const backParams = {
|
|
39
|
+
type: "webpage",
|
|
40
|
+
...params,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
console.log("调用goBack,参数:", backParams);
|
|
44
|
+
await globalBridge.bridgeCallHandler("Promise", "goback", backParams);
|
|
45
|
+
console.log("返回App成功");
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("返回App失败:", error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 关闭当前页面
|
|
54
|
+
*/
|
|
55
|
+
async closeSJKH(): Promise<void> {
|
|
56
|
+
try {
|
|
57
|
+
await this.goBack({ type: "component" });
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("关闭页面失败:", error);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 通过url打开新的webview打开外部链接
|
|
65
|
+
*/
|
|
66
|
+
goWebview(url: string) {
|
|
67
|
+
const timestamp = new Date().getTime();
|
|
68
|
+
const pinurl = url.includes('?') ? url+'×tamp='+timestamp :url+'?timestamp='+timestamp;
|
|
69
|
+
if (ios) {
|
|
70
|
+
location.href = `client://hxsecurity.frame.router/browser?url=${encodeURIComponent(pinurl)}&rp_flag_push_to_stack_directly=true&rp_flag_back_to_last_tab=true&rp_flag_finish_when_back_to_last_tab=true&hideNavBar=1&isHiddenNavigationBar=1`
|
|
71
|
+
} else {
|
|
72
|
+
location.href = `client://hxsecurity.frame.router/browser?url=${encodeURIComponent(pinurl)}&rp_flag_recreate=true&rp_flag_push_to_stack_directly=true&rp_flag_finish_when_back_to_last_tab=true&hideNavBar=1&isHiddenNavigationBar=1&fontzoom=no`
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 设置原生状态栏颜色
|
|
78
|
+
* @param {object} params
|
|
79
|
+
* @param {string} params.color 状态栏背景颜色,如#ff0000
|
|
80
|
+
* @param {string} params.wordColorStyle 状态栏文字颜色,0 白色,1 黑色
|
|
81
|
+
*/
|
|
82
|
+
async setStatusBar(params: any) {
|
|
83
|
+
console.log("设置状态栏参数:", params);
|
|
84
|
+
try {
|
|
85
|
+
// 根据参考文件,使用setStatusBarState方法
|
|
86
|
+
await globalBridge.bridgeCallHandler("Promise", "modifyStatusColor", {
|
|
87
|
+
statusColor: params.color,
|
|
88
|
+
});
|
|
89
|
+
console.log("设置状态栏颜色成功");
|
|
90
|
+
return { success: true };
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error("设置状态栏颜色失败:", error);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 分享功能
|
|
99
|
+
* @param params 分享参数
|
|
100
|
+
*/
|
|
101
|
+
async share(params: {
|
|
102
|
+
type?: string; // "1"分享网页,"2"分享图片
|
|
103
|
+
title?: string;
|
|
104
|
+
content?: string;
|
|
105
|
+
url?: string;
|
|
106
|
+
bmpRes?: string; // 图片来源 1网络图片 2截屏 3默认图片
|
|
107
|
+
bmpUrl?: string;
|
|
108
|
+
}): Promise<any> {
|
|
109
|
+
try {
|
|
110
|
+
const shareParams = {
|
|
111
|
+
type: "1", // 默认分享网页
|
|
112
|
+
bmpRes: "3", // 默认图片
|
|
113
|
+
...params,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
console.log("调用分享,参数:", shareParams);
|
|
117
|
+
const result = await globalBridge.bridgeCallHandler(
|
|
118
|
+
"Promise",
|
|
119
|
+
"hexinShare",
|
|
120
|
+
shareParams
|
|
121
|
+
);
|
|
122
|
+
console.log("分享调用成功:", result);
|
|
123
|
+
return result;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error("分享失败:", error);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 保存图片到相册
|
|
132
|
+
* @param imageData 图片的base64格式字符串
|
|
133
|
+
*/
|
|
134
|
+
async saveImageToAlbum(imageData: string): Promise<any> {
|
|
135
|
+
try {
|
|
136
|
+
const params = { imageData };
|
|
137
|
+
console.log("保存图片到相册");
|
|
138
|
+
const result = await globalBridge.bridgeCallHandler(
|
|
139
|
+
"Promise",
|
|
140
|
+
"saveImageToAlbum",
|
|
141
|
+
params
|
|
142
|
+
);
|
|
143
|
+
console.log("保存图片成功:", result);
|
|
144
|
+
return result;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error("保存图片失败:", error);
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 拦截Android物理返回键事件,并回调给前端 --- 仅安卓
|
|
153
|
+
*/
|
|
154
|
+
interceptBack(callback: Function) {
|
|
155
|
+
try {
|
|
156
|
+
// 联储证券实现
|
|
157
|
+
globalBridge.registerHandler("interceptBack", (data: any) => {
|
|
158
|
+
callback && callback(data);
|
|
159
|
+
});
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error("拦截返回键失败:", error);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 跳转个股详情页
|
|
167
|
+
*/
|
|
168
|
+
goStockDetail(params: { code?: string; market?: string }, type: string = "StockSnap") {
|
|
169
|
+
const { code, market } = params;
|
|
170
|
+
let instanceId = "hxqRequestBridge" + Math.floor(Math.random()*999 + 1)
|
|
171
|
+
let data = {
|
|
172
|
+
instanceId: instanceId,
|
|
173
|
+
type,
|
|
174
|
+
params: {
|
|
175
|
+
stockCode: code,
|
|
176
|
+
stockmarket: market,
|
|
177
|
+
},
|
|
178
|
+
cancel: "",
|
|
179
|
+
subscribe: ""
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
globalBridge.bridgeCallHandler("", "hxqRequestBridge", data);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.error("跳转个股详情失败:", error);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 获取客户端版本号
|
|
190
|
+
*/
|
|
191
|
+
getVersion() {
|
|
192
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
193
|
+
let regex: any = "";
|
|
194
|
+
regex = /lczq[/_]([\d.]+)/;
|
|
195
|
+
const match = ua.match(regex);
|
|
196
|
+
console.log(match, "===match===");
|
|
197
|
+
if (match) {
|
|
198
|
+
const version = match[1];
|
|
199
|
+
return version;
|
|
200
|
+
} else {
|
|
201
|
+
console.warn("version没有找到匹配项");
|
|
202
|
+
return "0.0.0";
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 获取Bridge实例(供其他模块使用)
|
|
208
|
+
*/
|
|
209
|
+
getBridge() {
|
|
210
|
+
return globalBridge;
|
|
211
|
+
},
|
|
212
|
+
};
|