@lingxiteam/assets 0.8.30-alpha.7 → 0.9.30-alpha.2
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/lib/IconSvg/index.d.ts +6 -0
- package/lib/IconSvg/index.js +38 -0
- package/lib/index.d.ts +4 -0
- package/lib/security/const.d.ts +14 -0
- package/lib/security/const.js +30 -0
- package/lib/security/encipher/aes.d.ts +2 -0
- package/lib/security/encipher/aes.js +49 -0
- package/lib/security/encipher/des.d.ts +2 -0
- package/lib/security/encipher/des.js +48 -0
- package/lib/security/encipher/rsa.d.ts +2 -0
- package/lib/security/encipher/rsa.js +34 -0
- package/lib/security/encipher/sign.d.ts +6 -0
- package/lib/security/encipher/sign.js +157 -0
- package/lib/security/fetch.d.ts +9 -0
- package/lib/security/fetch.js +263 -0
- package/lib/security/httpEncryption.js +95 -0
- package/lib/security/index.d.ts +26 -0
- package/lib/security/index.js +22 -0
- package/lib/svg/check.svg +10 -0
- package/lib/svg/normal-check.svg +10 -0
- package/lib/utils/img.d.ts +1 -0
- package/lib/utils/img.js +12 -0
- package/lib/utils/url.d.ts +2 -0
- package/lib/utils/url.js +49 -0
- package/package.json +2 -2
- package/es/security/store.d.ts +0 -1
- package/es/security/store.js +0 -61
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
|
|
10
|
+
var _img = require("../utils/img");
|
|
11
|
+
|
|
12
|
+
var _excluded = ["style", "src"];
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
|
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
+
|
|
20
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
21
|
+
|
|
22
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
23
|
+
|
|
24
|
+
var IconSvg = function IconSvg(props) {
|
|
25
|
+
var _props$style = props.style,
|
|
26
|
+
style = _props$style === void 0 ? {} : _props$style,
|
|
27
|
+
src = props.src,
|
|
28
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
29
|
+
|
|
30
|
+
return (0, _jsxRuntime.jsx)("i", _objectSpread(_objectSpread({}, restProps), {}, {
|
|
31
|
+
style: _objectSpread(_objectSpread({}, restProps), {}, {
|
|
32
|
+
backgroundImage: (0, _img.getSvgImageBase64)(src)
|
|
33
|
+
})
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var _default = IconSvg;
|
|
38
|
+
exports.default = _default;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const securityHeaderKey = "XA-TYPE";
|
|
2
|
+
export declare const defaultSignKey = "X-SIGN";
|
|
3
|
+
export declare const MODE: {
|
|
4
|
+
SIGN_KEY: string;
|
|
5
|
+
SIGN: string;
|
|
6
|
+
RSA: string;
|
|
7
|
+
AES: string;
|
|
8
|
+
DES: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const signKey: string;
|
|
11
|
+
export declare const rsaPublicKey: string | undefined;
|
|
12
|
+
export declare const rsaPrivKey: string | undefined;
|
|
13
|
+
export declare const aesKey: string;
|
|
14
|
+
export declare const desKey: string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.signKey = exports.securityHeaderKey = exports.rsaPublicKey = exports.rsaPrivKey = exports.desKey = exports.defaultSignKey = exports.aesKey = exports.MODE = void 0;
|
|
7
|
+
var defaultAESKey = 'd86d7bab3d6ac01a';
|
|
8
|
+
var defaultDESKey = '91THRABY';
|
|
9
|
+
var securityHeaderKey = 'XA-TYPE';
|
|
10
|
+
exports.securityHeaderKey = securityHeaderKey;
|
|
11
|
+
var defaultSignKey = 'X-SIGN';
|
|
12
|
+
exports.defaultSignKey = defaultSignKey;
|
|
13
|
+
var MODE = {
|
|
14
|
+
SIGN_KEY: 'signKey',
|
|
15
|
+
SIGN: '1.0',
|
|
16
|
+
RSA: '2.0',
|
|
17
|
+
AES: '3.0',
|
|
18
|
+
DES: '4.0'
|
|
19
|
+
};
|
|
20
|
+
exports.MODE = MODE;
|
|
21
|
+
var signKey = process.env.LINGXI_HTTP_SIGN_HEADER_KEY || process.env.REACT_APP_HTTP_SIGN_HEADER_KEY || process.env.UMI_APP_HTTP_SIGN_HEADER_KEY || process.env.FISHX_APP_HTTP_SIGN_HEADER_KEY || defaultSignKey;
|
|
22
|
+
exports.signKey = signKey;
|
|
23
|
+
var rsaPublicKey = process.env.LINGXI_HTTP_RSA_PUBLIC_KEY || process.env.REACT_APP_HTTP_RSA_PUBLIC_KEY || process.env.UMI_APP_HTTP_RSA_PUBLIC_KEY || process.env.FISHX_APP_HTTP_RSA_PUBLIC_KEY;
|
|
24
|
+
exports.rsaPublicKey = rsaPublicKey;
|
|
25
|
+
var rsaPrivKey = process.env.LINGXI_HTTP_RSA_PRIV_KEY || process.env.REACT_APP_HTTP_RSA_PRIV_KEY || process.env.UMI_APP_HTTP_RSA_PRIV_KEY || process.env.FISHX_APP_HTTP_RSA_PRIV_KEY;
|
|
26
|
+
exports.rsaPrivKey = rsaPrivKey;
|
|
27
|
+
var aesKey = process.env.LINGXI_HTTP_AES_KEY || process.env.REACT_APP_HTTP_AES_KEY || process.env.UMI_APP_HTTP_AES_KEY || process.env.FISHX_APP_HTTP_AES_KEY || defaultAESKey;
|
|
28
|
+
exports.aesKey = aesKey;
|
|
29
|
+
var desKey = process.env.LINGXI_HTTP_DES_KEY || process.env.REACT_APP_HTTP_DES_KEY || process.env.UMI_APP_HTTP_DES_KEY || process.env.FISHX_APP_HTTP_DES_KEY || defaultDESKey;
|
|
30
|
+
exports.desKey = desKey;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AESEncrypt = exports.AESDecrypt = void 0;
|
|
7
|
+
|
|
8
|
+
var _cryptoJs = _interopRequireDefault(require("crypto-js"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var AESEncrypt = function AESEncrypt(value, aesKey, handle) {
|
|
13
|
+
if (typeof handle === 'function') {
|
|
14
|
+
return handle(value, aesKey, _cryptoJs.default);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var key = _cryptoJs.default.enc.Utf8.parse(aesKey);
|
|
18
|
+
|
|
19
|
+
var ciphertext = _cryptoJs.default.enc.Utf8.parse(value);
|
|
20
|
+
|
|
21
|
+
var encrypted = _cryptoJs.default.AES.encrypt(ciphertext, key, {
|
|
22
|
+
mode: _cryptoJs.default.mode.ECB,
|
|
23
|
+
padding: _cryptoJs.default.pad.Pkcs7
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return encrypted.toString();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.AESEncrypt = AESEncrypt;
|
|
30
|
+
|
|
31
|
+
var AESDecrypt = function AESDecrypt(value, aesKey, handle) {
|
|
32
|
+
if (typeof handle === 'function') {
|
|
33
|
+
return handle(value, aesKey, _cryptoJs.default);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var key = _cryptoJs.default.enc.Utf8.parse(aesKey);
|
|
37
|
+
|
|
38
|
+
var ciphertext = _cryptoJs.default.enc.Base64.stringify(_cryptoJs.default.enc.Base64.parse(value)); // const ciphertext = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Base64.parse(CryptoJS.enc.Utf8.parse(value).toString(CryptoJS.enc.Utf8)));
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var encrypted = _cryptoJs.default.AES.decrypt(ciphertext, key, {
|
|
42
|
+
mode: _cryptoJs.default.mode.ECB,
|
|
43
|
+
padding: _cryptoJs.default.pad.Pkcs7
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return encrypted.toString(_cryptoJs.default.enc.Utf8);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.AESDecrypt = AESDecrypt;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DESEncrypt = exports.DESDecrypt = void 0;
|
|
7
|
+
|
|
8
|
+
var _cryptoJs = _interopRequireDefault(require("crypto-js"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var DESEncrypt = function DESEncrypt(value, aesKey, handle) {
|
|
13
|
+
if (typeof handle === 'function') {
|
|
14
|
+
return handle(value, aesKey, _cryptoJs.default);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var key = _cryptoJs.default.enc.Utf8.parse(aesKey);
|
|
18
|
+
|
|
19
|
+
var ciphertext = _cryptoJs.default.enc.Utf8.parse(value);
|
|
20
|
+
|
|
21
|
+
var encrypted = _cryptoJs.default.DES.encrypt(ciphertext, key, {
|
|
22
|
+
mode: _cryptoJs.default.mode.ECB,
|
|
23
|
+
padding: _cryptoJs.default.pad.Pkcs7
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return encrypted.toString();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.DESEncrypt = DESEncrypt;
|
|
30
|
+
|
|
31
|
+
var DESDecrypt = function DESDecrypt(value, aesKey, handle) {
|
|
32
|
+
if (typeof handle === 'function') {
|
|
33
|
+
return handle(value, aesKey, _cryptoJs.default);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var key = _cryptoJs.default.enc.Utf8.parse(aesKey);
|
|
37
|
+
|
|
38
|
+
var ciphertext = _cryptoJs.default.enc.Base64.stringify(_cryptoJs.default.enc.Base64.parse(value));
|
|
39
|
+
|
|
40
|
+
var encrypted = _cryptoJs.default.DES.decrypt(ciphertext, key, {
|
|
41
|
+
mode: _cryptoJs.default.mode.ECB,
|
|
42
|
+
padding: _cryptoJs.default.pad.Pkcs7
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return encrypted.toString(_cryptoJs.default.enc.Utf8);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.DESDecrypt = DESDecrypt;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RSAEncrypt = exports.RSADecrypt = void 0;
|
|
7
|
+
|
|
8
|
+
var _jsencrypt = _interopRequireDefault(require("jsencrypt"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var RSAEncrypt = function RSAEncrypt(value, publicKey, handle) {
|
|
13
|
+
if (typeof handle === 'function') {
|
|
14
|
+
return handle(value, publicKey, _jsencrypt.default);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var encryptor = new _jsencrypt.default();
|
|
18
|
+
encryptor.setPublicKey(publicKey);
|
|
19
|
+
return encryptor.encrypt(value);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.RSAEncrypt = RSAEncrypt;
|
|
23
|
+
|
|
24
|
+
var RSADecrypt = function RSADecrypt(value, privKey, handle) {
|
|
25
|
+
if (typeof handle === 'function') {
|
|
26
|
+
return handle(value, privKey, _jsencrypt.default);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var decrypt = new _jsencrypt.default();
|
|
30
|
+
decrypt.setPrivateKey(privKey);
|
|
31
|
+
return decrypt.decrypt(value);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.RSADecrypt = RSADecrypt;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.createHttpSignStr = void 0;
|
|
7
|
+
|
|
8
|
+
var _jsSha = require("js-sha256");
|
|
9
|
+
|
|
10
|
+
var _url = require("../../utils/url");
|
|
11
|
+
|
|
12
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
13
|
+
|
|
14
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
|
+
|
|
16
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
+
|
|
18
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
19
|
+
|
|
20
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
|
+
|
|
22
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
23
|
+
|
|
24
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
|
+
|
|
26
|
+
var SIGN_KEY = process.env.LING_XI_HTTP_SIGN_KEY || 'zrT5bi2escXilaH1fs653uZiH9RWfzCS'; // 1、签名算法:
|
|
27
|
+
// 通过对url、参数、秘钥拼接成字符串,然后对字符串使用算法SHA-256得到64个字符串,放到header, X-SIGN=XXXXXXX。
|
|
28
|
+
// 2、签名字符串拼接规则:
|
|
29
|
+
// a.get 请求:url+"#"+header+"#"+参数+"#"+秘钥
|
|
30
|
+
// b.post 请求:url+"#"+header+"#"+body+"#"秘钥
|
|
31
|
+
// 参数说明:
|
|
32
|
+
// ● 如果其中的变量为空,则为空字符串。
|
|
33
|
+
// ● url :不包含参数,(2022.08.08 更改为apiName)
|
|
34
|
+
// ● header :取X-开头的header,或者APP-ID,多个则逗号分隔拼接。比如X-AA=a;APP-ID=88888
|
|
35
|
+
// ● get 参数:就是url 问号后面的串
|
|
36
|
+
// ● body:post 请求体
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 组装X-SIGN请求头
|
|
40
|
+
* @param {请求地址} url 接口请求地址
|
|
41
|
+
* @param {请求参数} options
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
// 由于X-B 的规则可能被业务网关使用,并往请求头增加内容,导致前后端加密不一致
|
|
45
|
+
// 2022.08.09 使用以下3个固定值 + X-LX-*匹配 方式
|
|
46
|
+
|
|
47
|
+
var hKeys = ['X-B-AUTH', 'X-B-TARGET-ID', 'APP-ID']; // 配置指定接口前缀
|
|
48
|
+
|
|
49
|
+
var apiPrefix = process.env.LING_XI_HTTP_SIGN_API_PERFIX || process.env.REACT_APP_HTTP_SIGN_API_PERFIX || process.env.UMI_APP_HTTP_SIGN_API_PERFIX || process.env.FISHX_APP_HTTP_SIGN_API_PERFIX || 'portal,asset,rhin,lcdp,ncdp,flow'; // 获取接口路径
|
|
50
|
+
// =========================
|
|
51
|
+
// api/a/b/c
|
|
52
|
+
// ../api/a/b/c
|
|
53
|
+
// ../../api/a/b/c
|
|
54
|
+
// /api/a/b/c
|
|
55
|
+
// http://host.com/api/a/b/c
|
|
56
|
+
// https://host.com/api/a/b/c
|
|
57
|
+
// //host.com/api/a/b/c
|
|
58
|
+
// => /api/a/b/c
|
|
59
|
+
// =========================
|
|
60
|
+
|
|
61
|
+
var getApiPath = function getApiPath(url) {
|
|
62
|
+
// 移除host、相对路径部分,保证地址前都是'/'开头
|
|
63
|
+
var fixurl = "/".concat(url.replace(/(^(http:\/\/|https:\/\/|\/\/)[^/]*)|(^\.[./]*)/g, '')).replace('//', '/');
|
|
64
|
+
|
|
65
|
+
if (apiPrefix) {
|
|
66
|
+
// 配了接口前缀规则,通过前缀匹配
|
|
67
|
+
// =========================
|
|
68
|
+
// /api/a/api/b => /api/b
|
|
69
|
+
// api/c => /api/c
|
|
70
|
+
// /lapi/d => ''
|
|
71
|
+
// =========================
|
|
72
|
+
return apiPrefix.split(',').reduce(function (pre, n) {
|
|
73
|
+
var matchPath = fixurl.split("/".concat(n, "/")).pop();
|
|
74
|
+
|
|
75
|
+
if (matchPath !== fixurl) {
|
|
76
|
+
pre.push("/".concat(n, "/").concat(matchPath));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return pre;
|
|
80
|
+
}, []).sort(function (a, b) {
|
|
81
|
+
return a.length - b.length;
|
|
82
|
+
})[0] || '';
|
|
83
|
+
} // 没有配置接口前缀,使用接口最后三级路径,不足三级取最大层级路径
|
|
84
|
+
// =========================
|
|
85
|
+
// /a/b/c/d => /b/c/d
|
|
86
|
+
// a/b => /a/b
|
|
87
|
+
// =========================
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
return "".concat(fixurl.split('/').slice(-3).join('/'));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
var createHttpSignStr = function createHttpSignStr(url, options) {
|
|
94
|
+
if (!url || !options || !options.method) {
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var method = options.method,
|
|
99
|
+
headers = options.headers,
|
|
100
|
+
body = options.body,
|
|
101
|
+
search = options.search; // 获取参数1: 接口名称
|
|
102
|
+
|
|
103
|
+
var mixUrl = url;
|
|
104
|
+
|
|
105
|
+
if (search && search instanceof Object) {
|
|
106
|
+
mixUrl += (url.indexOf('?') !== -1 ? '&' : '?') + (0, _url.obj2QueryString)(search);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var _mixUrl$split = mixUrl.split('?'),
|
|
110
|
+
_mixUrl$split2 = _slicedToArray(_mixUrl$split, 2),
|
|
111
|
+
urlPath = _mixUrl$split2[0],
|
|
112
|
+
_mixUrl$split2$ = _mixUrl$split2[1],
|
|
113
|
+
urlSearch = _mixUrl$split2$ === void 0 ? '' : _mixUrl$split2$;
|
|
114
|
+
|
|
115
|
+
var apiPath = getApiPath(urlPath); // 获取参数2: 请求头部参数
|
|
116
|
+
|
|
117
|
+
var headerParams = '';
|
|
118
|
+
var headersKeyArr = [];
|
|
119
|
+
|
|
120
|
+
if (headers) {
|
|
121
|
+
Object.keys(headers).forEach(function (key) {
|
|
122
|
+
if (key.startsWith('X-LX-') || hKeys.includes(key)) {
|
|
123
|
+
headersKeyArr.push("".concat(key.toLowerCase(), "=").concat(headers[key]));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
headerParams = headersKeyArr.sort().join(';'); // 获取参数3: 请求参数
|
|
129
|
+
|
|
130
|
+
var params = '';
|
|
131
|
+
|
|
132
|
+
if (method.toLowerCase() === 'get') {
|
|
133
|
+
params = urlSearch;
|
|
134
|
+
} else {
|
|
135
|
+
params = _typeof(body) === 'object' ? JSON.stringify(body) : body;
|
|
136
|
+
} // 组装加密字符串
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
var str = [apiPath, headerParams, params, SIGN_KEY].join('#');
|
|
140
|
+
|
|
141
|
+
if (typeof window !== 'undefined' && (window.lxDebug || window.localStorage.getItem('lxDebug'))) {
|
|
142
|
+
console.log(' --- signDebug ---');
|
|
143
|
+
console.log('url', url);
|
|
144
|
+
console.log('str', str);
|
|
145
|
+
console.log('sign', (0, _jsSha.sha256)(str));
|
|
146
|
+
} // 生成约定签名
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
return (0, _jsSha.sha256)(str);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
exports.createHttpSignStr = createHttpSignStr;
|
|
153
|
+
var _default = {
|
|
154
|
+
createHttpSignStr: createHttpSignStr,
|
|
155
|
+
getApiPath: getApiPath
|
|
156
|
+
};
|
|
157
|
+
exports.default = _default;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _sign = require("./encipher/sign");
|
|
11
|
+
|
|
12
|
+
var _rsa = require("./encipher/rsa");
|
|
13
|
+
|
|
14
|
+
var _aes = require("./encipher/aes");
|
|
15
|
+
|
|
16
|
+
var _des = require("./encipher/des");
|
|
17
|
+
|
|
18
|
+
var _const = require("./const");
|
|
19
|
+
|
|
20
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
21
|
+
|
|
22
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
23
|
+
|
|
24
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
25
|
+
|
|
26
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
27
|
+
|
|
28
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
29
|
+
|
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
|
+
|
|
32
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
33
|
+
|
|
34
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
35
|
+
|
|
36
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
37
|
+
|
|
38
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
39
|
+
|
|
40
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
41
|
+
|
|
42
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
43
|
+
|
|
44
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
45
|
+
|
|
46
|
+
// import { store } from './store';
|
|
47
|
+
var originFetch = window.fetch; // const debugData = store('debugData');
|
|
48
|
+
// (window as any).debugData = debugData;
|
|
49
|
+
|
|
50
|
+
var LXREQ = {};
|
|
51
|
+
window.LXREQ = LXREQ;
|
|
52
|
+
|
|
53
|
+
function encryptedStr(str, type) {
|
|
54
|
+
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
55
|
+
|
|
56
|
+
if (type === _const.MODE.AES) {
|
|
57
|
+
var _config$aesOptions, _config$aesOptions2;
|
|
58
|
+
|
|
59
|
+
return (0, _aes.AESEncrypt)(str, ((_config$aesOptions = config.aesOptions) === null || _config$aesOptions === void 0 ? void 0 : _config$aesOptions.key) || _const.aesKey, (_config$aesOptions2 = config.aesOptions) === null || _config$aesOptions2 === void 0 ? void 0 : _config$aesOptions2.encrypt);
|
|
60
|
+
} else if (type === _const.MODE.RSA) {
|
|
61
|
+
var _config$rsaOptions, _config$rsaOptions2;
|
|
62
|
+
|
|
63
|
+
return (0, _rsa.RSAEncrypt)(str, ((_config$rsaOptions = config.rsaOptions) === null || _config$rsaOptions === void 0 ? void 0 : _config$rsaOptions.publicKey) || _const.rsaPublicKey, (_config$rsaOptions2 = config.rsaOptions) === null || _config$rsaOptions2 === void 0 ? void 0 : _config$rsaOptions2.encrypt);
|
|
64
|
+
} else if (type === _const.MODE.DES) {
|
|
65
|
+
var _config$desOptions, _config$desOptions2;
|
|
66
|
+
|
|
67
|
+
return (0, _des.DESEncrypt)(str, ((_config$desOptions = config.desOptions) === null || _config$desOptions === void 0 ? void 0 : _config$desOptions.key) || _const.desKey, (_config$desOptions2 = config.desOptions) === null || _config$desOptions2 === void 0 ? void 0 : _config$desOptions2.encrypt);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return str;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function decryptedStr(str, type) {
|
|
74
|
+
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
75
|
+
|
|
76
|
+
if (type === _const.MODE.AES) {
|
|
77
|
+
var _config$aesOptions3, _config$aesOptions4;
|
|
78
|
+
|
|
79
|
+
return (0, _aes.AESDecrypt)(str, ((_config$aesOptions3 = config.aesOptions) === null || _config$aesOptions3 === void 0 ? void 0 : _config$aesOptions3.key) || _const.aesKey, (_config$aesOptions4 = config.aesOptions) === null || _config$aesOptions4 === void 0 ? void 0 : _config$aesOptions4.decrypt);
|
|
80
|
+
} else if (type === _const.MODE.RSA) {
|
|
81
|
+
var _config$rsaOptions3, _config$rsaOptions4;
|
|
82
|
+
|
|
83
|
+
return (0, _rsa.RSADecrypt)(str, ((_config$rsaOptions3 = config.rsaOptions) === null || _config$rsaOptions3 === void 0 ? void 0 : _config$rsaOptions3.privKey) || _const.rsaPrivKey, (_config$rsaOptions4 = config.rsaOptions) === null || _config$rsaOptions4 === void 0 ? void 0 : _config$rsaOptions4.decrypt) || '';
|
|
84
|
+
} else if (type === _const.MODE.DES) {
|
|
85
|
+
var _config$desOptions3, _config$desOptions4;
|
|
86
|
+
|
|
87
|
+
return (0, _des.DESDecrypt)(str, ((_config$desOptions3 = config.desOptions) === null || _config$desOptions3 === void 0 ? void 0 : _config$desOptions3.key) || _const.desKey, (_config$desOptions4 = config.desOptions) === null || _config$desOptions4 === void 0 ? void 0 : _config$desOptions4.decrypt);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return str;
|
|
91
|
+
} // 统一请求参数加密
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
function encrypted(url, opts, type) {
|
|
95
|
+
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
96
|
+
var reqId = arguments.length > 4 ? arguments[4] : undefined;
|
|
97
|
+
var isFormData = opts.body instanceof FormData;
|
|
98
|
+
var headerReqId = reqId ? {
|
|
99
|
+
'LX-REQ-ID': "LXREQ.".concat(reqId)
|
|
100
|
+
} : {}; // search 部分加密
|
|
101
|
+
|
|
102
|
+
var encryptedUrl = url.indexOf('?') !== -1 ? url.replace(/(?!\?)([^?])+$/g, function (search) {
|
|
103
|
+
var params = search.split('&').map(function (param) {
|
|
104
|
+
var _param$split = param.split('='),
|
|
105
|
+
_param$split2 = _slicedToArray(_param$split, 2),
|
|
106
|
+
k = _param$split2[0],
|
|
107
|
+
v = _param$split2[1];
|
|
108
|
+
|
|
109
|
+
return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(encryptedStr(v, type, config)));
|
|
110
|
+
});
|
|
111
|
+
return params.join('&');
|
|
112
|
+
}) : url; // body参数加密
|
|
113
|
+
|
|
114
|
+
var encryptedOpts = Object.assign({}, opts);
|
|
115
|
+
encryptedOpts.headers = _objectSpread(_objectSpread(_objectSpread({}, opts.headers), headerReqId), {}, _defineProperty({}, _const.securityHeaderKey, type));
|
|
116
|
+
|
|
117
|
+
if (isFormData) {
|
|
118
|
+
// formData 加密
|
|
119
|
+
var formData = new FormData();
|
|
120
|
+
var reqBody = opts.body;
|
|
121
|
+
|
|
122
|
+
var _iterator = _createForOfIteratorHelper(reqBody.keys()),
|
|
123
|
+
_step;
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
127
|
+
var key = _step.value;
|
|
128
|
+
var value = reqBody.get(key);
|
|
129
|
+
formData.append(key, encryptedStr(value, type, config));
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
_iterator.e(err);
|
|
133
|
+
} finally {
|
|
134
|
+
_iterator.f();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
encryptedOpts.body = formData;
|
|
138
|
+
} else if (opts.body) {
|
|
139
|
+
// 文本加密
|
|
140
|
+
encryptedOpts.body = encryptedStr(opts.body, type, config);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return [encryptedUrl, encryptedOpts];
|
|
144
|
+
} // 将解密数据
|
|
145
|
+
// function debugRecords(id: string, value: any) {
|
|
146
|
+
// // sessionStorage.setItem(id, JSON.stringify(value));
|
|
147
|
+
// Object.defineProperty(LXREQ, id, {
|
|
148
|
+
// get() {
|
|
149
|
+
// // debugData.show(id)
|
|
150
|
+
// return '';
|
|
151
|
+
// },
|
|
152
|
+
// });
|
|
153
|
+
// }
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
var fetch = function fetch(url) {
|
|
157
|
+
var fetchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
158
|
+
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
159
|
+
|
|
160
|
+
var opts = _objectSpread({}, fetchOptions);
|
|
161
|
+
|
|
162
|
+
var optSecurityHeaderKey = (opts.headers || {})[_const.securityHeaderKey];
|
|
163
|
+
var isDebug = (config === null || config === void 0 ? void 0 : config.debug) || window.lxDebug || !!window.localStorage.getItem('lxDebug') || true; // ------ 参数签名(默认) ------
|
|
164
|
+
|
|
165
|
+
if ( // 配置开启加密
|
|
166
|
+
(config.mode === _const.MODE.SIGN_KEY || config.mode === _const.MODE.SIGN) && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.disabledSignKey) !== true || // 请求头开启加密
|
|
167
|
+
optSecurityHeaderKey === '1.0') {
|
|
168
|
+
var _config$signKeyOption;
|
|
169
|
+
|
|
170
|
+
opts.headers = _objectSpread(_objectSpread({}, opts.headers), {}, _defineProperty({}, (config === null || config === void 0 ? void 0 : (_config$signKeyOption = config.signKeyOptions) === null || _config$signKeyOption === void 0 ? void 0 : _config$signKeyOption.key) || _const.signKey, (0, _sign.createHttpSignStr)(url, fetchOptions)));
|
|
171
|
+
return originFetch(url, opts);
|
|
172
|
+
} // ------ 参数加密 ------
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
if ((config.mode === _const.MODE.RSA || config.mode === _const.MODE.AES) && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.disabledEncrypted) !== true || optSecurityHeaderKey === '2.0' || optSecurityHeaderKey === '3.0' || optSecurityHeaderKey === '4.0') {
|
|
176
|
+
// 标记请求ID,用于获取解密数据
|
|
177
|
+
var reqId = "XA".concat(+new Date()); // search和body加密
|
|
178
|
+
|
|
179
|
+
var _encrypted = encrypted(url, opts, config.mode || optSecurityHeaderKey, config, reqId),
|
|
180
|
+
_encrypted2 = _slicedToArray(_encrypted, 2),
|
|
181
|
+
encryptedUrl = _encrypted2[0],
|
|
182
|
+
encryptedOpts = _encrypted2[1];
|
|
183
|
+
|
|
184
|
+
return originFetch(encryptedUrl, encryptedOpts).then( /*#__PURE__*/function () {
|
|
185
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(response) {
|
|
186
|
+
var securityType, respResult, result, json, blob;
|
|
187
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
188
|
+
while (1) {
|
|
189
|
+
switch (_context.prev = _context.next) {
|
|
190
|
+
case 0:
|
|
191
|
+
// 响应解密
|
|
192
|
+
securityType = response.headers.get(_const.securityHeaderKey);
|
|
193
|
+
|
|
194
|
+
if (!(securityType && response.body)) {
|
|
195
|
+
_context.next = 22;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
_context.next = 4;
|
|
200
|
+
return response.text();
|
|
201
|
+
|
|
202
|
+
case 4:
|
|
203
|
+
respResult = _context.sent;
|
|
204
|
+
_context.prev = 5;
|
|
205
|
+
result = decryptedStr(respResult, securityType, config);
|
|
206
|
+
_context.next = 18;
|
|
207
|
+
break;
|
|
208
|
+
|
|
209
|
+
case 9:
|
|
210
|
+
_context.prev = 9;
|
|
211
|
+
_context.t0 = _context["catch"](5);
|
|
212
|
+
console.error('--------解密失败--------');
|
|
213
|
+
console.error("\u8BF7\u6C42ID\uFF1A".concat(reqId));
|
|
214
|
+
console.error("\u8BF7\u6C42\u5730\u5740\uFF1A".concat(url));
|
|
215
|
+
console.error("\u89E3\u5BC6\u65B9\u5F0F\uFF1A".concat(securityType));
|
|
216
|
+
console.error("\u89E3\u5BC6\u62A5\u6587\uFF1A".concat(respResult));
|
|
217
|
+
console.error("\u5931\u8D25\u539F\u56E0\uFF1A".concat(_context.t0));
|
|
218
|
+
return _context.abrupt("return", new Response(null, {
|
|
219
|
+
status: 400,
|
|
220
|
+
statusText: String(_context.t0)
|
|
221
|
+
}));
|
|
222
|
+
|
|
223
|
+
case 18:
|
|
224
|
+
// 开启调试模式,记录解密数据
|
|
225
|
+
if (isDebug || true) {// debugRecords(reqId, result);
|
|
226
|
+
} // 覆盖响应值
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
json = JSON.parse(result);
|
|
231
|
+
} catch (e) {
|
|
232
|
+
json = result;
|
|
233
|
+
console.warn("reqId: ".concat(reqId, " \u8F6C\u6362JSON\u5931\u8D25, \u5185\u5BB9\u4E3A"), result);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
blob = new Blob([JSON.stringify(json, null, 2)], {
|
|
237
|
+
type: 'application/json'
|
|
238
|
+
});
|
|
239
|
+
return _context.abrupt("return", new Response(blob));
|
|
240
|
+
|
|
241
|
+
case 22:
|
|
242
|
+
return _context.abrupt("return", response);
|
|
243
|
+
|
|
244
|
+
case 23:
|
|
245
|
+
case "end":
|
|
246
|
+
return _context.stop();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}, _callee, null, [[5, 9]]);
|
|
250
|
+
}));
|
|
251
|
+
|
|
252
|
+
return function (_x) {
|
|
253
|
+
return _ref.apply(this, arguments);
|
|
254
|
+
};
|
|
255
|
+
}());
|
|
256
|
+
} // 其他
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
return originFetch(url, opts);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
var _default = fetch;
|
|
263
|
+
exports.default = _default;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _sign = require("./encipher/sign");
|
|
9
|
+
|
|
10
|
+
var _fetch = _interopRequireDefault(require("./fetch"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/* eslint-disable no-console */
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* @Author: 张国永 zhang.guoyong2@iwhalecloud.com
|
|
18
|
+
* @Date: 2022-08-08 15:08:58
|
|
19
|
+
* @Description: 一个简单的http请求安全加密处理
|
|
20
|
+
*/
|
|
21
|
+
// TODO 支持XMLHttpRequest拦截、参数混淆、响应拦截
|
|
22
|
+
// 使用方式1: 使用fetch请求模块,start({ mode: signKey }),适应经过封装的fetch模块
|
|
23
|
+
// 使用方式2: 使用fetch请求模块,将window.fetch 替换成 fetch,适应自己封装的fetch模块
|
|
24
|
+
// 使用方式3: 不使用fetch请求模块,使用createHttpSignStr自己获取签名,自行在header上添加参数
|
|
25
|
+
// eslint-disable-next-line import/no-named-as-default, import/no-named-as-default-member
|
|
26
|
+
var isHttpEncryption = false;
|
|
27
|
+
var originFetch = window.fetch;
|
|
28
|
+
|
|
29
|
+
function start(_ref) {
|
|
30
|
+
var _ref$mode = _ref.mode,
|
|
31
|
+
mode = _ref$mode === void 0 ? '1.0' : _ref$mode,
|
|
32
|
+
_ref$signKeyOptions = _ref.signKeyOptions,
|
|
33
|
+
signKeyOptions = _ref$signKeyOptions === void 0 ? {} : _ref$signKeyOptions,
|
|
34
|
+
_ref$aesOptions = _ref.aesOptions,
|
|
35
|
+
aesOptions = _ref$aesOptions === void 0 ? {} : _ref$aesOptions,
|
|
36
|
+
_ref$desOptions = _ref.desOptions,
|
|
37
|
+
desOptions = _ref$desOptions === void 0 ? {} : _ref$desOptions,
|
|
38
|
+
_ref$rsaOptions = _ref.rsaOptions,
|
|
39
|
+
rsaOptions = _ref$rsaOptions === void 0 ? {} : _ref$rsaOptions;
|
|
40
|
+
|
|
41
|
+
if (!mode) {
|
|
42
|
+
console.error('http加密开启失败,缺少mode参数');
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (isHttpEncryption) return true;
|
|
47
|
+
|
|
48
|
+
switch (mode) {
|
|
49
|
+
case 'signKey': // 兼容旧数据
|
|
50
|
+
|
|
51
|
+
case '1.0':
|
|
52
|
+
case '2.0':
|
|
53
|
+
case '3.0':
|
|
54
|
+
case '4.0':
|
|
55
|
+
{
|
|
56
|
+
if (typeof window.fetch === 'function') {
|
|
57
|
+
isHttpEncryption = true;
|
|
58
|
+
|
|
59
|
+
window.fetch = function (url) {
|
|
60
|
+
var fetchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
61
|
+
return (0, _fetch.default)(url, fetchOptions, {
|
|
62
|
+
mode: mode,
|
|
63
|
+
signKeyOptions: signKeyOptions,
|
|
64
|
+
aesOptions: aesOptions,
|
|
65
|
+
desOptions: desOptions,
|
|
66
|
+
rsaOptions: rsaOptions
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
} else {
|
|
70
|
+
console.error('http加密开启失败,目前仅支持window.fetch方式');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
default:
|
|
77
|
+
console.error("http\u52A0\u5BC6\u5F00\u542F\u5931\u8D25\uFF0C\u4E0D\u652F\u6301".concat(mode, "\u6A21\u5F0F"));
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return isHttpEncryption;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function stop() {
|
|
85
|
+
isHttpEncryption = false;
|
|
86
|
+
window.fetch = originFetch;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var _default = {
|
|
90
|
+
start: start,
|
|
91
|
+
stop: stop,
|
|
92
|
+
fetch: _fetch.default,
|
|
93
|
+
createHttpSignStr: _sign.createHttpSignStr
|
|
94
|
+
};
|
|
95
|
+
exports.default = _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
httpEncryption: {
|
|
3
|
+
start: ({ mode, signKeyOptions, aesOptions, desOptions, rsaOptions }: {
|
|
4
|
+
mode?: string | undefined;
|
|
5
|
+
signKeyOptions?: {} | undefined;
|
|
6
|
+
aesOptions?: {} | undefined;
|
|
7
|
+
desOptions?: {} | undefined;
|
|
8
|
+
rsaOptions?: {} | undefined;
|
|
9
|
+
}) => boolean;
|
|
10
|
+
stop: () => void;
|
|
11
|
+
fetch: (url: any, fetchOptions?: any, config?: {
|
|
12
|
+
mode?: string | undefined;
|
|
13
|
+
signKeyOptions?: any;
|
|
14
|
+
aesOptions?: any;
|
|
15
|
+
desOptions?: any;
|
|
16
|
+
rsaOptions?: any;
|
|
17
|
+
debug?: boolean | undefined;
|
|
18
|
+
}) => Promise<Response>;
|
|
19
|
+
createHttpSignStr: (url: string, options: any) => string;
|
|
20
|
+
};
|
|
21
|
+
sign: {
|
|
22
|
+
createHttpSignStr: (url: string, options: any) => string;
|
|
23
|
+
getApiPath: (url: string) => any;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _httpEncryption = _interopRequireDefault(require("./httpEncryption"));
|
|
9
|
+
|
|
10
|
+
var _sign = _interopRequireDefault(require("./encipher/sign"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
window.lingxiSecurity = {
|
|
15
|
+
httpEncryption: _httpEncryption.default,
|
|
16
|
+
sign: _sign.default
|
|
17
|
+
};
|
|
18
|
+
var _default = {
|
|
19
|
+
httpEncryption: _httpEncryption.default,
|
|
20
|
+
sign: _sign.default
|
|
21
|
+
};
|
|
22
|
+
exports.default = _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="22px" height="22px" viewBox="0 0 22 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
+
<title>全局样式:20/原子级控件/复选/状态:#选中</title>
|
|
4
|
+
<g id="控件" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
5
|
+
<g id="system-complete">
|
|
6
|
+
<path d="M11,0 C17.075904,0 22,4.92409598 22,11 C22,17.075904 17.0734732,22 11,22 C4.92652679,22 0,17.0734732 0,11 C0,4.92652679 4.92409598,0 11,0 Z" id="Shape" fill="#1890FF"></path>
|
|
7
|
+
<path d="M9.42871875,12.9681652 L7.2069029,10.7463493 C6.90006126,10.4395077 6.40257267,10.4395077 6.09573103,10.7463493 C5.78889035,11.05319 5.78889035,11.550677 6.09573103,11.8575177 C6.09573161,11.8575183 6.0957322,11.8575189 6.09573278,11.8575195 L8.72212536,14.4838955 C9.11265701,14.8744045 9.74581424,14.874407 10.136349,14.483901 L10.5404063,14.0798527 L10.5404063,14.0798527 L16.2813591,8.33795955 C16.588183,8.03108543 16.5881626,7.53359119 16.2813136,7.22674219 C15.974472,6.91990055 15.4769834,6.91990055 15.1701417,7.22674219 L9.42871875,12.9681652 L9.42871875,12.9681652 Z" id="Path" fill="#FFFFFF"></path>
|
|
8
|
+
</g>
|
|
9
|
+
</g>
|
|
10
|
+
</svg>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="22px" height="22px" viewBox="0 0 22 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
+
<title>全局样式:20/原子级控件/复选/状态:未选中</title>
|
|
4
|
+
<g id="控件" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
5
|
+
<g id="元素/选择/未选中">
|
|
6
|
+
<path d="M11,22 C4.93492502,22 0,17.0653546 0,10.999496 C0,4.9337633 4.93492502,0 11,0 C17.065075,0 22,4.93464539 22,10.999496 C22,17.0644725 17.0660846,22 11,22" id="Fill" fill="#FFFFFF"></path>
|
|
7
|
+
<path d="M11,0.5 C13.8998633,0.5 16.5248731,1.67505184 18.4249106,3.57508938 C20.3249482,5.47512693 21.5,8.10013672 21.5,11 C21.5,13.8995696 20.3245821,16.5243277 18.4245965,18.4243132 C16.5242275,20.3246822 13.8989967,21.5 11,21.5 C8.10129687,21.5 5.47631792,20.324316 3.57600094,18.4239991 C1.67568396,16.5236821 0.5,13.8987031 0.5,11 C0.5,8.10100334 1.67531776,5.47577251 3.57568679,3.57540349 C5.47567234,1.67541793 8.10043037,0.5 11,0.5 Z" id="Shape" stroke="#CCCCCC"></path>
|
|
8
|
+
</g>
|
|
9
|
+
</g>
|
|
10
|
+
</svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getSvgImageBase64: (text: string) => string;
|
package/lib/utils/img.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSvgImageBase64 = void 0;
|
|
7
|
+
|
|
8
|
+
var getSvgImageBase64 = function getSvgImageBase64(text) {
|
|
9
|
+
return "data:image/svg+xml;charset=utf-8,".concat(encodeURIComponent(text));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.getSvgImageBase64 = getSvgImageBase64;
|
package/lib/utils/url.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.obj2QueryString = exports.getSearchObj = void 0;
|
|
7
|
+
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
|
|
10
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
15
|
+
|
|
16
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
17
|
+
|
|
18
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
|
+
|
|
20
|
+
var obj2QueryString = function obj2QueryString(params) {
|
|
21
|
+
var queryString = Object.keys(params).map(function (key) {
|
|
22
|
+
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(params[key]));
|
|
23
|
+
}).join('&');
|
|
24
|
+
return queryString;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.obj2QueryString = obj2QueryString;
|
|
28
|
+
|
|
29
|
+
var getSearchObj = function getSearchObj() {
|
|
30
|
+
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location.href;
|
|
31
|
+
var urlArr = url.split('?');
|
|
32
|
+
if (urlArr.length === 1) return {};
|
|
33
|
+
var search = urlArr.pop() || '';
|
|
34
|
+
var objs = search.split('&');
|
|
35
|
+
var obj = {};
|
|
36
|
+
objs.forEach(function (value) {
|
|
37
|
+
var _value$split = value.split('='),
|
|
38
|
+
_value$split2 = _slicedToArray(_value$split, 2),
|
|
39
|
+
k = _value$split2[0],
|
|
40
|
+
v = _value$split2[1];
|
|
41
|
+
|
|
42
|
+
if (v) {
|
|
43
|
+
obj[decodeURIComponent(k)] = decodeURIComponent(v);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return obj;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.getSearchObj = getSearchObj;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingxiteam/assets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.30-alpha.2",
|
|
4
4
|
"description": "灵犀低代码平台移动端 - 工具类",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"authors": [],
|
|
10
10
|
"files": [
|
|
11
11
|
"es",
|
|
12
|
-
"
|
|
12
|
+
"lib",
|
|
13
13
|
"*.md"
|
|
14
14
|
],
|
|
15
15
|
"publishConfig": {
|
package/es/security/store.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const store: (name: string, options?: any) => any;
|
package/es/security/store.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
var dbStore = {};
|
|
2
|
-
var db;
|
|
3
|
-
var version = 1;
|
|
4
|
-
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
|
5
|
-
export var store = function store(name) {
|
|
6
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7
|
-
|
|
8
|
-
if (!db) {
|
|
9
|
-
db = indexedDB.open('LINGXI', version);
|
|
10
|
-
console.log('db', db);
|
|
11
|
-
|
|
12
|
-
db.onerror = function (error) {
|
|
13
|
-
console.log(error);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
db.onsuccess = function (event) {
|
|
17
|
-
console.log(event);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
db.onupgradeneeded = function (e) {
|
|
21
|
-
// 数据库创建或升级的时候会触发
|
|
22
|
-
console.log('ssss'); // let objectStore
|
|
23
|
-
// if (!e.target.result.objectStoreNames.contains(name)) {
|
|
24
|
-
// objectStore = e.target.result.createObjectStore(name, { keyPath: 'id',autoIncrement: false }) // 创建表
|
|
25
|
-
// }
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
if (dbStore[name]) return dbStore[name];
|
|
29
|
-
return dbStore[name] = {
|
|
30
|
-
add: function add(data) {
|
|
31
|
-
return new Promise(function (resolve, reject) {
|
|
32
|
-
var req = indexedDB.open('LINGXI', version).transaction([name], 'readwrite').objectStore(name) // 仓库对象
|
|
33
|
-
.add(data); // 操作成功
|
|
34
|
-
|
|
35
|
-
req.onsuccess = function () {
|
|
36
|
-
resolve(data);
|
|
37
|
-
}; // 操作失败
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
req.onerror = function () {
|
|
41
|
-
reject(data);
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
put: function put(data) {
|
|
46
|
-
return new Promise(function (resolve, reject) {
|
|
47
|
-
var req = indexedDB.open('LINGXI', version).transaction([name], 'readwrite').objectStore(name).put(data); // 操作成功
|
|
48
|
-
|
|
49
|
-
req.onsuccess = function () {
|
|
50
|
-
resolve(data);
|
|
51
|
-
}; // 操作失败
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
req.onerror = function () {
|
|
55
|
-
reject(data);
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
};
|