crh-jssdk 0.0.2 → 0.0.4

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.
@@ -1,23 +1,60 @@
1
-
2
1
  //调用sdk通用方法
3
- const common = (promise, name) => {
2
+ const common = (promise: any, name: string) => {
4
3
  if (!promise) {
5
- return () => Promise.resolve([{ code: '-1', data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` }])
4
+ return () =>
5
+ Promise.resolve([
6
+ {
7
+ code: "-1",
8
+ data: null,
9
+ msg: `jssdk暂不支持${name}方法, 请与管理员联系`,
10
+ },
11
+ ]);
6
12
  }
7
- return async (...params) => {
8
- console.log(`方法:${name};请求参数如下:${JSON.stringify(params)}`)
13
+ return async (...params: any[]) => {
14
+ console.log(`方法:${name};请求参数如下:${JSON.stringify(params)}`);
9
15
  const res = await promise(...params);
10
- return res
16
+ return res;
17
+ };
18
+ };
19
+
20
+ const empty = (name: string) =>
21
+ Promise.resolve([
22
+ { code: "-1", data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` },
23
+ ]);
24
+
25
+ const u: string = navigator.userAgent as string;
26
+ const ios: boolean = <boolean>!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
27
+
28
+ function checkIsHarmonyOS() {
29
+ try {
30
+ if (window.HarmonyBridge && window.HarmonyBridge.callJsHandler) {
31
+ return true;
32
+ }
33
+ } catch (e) {
34
+ console.log("获取鸿蒙标识出错");
35
+ console.log(e);
11
36
  }
37
+ return false;
12
38
  }
13
39
 
14
- const empty = (name) => Promise.resolve([{ code: '-1', data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` }])
15
-
16
- var u: string = navigator.userAgent as string
17
- var ios: boolean = <boolean>!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
40
+ /**
41
+ * @desc 调用鸿蒙方法
42
+ * @param key
43
+ * @param data
44
+ */
45
+ function harmonyCallJsHandler(key: string, data: string | object) {
46
+ var params = {};
47
+ try {
48
+ if (typeof data === "string") {
49
+ params = JSON.parse(data);
50
+ } else {
51
+ params = data;
52
+ }
53
+ } catch (_) {
54
+ params = {};
55
+ }
56
+ console.log('调用 HarmonyBridge: ', key, JSON.stringify(params))
57
+ window.HarmonyBridge.callJsHandler(key, JSON.stringify(params))
58
+ }
18
59
 
19
- export {
20
- common,
21
- empty,
22
- ios
23
- }
60
+ export { common, empty, ios, checkIsHarmonyOS, harmonyCallJsHandler };
@@ -0,0 +1,426 @@
1
+ import { ios } from "../common/utils";
2
+
3
+ //解析opStation
4
+ const parsOpStation = (json: string) => {
5
+ // 匹配任何键名为字符串并且对应值为字符串的情况
6
+ const regex = /"([^"]+)":"({[^}]+})"/g;
7
+ let result = json;
8
+
9
+ // 循环匹配所有键值对
10
+ let match;
11
+ while ((match = regex.exec(json)) !== null) {
12
+ const key = match[1];
13
+ const valueStr = match[2];
14
+ try {
15
+ const valueObj = JSON.parse(valueStr);
16
+ // 将解析后的对象替换原始字符串中的对应键值对
17
+ result = result.replace(
18
+ `"${key}":"${valueStr}"`,
19
+ `"${key}":${JSON.stringify(valueObj)}`
20
+ );
21
+ } catch (e) {
22
+ console.error(`转为json格式有误,key为=> "${key}":`, e);
23
+ }
24
+ }
25
+
26
+ return result;
27
+ };
28
+
29
+ const APPID = 'b5bae4daa01aa0c2';
30
+
31
+ // webview类型
32
+ const webviewType = (() => {
33
+ const ua = navigator.userAgent;
34
+ const isWTSDK = ua.includes('cxzqwtsdk');
35
+ return {
36
+ isWTSDK,
37
+ // 新乐赚
38
+ isNewLeZhuan: !isWTSDK && ua.toLowerCase().includes('lezhuan'),
39
+ // 新聚财
40
+ isNewJuCai:
41
+ !isWTSDK &&
42
+ !ua.includes('crhsdk') &&
43
+ (ua.includes('Android_CFZQ_JUCAI') || ua.includes('iOS_CFZQ_JUCAI')),
44
+ // 老聚财
45
+ isOldJuCai: ua.includes('crhsdk') && !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 {
58
+ window.location.href = str;
59
+ }
60
+ },
61
+ // 财信调用action路径
62
+ callAction(actionId: string | number, param?: any, cbFunName?: any) {
63
+ let url = `http://action:${actionId}/?target=2`;
64
+ if (param) {
65
+ const paramStr = JSON.stringify(param);
66
+ url += `&param=${encodeURIComponent(paramStr)}`;
67
+ }
68
+ if (cbFunName) {
69
+ url += `&callback=${cbFunName}`;
70
+ }
71
+ console.log('callAction:', url);
72
+ this.onJsOverrideUrlLoading(url);
73
+ },
74
+ // 财信聚财通过js bridge调用app接口
75
+ setupWebViewJavascriptBridge(callback: any) {
76
+ if (window.WebViewJavascriptBridge) {
77
+ callback(window.WebViewJavascriptBridge);
78
+ } else {
79
+ document.addEventListener(
80
+ 'WebViewJavascriptBridgeReady',
81
+ () => {
82
+ callback(window.WebViewJavascriptBridge);
83
+ },
84
+ false
85
+ );
86
+ if (!/android/gi.test(navigator.userAgent)) {
87
+ if (window.WebViewJavascriptBridge) {
88
+ callback(window.WebViewJavascriptBridge);
89
+ return;
90
+ }
91
+ if (window.WVJBCallbacks) {
92
+ window.WVJBCallbacks.push(callback);
93
+ return;
94
+ }
95
+ window.WVJBCallbacks = [callback];
96
+ const WVJBIframe = document.createElement('iframe');
97
+ WVJBIframe.style.display = 'none';
98
+ WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
99
+ document.documentElement.appendChild(WVJBIframe);
100
+ setTimeout(() => {
101
+ document.documentElement.removeChild(WVJBIframe);
102
+ }, 0);
103
+ }
104
+ }
105
+ },
106
+ // 聚财Android调用app接口
107
+ callAndroidActionOfJvCai(param: any) {
108
+ const paramStr = JSON.stringify(param);
109
+ if (window.mobile) {
110
+ window.mobile.onActionEvent(paramStr);
111
+ }
112
+ },
113
+ // 财信调用聚财方法
114
+ callJuCaiAction(funName: any, data?: any, callback?: any) {
115
+ console.log('callJuCaiAction:', funName, data, callback);
116
+ if (ios) {
117
+ this.setupWebViewJavascriptBridge((bridge: any) => {
118
+ bridge.callHandler(funName, data, window[callback]);
119
+ });
120
+ } else {
121
+ const param: any = {
122
+ funName,
123
+ callbackFunName: callback
124
+ };
125
+ if (data) {
126
+ param.data = data;
127
+ }
128
+ this.callAndroidActionOfJvCai(param);
129
+ }
130
+ },
131
+ /**
132
+ * iOS客户端方法加载函数(老乐赚老聚财)
133
+ * @param {string} url
134
+ */
135
+ loadIOSNative(url: string) {
136
+ let iFrame: any = '';
137
+ iFrame = document.createElement('iframe');
138
+ iFrame.setAttribute('src', url);
139
+ iFrame.setAttribute('style', 'display:none;');
140
+ iFrame.setAttribute('height', '0px');
141
+ iFrame.setAttribute('width', '0px');
142
+ iFrame.setAttribute('frameborder', '0');
143
+ document.body.appendChild(iFrame);
144
+ iFrame.parentNode.removeChild(iFrame);
145
+ iFrame = null;
146
+ }
147
+ }
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
+ //是否在app内
163
+ isApp() {
164
+ const ua = navigator.userAgent;
165
+ const isAppFlags = [
166
+ 'crhsdk',
167
+ 'crhapp',
168
+ 'cfzqsdk',
169
+ 'LeZhuan',
170
+ 'LEZHUAN',
171
+ 'Android_CFZQ_JUCAI',
172
+ 'iOS_CFZQ_JUCAI'
173
+ ];
174
+ return isAppFlags.some(flag => ua.includes(flag));
175
+ },
176
+ // 拦截Android物理返回键事件,并回调给前端 --- 仅安卓
177
+ interceptBack(callback: Function) {
178
+ window.jtoJHandle.interceptBack('interceptBackCallBack')
179
+ window.interceptBackCallBack = function (e: any) {
180
+ callback && callback(e)
181
+ }
182
+ },
183
+
184
+ // 关闭页面 closeSJKH
185
+ closeSJKH() {
186
+ if (webviewType.isNewLeZhuan) {
187
+ actionMap.callAction(3);
188
+ } else if (webviewType.isNewJuCai) { // iphone
189
+ actionMap.callJuCaiAction('closePage', {});
190
+ } else if (ios) { // iphone
191
+ window.location.href = 'objc://callIOSQuit/';
192
+ } else {
193
+ window.jtoJHandle.closeSJKH();
194
+ }
195
+ },
196
+ /**
197
+ * 通过打开新的webview打开外部链接
198
+ */
199
+ goWebview(pageId: string | number, url: string, callback: Function) {
200
+ const jsonObj = {
201
+ indexUrl: url,
202
+ uploadPicUrl: '',
203
+ cookieDomain: '',
204
+ closeBusiness: 'closeCallBack',
205
+ module: '',
206
+ identifier: 'zt'
207
+ };
208
+ const jsonStr = JSON.stringify(jsonObj);
209
+ if (webviewType.isNewLeZhuan) {
210
+ actionMap.callAction(207, { pageId: pageId || '1', needLogin: '0' });
211
+ } else if (webviewType.isNewJuCai) {
212
+ actionMap.callJuCaiAction('gotoClientPage', { pageId: ios ? String(pageId) : pageId, needLogin: '0' });
213
+ } else if (ios) { // iphone
214
+ actionMap.loadIOSNative(`objc://openNewBusiness/$?${jsonStr}`);
215
+ } else {
216
+ window.jtoJHandle.openNewBusiness(jsonStr);
217
+ }
218
+ },
219
+ /**
220
+ * 获取用户信息
221
+ */
222
+ getUser() {
223
+ return new Promise(async resolve => {
224
+ window.getUserInfoCB = (actionId: any, response: any = {}) => {
225
+ let isLogin = false;
226
+ let isPhoneLogin = false;
227
+ const statusInfo = response;
228
+ console.log('getUserInfoCB:', actionId, response);
229
+ if (+response.ret !== 0 && !response.login_status) {
230
+ console.warn('调用失败!', 'getUserInfoCB');
231
+ } else {
232
+ if (response.isTradeLogin === 1) {
233
+ console.log('交易已登录');
234
+ isLogin = true;
235
+ }
236
+ if (response.isSnsLogin === 1) {
237
+ console.log('手机号已登录');
238
+ isPhoneLogin = true;
239
+ }
240
+ }
241
+ resolve({
242
+ ...response
243
+ });
244
+ };
245
+ if (webviewType.isNewLeZhuan) {
246
+ actionMap.callAction(909, {}, 'getUserInfoCB');
247
+ } else if (webviewType.isNewJuCai) {
248
+ const data: any = await this.getDeviceInfo();
249
+ // window.getUserInfoCB(null, data);
250
+ resolve({
251
+ ...data
252
+ });
253
+ } else if (webviewType.isOldJuCai) {
254
+ // 老聚财
255
+ const res:any = await this.jcLogin();
256
+ resolve({
257
+ ...res
258
+ });
259
+ } else {
260
+ this.businessAlertView('http://action:909/?target=2&callback=getUserInfoCB');
261
+ }
262
+ });
263
+ },
264
+ // 获取客户端用户和设备信息
265
+ getDeviceInfo(type = 'fetch') {
266
+ console.log('getDeviceInfo----');
267
+ return new Promise(async resolve => {
268
+ window.getDeviceInfoCB = (actionId: any, info = {}) => {
269
+ console.log('getDeviceInfo回调:', actionId, info);
270
+ /**
271
+ * info = "{"appName":"lezhuan","channel":"38106","clientId":"200030002048","deviceId":"dd2375d70947a02a","isp":"CU","mac":"1CB796216DC3","mobileType":"Android","model":"SEA-AL10","netType":"wifi","osVer":"10","phoneNo":"18888888888","resolution":"1080*2259","ret":0,"version":"5.7.0","appConfig":{"canShowMonitor":1,"dailybill":1,"globalQuotation":0,"imSwitch":1,"isShowStockNewsTag":1,"magicNineTurn":1,"onekeyLogin":1,"profitLossFlag":1,"searchMethod":2,"stockDetailNews":1},"grayRelease":{"WEALTH_TAB":0,"quotationNews":1,"CONDITION_SHEET":1}}"
272
+ */
273
+ if (typeof info === 'string') {
274
+ info = JSON.parse(info);
275
+ }
276
+ resolve({
277
+ ...info,
278
+ });
279
+ delete window.getDeviceInfoCB;
280
+ };
281
+ if (webviewType.isNewLeZhuan) {
282
+ actionMap.callAction(903, {}, 'getDeviceInfoCB');
283
+ } else if (webviewType.isNewJuCai) {
284
+ const data: any = await this.jcLogin('fetch');
285
+ console.log(data, 'data');
286
+ resolve({ ...data })
287
+ } else {
288
+ if (ios) {
289
+ actionMap.loadIOSNative('objc://getDeviceInfo/?getDeviceInfoCB');
290
+ } else {
291
+ window.jtoJHandle?.getDeviceInfo('getDeviceInfoCB');
292
+ }
293
+ }
294
+ });
295
+ },
296
+ // 聚财获取登录信息或者未登录调起登录,调登录type传callback_after_login
297
+ jcLogin(type = 'fetch') {
298
+ return new Promise(resolve => {
299
+ if (webviewType.isNewJuCai) {
300
+ const data = { info_type: 'wt', call_type: type, key_type: '' };
301
+ actionMap.setupWebViewJavascriptBridge((bridge: any) => {
302
+ bridge.callHandler('getUserInfoByRsa', data, (info: any) => {
303
+ console.log('getNewJcDeviceInfoCB:', info);
304
+ const deviceInfo:any = {};
305
+ const mobileInfo = info.mobile_hardware
306
+ ? info.mobile_hardware.replace('HDInfo=', '').split(',')
307
+ : [];
308
+ mobileInfo.forEach((item: any) => {
309
+ const index = item.indexOf(':');
310
+ deviceInfo[item.substring(0, index)] = item.substring(index + 1);
311
+ });
312
+ console.log('deviceInfo:', deviceInfo);
313
+ resolve({
314
+ ...info,
315
+ deviceInfo,
316
+ isLogin: info.login_status === '1',
317
+ token: info.param,
318
+ fundAccount: '',
319
+ mobile: deviceInfo.RMRN || ''
320
+ });
321
+ });
322
+ });
323
+ } else if (webviewType.isOldJuCai) {
324
+ window.oldJuCaiLoginCB = (token: any) => {
325
+ console.log('oldJuCaiLoginCB:', token);
326
+ resolve({
327
+ isLogin: !!token,
328
+ token: JSON.parse(JSON.stringify(token)),
329
+ fundAccount: '',
330
+ mobile: ''
331
+ });
332
+ };
333
+ if (ios) {
334
+ window.location.href = 'objc://getUser/?oldJuCaiLoginCB';
335
+ } else if (window.jtoJHandle) {
336
+ window.jtoJHandle.getUser('oldJuCaiLoginCB');
337
+ }
338
+ }
339
+ });
340
+ },
341
+ // app各种方法:交易密码登录框、银证转账充值等。
342
+ // 参数格式:http://action:actionID/?target=tType&callback=funName&param=requestJSON
343
+ businessAlertView(url: string, callback?: any) {
344
+ console.log('businessAlertView:', url, callback);
345
+ if (ios) {
346
+ if (callback) {
347
+ url = `${url}$?${callback}`;
348
+ }
349
+ actionMap.loadIOSNative(`objc://businessAlertView/$?${url}`);
350
+ } else if (window.jtoJHandle) {
351
+ if (callback) {
352
+ window.jtoJHandle.businessAlertView(url, callback);
353
+ } else {
354
+ window.jtoJHandle.businessAlertView(url);
355
+ }
356
+ } else {
357
+ }
358
+ },
359
+ // 获取交易登录的token(弹出登录框)
360
+ getTradeLoginToken(appid?: string) {
361
+ const tradeParam = { appId: appid || APPID };
362
+ console.log('tradeParam:', tradeParam);
363
+ return new Promise(async resolve => {
364
+ // 乐赚交易登录回调获取token准备传入u001
365
+ window.getTradeLoginTokenCB = (actionId: any, response:any) => {
366
+ console.log('getTradeLoginTokenCB:', actionId, response);
367
+ if (response.ret === 0) {
368
+ resolve(response.token);
369
+ } else {
370
+ resolve('');
371
+ }
372
+ delete window.getTradeLoginTokenCB;
373
+ };
374
+ if (webviewType.isNewLeZhuan) {
375
+ actionMap.callAction(209, tradeParam, 'getTradeLoginTokenCB');
376
+ } else if (webviewType.isNewJuCai) {
377
+ const res: any = await this.getDeviceInfo();
378
+ console.log(res, 'res')
379
+ if (!res.isLogin) {
380
+ const jcLoginRes: any = await this.jcLogin('callback_after_login');
381
+ resolve(jcLoginRes.token);
382
+ } else {
383
+ resolve(res.token);
384
+ }
385
+ } else if (webviewType.isOldJuCai) {
386
+ const jcLoginRes: any = await this.jcLogin('callback_after_login');
387
+ resolve(jcLoginRes.token);
388
+ } else {
389
+ this.businessAlertView(
390
+ `http://action:209/?target=2&callback=getTradeLoginTokenCB&param=${encodeURIComponent(
391
+ JSON.stringify(tradeParam)
392
+ )}`
393
+ );
394
+ }
395
+ });
396
+ },
397
+ /**
398
+ * 获取手机号token
399
+ * @returns {string} token
400
+ */
401
+ getPhoneToken() {
402
+ return new Promise(async resolve => {
403
+ window.communityLoginCB = (actionId: any, response: any) => {
404
+ console.log(`社区token的值:`, actionId, response.token);
405
+ if (response.ret === 0) {
406
+ resolve(`${response.token},${APPID}`);
407
+ } else {
408
+ resolve('');
409
+ }
410
+ };
411
+ const communityParam = { appId: APPID, tokenRetry: true };
412
+ if (webviewType.isNewLeZhuan) {
413
+ actionMap.callAction(229, communityParam, 'communityLoginCB');
414
+ } else if (webviewType.isNewJuCai) {
415
+ const res: any = await this.getDeviceInfo();
416
+ resolve(res.token);
417
+ } else {
418
+ this.businessAlertView(
419
+ `http://action:229/?target=2&callback=communityLoginCB&param=${encodeURIComponent(
420
+ JSON.stringify(communityParam)
421
+ )}`
422
+ );
423
+ }
424
+ });
425
+ }
426
+ };
@@ -1,7 +1,7 @@
1
- import { ios } from '../common/utils'
1
+ import { ios, checkIsHarmonyOS, harmonyCallJsHandler } from "../common/utils";
2
2
 
3
3
  //解析opStation
4
- const parsOpStation = (json) => {
4
+ const parsOpStation = (json: string) => {
5
5
  // 匹配任何键名为字符串并且对应值为字符串的情况
6
6
  const regex = /"([^"]+)":"({[^}]+})"/g;
7
7
  let result = json;
@@ -31,11 +31,15 @@ export default {
31
31
  getDeviceInfo(fn?: <T>(v: T) => {}) {
32
32
  if (ios) {
33
33
  window.location.href = "objc://getDeviceInfo/?getDeviceInfoCallBack";
34
+ } else if (checkIsHarmonyOS()) {
35
+ harmonyCallJsHandler("getDeviceInfo", {
36
+ callback: "getDeviceInfoCallBack",
37
+ });
34
38
  } else {
35
39
  window.jtoJHandle.getDeviceInfo("getDeviceInfoCallBack");
36
40
  }
37
41
 
38
- window.getDeviceInfoCallBack = function(res: any) {
42
+ window.getDeviceInfoCallBack = function (res: any) {
39
43
  console.log("getDeviceInfo-sdk", res);
40
44
  let data: any = {};
41
45
  try {
@@ -67,4 +71,89 @@ export default {
67
71
  fn && fn(real_res);
68
72
  };
69
73
  },
74
+
75
+ // 拦截Android物理返回键事件,并回调给前端 --- 仅安卓 鸿蒙
76
+ interceptBack(callback: Function) {
77
+ if (checkIsHarmonyOS()) {
78
+ harmonyCallJsHandler("interceptBack", {
79
+ callback: "interceptBackCallBack",
80
+ });
81
+ } else {
82
+ window.jtoJHandle.interceptBack('interceptBackCallBack')
83
+ }
84
+
85
+ window.interceptBackCallBack = function (e: any) {
86
+ callback && callback(e)
87
+ }
88
+ },
89
+
90
+ // 关闭页面 closeSJKH
91
+ callQuit() {
92
+ if (ios) {
93
+ window.location.href = "objc://callIOSQuit";
94
+ } else if (checkIsHarmonyOS()) {
95
+ harmonyCallJsHandler("closeSJKH", '');
96
+ } else {
97
+ window.jtoJHandle.interceptBack('closeSJKH')
98
+ }
99
+ },
100
+
101
+ goWebview(title: string, url: string, callback: Function) {
102
+ const params = {
103
+ title: title,
104
+ url: url,
105
+ callback: 'openOwnPageCallBack'
106
+ }
107
+ if (ios) {
108
+ window.location.href = `objc://openOwnPage/$?${JSON.stringify(params)}"`;
109
+ } else if (checkIsHarmonyOS()) {
110
+ harmonyCallJsHandler("openOwnPage", params);
111
+ } else {
112
+ window.jtoJHandle.openOwnPage(JSON.stringify(params))
113
+ }
114
+ window.openOwnPageCallBack = function (e: any) {
115
+ callback && callback(e)
116
+ }
117
+ },
118
+ // 获取用户信息
119
+ getUser() {
120
+ return new Promise((resolve) => {
121
+ if (ios) {
122
+ window.location.href = "objc://getUser/?getUserCallBack";
123
+ } else if (checkIsHarmonyOS()) {
124
+ harmonyCallJsHandler("getUser", {
125
+ callback: "getUserCallBack",
126
+ });
127
+ } else if (window.jtoJHandle) {
128
+ window.jtoJHandle.getUser("getUserCallBack");
129
+ }
130
+ window.getUserInfoCallBack = function(account = "", pwd = "") {
131
+ console.log("getUser-sdk", account, pwd);
132
+ resolve({
133
+ account,
134
+ pwd,
135
+ });
136
+ };
137
+ });
138
+ },
139
+ // 爱建统一登录
140
+ callOtherLogin() {
141
+ return new Promise((resolve) => {
142
+ if (ios) {
143
+ window.location.href = "objc://callOtherLogin/?callOtherLoginCallBack";
144
+ } else if (checkIsHarmonyOS()) {
145
+ harmonyCallJsHandler("callOtherLogin", {
146
+ callback: "callOtherLoginCallBack",
147
+ });
148
+ } else if (window.jtoJHandle) {
149
+ window.jtoJHandle.callOtherLogin("callOtherLoginCallBack");
150
+ }
151
+ window.callOtherLoginCallBack = function(loginInfo: object) {
152
+ console.log("callOtherLogin-sdk", loginInfo);
153
+ resolve({
154
+ loginInfo
155
+ });
156
+ };
157
+ });
158
+ },
70
159
  };
@@ -1,27 +1,72 @@
1
1
  /**
2
2
  * @desc 商城sdk
3
- * 1 光大app sdk;2:财人汇app sdk
3
+ * 1 财人汇app sdk
4
4
  */
5
5
  import { common, empty } from "../common/utils.js";
6
- import CrhAppSdk from "./crh-app-sdk.js"; //财人汇app sdk
7
-
8
- const getDeviceInfo = {
9
- //获取设备信息
10
- 2: (...params) => common(CrhAppSdk.getDeviceInfo, "getDeviceInfo")(...params),
11
- };
12
6
 
13
7
  export default class MALL {
14
- public sdkType: number; // 初始化确定是哪种sdk 财人汇 光大 同花顺
8
+ public sdkType: number; // 初始化确定是哪种sdk 财人汇
9
+ public sdkObj: any; //具体的sdk对象
15
10
 
16
11
  constructor(sdkType: number) {
17
- this.sdkType = sdkType; // 1 财人汇 2 光大 3 同花顺 4 大智慧
12
+ this.sdkType = sdkType; // 1 财人汇
13
+ }
14
+
15
+ public async initSdk() {
16
+ console.log("start initSdk");
17
+ if (+this.sdkType === 1) {
18
+ this.sdkObj = (await import("./crh-app-sdk")).default;
19
+ } else if (+this.sdkType === 2) {
20
+ this.sdkObj = (await import("./crh-app-sdk-cxzq")).default;
21
+ }
22
+ console.log("sdk初始化了", this.sdkType);
18
23
  }
19
24
 
20
25
  //获取设备信息
21
- public getDeviceInfo(fn) {
22
- if (!getDeviceInfo[this.sdkType]) {
26
+ public getDeviceInfo(fn: <T>(v: T) => {}) {
27
+ if (!this.sdkObj.getDeviceInfo) {
23
28
  return empty("getDeviceInfo");
24
29
  }
25
- return getDeviceInfo[this.sdkType](fn);
30
+ return this.sdkObj.getDeviceInfo(fn);
31
+ }
32
+
33
+ //拦截Android物理返回键事件,并回调给前端 --- 仅安卓 鸿蒙
34
+ public interceptBack(fn: <T>(v: T) => {}) {
35
+ if (!this.sdkObj.interceptBack) {
36
+ return empty("interceptBack");
37
+ }
38
+ return this.sdkObj.interceptBack(fn);
39
+ }
40
+
41
+ //关闭页面
42
+ public closeSJKH(fn: <T>(v: T) => {}) {
43
+ if (!this.sdkObj.closeSJKH) {
44
+ return empty("closeSJKH");
45
+ }
46
+ return this.sdkObj.closeSJKH(fn);
47
+ }
48
+
49
+ //打开新页面
50
+ public openOwnPage(fn: <T>(v: T) => {}) {
51
+ if (!this.sdkObj.openOwnPage) {
52
+ return empty("openOwnPage");
53
+ }
54
+ return this.sdkObj.openOwnPage(fn);
55
+ }
56
+
57
+ //获取用户信息
58
+ public getUserInfo(fn: <T>(v: T) => {}) {
59
+ if (!this.sdkObj.getUserInfo) {
60
+ return empty("getUserInfo");
61
+ }
62
+ return this.sdkObj.getUserInfo(fn);
63
+ }
64
+
65
+ //调起客户端登录
66
+ public callOtherLogin(fn: <T>(v: T) => {}) {
67
+ if (!this.sdkObj.callOtherLogin) {
68
+ return empty("callOtherLogin");
69
+ }
70
+ return this.sdkObj.callOtherLogin(fn);
26
71
  }
27
72
  }
package/declare.d.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  declare interface Window {
5
5
  browser: any;
6
6
  getDeviceInfoCallBack: any;
7
+ getUserInfoCallBack: any;
8
+ callOtherLoginCallBack: any;
7
9
  svideoCheckCallback: any;
8
10
  faceVertifyCallBack: any;
9
11
  sensorsTrack: any;
@@ -15,6 +17,7 @@ declare interface Window {
15
17
  cbas3: any;
16
18
  meteor: any;
17
19
  jtoJHandle: any;
20
+ HarmonyBridge: any;
18
21
  hasDialogDownloadFlag: any;
19
22
  hasStartAISvideoFlag: any;
20
23
  vuelog: (...args: any[]) => void;
@@ -22,4 +25,20 @@ declare interface Window {
22
25
  MobileDetect: any;
23
26
  execNew: any;
24
27
  initJsBridge: any;
28
+ interceptBackCallBack:any;
29
+ closeSJKH:any;
30
+ jumpNewPage:any;
31
+ jumpNewPageCallBack:any;
32
+ openOwnPage:any;
33
+ openOwnPageCallBack:any;
34
+ WebViewJavascriptBridge:any;
35
+ WVJBCallbacks:any;
36
+ webkit:any;
37
+ MyWebView:any;
38
+ getUserInfoCB:any;
39
+ getDeviceInfoCB:any;
40
+ oldJuCaiLoginCB:any;
41
+ mobile:any;
42
+ getTradeLoginTokenCB: any;
43
+ communityLoginCB: any;
25
44
  }
package/index.ts CHANGED
@@ -3,14 +3,14 @@ import {
3
3
  } from './business/index'
4
4
 
5
5
 
6
- function JSSDK(system, sdkType) {
6
+ function JSSDK(system: string, sdkType: string) {
7
7
 
8
8
  let System: any = null
9
9
  if (system === 'mall') {
10
10
  System = MALL
11
11
  }
12
12
  return class extends System {
13
- constructor(option) {
13
+ constructor(option: any) {
14
14
  super(option)
15
15
  this.sdkType = sdkType
16
16
  }
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "crh-jssdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "crh-jssdk",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "build": "tsc"
8
8
  },
9
+ "keywords": [
10
+ "typescript"
11
+ ],
9
12
  "publishConfig": {
10
13
  "access": "public"
11
14
  },
package/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  // "incremental": true, /* Enable incremental compilation */
7
7
  "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
8
  "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
+ "lib": ["es2015", "dom"],
9
10
  // "lib": [], /* Specify library files to be included in the compilation. */
10
11
  // "allowJs": true, /* Allow javascript files to be compiled. */
11
12
  // "checkJs": true, /* Report errors in .js files. */