@das-fed/upf-utils 6.4.0-dev.214 → 6.4.0-dev.216
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/api-services/es5.js +1450 -1438
- package/api-services/index.js +1190 -1167
- package/api-services/index.js.gz +0 -0
- package/api-services/modules/app-manage/es5.js +967 -955
- package/api-services/modules/app-manage/index.js +793 -770
- package/api-services/modules/app-manage/index.js.gz +0 -0
- package/api-services/modules/authentication/es5.js +940 -931
- package/api-services/modules/authentication/index.js +769 -750
- package/api-services/modules/authentication/index.js.gz +0 -0
- package/api-services/modules/bems/es5.js +836 -833
- package/api-services/modules/bems/index.js +654 -645
- package/api-services/modules/bems/index.js.gz +0 -0
- package/api-services/modules/contract/es5.js +2 -2
- package/api-services/modules/contract/index.js +7 -2
- package/api-services/modules/contract/index.js.gz +0 -0
- package/api-services/modules/duty-manage/es5.js +2 -2
- package/api-services/modules/duty-manage/index.js +7 -2
- package/api-services/modules/duty-manage/index.js.gz +0 -0
- package/api-services/modules/enterpriseright/es5.js +558 -558
- package/api-services/modules/enterpriseright/index.js +501 -496
- package/api-services/modules/enterpriseright/index.js.gz +0 -0
- package/api-services/modules/es5.js +1335 -1347
- package/api-services/modules/file/es5.js +1226 -1217
- package/api-services/modules/file/index.js +1032 -1013
- package/api-services/modules/file/index.js.gz +0 -0
- package/api-services/modules/gateway-edge/es5.js +2 -2
- package/api-services/modules/gateway-edge/index.js +7 -2
- package/api-services/modules/gateway-edge/index.js.gz +0 -0
- package/api-services/modules/index.js +1083 -1096
- package/api-services/modules/index.js.gz +0 -0
- package/api-services/modules/iot/es5.js +2 -2
- package/api-services/modules/iot/index.js +7 -2
- package/api-services/modules/iot/index.js.gz +0 -0
- package/api-services/modules/justauth/es5.js +2 -2
- package/api-services/modules/justauth/index.js +7 -2
- package/api-services/modules/justauth/index.js.gz +0 -0
- package/api-services/modules/knowledge/es5.js +955 -967
- package/api-services/modules/knowledge/index.js +775 -788
- package/api-services/modules/knowledge/index.js.gz +0 -0
- package/api-services/modules/link/es5.js +832 -835
- package/api-services/modules/link/index.js +649 -648
- package/api-services/modules/link/index.js.gz +0 -0
- package/api-services/modules/permission/es5.js +2 -2
- package/api-services/modules/permission/index.js +7 -2
- package/api-services/modules/permission/index.js.gz +0 -0
- package/api-services/modules/platformManage/es5.js +2 -2
- package/api-services/modules/platformManage/index.js +7 -2
- package/api-services/modules/platformManage/index.js.gz +0 -0
- package/api-services/modules/portal/es5.js +2 -2
- package/api-services/modules/portal/index.js +7 -2
- package/api-services/modules/portal/index.js.gz +0 -0
- package/api-services/modules/space-manage/es5.js +967 -955
- package/api-services/modules/space-manage/index.js +793 -770
- package/api-services/modules/space-manage/index.js.gz +0 -0
- package/api-services/modules/super-admin/es5.js +2 -2
- package/api-services/modules/super-admin/index.js +7 -2
- package/api-services/modules/super-admin/index.js.gz +0 -0
- package/api-services/modules/supplier/es5.js +1256 -1268
- package/api-services/modules/supplier/index.js +1065 -1078
- package/api-services/modules/supplier/index.js.gz +0 -0
- package/api-services/modules/supplychain-manage/es5.js +801 -799
- package/api-services/modules/supplychain-manage/index.js +628 -619
- package/api-services/modules/supplychain-manage/index.js.gz +0 -0
- package/api-services/modules/systemConfiguration/es5.js +2 -2
- package/api-services/modules/systemConfiguration/index.js +7 -2
- package/api-services/modules/systemConfiguration/index.js.gz +0 -0
- package/api-services/modules/tool/es5.js +2 -2
- package/api-services/modules/tool/index.js +7 -2
- package/api-services/modules/tool/index.js.gz +0 -0
- package/api-services/src/create-service/es5.js +2 -2
- package/api-services/src/create-service/index.js +7 -2
- package/api-services/src/create-service/index.js.gz +0 -0
- package/common-info/es5.js +11 -9
- package/common-info/getInfoFromUrl/es5.js +40 -40
- package/common-info/getInfoFromUrl/index.js +36 -36
- package/common-info/getInfoFromUrl/index.js.gz +0 -0
- package/common-info/index.js +17 -13
- package/common-info/index.js.gz +0 -0
- package/common-info/set-personal-info/es5.js +22 -22
- package/common-info/set-personal-info/index.js +25 -20
- package/common-info/set-personal-info/index.js.gz +0 -0
- package/common-tools/extract-file-name/es5.js +2 -2
- package/common-tools/extract-file-name/index.js +7 -2
- package/common-tools/extract-file-name/index.js.gz +0 -0
- package/common-tools/handle-data/es5.js +118 -111
- package/common-tools/handle-data/index.js +89 -86
- package/common-tools/handle-data/index.js.gz +0 -0
- package/create-api-service/check-token/es5.js +127 -125
- package/create-api-service/check-token/index.js +123 -118
- package/create-api-service/check-token/index.js.gz +0 -0
- package/create-api-service/es5.js +953 -965
- package/create-api-service/index.js +774 -787
- package/create-api-service/index.js.gz +0 -0
- package/create-api-service/sso/es5.js +3 -3
- package/create-api-service/sso/index.js +8 -3
- package/create-api-service/sso/index.js.gz +0 -0
- package/curring-http/es5.js +2 -2
- package/curring-http/index.js +7 -2
- package/curring-http/index.js.gz +0 -0
- package/package.json +4 -4
- package/pinyin-first-character/es5.js +1 -1
- package/pinyin-first-character/index.js +1 -1
- package/pinyin-first-character/index.js.gz +0 -0
- package/webSocket-service/es5.js +53 -41
- package/webSocket-service/index.js +50 -40
- package/webSocket-service/index.js.gz +0 -0
|
Binary file
|
|
@@ -1801,12 +1801,12 @@ ce.transitional = function (t, n, r) {
|
|
|
1801
1801
|
}
|
|
1802
1802
|
return function (o, i, c) {
|
|
1803
1803
|
if (t === false) throw new y(s(i, " has been removed" + (n ? " in " + n : "")), y.ERR_DEPRECATED);
|
|
1804
|
-
return n && !He[i] && (He[i] = true), t ? t(o, i, c) : true;
|
|
1804
|
+
return n && !He[i] && (He[i] = true, console.warn(s(i, " has been deprecated since v" + n + " and will be removed in the near future"))), t ? t(o, i, c) : true;
|
|
1805
1805
|
};
|
|
1806
1806
|
};
|
|
1807
1807
|
ce.spelling = function (t) {
|
|
1808
1808
|
return function (n, r) {
|
|
1809
|
-
return true;
|
|
1809
|
+
return console.warn("".concat(r, " is likely a misspelling of ").concat(t)), true;
|
|
1810
1810
|
};
|
|
1811
1811
|
};
|
|
1812
1812
|
function pr(e, t, n) {
|
|
@@ -2547,7 +2547,7 @@ var vr = /*#__PURE__*/function () {
|
|
|
2547
2547
|
while (1) switch (_context0.p = _context0.n) {
|
|
2548
2548
|
case 0:
|
|
2549
2549
|
e = kt("code") || "";
|
|
2550
|
-
if (e) {
|
|
2550
|
+
if (!(console.log("getTokenFromCode===", e), !e)) {
|
|
2551
2551
|
_context0.n = 1;
|
|
2552
2552
|
break;
|
|
2553
2553
|
}
|
|
@@ -1357,11 +1357,16 @@ ce.transitional = function(t, n, r) {
|
|
|
1357
1357
|
s(i, " has been removed" + (n ? " in " + n : "")),
|
|
1358
1358
|
y.ERR_DEPRECATED
|
|
1359
1359
|
);
|
|
1360
|
-
return n && !He[i] && (He[i] = !0
|
|
1360
|
+
return n && !He[i] && (He[i] = !0, console.warn(
|
|
1361
|
+
s(
|
|
1362
|
+
i,
|
|
1363
|
+
" has been deprecated since v" + n + " and will be removed in the near future"
|
|
1364
|
+
)
|
|
1365
|
+
)), t ? t(o, i, c) : !0;
|
|
1361
1366
|
};
|
|
1362
1367
|
};
|
|
1363
1368
|
ce.spelling = function(t) {
|
|
1364
|
-
return (n, r) => !0;
|
|
1369
|
+
return (n, r) => (console.warn(`${r} is likely a misspelling of ${t}`), !0);
|
|
1365
1370
|
};
|
|
1366
1371
|
function pr(e, t, n) {
|
|
1367
1372
|
if (typeof e != "object")
|
|
@@ -1933,7 +1938,7 @@ const kt = (e) => new URL(location.href).searchParams.get(e), v = {
|
|
|
1933
1938
|
localStorage.getItem("idelTime") && Pt(Number(localStorage.getItem("idelTime")));
|
|
1934
1939
|
const vr = async () => {
|
|
1935
1940
|
const e = kt("code") || "";
|
|
1936
|
-
if (!e) return M();
|
|
1941
|
+
if (console.log("getTokenFromCode===", e), !e) return M();
|
|
1937
1942
|
const t = Ze(location.href, "kingdee_token") || "";
|
|
1938
1943
|
let n = {};
|
|
1939
1944
|
const r = {
|
|
Binary file
|
package/curring-http/es5.js
CHANGED
|
@@ -1795,12 +1795,12 @@ pe.transitional = function (t, n, r) {
|
|
|
1795
1795
|
}
|
|
1796
1796
|
return function (s, i, c) {
|
|
1797
1797
|
if (t === false) throw new b(o(i, " has been removed" + (n ? " in " + n : "")), b.ERR_DEPRECATED);
|
|
1798
|
-
return n && !et[i] && (et[i] = true), t ? t(s, i, c) : true;
|
|
1798
|
+
return n && !et[i] && (et[i] = true, console.warn(o(i, " has been deprecated since v" + n + " and will be removed in the near future"))), t ? t(s, i, c) : true;
|
|
1799
1799
|
};
|
|
1800
1800
|
};
|
|
1801
1801
|
pe.spelling = function (t) {
|
|
1802
1802
|
return function (n, r) {
|
|
1803
|
-
return true;
|
|
1803
|
+
return console.warn("".concat(r, " is likely a misspelling of ").concat(t)), true;
|
|
1804
1804
|
};
|
|
1805
1805
|
};
|
|
1806
1806
|
function vr(e, t, n) {
|
package/curring-http/index.js
CHANGED
|
@@ -1351,11 +1351,16 @@ pe.transitional = function(t, n, r) {
|
|
|
1351
1351
|
o(i, " has been removed" + (n ? " in " + n : "")),
|
|
1352
1352
|
b.ERR_DEPRECATED
|
|
1353
1353
|
);
|
|
1354
|
-
return n && !et[i] && (et[i] = !0
|
|
1354
|
+
return n && !et[i] && (et[i] = !0, console.warn(
|
|
1355
|
+
o(
|
|
1356
|
+
i,
|
|
1357
|
+
" has been deprecated since v" + n + " and will be removed in the near future"
|
|
1358
|
+
)
|
|
1359
|
+
)), t ? t(s, i, c) : !0;
|
|
1355
1360
|
};
|
|
1356
1361
|
};
|
|
1357
1362
|
pe.spelling = function(t) {
|
|
1358
|
-
return (n, r) => !0;
|
|
1363
|
+
return (n, r) => (console.warn(`${r} is likely a misspelling of ${t}`), !0);
|
|
1359
1364
|
};
|
|
1360
1365
|
function vr(e, t, n) {
|
|
1361
1366
|
if (typeof e != "object")
|
package/curring-http/index.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@das-fed/upf-utils",
|
|
3
|
-
"version": "6.4.0-dev.
|
|
3
|
+
"version": "6.4.0-dev.216",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@antv/x6": "^2.18.1",
|
|
12
|
-
"@das-fed/upf-utils": "6.4.0-dev.
|
|
12
|
+
"@das-fed/upf-utils": "6.4.0-dev.216",
|
|
13
13
|
"@vue/shared": "^3.4.21",
|
|
14
14
|
"@vueuse/core": "^9.6.0",
|
|
15
15
|
"axios": "^1.6.7",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@babel/preset-env": "7.26.0",
|
|
25
|
-
"@das-fed/upf-cli": "6.4.0-dev.
|
|
26
|
-
"@das-fed/upf-web": "6.4.0-dev.
|
|
25
|
+
"@das-fed/upf-cli": "6.4.0-dev.216",
|
|
26
|
+
"@das-fed/upf-web": "6.4.0-dev.216",
|
|
27
27
|
"@rollup/plugin-babel": "6.0.4",
|
|
28
28
|
"@types/js-cookie": "^3.0.6",
|
|
29
29
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -9141,7 +9141,7 @@ var mn = new F(),
|
|
|
9141
9141
|
}), g.join(" ");
|
|
9142
9142
|
},
|
|
9143
9143
|
Sn = function Sn(n) {
|
|
9144
|
-
return typeof n
|
|
9144
|
+
return typeof n != "string" ? (console.error("The first param of pinyin is error: " + n + ' is not assignable to type "string".'), false) : true;
|
|
9145
9145
|
};
|
|
9146
9146
|
function p(n, i) {
|
|
9147
9147
|
return i instanceof RegExp ? i.test(n) : true;
|
|
@@ -23799,7 +23799,7 @@ const mn = new F(), pn = () => mn, e = (n) => {
|
|
|
23799
23799
|
return n.split(" ").forEach((u) => {
|
|
23800
23800
|
g.push(i ? u[0] : u);
|
|
23801
23801
|
}), g.join(" ");
|
|
23802
|
-
}, Sn = (n) => typeof n
|
|
23802
|
+
}, Sn = (n) => typeof n != "string" ? (console.error("The first param of pinyin is error: " + n + ' is not assignable to type "string".'), !1) : !0;
|
|
23803
23803
|
function p(n, i) {
|
|
23804
23804
|
return i instanceof RegExp ? i.test(n) : !0;
|
|
23805
23805
|
}
|
|
Binary file
|
package/webSocket-service/es5.js
CHANGED
|
@@ -17,74 +17,81 @@ var c = config.getConfig(),
|
|
|
17
17
|
var s = "";
|
|
18
18
|
return c.baseURL ? s = c.baseURL : s = location.origin, s.replace("https://", "wss://").replace("http://", "ws://") || "";
|
|
19
19
|
},
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
return
|
|
20
|
+
b = function b(s) {
|
|
21
|
+
var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22
|
+
var t = commonTools.objectToUrlparams(e);
|
|
23
|
+
return t ? h() + s + "?".concat(t) : h() + s;
|
|
24
24
|
},
|
|
25
|
-
|
|
26
|
-
return Math.floor(Math.random() * (
|
|
25
|
+
g = function g(s, e) {
|
|
26
|
+
return Math.floor(Math.random() * (e - s + 1)) + s;
|
|
27
27
|
};
|
|
28
28
|
var R = /*#__PURE__*/function () {
|
|
29
29
|
function R(_ref) {
|
|
30
|
-
var
|
|
30
|
+
var e = _ref.url,
|
|
31
31
|
_ref$params = _ref.params,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
t = _ref$params === void 0 ? {} : _ref$params,
|
|
33
|
+
n = _ref.opened,
|
|
34
|
+
r = _ref.close,
|
|
35
|
+
o = _ref.error,
|
|
36
|
+
i = _ref.message,
|
|
37
|
+
l = _ref.ifReconnect,
|
|
38
|
+
a = _ref.reconnectNum,
|
|
39
39
|
u = _ref.reconnectWhenClose;
|
|
40
40
|
_classCallCheck(this, R);
|
|
41
|
-
if (this.$ws = null, this.url = "", this.params = {}, this.lockReturn = false, this.startTime = 0, this.heartbeatInterval = null, this.ifReconnect = true, this.reconnectId = null, this.reconnectNum = 3, this.reconnectWhenClose = false, this.currentReconnectNum = 0, this.$ws = null, this.startTime = 0, this.heartbeatInterval = null, this.ifReconnect =
|
|
41
|
+
if (this.$ws = null, this.url = "", this.params = {}, this.lockReturn = false, this.startTime = 0, this.heartbeatInterval = null, this.ifReconnect = true, this.reconnectId = null, this.reconnectNum = 3, this.reconnectWhenClose = false, this.currentReconnectNum = 0, this.$ws = null, this.startTime = 0, this.heartbeatInterval = null, this.ifReconnect = l !== null && l !== void 0 ? l : true, this.reconnectNum = a !== null && a !== void 0 ? a : 3, this.reconnectWhenClose = u !== null && u !== void 0 ? u : false, this.lockReturn = false, this.currentReconnectNum = 0, this.reconnectId = null, this.params = _objectSpread(_objectSpread({}, t), {}, {
|
|
42
42
|
access_token: commonInfo.getToken()
|
|
43
|
-
}),
|
|
44
|
-
|
|
43
|
+
}), e) this.url = e;else throw new Error("url is required");
|
|
44
|
+
n && (this.opened = n), r && (this.close = r), o && (this.error = o), i && (this.afterMsg = i), this.initWebSocket();
|
|
45
45
|
}
|
|
46
46
|
return _createClass(R, [{
|
|
47
47
|
key: "initWebSocket",
|
|
48
48
|
value: function initWebSocket() {
|
|
49
49
|
var _this = this;
|
|
50
50
|
if ((typeof WebSocket === "undefined" ? "undefined" : _typeof(WebSocket)) > "u") throw new Error("您的浏览器不支持websocket");
|
|
51
|
-
var
|
|
52
|
-
this.$ws = new WebSocket(
|
|
51
|
+
var e = b(this.url, this.params);
|
|
52
|
+
this.$ws = new WebSocket(e), this.$ws.onopen = function () {
|
|
53
53
|
_this.open();
|
|
54
|
-
}, this.$ws.onclose = function (
|
|
55
|
-
_this.close(
|
|
56
|
-
}, this.$ws.onmessage = function (
|
|
57
|
-
_this.message(
|
|
58
|
-
}, this.$ws.onerror = function (
|
|
59
|
-
_this.error(
|
|
54
|
+
}, this.$ws.onclose = function (t) {
|
|
55
|
+
_this.close(t);
|
|
56
|
+
}, this.$ws.onmessage = function (t) {
|
|
57
|
+
_this.message(t);
|
|
58
|
+
}, this.$ws.onerror = function (t) {
|
|
59
|
+
_this.error(t);
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}, {
|
|
63
63
|
key: "open",
|
|
64
64
|
value: function open() {
|
|
65
|
-
this.currentReconnectNum = 0, this.startTime = (/* @__PURE__ */new Date()).getTime(), this.opened(this.$ws), this.startHeartbeat();
|
|
65
|
+
this.currentReconnectNum = 0, this.startTime = (/* @__PURE__ */new Date()).getTime(), this.opened(this.$ws), this.startHeartbeat(), console.log(this.url + " =>websocket连接成功,可以开始通讯");
|
|
66
66
|
}
|
|
67
67
|
}, {
|
|
68
68
|
key: "opened",
|
|
69
|
-
value: function opened(
|
|
69
|
+
value: function opened(e) {
|
|
70
|
+
console.log(this.url + " =>websocket连接已打开:", e);
|
|
71
|
+
}
|
|
70
72
|
}, {
|
|
71
73
|
key: "close",
|
|
72
|
-
value: function close(
|
|
73
|
-
this.$ws.readyState === WebSocket.CLOSED
|
|
74
|
+
value: function close(e) {
|
|
75
|
+
if (this.$ws.readyState === WebSocket.CLOSED) {
|
|
76
|
+
var t = (/* @__PURE__ */new Date()).getTime();
|
|
77
|
+
this.reconnectWhenClose && this.reconnect(), clearInterval(this.heartbeatInterval), console.log("".concat(this.url, "=>WebSocket\u8FDE\u63A5\u5DF2\u7ECF\u5173\u95ED,\u8FDE\u63A5\u603B\u65F6\u957F: ").concat(t - this.startTime, "ms"));
|
|
78
|
+
}
|
|
74
79
|
}
|
|
75
80
|
}, {
|
|
76
81
|
key: "message",
|
|
77
|
-
value: function message(
|
|
78
|
-
var
|
|
79
|
-
this.afterMsg(
|
|
82
|
+
value: function message(e) {
|
|
83
|
+
var t = _typeof(e.data) == "object" ? e.data : JSON.parse(e.data);
|
|
84
|
+
this.afterMsg(t);
|
|
80
85
|
}
|
|
81
86
|
}, {
|
|
82
87
|
key: "afterMsg",
|
|
83
|
-
value: function afterMsg(
|
|
88
|
+
value: function afterMsg(e) {
|
|
89
|
+
console.log(this.url + " =>接收到websocket的消息:", e);
|
|
90
|
+
}
|
|
84
91
|
}, {
|
|
85
92
|
key: "error",
|
|
86
|
-
value: function error(
|
|
87
|
-
return this.ifReconnect && this.reconnect(),
|
|
93
|
+
value: function error(e) {
|
|
94
|
+
return this.ifReconnect && this.reconnect(), e;
|
|
88
95
|
}
|
|
89
96
|
/** websocket重连 */
|
|
90
97
|
}, {
|
|
@@ -98,9 +105,13 @@ var R = /*#__PURE__*/function () {
|
|
|
98
105
|
/** 发送消息给服务器 */
|
|
99
106
|
}, {
|
|
100
107
|
key: "send",
|
|
101
|
-
value: function send(
|
|
102
|
-
var
|
|
103
|
-
((
|
|
108
|
+
value: function send(e) {
|
|
109
|
+
var t;
|
|
110
|
+
if (((t = this.$ws) == null ? undefined : t.readyState) !== WebSocket.OPEN) {
|
|
111
|
+
console.log(this.url + "=>websocket连接未建立,还不能发送消息");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.$ws.send(e);
|
|
104
115
|
}
|
|
105
116
|
// 启动心跳检测==>30s-5分钟内随机发一次心跳保持会话(时间区间内随机是为了降低突增流量的概率)
|
|
106
117
|
}, {
|
|
@@ -108,14 +119,15 @@ var R = /*#__PURE__*/function () {
|
|
|
108
119
|
value: function startHeartbeat() {
|
|
109
120
|
var _this3 = this;
|
|
110
121
|
this.heartbeatInterval = setInterval(function () {
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
var e = "";
|
|
123
|
+
_this3.send(e), console.log(_this3.url + "=>心跳检测发送消息:", e);
|
|
124
|
+
}, g(3e4, 3e5));
|
|
113
125
|
}
|
|
114
126
|
/** 断开连接 */
|
|
115
127
|
}, {
|
|
116
128
|
key: "disconnect",
|
|
117
129
|
value: function disconnect() {
|
|
118
|
-
this.$ws.close();
|
|
130
|
+
this.$ws.close(), console.log(this.url + " =>主动断开websocket连接");
|
|
119
131
|
}
|
|
120
132
|
}]);
|
|
121
133
|
}();
|
|
@@ -1,60 +1,65 @@
|
|
|
1
1
|
import { getConfig as m } from "@das-fed/upf-utils/config";
|
|
2
2
|
import { getToken as f } from "@das-fed/upf-utils/common-info";
|
|
3
|
-
import { objectToUrlparams as
|
|
3
|
+
import { objectToUrlparams as w } from "@das-fed/upf-utils/common-tools";
|
|
4
4
|
const c = m(), h = () => {
|
|
5
5
|
let s = "";
|
|
6
6
|
return c.baseURL ? s = c.baseURL : s = location.origin, s.replace("https://", "wss://").replace("http://", "ws://") || "";
|
|
7
|
-
},
|
|
8
|
-
const
|
|
9
|
-
return
|
|
10
|
-
},
|
|
7
|
+
}, b = (s, e = {}) => {
|
|
8
|
+
const t = w(e);
|
|
9
|
+
return t ? h() + s + `?${t}` : h() + s;
|
|
10
|
+
}, g = (s, e) => Math.floor(Math.random() * (e - s + 1)) + s;
|
|
11
11
|
class R {
|
|
12
12
|
constructor({
|
|
13
|
-
url:
|
|
14
|
-
params:
|
|
15
|
-
opened:
|
|
16
|
-
close:
|
|
17
|
-
error:
|
|
18
|
-
message:
|
|
19
|
-
ifReconnect:
|
|
20
|
-
reconnectNum:
|
|
13
|
+
url: e,
|
|
14
|
+
params: t = {},
|
|
15
|
+
opened: n,
|
|
16
|
+
close: r,
|
|
17
|
+
error: o,
|
|
18
|
+
message: i,
|
|
19
|
+
ifReconnect: l,
|
|
20
|
+
reconnectNum: a,
|
|
21
21
|
reconnectWhenClose: u
|
|
22
22
|
}) {
|
|
23
|
-
if (this.$ws = null, this.url = "", this.params = {}, this.lockReturn = !1, this.startTime = 0, this.heartbeatInterval = null, this.ifReconnect = !0, this.reconnectId = null, this.reconnectNum = 3, this.reconnectWhenClose = !1, this.currentReconnectNum = 0, this.$ws = null, this.startTime = 0, this.heartbeatInterval = null, this.ifReconnect =
|
|
24
|
-
this.url =
|
|
23
|
+
if (this.$ws = null, this.url = "", this.params = {}, this.lockReturn = !1, this.startTime = 0, this.heartbeatInterval = null, this.ifReconnect = !0, this.reconnectId = null, this.reconnectNum = 3, this.reconnectWhenClose = !1, this.currentReconnectNum = 0, this.$ws = null, this.startTime = 0, this.heartbeatInterval = null, this.ifReconnect = l ?? !0, this.reconnectNum = a ?? 3, this.reconnectWhenClose = u ?? !1, this.lockReturn = !1, this.currentReconnectNum = 0, this.reconnectId = null, this.params = { ...t, access_token: f() }, e)
|
|
24
|
+
this.url = e;
|
|
25
25
|
else
|
|
26
26
|
throw new Error("url is required");
|
|
27
|
-
|
|
27
|
+
n && (this.opened = n), r && (this.close = r), o && (this.error = o), i && (this.afterMsg = i), this.initWebSocket();
|
|
28
28
|
}
|
|
29
29
|
initWebSocket() {
|
|
30
30
|
if (typeof WebSocket > "u") throw new Error("您的浏览器不支持websocket");
|
|
31
|
-
const
|
|
32
|
-
this.$ws = new WebSocket(
|
|
31
|
+
const e = b(this.url, this.params);
|
|
32
|
+
this.$ws = new WebSocket(e), this.$ws.onopen = () => {
|
|
33
33
|
this.open();
|
|
34
|
-
}, this.$ws.onclose = (
|
|
35
|
-
this.close(
|
|
36
|
-
}, this.$ws.onmessage = (
|
|
37
|
-
this.message(
|
|
38
|
-
}, this.$ws.onerror = (
|
|
39
|
-
this.error(
|
|
34
|
+
}, this.$ws.onclose = (t) => {
|
|
35
|
+
this.close(t);
|
|
36
|
+
}, this.$ws.onmessage = (t) => {
|
|
37
|
+
this.message(t);
|
|
38
|
+
}, this.$ws.onerror = (t) => {
|
|
39
|
+
this.error(t);
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
open() {
|
|
43
|
-
this.currentReconnectNum = 0, this.startTime = (/* @__PURE__ */ new Date()).getTime(), this.opened(this.$ws), this.startHeartbeat();
|
|
43
|
+
this.currentReconnectNum = 0, this.startTime = (/* @__PURE__ */ new Date()).getTime(), this.opened(this.$ws), this.startHeartbeat(), console.log(this.url + " =>websocket连接成功,可以开始通讯");
|
|
44
44
|
}
|
|
45
|
-
opened(
|
|
45
|
+
opened(e) {
|
|
46
|
+
console.log(this.url + " =>websocket连接已打开:", e);
|
|
46
47
|
}
|
|
47
|
-
close(
|
|
48
|
-
this.$ws.readyState === WebSocket.CLOSED
|
|
48
|
+
close(e) {
|
|
49
|
+
if (this.$ws.readyState === WebSocket.CLOSED) {
|
|
50
|
+
const t = (/* @__PURE__ */ new Date()).getTime();
|
|
51
|
+
this.reconnectWhenClose && this.reconnect(), clearInterval(this.heartbeatInterval), console.log(`${this.url}=>WebSocket连接已经关闭,连接总时长: ${t - this.startTime}ms`);
|
|
52
|
+
}
|
|
49
53
|
}
|
|
50
|
-
message(
|
|
51
|
-
const
|
|
52
|
-
this.afterMsg(
|
|
54
|
+
message(e) {
|
|
55
|
+
const t = typeof e.data == "object" ? e.data : JSON.parse(e.data);
|
|
56
|
+
this.afterMsg(t);
|
|
53
57
|
}
|
|
54
|
-
afterMsg(
|
|
58
|
+
afterMsg(e) {
|
|
59
|
+
console.log(this.url + " =>接收到websocket的消息:", e);
|
|
55
60
|
}
|
|
56
|
-
error(
|
|
57
|
-
return this.ifReconnect && this.reconnect(),
|
|
61
|
+
error(e) {
|
|
62
|
+
return this.ifReconnect && this.reconnect(), e;
|
|
58
63
|
}
|
|
59
64
|
/** websocket重连 */
|
|
60
65
|
reconnect() {
|
|
@@ -63,19 +68,24 @@ class R {
|
|
|
63
68
|
}, 3e3)));
|
|
64
69
|
}
|
|
65
70
|
/** 发送消息给服务器 */
|
|
66
|
-
send(
|
|
67
|
-
var
|
|
68
|
-
((
|
|
71
|
+
send(e) {
|
|
72
|
+
var t;
|
|
73
|
+
if (((t = this.$ws) == null ? void 0 : t.readyState) !== WebSocket.OPEN) {
|
|
74
|
+
console.log(this.url + "=>websocket连接未建立,还不能发送消息");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.$ws.send(e);
|
|
69
78
|
}
|
|
70
79
|
// 启动心跳检测==>30s-5分钟内随机发一次心跳保持会话(时间区间内随机是为了降低突增流量的概率)
|
|
71
80
|
startHeartbeat() {
|
|
72
81
|
this.heartbeatInterval = setInterval(() => {
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
const e = "";
|
|
83
|
+
this.send(e), console.log(this.url + "=>心跳检测发送消息:", e);
|
|
84
|
+
}, g(3e4, 3e5));
|
|
75
85
|
}
|
|
76
86
|
/** 断开连接 */
|
|
77
87
|
disconnect() {
|
|
78
|
-
this.$ws.close();
|
|
88
|
+
this.$ws.close(), console.log(this.url + " =>主动断开websocket连接");
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
91
|
export {
|
|
Binary file
|