crh-jssdk 0.0.2 → 0.0.3

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,70 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ios = exports.empty = exports.common = void 0;
40
+ //调用sdk通用方法
41
+ var common = function (promise, name) {
42
+ if (!promise) {
43
+ return function () { return Promise.resolve([{ code: '-1', data: null, msg: "jssdk\u6682\u4E0D\u652F\u6301".concat(name, "\u65B9\u6CD5, \u8BF7\u4E0E\u7BA1\u7406\u5458\u8054\u7CFB") }]); };
44
+ }
45
+ return function () {
46
+ var params = [];
47
+ for (var _i = 0; _i < arguments.length; _i++) {
48
+ params[_i] = arguments[_i];
49
+ }
50
+ return __awaiter(void 0, void 0, void 0, function () {
51
+ var res;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ console.log("\u65B9\u6CD5:".concat(name, ";\u8BF7\u6C42\u53C2\u6570\u5982\u4E0B:").concat(JSON.stringify(params)));
56
+ return [4 /*yield*/, promise.apply(void 0, params)];
57
+ case 1:
58
+ res = _a.sent();
59
+ return [2 /*return*/, res];
60
+ }
61
+ });
62
+ });
63
+ };
64
+ };
65
+ exports.common = common;
66
+ var empty = function (name) { return Promise.resolve([{ code: '-1', data: null, msg: "jssdk\u6682\u4E0D\u652F\u6301".concat(name, "\u65B9\u6CD5, \u8BF7\u4E0E\u7BA1\u7406\u5458\u8054\u7CFB") }]); };
67
+ exports.empty = empty;
68
+ var u = navigator.userAgent;
69
+ var ios = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
70
+ exports.ios = ios;
@@ -1,17 +1,17 @@
1
1
 
2
2
  //调用sdk通用方法
3
- const common = (promise, name) => {
3
+ const common = (promise: any, name: string) => {
4
4
  if (!promise) {
5
5
  return () => Promise.resolve([{ code: '-1', data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` }])
6
6
  }
7
- return async (...params) => {
7
+ return async (...params: any[]) => {
8
8
  console.log(`方法:${name};请求参数如下:${JSON.stringify(params)}`)
9
9
  const res = await promise(...params);
10
10
  return res
11
11
  }
12
12
  }
13
13
 
14
- const empty = (name) => Promise.resolve([{ code: '-1', data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` }])
14
+ const empty = (name: string) => Promise.resolve([{ code: '-1', data: null, msg: `jssdk暂不支持${name}方法, 请与管理员联系` }])
15
15
 
16
16
  var u: string = navigator.userAgent as string
17
17
  var ios: boolean = <boolean>!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MALL = void 0;
7
+ var mall_1 = require("./mall");
8
+ Object.defineProperty(exports, "MALL", { enumerable: true, get: function () { return __importDefault(mall_1).default; } });
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var utils_1 = require("../common/utils");
4
+ //解析opStation
5
+ var parsOpStation = function (json) {
6
+ // 匹配任何键名为字符串并且对应值为字符串的情况
7
+ var regex = /"([^"]+)":"({[^}]+})"/g;
8
+ var result = json;
9
+ // 循环匹配所有键值对
10
+ var match;
11
+ while ((match = regex.exec(json)) !== null) {
12
+ var key = match[1];
13
+ var valueStr = match[2];
14
+ try {
15
+ var valueObj = JSON.parse(valueStr);
16
+ // 将解析后的对象替换原始字符串中的对应键值对
17
+ result = result.replace("\"".concat(key, "\":\"").concat(valueStr, "\""), "\"".concat(key, "\":").concat(JSON.stringify(valueObj)));
18
+ }
19
+ catch (e) {
20
+ console.error("\u8F6C\u4E3Ajson\u683C\u5F0F\u6709\u8BEF\uFF0Ckey\u4E3A=> \"".concat(key, "\":"), e);
21
+ }
22
+ }
23
+ return result;
24
+ };
25
+ exports.default = {
26
+ // 获取设备信息
27
+ getDeviceInfo: function (fn) {
28
+ if (utils_1.ios) {
29
+ window.location.href = "objc://getDeviceInfo/?getDeviceInfoCallBack";
30
+ }
31
+ else {
32
+ window.jtoJHandle.getDeviceInfo("getDeviceInfoCallBack");
33
+ }
34
+ window.getDeviceInfoCallBack = function (res) {
35
+ console.log("getDeviceInfo-sdk", res);
36
+ var data = {};
37
+ try {
38
+ data = JSON.parse(res);
39
+ }
40
+ catch (error) {
41
+ res = parsOpStation(res);
42
+ data = JSON.parse(res);
43
+ }
44
+ var real_res = {
45
+ device_id: data.deviceId || "",
46
+ app_name: data.appName || "",
47
+ net_type: data.appnettype || "",
48
+ mac: data.mac || "",
49
+ brand: data.brand || "",
50
+ mobile_tel: data.mobileNo || "",
51
+ os_version: data.osVersion || "",
52
+ imsi: data.imsi || "",
53
+ lanip: data.lanIP || "",
54
+ app_version: data.appVersion || "",
55
+ sdk_version: data.sdkVersion || "",
56
+ opStation: data.opStation || "",
57
+ };
58
+ // if (data.appVersion && navigator.userAgent.indexOf("crhapp") > -1) {
59
+ // this.the_login_register_req.device_info.app_ver = data.appVersion;
60
+ // } else {
61
+ // this.the_login_register_req.device_info.app_ver = data.sdkVersion;
62
+ // }
63
+ console.log(real_res, "real_res");
64
+ fn && fn(real_res);
65
+ };
66
+ },
67
+ };
@@ -1,7 +1,7 @@
1
1
  import { ios } 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;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * @desc 商城sdk
