@das-fed/upf-utils 6.4.0-hot.8 → 6.4.0-test.0
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 +1576 -1470
- package/api-services/index.js +1067 -1032
- package/api-services/index.js.gz +0 -0
- package/api-services/modules/app-manage/es5.js +1359 -1266
- package/api-services/modules/app-manage/index.js +1071 -1055
- package/api-services/modules/app-manage/index.js.gz +0 -0
- package/api-services/modules/authentication/es5.js +1316 -1223
- package/api-services/modules/authentication/index.js +1029 -1013
- package/api-services/modules/authentication/index.js.gz +0 -0
- package/api-services/modules/bems/es5.js +1819 -1738
- package/api-services/modules/bems/index.js +1422 -1424
- package/api-services/modules/bems/index.js.gz +0 -0
- package/api-services/modules/contract/es5.js +1359 -1266
- package/api-services/modules/contract/index.js +1071 -1055
- package/api-services/modules/contract/index.js.gz +0 -0
- package/api-services/modules/duty-manage/es5.js +1859 -1754
- package/api-services/modules/duty-manage/index.js +1461 -1427
- package/api-services/modules/duty-manage/index.js.gz +0 -0
- package/api-services/modules/enterpriseright/es5.js +1359 -1266
- package/api-services/modules/enterpriseright/index.js +1071 -1055
- package/api-services/modules/enterpriseright/index.js.gz +0 -0
- package/api-services/modules/es5.js +1880 -1795
- package/api-services/modules/file/es5.js +1460 -1354
- package/api-services/modules/file/index.js +996 -961
- package/api-services/modules/file/index.js.gz +0 -0
- package/api-services/modules/gateway-edge/es5.js +1819 -1738
- package/api-services/modules/gateway-edge/index.js +1423 -1425
- package/api-services/modules/gateway-edge/index.js.gz +0 -0
- package/api-services/modules/index.js +1337 -1334
- package/api-services/modules/index.js.gz +0 -0
- package/api-services/modules/iot/es5.js +1875 -1770
- package/api-services/modules/iot/index.js +1475 -1441
- package/api-services/modules/iot/index.js.gz +0 -0
- package/api-services/modules/justauth/es5.js +1821 -1740
- package/api-services/modules/justauth/index.js +1424 -1426
- package/api-services/modules/justauth/index.js.gz +0 -0
- package/api-services/modules/knowledge/es5.js +1359 -1266
- package/api-services/modules/knowledge/index.js +1071 -1055
- package/api-services/modules/knowledge/index.js.gz +0 -0
- package/api-services/modules/link/es5.js +1359 -1266
- package/api-services/modules/link/index.js +1071 -1055
- package/api-services/modules/link/index.js.gz +0 -0
- package/api-services/modules/permission/es5.js +1850 -1745
- package/api-services/modules/permission/index.js +1456 -1422
- package/api-services/modules/permission/index.js.gz +0 -0
- package/api-services/modules/platformManage/es5.js +1369 -1276
- package/api-services/modules/platformManage/index.js +1074 -1058
- package/api-services/modules/platformManage/index.js.gz +0 -0
- package/api-services/modules/portal/es5.js +1359 -1266
- package/api-services/modules/portal/index.js +1071 -1055
- package/api-services/modules/portal/index.js.gz +0 -0
- package/api-services/modules/space-manage/es5.js +1359 -1266
- package/api-services/modules/space-manage/index.js +1071 -1055
- package/api-services/modules/space-manage/index.js.gz +0 -0
- package/api-services/modules/super-admin/es5.js +1390 -1297
- package/api-services/modules/super-admin/index.js +1088 -1072
- package/api-services/modules/super-admin/index.js.gz +0 -0
- package/api-services/modules/supplier/es5.js +1758 -1668
- package/api-services/modules/supplier/index.js +1354 -1342
- package/api-services/modules/supplier/index.js.gz +0 -0
- package/api-services/modules/supplychain-manage/es5.js +1679 -1584
- package/api-services/modules/supplychain-manage/index.js +1303 -1283
- package/api-services/modules/supplychain-manage/index.js.gz +0 -0
- package/api-services/modules/systemConfiguration/es5.js +1359 -1266
- package/api-services/modules/systemConfiguration/index.js +1071 -1055
- package/api-services/modules/systemConfiguration/index.js.gz +0 -0
- package/api-services/modules/tool/es5.js +1850 -1745
- package/api-services/modules/tool/index.js +1456 -1422
- package/api-services/modules/tool/index.js.gz +0 -0
- package/api-services/src/create-service/es5.js +1357 -1264
- package/api-services/src/create-service/index.js +1070 -1055
- package/api-services/src/create-service/index.js.gz +0 -0
- package/common-info/es5.js +4468 -220
- 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/getPermissionMethod/es5.js +4218 -0
- package/common-info/getPermissionMethod/index.d.ts +26 -0
- package/common-info/getPermissionMethod/index.js +3342 -0
- package/common-info/getPermissionMethod/index.js.gz +0 -0
- package/common-info/index.d.ts +11 -2
- package/common-info/index.js +3540 -187
- package/common-info/index.js.gz +0 -0
- package/common-info/set-personal-info/es5.js +22 -23
- package/common-info/set-personal-info/index.js +20 -26
- 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 +2 -7
- package/common-tools/extract-file-name/index.js.gz +0 -0
- package/common-tools/handle-data/es5.js +111 -118
- package/common-tools/handle-data/index.js +86 -89
- package/common-tools/handle-data/index.js.gz +0 -0
- package/create-api-service/check-token/es5.js +125 -127
- package/create-api-service/check-token/index.js +118 -123
- package/create-api-service/check-token/index.js.gz +0 -0
- package/create-api-service/es5.js +1358 -1264
- package/create-api-service/index.d.ts +7 -7
- package/create-api-service/index.js +1072 -1056
- package/create-api-service/index.js.gz +0 -0
- package/create-api-service/sso/es5.js +317 -325
- package/create-api-service/sso/index.js +273 -279
- package/create-api-service/sso/index.js.gz +0 -0
- package/curring-http/es5.js +2 -2
- package/curring-http/index.js +2 -7
- package/curring-http/index.js.gz +0 -0
- package/directive/auth/es5.js +60 -68
- package/directive/auth/index.js +37 -45
- package/directive/auth/index.js.gz +0 -0
- package/esm-map.json +11 -1
- package/hooks/use-get-auth/es5.js +57 -191
- package/hooks/use-get-auth/index.d.ts +2 -7
- package/hooks/use-get-auth/index.js +16 -50
- package/i18n-bridge/es5.js +23 -0
- package/i18n-bridge/index.d.ts +10 -0
- package/i18n-bridge/index.js +16 -0
- package/package.json +3 -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 +41 -53
- package/webSocket-service/index.js +40 -50
- package/webSocket-service/index.js.gz +0 -0
- package/hooks/use-get-auth/apis.d.ts +0 -4
- package/hooks/use-get-auth/index.js.gz +0 -0
|
@@ -1,53 +1,19 @@
|
|
|
1
|
-
import { flatTree as
|
|
2
|
-
import { projectNextTick as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
}, g = async (r, i, t, s = "enterpriseadmin") => {
|
|
14
|
-
var c;
|
|
15
|
-
await A();
|
|
16
|
-
let u = null, l = {
|
|
17
|
-
code: r,
|
|
18
|
-
showBtn: !0
|
|
19
|
-
};
|
|
20
|
-
s === "superadmin" ? u = P().run : (l.userType = 1, u = L().run);
|
|
21
|
-
const [f, e] = await u(l);
|
|
22
|
-
if (f || !e || !e.length)
|
|
23
|
-
return i || t ? void 0 : [];
|
|
24
|
-
if (!i && !t) return e;
|
|
25
|
-
const p = e != null && e.length ? e.filter((n) => n.routeUrl) : [], m = e != null && e.length ? e.filter((n) => !n.routeUrl && n.children).map((n) => n.children).flat() : [], o = [...p, ...m];
|
|
1
|
+
import { flatTree as o } from "@das-fed/upf-utils/common-tools";
|
|
2
|
+
import { projectNextTick as s } from "@das-fed/upf-utils/nextTiken";
|
|
3
|
+
const l = () => ({
|
|
4
|
+
getApplication: async (t) => {
|
|
5
|
+
await s();
|
|
6
|
+
const i = JSON.parse(sessionStorage.getItem("menuList") || "[]").filter((e) => e.type === "application");
|
|
7
|
+
return t ? i.find((e) => e.appId === t) : i;
|
|
8
|
+
},
|
|
9
|
+
getMenu: async (t, n) => {
|
|
10
|
+
await s();
|
|
11
|
+
const i = JSON.parse(sessionStorage.getItem("menuList") || "[]"), e = o(i).filter((r) => r.type === "menu");
|
|
12
|
+
if (!t && !n) return e;
|
|
26
13
|
let a;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const n = t.replace(((c = o[0]) == null ? void 0 : c.applicationPath) ?? "", "").replace(/\/\//g, "/");
|
|
31
|
-
a = o.find((h) => h.routeUrl && h.routeUrl === n);
|
|
32
|
-
}
|
|
33
|
-
return a;
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
getApplication: d,
|
|
37
|
-
getMenu: g,
|
|
38
|
-
getAuth: async (r, i = "enterpriseadmin") => {
|
|
39
|
-
var o;
|
|
40
|
-
const t = (r == null ? void 0 : r.applicationCode) ?? "", s = (r == null ? void 0 : r.menuCode) ?? "", u = (r == null ? void 0 : r.code) ?? "";
|
|
41
|
-
if (JSON.parse(sessionStorage.getItem("permission-btn") || "{}")[s]) return M(null, { applicationCode: t, menuCode: s, code: u });
|
|
42
|
-
if (!await d(t, i)) return !1;
|
|
43
|
-
const e = await g(t, s, i);
|
|
44
|
-
return !e || !(e != null && e.children) || !((o = e.children) != null && o.length) ? !1 : !!w(e.children).find((a) => {
|
|
45
|
-
let c = (a == null ? void 0 : a.originalCode) ?? a.code;
|
|
46
|
-
return c.includes(s + ".") && (c = c.replace(s + ".", "").replaceAll(".", "-")), c === u;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
};
|
|
14
|
+
return t ? a = e.find((r) => r.routeCode === t || r.originalCode === t) : n && (a = e.find((r) => r.routeUrl === n)), a;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
51
17
|
export {
|
|
52
|
-
|
|
18
|
+
l as useGetAuth
|
|
53
19
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var n = {
|
|
4
|
+
// 默认返回 key,避免 bridge 未初始化时出现运行时异常。
|
|
5
|
+
t: function t(_t) {
|
|
6
|
+
return _t;
|
|
7
|
+
},
|
|
8
|
+
currentLang: {
|
|
9
|
+
value: ""
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var e = n;
|
|
13
|
+
var r = function r(t) {
|
|
14
|
+
e = {
|
|
15
|
+
t: t.t || e.t,
|
|
16
|
+
currentLang: t.currentLang || e.currentLang
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
a = function a() {
|
|
20
|
+
return e;
|
|
21
|
+
};
|
|
22
|
+
exports.getI18nBridge = a;
|
|
23
|
+
exports.setI18nBridge = r;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type I18nBridgeLangRef = {
|
|
2
|
+
value: string;
|
|
3
|
+
};
|
|
4
|
+
export type I18nBridgeT = (key: string, ...args: any[]) => string;
|
|
5
|
+
export type I18nBridgeState = {
|
|
6
|
+
t: I18nBridgeT;
|
|
7
|
+
currentLang: I18nBridgeLangRef;
|
|
8
|
+
};
|
|
9
|
+
export declare const setI18nBridge: (next: Partial<I18nBridgeState>) => void;
|
|
10
|
+
export declare const getI18nBridge: () => I18nBridgeState;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const n = {
|
|
2
|
+
// 默认返回 key,避免 bridge 未初始化时出现运行时异常。
|
|
3
|
+
t: (t) => t,
|
|
4
|
+
currentLang: { value: "" }
|
|
5
|
+
};
|
|
6
|
+
let e = n;
|
|
7
|
+
const r = (t) => {
|
|
8
|
+
e = {
|
|
9
|
+
t: t.t || e.t,
|
|
10
|
+
currentLang: t.currentLang || e.currentLang
|
|
11
|
+
};
|
|
12
|
+
}, a = () => e;
|
|
13
|
+
export {
|
|
14
|
+
a as getI18nBridge,
|
|
15
|
+
r as setI18nBridge
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@das-fed/upf-utils",
|
|
3
|
-
"version": "6.4.0-
|
|
3
|
+
"version": "6.4.0-test.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@antv/x6": "^2.18.1",
|
|
12
|
-
"@das-fed/upf-utils": "6.4.0-hot.8",
|
|
13
12
|
"@vue/shared": "^3.4.21",
|
|
14
13
|
"@vueuse/core": "^9.6.0",
|
|
15
14
|
"axios": "^1.6.7",
|
|
@@ -22,8 +21,8 @@
|
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"@babel/preset-env": "7.26.0",
|
|
25
|
-
"@das-fed/upf-cli": "6.4.0-
|
|
26
|
-
"@das-fed/upf-web": "6.4.0-
|
|
24
|
+
"@das-fed/upf-cli": "6.4.0-test.0",
|
|
25
|
+
"@das-fed/upf-web": "6.4.0-test.0",
|
|
27
26
|
"@rollup/plugin-babel": "6.0.4",
|
|
28
27
|
"@types/js-cookie": "^3.0.6",
|
|
29
28
|
"@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";
|
|
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";
|
|
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,81 +17,74 @@ 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
|
+
w = function w(s) {
|
|
21
|
+
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22
|
+
var e = commonTools.objectToUrlparams(t);
|
|
23
|
+
return e ? h() + s + "?".concat(e) : h() + s;
|
|
24
24
|
},
|
|
25
|
-
|
|
26
|
-
return Math.floor(Math.random() * (
|
|
25
|
+
p = function p(s, t) {
|
|
26
|
+
return Math.floor(Math.random() * (t - s + 1)) + s;
|
|
27
27
|
};
|
|
28
28
|
var R = /*#__PURE__*/function () {
|
|
29
29
|
function R(_ref) {
|
|
30
|
-
var
|
|
30
|
+
var t = _ref.url,
|
|
31
31
|
_ref$params = _ref.params,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
e = _ref$params === void 0 ? {} : _ref$params,
|
|
33
|
+
r = _ref.opened,
|
|
34
|
+
n = _ref.close,
|
|
35
|
+
i = _ref.error,
|
|
36
|
+
o = _ref.message,
|
|
37
|
+
a = _ref.ifReconnect,
|
|
38
|
+
l = _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 = a !== null && a !== void 0 ? a : true, this.reconnectNum = l !== null && l !== void 0 ? l : 3, this.reconnectWhenClose = u !== null && u !== void 0 ? u : false, this.lockReturn = false, this.currentReconnectNum = 0, this.reconnectId = null, this.params = _objectSpread(_objectSpread({}, e), {}, {
|
|
42
42
|
access_token: commonInfo.getToken()
|
|
43
|
-
}),
|
|
44
|
-
|
|
43
|
+
}), t) this.url = t;else throw new Error("url is required");
|
|
44
|
+
r && (this.opened = r), n && (this.close = n), i && (this.error = i), o && (this.afterMsg = o), 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 t = w(this.url, this.params);
|
|
52
|
+
this.$ws = new WebSocket(t), 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 (e) {
|
|
55
|
+
_this.close(e);
|
|
56
|
+
}, this.$ws.onmessage = function (e) {
|
|
57
|
+
_this.message(e);
|
|
58
|
+
}, this.$ws.onerror = function (e) {
|
|
59
|
+
_this.error(e);
|
|
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();
|
|
66
66
|
}
|
|
67
67
|
}, {
|
|
68
68
|
key: "opened",
|
|
69
|
-
value: function opened(
|
|
70
|
-
console.log(this.url + " =>websocket连接已打开:", e);
|
|
71
|
-
}
|
|
69
|
+
value: function opened(t) {}
|
|
72
70
|
}, {
|
|
73
71
|
key: "close",
|
|
74
|
-
value: function close(
|
|
75
|
-
|
|
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
|
-
}
|
|
72
|
+
value: function close(t) {
|
|
73
|
+
this.$ws.readyState === WebSocket.CLOSED && ((/* @__PURE__ */new Date()).getTime(), this.reconnectWhenClose && this.reconnect(), clearInterval(this.heartbeatInterval));
|
|
79
74
|
}
|
|
80
75
|
}, {
|
|
81
76
|
key: "message",
|
|
82
|
-
value: function message(
|
|
83
|
-
var
|
|
84
|
-
this.afterMsg(
|
|
77
|
+
value: function message(t) {
|
|
78
|
+
var e = _typeof(t.data) == "object" ? t.data : JSON.parse(t.data);
|
|
79
|
+
this.afterMsg(e);
|
|
85
80
|
}
|
|
86
81
|
}, {
|
|
87
82
|
key: "afterMsg",
|
|
88
|
-
value: function afterMsg(
|
|
89
|
-
console.log(this.url + " =>接收到websocket的消息:", e);
|
|
90
|
-
}
|
|
83
|
+
value: function afterMsg(t) {}
|
|
91
84
|
}, {
|
|
92
85
|
key: "error",
|
|
93
|
-
value: function error(
|
|
94
|
-
return this.ifReconnect && this.reconnect(),
|
|
86
|
+
value: function error(t) {
|
|
87
|
+
return this.ifReconnect && this.reconnect(), t;
|
|
95
88
|
}
|
|
96
89
|
/** websocket重连 */
|
|
97
90
|
}, {
|
|
@@ -105,13 +98,9 @@ var R = /*#__PURE__*/function () {
|
|
|
105
98
|
/** 发送消息给服务器 */
|
|
106
99
|
}, {
|
|
107
100
|
key: "send",
|
|
108
|
-
value: function send(
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
console.log(this.url + "=>websocket连接未建立,还不能发送消息");
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
this.$ws.send(e);
|
|
101
|
+
value: function send(t) {
|
|
102
|
+
var e;
|
|
103
|
+
((e = this.$ws) == null ? undefined : e.readyState) === WebSocket.OPEN && this.$ws.send(t);
|
|
115
104
|
}
|
|
116
105
|
// 启动心跳检测==>30s-5分钟内随机发一次心跳保持会话(时间区间内随机是为了降低突增流量的概率)
|
|
117
106
|
}, {
|
|
@@ -119,15 +108,14 @@ var R = /*#__PURE__*/function () {
|
|
|
119
108
|
value: function startHeartbeat() {
|
|
120
109
|
var _this3 = this;
|
|
121
110
|
this.heartbeatInterval = setInterval(function () {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}, g(3e4, 3e5));
|
|
111
|
+
_this3.send("");
|
|
112
|
+
}, p(3e4, 3e5));
|
|
125
113
|
}
|
|
126
114
|
/** 断开连接 */
|
|
127
115
|
}, {
|
|
128
116
|
key: "disconnect",
|
|
129
117
|
value: function disconnect() {
|
|
130
|
-
this.$ws.close()
|
|
118
|
+
this.$ws.close();
|
|
131
119
|
}
|
|
132
120
|
}]);
|
|
133
121
|
}();
|
|
@@ -1,65 +1,60 @@
|
|
|
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 d } 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
|
+
}, w = (s, t = {}) => {
|
|
8
|
+
const e = d(t);
|
|
9
|
+
return e ? h() + s + `?${e}` : h() + s;
|
|
10
|
+
}, p = (s, t) => Math.floor(Math.random() * (t - 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: t,
|
|
14
|
+
params: e = {},
|
|
15
|
+
opened: r,
|
|
16
|
+
close: n,
|
|
17
|
+
error: i,
|
|
18
|
+
message: o,
|
|
19
|
+
ifReconnect: a,
|
|
20
|
+
reconnectNum: l,
|
|
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 = a ?? !0, this.reconnectNum = l ?? 3, this.reconnectWhenClose = u ?? !1, this.lockReturn = !1, this.currentReconnectNum = 0, this.reconnectId = null, this.params = { ...e, access_token: f() }, t)
|
|
24
|
+
this.url = t;
|
|
25
25
|
else
|
|
26
26
|
throw new Error("url is required");
|
|
27
|
-
|
|
27
|
+
r && (this.opened = r), n && (this.close = n), i && (this.error = i), o && (this.afterMsg = o), 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 t = w(this.url, this.params);
|
|
32
|
+
this.$ws = new WebSocket(t), 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 = (e) => {
|
|
35
|
+
this.close(e);
|
|
36
|
+
}, this.$ws.onmessage = (e) => {
|
|
37
|
+
this.message(e);
|
|
38
|
+
}, this.$ws.onerror = (e) => {
|
|
39
|
+
this.error(e);
|
|
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();
|
|
44
44
|
}
|
|
45
|
-
opened(
|
|
46
|
-
console.log(this.url + " =>websocket连接已打开:", e);
|
|
45
|
+
opened(t) {
|
|
47
46
|
}
|
|
48
|
-
close(
|
|
49
|
-
|
|
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
|
-
}
|
|
47
|
+
close(t) {
|
|
48
|
+
this.$ws.readyState === WebSocket.CLOSED && ((/* @__PURE__ */ new Date()).getTime(), this.reconnectWhenClose && this.reconnect(), clearInterval(this.heartbeatInterval));
|
|
53
49
|
}
|
|
54
|
-
message(
|
|
55
|
-
const
|
|
56
|
-
this.afterMsg(
|
|
50
|
+
message(t) {
|
|
51
|
+
const e = typeof t.data == "object" ? t.data : JSON.parse(t.data);
|
|
52
|
+
this.afterMsg(e);
|
|
57
53
|
}
|
|
58
|
-
afterMsg(
|
|
59
|
-
console.log(this.url + " =>接收到websocket的消息:", e);
|
|
54
|
+
afterMsg(t) {
|
|
60
55
|
}
|
|
61
|
-
error(
|
|
62
|
-
return this.ifReconnect && this.reconnect(),
|
|
56
|
+
error(t) {
|
|
57
|
+
return this.ifReconnect && this.reconnect(), t;
|
|
63
58
|
}
|
|
64
59
|
/** websocket重连 */
|
|
65
60
|
reconnect() {
|
|
@@ -68,24 +63,19 @@ class R {
|
|
|
68
63
|
}, 3e3)));
|
|
69
64
|
}
|
|
70
65
|
/** 发送消息给服务器 */
|
|
71
|
-
send(
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
console.log(this.url + "=>websocket连接未建立,还不能发送消息");
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this.$ws.send(e);
|
|
66
|
+
send(t) {
|
|
67
|
+
var e;
|
|
68
|
+
((e = this.$ws) == null ? void 0 : e.readyState) === WebSocket.OPEN && this.$ws.send(t);
|
|
78
69
|
}
|
|
79
70
|
// 启动心跳检测==>30s-5分钟内随机发一次心跳保持会话(时间区间内随机是为了降低突增流量的概率)
|
|
80
71
|
startHeartbeat() {
|
|
81
72
|
this.heartbeatInterval = setInterval(() => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, g(3e4, 3e5));
|
|
73
|
+
this.send("");
|
|
74
|
+
}, p(3e4, 3e5));
|
|
85
75
|
}
|
|
86
76
|
/** 断开连接 */
|
|
87
77
|
disconnect() {
|
|
88
|
-
this.$ws.close()
|
|
78
|
+
this.$ws.close();
|
|
89
79
|
}
|
|
90
80
|
}
|
|
91
81
|
export {
|
|
Binary file
|
|
Binary file
|