crh-jssdk 0.10.4 → 0.10.5

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.
@@ -0,0 +1,471 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var utils_1 = require("../utils");
43
+ var cx_share_png_1 = __importDefault(require("../assets/cx_share.png"));
44
+ var crh_app_sdk_cxzq_1 = __importDefault(require("../profession/crh-app-sdk-cxzq"));
45
+ /**
46
+ * @name 版本号比较
47
+ * @param {string} version1 版本号1
48
+ * @param {string} version2 版本号2
49
+ * @returns 1: 版本1大于版本2 | -1: 版本1小于版本2 | 0: 版本相等
50
+ */
51
+ var compareVersion = function (version1, version2) {
52
+ version1 = version1.split(".");
53
+ version2 = version2.split(".");
54
+ var n = Math.max(version1.length, version2.length);
55
+ for (var i = 0; i < n; i++) {
56
+ var code1 = version1[i] === undefined ? 0 : parseInt(version1[i], 10);
57
+ var code2 = version2[i] === undefined ? 0 : parseInt(version2[i], 10);
58
+ if (code1 > code2) {
59
+ return 1;
60
+ }
61
+ if (code1 < code2) {
62
+ return -1;
63
+ }
64
+ }
65
+ return 0;
66
+ };
67
+ // webview类型
68
+ var webviewType = (function () {
69
+ var ua = navigator.userAgent;
70
+ var isWTSDK = ua.includes("cxzqwtsdk");
71
+ return {
72
+ isWTSDK: isWTSDK,
73
+ // 新乐赚
74
+ isNewLeZhuan: !isWTSDK && ua.toLowerCase().includes("lezhuan"),
75
+ // 新聚财
76
+ isNewJuCai: !isWTSDK &&
77
+ !ua.includes("crhsdk") &&
78
+ (ua.includes("Android_CFZQ_JUCAI") || ua.includes("iOS_CFZQ_JUCAI")),
79
+ // 老聚财
80
+ isOldJuCai: ua.includes("crhsdk") && !ua.includes("cfzqsdk"),
81
+ isLeZhuan: (!isWTSDK && ua.toLowerCase().includes("lezhuan")) ||
82
+ ua.includes("cfzqsdk"),
83
+ isCRH: ua.includes("crhsdk") || ua.includes("crhapp"),
84
+ };
85
+ })();
86
+ var actionMap = {
87
+ // 财信处理action地址方法
88
+ onJsOverrideUrlLoading: function (str) {
89
+ var _a, _b, _c;
90
+ if (utils_1.ios && ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.lzforward)) {
91
+ (_c = window.webkit.messageHandlers.lzforward) === null || _c === void 0 ? void 0 : _c.postMessage(str);
92
+ }
93
+ else if (window.MyWebView && window.MyWebView.onJsOverrideUrlLoading) {
94
+ window.MyWebView.onJsOverrideUrlLoading(str);
95
+ }
96
+ else {
97
+ window.location.href = str;
98
+ }
99
+ },
100
+ // 财信调用action路径
101
+ callAction: function (actionId, param, cbFunName) {
102
+ var url = "http://action:".concat(actionId, "/?target=2");
103
+ if (param) {
104
+ var paramStr = JSON.stringify(param);
105
+ url += "&param=".concat(encodeURIComponent(paramStr));
106
+ }
107
+ if (cbFunName) {
108
+ url += "&callback=".concat(cbFunName);
109
+ }
110
+ console.log("callAction:", url);
111
+ this.onJsOverrideUrlLoading(url);
112
+ },
113
+ // 财信聚财通过js bridge调用app接口
114
+ setupWebViewJavascriptBridge: function (callback) {
115
+ if (window.WebViewJavascriptBridge) {
116
+ callback(window.WebViewJavascriptBridge);
117
+ }
118
+ else {
119
+ document.addEventListener("WebViewJavascriptBridgeReady", function () {
120
+ callback(window.WebViewJavascriptBridge);
121
+ }, false);
122
+ if (!/android/gi.test(navigator.userAgent)) {
123
+ if (window.WebViewJavascriptBridge) {
124
+ callback(window.WebViewJavascriptBridge);
125
+ return;
126
+ }
127
+ if (window.WVJBCallbacks) {
128
+ window.WVJBCallbacks.push(callback);
129
+ return;
130
+ }
131
+ window.WVJBCallbacks = [callback];
132
+ var WVJBIframe_1 = document.createElement("iframe");
133
+ WVJBIframe_1.style.display = "none";
134
+ WVJBIframe_1.src = "wvjbscheme://__BRIDGE_LOADED__";
135
+ document.documentElement.appendChild(WVJBIframe_1);
136
+ setTimeout(function () {
137
+ document.documentElement.removeChild(WVJBIframe_1);
138
+ }, 0);
139
+ }
140
+ }
141
+ },
142
+ // 聚财Android调用app接口
143
+ callAndroidActionOfJvCai: function (param) {
144
+ var paramStr = JSON.stringify(param);
145
+ if (window.mobile) {
146
+ window.mobile.onActionEvent(paramStr);
147
+ }
148
+ },
149
+ // 财信调用聚财方法
150
+ callJuCaiAction: function (funName, data, callback) {
151
+ console.log("callJuCaiAction:", funName, data, callback);
152
+ if (utils_1.ios) {
153
+ this.setupWebViewJavascriptBridge(function (bridge) {
154
+ bridge.callHandler(funName, data, window[callback]);
155
+ });
156
+ }
157
+ else {
158
+ var param = {
159
+ funName: funName,
160
+ callbackFunName: callback,
161
+ };
162
+ if (data) {
163
+ param.data = data;
164
+ }
165
+ this.callAndroidActionOfJvCai(param);
166
+ }
167
+ },
168
+ /**
169
+ * iOS客户端方法加载函数(老乐赚老聚财)
170
+ * @param {string} url
171
+ */
172
+ loadIOSNative: function (url) {
173
+ var iFrame = "";
174
+ iFrame = document.createElement("iframe");
175
+ iFrame.setAttribute("src", url);
176
+ iFrame.setAttribute("style", "display:none;");
177
+ iFrame.setAttribute("height", "0px");
178
+ iFrame.setAttribute("width", "0px");
179
+ iFrame.setAttribute("frameborder", "0");
180
+ document.body.appendChild(iFrame);
181
+ iFrame.parentNode.removeChild(iFrame);
182
+ iFrame = null;
183
+ },
184
+ };
185
+ try {
186
+ if (!utils_1.ios && webviewType.isNewJuCai) {
187
+ actionMap.setupWebViewJavascriptBridge(function (bridge) {
188
+ bridge.init();
189
+ });
190
+ }
191
+ }
192
+ catch (e) {
193
+ console.log("初始化失败");
194
+ }
195
+ exports.default = {
196
+ compareVersion: compareVersion,
197
+ actionMap: actionMap,
198
+ webviewType: function () {
199
+ return webviewType;
200
+ },
201
+ //是否在app内
202
+ isApp: function () {
203
+ var ua = navigator.userAgent;
204
+ var isAppFlags = [
205
+ "crhsdk",
206
+ "crhapp",
207
+ "cfzqsdk",
208
+ "LeZhuan",
209
+ "LEZHUAN",
210
+ "Android_CFZQ_JUCAI",
211
+ "iOS_CFZQ_JUCAI",
212
+ ];
213
+ return isAppFlags.some(function (flag) { return ua.includes(flag); });
214
+ },
215
+ // 拦截Android物理返回键事件,并回调给前端 --- 仅安卓
216
+ interceptBack: function (callback) {
217
+ window.jtoJHandle.interceptBack("interceptBackCallBack");
218
+ window.interceptBackCallBack = function (e) {
219
+ callback && callback(e);
220
+ };
221
+ },
222
+ // 关闭页面 closeSJKH
223
+ closeSJKH: function () {
224
+ if (webviewType.isNewLeZhuan) {
225
+ actionMap.callAction(3);
226
+ }
227
+ else if (webviewType.isNewJuCai) {
228
+ // iphone
229
+ actionMap.callJuCaiAction("closePage", {});
230
+ }
231
+ else if (utils_1.ios) {
232
+ // iphone
233
+ window.location.href = "objc://callIOSQuit/";
234
+ }
235
+ else {
236
+ window.jtoJHandle.closeSJKH();
237
+ }
238
+ },
239
+ /**
240
+ * 通过pageId打开新的webview打开外部链接
241
+ */
242
+ goWebview: function (params) {
243
+ var sdk = params.sdk, h5 = params.h5, _a = params.h5url, h5url = _a === void 0 ? "" : _a;
244
+ var jsonObj = {
245
+ indexUrl: h5,
246
+ uploadPicUrl: "",
247
+ cookieDomain: "",
248
+ closeBusiness: "closeCallBack",
249
+ module: "",
250
+ identifier: "zt",
251
+ };
252
+ var jsonStr = JSON.stringify(jsonObj);
253
+ if (!this.isApp()) {
254
+ window.location.href = h5url;
255
+ return;
256
+ }
257
+ if (webviewType.isNewLeZhuan) {
258
+ actionMap.callAction(207, { pageId: sdk || "1", needLogin: "0" });
259
+ }
260
+ else if (webviewType.isNewJuCai) {
261
+ actionMap.callJuCaiAction("gotoClientPage", {
262
+ pageId: utils_1.ios ? String(sdk) : sdk,
263
+ needLogin: "0",
264
+ });
265
+ }
266
+ else if (utils_1.ios) {
267
+ // iphone
268
+ actionMap.loadIOSNative("objc://openNewBusiness/$?".concat(jsonStr));
269
+ }
270
+ else {
271
+ window.jtoJHandle.openNewBusiness(jsonStr);
272
+ }
273
+ },
274
+ /**
275
+ * 通过打开新的webview打开外部链接
276
+ * @param {string} url 跳转地址
277
+ * @param {boolean} needTitle 打开新webview是否需要页头1需要0不需要
278
+ */
279
+ goWebview2: function (_a) {
280
+ var _b, _c;
281
+ var _d = _a.url, url = _d === void 0 ? "" : _d, _e = _a.needTitle, needTitle = _e === void 0 ? false : _e, _f = _a.noNewWebView, noNewWebView = _f === void 0 ? false : _f;
282
+ var targetUrl = url === null || url === void 0 ? void 0 : url.trim();
283
+ if (!targetUrl) {
284
+ console.log("targetUrl不能为空");
285
+ return;
286
+ }
287
+ var urlParams = {};
288
+ var prefix = "";
289
+ if (targetUrl.includes("#")) {
290
+ prefix = targetUrl.split("#")[1].includes("?") ? "&" : "?";
291
+ }
292
+ else {
293
+ prefix = targetUrl.includes("?") ? "&" : "?";
294
+ }
295
+ var from = "";
296
+ if (!targetUrl.includes("from=")) {
297
+ from = "from=newMall";
298
+ urlParams.from = "newMall";
299
+ }
300
+ var currentPage = window.location.hash
301
+ ? (_b = window.location.hash.match(/#([^?]*)/)) === null || _b === void 0 ? void 0 : _b[1]
302
+ : "/";
303
+ urlParams.fromPage = currentPage;
304
+ if (!noNewWebView) {
305
+ // 新开webview
306
+ urlParams.opentype = "newpage";
307
+ }
308
+ if (webviewType.isNewJuCai) {
309
+ delete urlParams.opentype;
310
+ }
311
+ if (!needTitle && !targetUrl.includes("needtitle=")) {
312
+ // 不显示原生标题栏
313
+ urlParams.needtitle = "0";
314
+ }
315
+ if (targetUrl.includes("#") &&
316
+ (urlParams.opentype || urlParams.needtitle)) {
317
+ // opentype和needtitle处理,需在#号前加
318
+ var tempUrl = targetUrl.split("#");
319
+ var preParams = {};
320
+ if (urlParams.opentype && !tempUrl[0].includes("opentype=")) {
321
+ preParams.opentype = urlParams.opentype;
322
+ }
323
+ if (urlParams.needtitle && !tempUrl[0].includes("needtitle=")) {
324
+ preParams.needtitle = urlParams.needtitle;
325
+ }
326
+ var fromAppTab = sessionStorage.getItem("fromAppTab") || "";
327
+ if (+fromAppTab === 1 && !tempUrl[0].includes("fromAppTab=")) {
328
+ preParams.fromAppTab = "1";
329
+ }
330
+ var urlParamsStr_1 = new URLSearchParams(preParams).toString();
331
+ targetUrl = "".concat(tempUrl[0]).concat(tempUrl[0].includes("?") ? "&" : "?").concat(urlParamsStr_1, "#").concat(tempUrl[1]);
332
+ }
333
+ if (urlParams.opentype) {
334
+ // 新开标识
335
+ urlParams.isInNewWebView = "1";
336
+ }
337
+ /* if (+getSessionStore('fromAppTab') === 1) {
338
+ urlParams.fromAppTab = '1';
339
+ } */
340
+ var urlParamsStr = new URLSearchParams(urlParams).toString();
341
+ var mregeUrl = "".concat(targetUrl).concat(prefix).concat(urlParamsStr);
342
+ console.log("goWebView:", mregeUrl);
343
+ if (webviewType.isNewLeZhuan) {
344
+ window.location.href = mregeUrl;
345
+ }
346
+ else if (webviewType.isNewJuCai) {
347
+ if (utils_1.ios) {
348
+ actionMap.setupWebViewJavascriptBridge(function (bridge) {
349
+ bridge.callHandler("gotoNextPage", {
350
+ needtitle: needTitle ? "1" : "0",
351
+ url: url,
352
+ }, function (data) {
353
+ console.log("goWebview:", data);
354
+ });
355
+ });
356
+ }
357
+ else {
358
+ // {“pageId”: “2804”, “needLogin”: “true”, “title”: “网页标题”, “url”: “http://www.baidu.com”}
359
+ // pageId=2804表示跳转客户端默认webview,pageId=5002跳转客户端无标题webview;needLogin=1表示需要先登录委托,未登录委托情况下会先跳转客户端委托登录
360
+ actionMap.callJuCaiAction("goWebViewPage", {
361
+ pageId: needTitle ? "2804" : "5002",
362
+ url: url,
363
+ });
364
+ }
365
+ }
366
+ else {
367
+ var paramsObj = {
368
+ indexUrl: url,
369
+ };
370
+ paramsObj = JSON.stringify(paramsObj);
371
+ if (utils_1.ios) {
372
+ actionMap.loadIOSNative("objc://openNewBusiness/$?".concat(paramsObj));
373
+ }
374
+ else {
375
+ (_c = window.jtoJHandle) === null || _c === void 0 ? void 0 : _c.openNewBusiness(paramsObj);
376
+ }
377
+ }
378
+ },
379
+ /**
380
+ * 获取客户端版本号
381
+ */
382
+ getVersion: function () {
383
+ var ua = navigator.userAgent.toLowerCase();
384
+ var regex = "";
385
+ if (webviewType.isNewLeZhuan) {
386
+ regex = utils_1.ios ? /cfzq_lezhuan_([\d.]+)/ : /cfzq_lezhuan([\d.]+)/;
387
+ }
388
+ else if (webviewType.isNewJuCai) {
389
+ regex = /cfzq_jucai_([\d.]+)/;
390
+ }
391
+ var match = ua.match(regex);
392
+ console.log(match, "===match===");
393
+ if (match) {
394
+ var version = match[1];
395
+ return version;
396
+ }
397
+ else {
398
+ console.warn("version没有找到匹配项");
399
+ return "0.0.0";
400
+ }
401
+ },
402
+ /**
403
+ * 设置原生状态栏颜色(乐赚客户端)
404
+ * @param {object} params
405
+ * @param {string} params.color 状态栏背景颜色,如#ff0000
406
+ * @param {string} params.wordColorStyle 状态栏文字颜色,0 白色,1 黑色
407
+ */
408
+ setStatusBar: function (params) {
409
+ return __awaiter(this, void 0, void 0, function () {
410
+ var data;
411
+ return __generator(this, function (_a) {
412
+ if (webviewType.isNewLeZhuan) {
413
+ if (compareVersion("6.1.0", this.getVersion()) === 1) {
414
+ console.log("---版本号低,无法设置状态栏颜色---");
415
+ return [2 /*return*/];
416
+ }
417
+ data = {
418
+ statusColor: params.color,
419
+ isDark: params.wordColorStyle === "1",
420
+ };
421
+ actionMap.callAction(933, data);
422
+ }
423
+ else if (webviewType.isCRH) {
424
+ if (utils_1.ios) {
425
+ actionMap.loadIOSNative("objc://setAppBackgroundColor/$?".concat(params.color));
426
+ }
427
+ else if (window.jtoJHandle) {
428
+ window.jtoJHandle.setAppBackgroundColor(params.color);
429
+ }
430
+ }
431
+ return [2 /*return*/];
432
+ });
433
+ });
434
+ },
435
+ /**
436
+ * 分享
437
+ * @param {object} params
438
+ * @param {string} params.img_url 分享展示的图片
439
+ * @param {string} params.url 分享链接
440
+ * @param {string} params.title 标题
441
+ * @param {string} params.message 内容
442
+ */
443
+ share: function (params) {
444
+ var _this = this;
445
+ if (webviewType.isLeZhuan) {
446
+ var shareParam = {
447
+ img_url: params.img_url || cx_share_png_1.default,
448
+ url: params.url,
449
+ title: params.title,
450
+ message: params.message,
451
+ };
452
+ if (webviewType.isNewLeZhuan) {
453
+ actionMap.callAction(900, shareParam, "");
454
+ }
455
+ else {
456
+ crh_app_sdk_cxzq_1.default.businessAlertView("http://action:900/?target=2&param=".concat(encodeURIComponent(JSON.stringify(shareParam))));
457
+ }
458
+ }
459
+ else {
460
+ return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
461
+ return __generator(this, function (_a) {
462
+ resolve({
463
+ error_no: "-3",
464
+ error_info: "当前APP不支持分享",
465
+ });
466
+ return [2 /*return*/];
467
+ });
468
+ }); });
469
+ }
470
+ },
471
+ };