8
+ * 1 光大app sdk;2:财人汇app sdk
9
+ */
10
+ var utils_js_1 = require("../common/utils.js");
11
+ var crh_app_sdk_js_1 = __importDefault(require("./crh-app-sdk.js")); //财人汇app sdk
12
+ var getDeviceInfo = {
13
+ //获取设备信息
14
+ 2: function () {
15
+ var params = [];
16
+ for (var _i = 0; _i < arguments.length; _i++) {
17
+ params[_i] = arguments[_i];
18
+ }
19
+ return (0, utils_js_1.common)(crh_app_sdk_js_1.default.getDeviceInfo, "getDeviceInfo").apply(void 0, params);
20
+ },
21
+ };
22
+ var MALL = /** @class */ (function () {
23
+ function MALL(sdkType) {
24
+ this.sdkType = sdkType; // 1 财人汇 2 光大 3 同花顺 4 大智慧
25
+ }
26
+ //获取设备信息
27
+ MALL.prototype.getDeviceInfo = function (fn) {
28
+ if (!getDeviceInfo[this.sdkType]) {
29
+ return (0, utils_js_1.empty)("getDeviceInfo");
30
+ }
31
+ return getDeviceInfo[this.sdkType](fn);
32
+ };
33
+ return MALL;
34
+ }());
35
+ exports.default = MALL;
@@ -5,9 +5,9 @@
5
5
  import { common, empty } from "../common/utils.js";
6
6
  import CrhAppSdk from "./crh-app-sdk.js"; //财人汇app sdk
7
7
 
8
- const getDeviceInfo = {
8
+ const getDeviceInfo: any = {
9
9
  //获取设备信息
10
- 2: (...params) => common(CrhAppSdk.getDeviceInfo, "getDeviceInfo")(...params),
10
+ 2: (...params: any[]) => common(CrhAppSdk.getDeviceInfo, "getDeviceInfo")(...params),
11
11
  };
12
12
 
13
13
  export default class MALL {
@@ -18,7 +18,7 @@ export default class MALL {
18
18
  }
19
19
 
20
20
  //获取设备信息
21
- public getDeviceInfo(fn) {
21
+ public getDeviceInfo(fn: <T>(v: T) => {}) {
22
22
  if (!getDeviceInfo[this.sdkType]) {
23
23
  return empty("getDeviceInfo");
24
24
  }
package/index.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ var index_1 = require("./business/index");
19
+ function JSSDK(system, sdkType) {
20
+ var System = null;
21
+ if (system === 'mall') {
22
+ System = index_1.MALL;
23
+ }
24
+ return /** @class */ (function (_super) {
25
+ __extends(class_1, _super);
26
+ function class_1(option) {
27
+ var _this = _super.call(this, option) || this;
28
+ _this.sdkType = sdkType;
29
+ return _this;
30
+ }
31
+ return class_1;
32
+ }(System));
33
+ }
34
+ exports.default = JSSDK;
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.3",
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
  },