crh-jssdk 0.0.1
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/common/utils.ts +23 -0
- package/business/index.ts +1 -0
- package/business/mall/crh-app-sdk.ts +70 -0
- package/business/mall/index.ts +27 -0
- package/declare.d.ts +25 -0
- package/index.ts +22 -0
- package/package.json +14 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
//调用sdk通用方法
|
|
3
|
+
const common = (promise, name) => {
|
|
4
|
+
if (!promise) {
|
|
5
|
+
return () => Promise.resolve([{ code: '-1', data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` }])
|
|
6
|
+
}
|
|
7
|
+
return async (...params) => {
|
|
8
|
+
console.log(`方法:${name};请求参数如下:${JSON.stringify(params)}`)
|
|
9
|
+
const res = await promise(...params);
|
|
10
|
+
return res
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
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/)
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
common,
|
|
21
|
+
empty,
|
|
22
|
+
ios
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as MALL } from './mall'
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ios } from '../common/utils'
|
|
2
|
+
|
|
3
|
+
//解析opStation
|
|
4
|
+
const parsOpStation = (json) => {
|
|
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
|
+
export default {
|
|
30
|
+
// 获取设备信息
|
|
31
|
+
getDeviceInfo(fn?: <T>(v: T) => {}) {
|
|
32
|
+
if (ios) {
|
|
33
|
+
window.location.href = "objc://getDeviceInfo/?getDeviceInfoCallBack";
|
|
34
|
+
} else {
|
|
35
|
+
window.jtoJHandle.getDeviceInfo("getDeviceInfoCallBack");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
window.getDeviceInfoCallBack = function(res: any) {
|
|
39
|
+
console.log("getDeviceInfo-sdk", res);
|
|
40
|
+
let data: any = {};
|
|
41
|
+
try {
|
|
42
|
+
data = JSON.parse(res);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
res = parsOpStation(res);
|
|
45
|
+
data = JSON.parse(res);
|
|
46
|
+
}
|
|
47
|
+
let real_res = {
|
|
48
|
+
device_id: data.deviceId || "",
|
|
49
|
+
app_name: data.appName || "",
|
|
50
|
+
net_type: data.appnettype || "",
|
|
51
|
+
mac: data.mac || "",
|
|
52
|
+
brand: data.brand || "",
|
|
53
|
+
mobile_tel: data.mobileNo || "",
|
|
54
|
+
os_version: data.osVersion || "",
|
|
55
|
+
imsi: data.imsi || "",
|
|
56
|
+
lanip: data.lanIP || "",
|
|
57
|
+
app_version: data.appVersion || "",
|
|
58
|
+
sdk_version: data.sdkVersion || "",
|
|
59
|
+
opStation: data.opStation || "",
|
|
60
|
+
};
|
|
61
|
+
// if (data.appVersion && navigator.userAgent.indexOf("crhapp") > -1) {
|
|
62
|
+
// this.the_login_register_req.device_info.app_ver = data.appVersion;
|
|
63
|
+
// } else {
|
|
64
|
+
// this.the_login_register_req.device_info.app_ver = data.sdkVersion;
|
|
65
|
+
// }
|
|
66
|
+
console.log(real_res, "real_res");
|
|
67
|
+
fn && fn(real_res);
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc 商城sdk
|
|
3
|
+
* 1 光大app sdk;2:财人汇app sdk
|
|
4
|
+
*/
|
|
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
|
+
|
|
13
|
+
export default class MALL {
|
|
14
|
+
public sdkType: number; // 初始化确定是哪种sdk 财人汇 光大 同花顺
|
|
15
|
+
|
|
16
|
+
constructor(sdkType: number) {
|
|
17
|
+
this.sdkType = sdkType; // 1 财人汇 2 光大 3 同花顺 4 大智慧
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//获取设备信息
|
|
21
|
+
public getDeviceInfo(fn) {
|
|
22
|
+
if (!getDeviceInfo[this.sdkType]) {
|
|
23
|
+
return empty("getDeviceInfo");
|
|
24
|
+
}
|
|
25
|
+
return getDeviceInfo[this.sdkType](fn);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/declare.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// *.d.ts文件中
|
|
4
|
+
declare interface Window {
|
|
5
|
+
browser: any;
|
|
6
|
+
getDeviceInfoCallBack: any;
|
|
7
|
+
svideoCheckCallback: any;
|
|
8
|
+
faceVertifyCallBack: any;
|
|
9
|
+
sensorsTrack: any;
|
|
10
|
+
sensors: any;
|
|
11
|
+
baiDuStack: any;
|
|
12
|
+
YDRZAuthLogin: any;
|
|
13
|
+
CryptoJS: any;
|
|
14
|
+
Sdk: any;
|
|
15
|
+
cbas3: any;
|
|
16
|
+
meteor: any;
|
|
17
|
+
jtoJHandle: any;
|
|
18
|
+
hasDialogDownloadFlag: any;
|
|
19
|
+
hasStartAISvideoFlag: any;
|
|
20
|
+
vuelog: (...args: any[]) => void;
|
|
21
|
+
app_height: number;
|
|
22
|
+
MobileDetect: any;
|
|
23
|
+
execNew: any;
|
|
24
|
+
initJsBridge: any;
|
|
25
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MALL
|
|
3
|
+
} from './business/index'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function JSSDK(system, sdkType) {
|
|
7
|
+
|
|
8
|
+
let System: any = null
|
|
9
|
+
if (system === 'mall') {
|
|
10
|
+
System = MALL
|
|
11
|
+
}
|
|
12
|
+
return class extends System {
|
|
13
|
+
constructor(option) {
|
|
14
|
+
super(option)
|
|
15
|
+
this.sdkType = sdkType
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export default JSSDK
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crh-jssdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "crh-jssdk",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"author": "crh-fe",
|
|
13
|
+
"license": "ISC"
|
|
14
|
+
}
|