@das-fed/utils 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-services/index.d.ts +1 -0
- package/api-services/index.js +3 -19845
- package/api-services/modules/app-manage.d.ts +2 -0
- package/api-services/modules/app-manage.js +5 -6
- package/api-services/modules/authentication.d.ts +2 -0
- package/api-services/modules/authentication.js +5 -6
- package/api-services/modules/bems.d.ts +6 -0
- package/api-services/modules/bems.js +8 -10
- package/api-services/modules/contract.d.ts +2 -0
- package/api-services/modules/contract.js +5 -6
- package/api-services/modules/duty-manage.d.ts +7 -0
- package/api-services/modules/duty-manage.js +9 -10
- package/api-services/modules/enterpriseright.d.ts +2 -0
- package/api-services/modules/enterpriseright.js +5 -6
- package/api-services/modules/file.d.ts +36 -0
- package/api-services/modules/file.js +449 -354
- package/api-services/modules/gateway-edge.d.ts +2 -0
- package/api-services/modules/gateway-edge.js +5 -6
- package/api-services/modules/index.d.ts +21 -0
- package/api-services/modules/index.js +501 -435
- package/api-services/modules/iot.d.ts +15 -0
- package/api-services/modules/iot.js +17 -18
- package/api-services/modules/justauth.d.ts +3 -0
- package/api-services/modules/justauth.js +6 -7
- package/api-services/modules/knowledge.d.ts +2 -0
- package/api-services/modules/knowledge.js +5 -6
- package/api-services/modules/link.d.ts +2 -0
- package/api-services/modules/link.js +5 -6
- package/api-services/modules/permission.d.ts +2 -0
- package/api-services/modules/permission.js +5 -6
- package/api-services/modules/platformManage.d.ts +14 -0
- package/api-services/modules/platformManage.js +12 -13
- package/api-services/modules/portal.d.ts +2 -0
- package/api-services/modules/portal.js +5 -6
- package/api-services/modules/space-manage.d.ts +2 -0
- package/api-services/modules/space-manage.js +5 -6
- package/api-services/modules/super-admin.d.ts +8 -0
- package/api-services/modules/super-admin.js +8 -9
- package/api-services/modules/supplier.d.ts +6 -0
- package/api-services/modules/supplier.js +7 -8
- package/api-services/modules/supplychain-manage.d.ts +2 -0
- package/api-services/modules/supplychain-manage.js +5 -6
- package/api-services/modules/systemConfiguration.d.ts +2 -0
- package/api-services/modules/systemConfiguration.js +5 -6
- package/api-services/modules/tool.d.ts +2 -0
- package/api-services/modules/tool.js +5 -6
- package/api-services/src/create-service.d.ts +2 -0
- package/api-services/src/create-service.js +3119 -19726
- package/api-services/src/sso.d.ts +29 -0
- package/api-services/src/sso.js +1547 -156
- package/api-services/src/util.d.ts +1 -0
- package/api-services/src/util.js +1462 -19
- package/atob/index.d.ts +2 -0
- package/atob/index.js +9 -10
- package/common-info/getIframeUrl.d.ts +9 -0
- package/common-info/getIframeUrl.js +9 -11
- package/common-info/index.d.ts +42 -0
- package/common-info/index.js +138 -272
- package/common-info/setInfoFromUrl.d.ts +8 -0
- package/common-info/setInfoFromUrl.js +60 -128
- package/common-tools/arr-tools.d.ts +15 -0
- package/common-tools/arr-tools.js +6 -13
- package/common-tools/date-format.d.ts +7 -0
- package/common-tools/date-format.js +18 -21
- package/common-tools/get-url-params.d.ts +33 -0
- package/common-tools/get-url-params.js +48 -88
- package/common-tools/handle-data.d.ts +6 -0
- package/common-tools/handle-data.js +3 -4
- package/common-tools/index.d.ts +7 -0
- package/common-tools/index.js +7 -213
- package/common-tools/nest-tree-format.d.ts +30 -0
- package/common-tools/nest-tree-format.js +22 -49
- package/common-tools/obj-tools.d.ts +7 -0
- package/common-tools/obj-tools.js +17 -18
- package/common-tools/setHtmlMinWH.d.ts +5 -0
- package/common-tools/setHtmlMinWH.js +6 -10
- package/common-tools/throttled.d.ts +7 -0
- package/common-tools/throttled.js +7 -16
- package/config/index.d.ts +2 -0
- package/config/index.js +8 -25
- package/curring-http/index.d.ts +11 -0
- package/curring-http/index.js +5150 -17289
- package/directive/auth.d.ts +8 -0
- package/directive/auth.js +54 -104
- package/directive/clickOutside.d.ts +5 -0
- package/directive/clickOutside.js +23 -49
- package/directive/hoverInside.d.ts +5 -0
- package/directive/hoverInside.js +16 -35
- package/directive/index.d.ts +3 -0
- package/directive/index.js +7 -182
- package/directive/utils.d.ts +7 -0
- package/directive/utils.js +6 -11
- package/dom-check-in/index.d.ts +6 -0
- package/dom-check-in/index.js +7 -15
- package/dom-watcher/index.d.ts +25 -0
- package/dom-watcher/index.js +7 -8
- package/hooks/popup-manager/use-zindex.d.ts +5 -0
- package/hooks/popup-manager/use-zindex.js +17 -36
- package/index.d.ts +2 -0
- package/index.js +2 -215
- package/load-js/index.d.ts +3 -0
- package/load-js/index.js +10 -20
- package/oss/index.d.ts +2 -0
- package/oss/index.js +11 -15
- package/package.json +8 -13
- package/pinyin-first-character/index.d.ts +2 -0
- package/pinyin-first-character/index.js +25011 -12217
- package/process-engine-info/index.d.ts +10 -0
- package/process-engine-info/index.js +8 -10
- package/pure-image-src/index.d.ts +2 -0
- package/pure-image-src/index.js +3 -29
- package/set-personal-info/index.d.ts +5 -0
- package/set-personal-info/index.js +1460 -16
- package/size-watcher/index.d.ts +6 -0
- package/size-watcher/index.js +17 -24
- package/style/index.d.ts +2 -0
- package/style/index.js +62 -103
- package/style/math.d.ts +9 -0
- package/style/math.js +16 -31
- package/style/style.d.ts +30 -0
- package/style/style.js +49 -72
- package/token-tools/index.d.ts +18 -0
- package/token-tools/index.js +72 -149
- package/vue/hooks/use-model-value.d.ts +3 -0
- package/vue/hooks/use-model-value.js +9 -10
- package/vue/index.d.ts +1 -0
- package/vue/index.js +3 -10
- package/webSocket-service/index.d.ts +40 -0
- package/webSocket-service/index.js +62 -138
- package/with-install/index.d.ts +10 -0
- package/with-install/index.js +5 -7
package/token-tools/index.js
CHANGED
|
@@ -1,179 +1,102 @@
|
|
|
1
|
-
import { tokenStorage } from
|
|
2
|
-
import { setProcessEngineToken } from
|
|
3
|
-
import { setPersonalInfo } from
|
|
4
|
-
|
|
1
|
+
import { tokenStorage as k } from "@das-fed/utils/api-services/src/sso";
|
|
2
|
+
import { setProcessEngineToken as C } from "@das-fed/utils/process-engine-info";
|
|
3
|
+
import { setPersonalInfo as D } from "@das-fed/utils/set-personal-info";
|
|
5
4
|
/*! js-cookie v3.0.5 | MIT */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
target[key] = source[key];
|
|
12
|
-
}
|
|
5
|
+
function u(o) {
|
|
6
|
+
for (var t = 1; t < arguments.length; t++) {
|
|
7
|
+
var f = arguments[t];
|
|
8
|
+
for (var a in f)
|
|
9
|
+
o[a] = f[a];
|
|
13
10
|
}
|
|
14
|
-
return
|
|
11
|
+
return o;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var defaultConverter = {
|
|
20
|
-
read: function (value) {
|
|
21
|
-
if (value[0] === '"') {
|
|
22
|
-
value = value.slice(1, -1);
|
|
23
|
-
}
|
|
24
|
-
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
|
|
13
|
+
var I = {
|
|
14
|
+
read: function(o) {
|
|
15
|
+
return o[0] === '"' && (o = o.slice(1, -1)), o.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
25
16
|
},
|
|
26
|
-
write: function
|
|
27
|
-
return encodeURIComponent(
|
|
17
|
+
write: function(o) {
|
|
18
|
+
return encodeURIComponent(o).replace(
|
|
28
19
|
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
29
20
|
decodeURIComponent
|
|
30
|
-
)
|
|
21
|
+
);
|
|
31
22
|
}
|
|
32
23
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
attributes = assign({}, defaultAttributes, attributes);
|
|
44
|
-
|
|
45
|
-
if (typeof attributes.expires === 'number') {
|
|
46
|
-
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
47
|
-
}
|
|
48
|
-
if (attributes.expires) {
|
|
49
|
-
attributes.expires = attributes.expires.toUTCString();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
name = encodeURIComponent(name)
|
|
53
|
-
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
54
|
-
.replace(/[()]/g, escape);
|
|
55
|
-
|
|
56
|
-
var stringifiedAttributes = '';
|
|
57
|
-
for (var attributeName in attributes) {
|
|
58
|
-
if (!attributes[attributeName]) {
|
|
59
|
-
continue
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
stringifiedAttributes += '; ' + attributeName;
|
|
63
|
-
|
|
64
|
-
if (attributes[attributeName] === true) {
|
|
65
|
-
continue
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Considers RFC 6265 section 5.2:
|
|
69
|
-
// ...
|
|
70
|
-
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
71
|
-
// character:
|
|
72
|
-
// Consume the characters of the unparsed-attributes up to,
|
|
73
|
-
// not including, the first %x3B (";") character.
|
|
74
|
-
// ...
|
|
75
|
-
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
24
|
+
function m(o, t) {
|
|
25
|
+
function f(n, i, e) {
|
|
26
|
+
if (!(typeof document > "u")) {
|
|
27
|
+
e = u({}, t, e), typeof e.expires == "number" && (e.expires = new Date(Date.now() + e.expires * 864e5)), e.expires && (e.expires = e.expires.toUTCString()), n = encodeURIComponent(n).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
|
|
28
|
+
var r = "";
|
|
29
|
+
for (var c in e)
|
|
30
|
+
e[c] && (r += "; " + c, e[c] !== !0 && (r += "=" + e[c].split(";")[0]));
|
|
31
|
+
return document.cookie = n + "=" + o.write(i, n) + r;
|
|
76
32
|
}
|
|
77
|
-
|
|
78
|
-
return (document.cookie =
|
|
79
|
-
name + '=' + converter.write(value, name) + stringifiedAttributes)
|
|
80
33
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var jar = {};
|
|
91
|
-
for (var i = 0; i < cookies.length; i++) {
|
|
92
|
-
var parts = cookies[i].split('=');
|
|
93
|
-
var value = parts.slice(1).join('=');
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
var found = decodeURIComponent(parts[0]);
|
|
97
|
-
jar[found] = converter.read(value, found);
|
|
98
|
-
|
|
99
|
-
if (name === found) {
|
|
100
|
-
break
|
|
34
|
+
function a(n) {
|
|
35
|
+
if (!(typeof document > "u" || arguments.length && !n)) {
|
|
36
|
+
for (var i = document.cookie ? document.cookie.split("; ") : [], e = {}, r = 0; r < i.length; r++) {
|
|
37
|
+
var c = i[r].split("="), p = c.slice(1).join("=");
|
|
38
|
+
try {
|
|
39
|
+
var g = decodeURIComponent(c[0]);
|
|
40
|
+
if (e[g] = o.read(p, g), n === g)
|
|
41
|
+
break;
|
|
42
|
+
} catch {
|
|
101
43
|
}
|
|
102
|
-
}
|
|
44
|
+
}
|
|
45
|
+
return n ? e[n] : e;
|
|
103
46
|
}
|
|
104
|
-
|
|
105
|
-
return name ? jar[name] : jar
|
|
106
47
|
}
|
|
107
|
-
|
|
108
48
|
return Object.create(
|
|
109
49
|
{
|
|
110
|
-
set,
|
|
111
|
-
get,
|
|
112
|
-
remove: function
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
50
|
+
set: f,
|
|
51
|
+
get: a,
|
|
52
|
+
remove: function(n, i) {
|
|
53
|
+
f(
|
|
54
|
+
n,
|
|
55
|
+
"",
|
|
56
|
+
u({}, i, {
|
|
117
57
|
expires: -1
|
|
118
58
|
})
|
|
119
59
|
);
|
|
120
60
|
},
|
|
121
|
-
withAttributes: function
|
|
122
|
-
return
|
|
61
|
+
withAttributes: function(n) {
|
|
62
|
+
return m(this.converter, u({}, this.attributes, n));
|
|
123
63
|
},
|
|
124
|
-
withConverter: function
|
|
125
|
-
return
|
|
64
|
+
withConverter: function(n) {
|
|
65
|
+
return m(u({}, this.converter, n), this.attributes);
|
|
126
66
|
}
|
|
127
67
|
},
|
|
128
68
|
{
|
|
129
|
-
attributes: { value: Object.freeze(
|
|
130
|
-
converter: { value: Object.freeze(
|
|
69
|
+
attributes: { value: Object.freeze(t) },
|
|
70
|
+
converter: { value: Object.freeze(o) }
|
|
131
71
|
}
|
|
132
|
-
)
|
|
72
|
+
);
|
|
133
73
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const { access_token, refresh_token, expires_in } = cookieTokenInfo;
|
|
148
|
-
const tokenData = {
|
|
149
|
-
accessToken: access_token,
|
|
150
|
-
accessTokenExpiredAt: +/* @__PURE__ */ new Date() + expires_in * 1e3,
|
|
151
|
-
refreshToken: refresh_token,
|
|
152
|
-
info: cookieTokenInfo
|
|
74
|
+
var s = m(I, { path: "/" });
|
|
75
|
+
const v = "accessToken", d = "accessTokenInfo", U = () => {
|
|
76
|
+
var f, a, n, i, e, r, c;
|
|
77
|
+
const o = s.get(v) ?? "";
|
|
78
|
+
let t = "";
|
|
79
|
+
if ((f = k().getData()) != null && f.info && JSON.stringify((a = k().getData()) == null ? void 0 : a.info) !== "{}" && (t = ((i = (n = k().getData()) == null ? void 0 : n.info) == null ? void 0 : i.access_token) ?? ((r = (e = k().getData()) == null ? void 0 : e.info) == null ? void 0 : r.accessToken) ?? ""), o && !t) {
|
|
80
|
+
const p = x();
|
|
81
|
+
if (p && JSON.stringify(p) !== "{}") {
|
|
82
|
+
const { access_token: g, refresh_token: T, expires_in: h } = p, l = {
|
|
83
|
+
accessToken: g,
|
|
84
|
+
accessTokenExpiredAt: +/* @__PURE__ */ new Date() + h * 1e3,
|
|
85
|
+
refreshToken: T,
|
|
86
|
+
info: p
|
|
153
87
|
};
|
|
154
|
-
|
|
155
|
-
setPersonalInfo(access_token);
|
|
156
|
-
setProcessEngineToken(tokenData);
|
|
88
|
+
k().save(l), D(g), C(l);
|
|
157
89
|
}
|
|
158
90
|
}
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
} else {
|
|
165
|
-
return {};
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const setAccessToken = (token, info) => {
|
|
169
|
-
api.set(KEY, token);
|
|
170
|
-
if (info)
|
|
171
|
-
api.set(INFOKEY, JSON.stringify(info));
|
|
91
|
+
return s.get(v) ?? ((c = k().getData()) == null ? void 0 : c.accessToken) ?? "";
|
|
92
|
+
}, x = () => s.get(d) ? JSON.parse(s.get(d)) : {}, y = (o, t) => {
|
|
93
|
+
s.set(v, o), t && s.set(d, JSON.stringify(t));
|
|
94
|
+
}, E = () => {
|
|
95
|
+
s.remove(v), s.get(d) && s.remove(d);
|
|
172
96
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
97
|
+
export {
|
|
98
|
+
U as getAccessToken,
|
|
99
|
+
x as getAccessTokenInfo,
|
|
100
|
+
E as removeAccessToken,
|
|
101
|
+
y as setAccessToken
|
|
177
102
|
};
|
|
178
|
-
|
|
179
|
-
export { getAccessToken, getAccessTokenInfo, removeAccessToken, setAccessToken };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ref, watchEffect } from
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ref as o, watchEffect as u } from "vue";
|
|
2
|
+
const c = (e, t) => {
|
|
3
|
+
const l = o(e[t]);
|
|
4
|
+
return u(() => {
|
|
5
|
+
l.value = e[t];
|
|
6
|
+
}), l;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
c as useModelValue
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
export { useModelValue };
|
package/vue/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useModelValue } from '@das-fed/utils/vue/hooks/use-model-value';
|
package/vue/index.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const modelValue = ref(props[propKey]);
|
|
5
|
-
watchEffect(() => {
|
|
6
|
-
modelValue.value = props[propKey];
|
|
7
|
-
});
|
|
8
|
-
return modelValue;
|
|
1
|
+
import { useModelValue as l } from "@das-fed/utils/vue/hooks/use-model-value";
|
|
2
|
+
export {
|
|
3
|
+
l as useModelValue
|
|
9
4
|
};
|
|
10
|
-
|
|
11
|
-
export { useModelValue };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { socketConfig } from './type';
|
|
2
|
+
export declare class socketService {
|
|
3
|
+
/** websocket实例 */
|
|
4
|
+
$ws: any;
|
|
5
|
+
/** websocket地址 */
|
|
6
|
+
url: string;
|
|
7
|
+
/** 请求参数 */
|
|
8
|
+
params: Record<string, any>;
|
|
9
|
+
/** 是否正在重连,避免ws重复连接 */
|
|
10
|
+
lockReturn: boolean;
|
|
11
|
+
/** websocket开启时间 */
|
|
12
|
+
startTime: any;
|
|
13
|
+
/** 心跳检测 */
|
|
14
|
+
heartbeatInterval: any;
|
|
15
|
+
/** 发生错误时是否重连,默认开启 */
|
|
16
|
+
ifReconnect: boolean;
|
|
17
|
+
/** 重连定时器 */
|
|
18
|
+
reconnectId: any;
|
|
19
|
+
/** 重连次数,默认为3,-1 表示一直重连 */
|
|
20
|
+
reconnectNum: number;
|
|
21
|
+
/** 连接close关闭时是否重连,默认关闭 */
|
|
22
|
+
reconnectWhenClose: boolean;
|
|
23
|
+
/** 当前重连次数 */
|
|
24
|
+
currentReconnectNum: number;
|
|
25
|
+
constructor({ url, params, opened, close, error, message, ifReconnect, reconnectNum, reconnectWhenClose, }: socketConfig);
|
|
26
|
+
initWebSocket(): void;
|
|
27
|
+
open(): void;
|
|
28
|
+
opened(ws: any): void;
|
|
29
|
+
close(event: CloseEvent): void;
|
|
30
|
+
message(event: any): void;
|
|
31
|
+
afterMsg(msg: any): void;
|
|
32
|
+
error(err: any): any;
|
|
33
|
+
/** websocket重连 */
|
|
34
|
+
reconnect(): void;
|
|
35
|
+
/** 发送消息给服务器 */
|
|
36
|
+
send(message: any): void;
|
|
37
|
+
startHeartbeat(): void;
|
|
38
|
+
/** 断开连接 */
|
|
39
|
+
disconnect(): void;
|
|
40
|
+
}
|
|
@@ -1,170 +1,94 @@
|
|
|
1
|
-
import { getConfig } from
|
|
2
|
-
import { getToken } from
|
|
3
|
-
import { objectToUrlparams } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const getBaseUrl = () => {
|
|
13
|
-
let baseUrl = "";
|
|
14
|
-
if (config.baseURL) {
|
|
15
|
-
baseUrl = config.baseURL;
|
|
16
|
-
} else {
|
|
17
|
-
baseUrl = location.origin;
|
|
18
|
-
}
|
|
19
|
-
return baseUrl.replace("https://", "wss://").replace("http://", "ws://") || "";
|
|
20
|
-
};
|
|
21
|
-
const getUrl = (url, params = {}) => {
|
|
22
|
-
const query = objectToUrlparams(params);
|
|
23
|
-
const result = query ? getBaseUrl() + url + `?${query}` : getBaseUrl() + url;
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
const getRandomInterval = (min, max) => {
|
|
27
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
28
|
-
};
|
|
29
|
-
class socketService {
|
|
1
|
+
import { getConfig as m } from "@das-fed/utils/config";
|
|
2
|
+
import { getToken as f } from "@das-fed/utils/common-info";
|
|
3
|
+
import { objectToUrlparams as w } from "@das-fed/utils/common-tools";
|
|
4
|
+
const c = m(), h = () => {
|
|
5
|
+
let s = "";
|
|
6
|
+
return c.baseURL ? s = c.baseURL : s = location.origin, s.replace("https://", "wss://").replace("http://", "ws://") || "";
|
|
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
|
+
class R {
|
|
30
12
|
constructor({
|
|
31
|
-
url,
|
|
32
|
-
params = {},
|
|
33
|
-
opened,
|
|
34
|
-
close,
|
|
35
|
-
error,
|
|
36
|
-
message,
|
|
37
|
-
ifReconnect,
|
|
38
|
-
reconnectNum,
|
|
39
|
-
reconnectWhenClose
|
|
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
|
+
reconnectWhenClose: u
|
|
40
22
|
}) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
__publicField(this, "url", "");
|
|
45
|
-
/** 请求参数 */
|
|
46
|
-
__publicField(this, "params", {});
|
|
47
|
-
/** 是否正在重连,避免ws重复连接 */
|
|
48
|
-
__publicField(this, "lockReturn", false);
|
|
49
|
-
/** websocket开启时间 */
|
|
50
|
-
__publicField(this, "startTime", 0);
|
|
51
|
-
/** 心跳检测 */
|
|
52
|
-
__publicField(this, "heartbeatInterval", null);
|
|
53
|
-
/** 发生错误时是否重连,默认开启 */
|
|
54
|
-
__publicField(this, "ifReconnect", true);
|
|
55
|
-
/** 重连定时器 */
|
|
56
|
-
__publicField(this, "reconnectId", null);
|
|
57
|
-
/** 重连次数,默认为3,-1 表示一直重连 */
|
|
58
|
-
__publicField(this, "reconnectNum", 3);
|
|
59
|
-
/** 连接close关闭时是否重连,默认关闭 */
|
|
60
|
-
__publicField(this, "reconnectWhenClose", false);
|
|
61
|
-
/** 当前重连次数 */
|
|
62
|
-
__publicField(this, "currentReconnectNum", 0);
|
|
63
|
-
this.$ws = null;
|
|
64
|
-
this.startTime = 0;
|
|
65
|
-
this.heartbeatInterval = null;
|
|
66
|
-
this.ifReconnect = ifReconnect ?? true;
|
|
67
|
-
this.reconnectNum = reconnectNum ?? 3;
|
|
68
|
-
this.reconnectWhenClose = reconnectWhenClose ?? false;
|
|
69
|
-
this.lockReturn = false;
|
|
70
|
-
this.currentReconnectNum = 0;
|
|
71
|
-
this.reconnectId = null;
|
|
72
|
-
this.params = { ...params, access_token: getToken() };
|
|
73
|
-
if (!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
|
+
else
|
|
74
26
|
throw new Error("url is required");
|
|
75
|
-
|
|
76
|
-
this.url = url;
|
|
77
|
-
}
|
|
78
|
-
opened && (this.opened = opened);
|
|
79
|
-
close && (this.close = close);
|
|
80
|
-
error && (this.error = error);
|
|
81
|
-
message && (this.afterMsg = message);
|
|
82
|
-
this.initWebSocket();
|
|
27
|
+
n && (this.opened = n), r && (this.close = r), o && (this.error = o), i && (this.afterMsg = i), this.initWebSocket();
|
|
83
28
|
}
|
|
84
29
|
initWebSocket() {
|
|
85
|
-
if (typeof WebSocket
|
|
86
|
-
throw new Error("
|
|
87
|
-
const
|
|
88
|
-
this.$ws = new WebSocket(
|
|
89
|
-
this.$ws.onopen = () => {
|
|
30
|
+
if (typeof WebSocket > "u")
|
|
31
|
+
throw new Error("您的浏览器不支持websocket");
|
|
32
|
+
const e = b(this.url, this.params);
|
|
33
|
+
this.$ws = new WebSocket(e), this.$ws.onopen = () => {
|
|
90
34
|
this.open();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.$ws.
|
|
96
|
-
this.
|
|
97
|
-
};
|
|
98
|
-
this.$ws.onerror = (event) => {
|
|
99
|
-
this.error(event);
|
|
35
|
+
}, this.$ws.onclose = (t) => {
|
|
36
|
+
this.close(t);
|
|
37
|
+
}, this.$ws.onmessage = (t) => {
|
|
38
|
+
this.message(t);
|
|
39
|
+
}, this.$ws.onerror = (t) => {
|
|
40
|
+
this.error(t);
|
|
100
41
|
};
|
|
101
42
|
}
|
|
102
43
|
open() {
|
|
103
|
-
this.currentReconnectNum = 0;
|
|
104
|
-
this.startTime = (/* @__PURE__ */ new Date()).getTime();
|
|
105
|
-
this.opened(this.$ws);
|
|
106
|
-
this.startHeartbeat();
|
|
107
|
-
console.log(this.url + " =>websocket\u8FDE\u63A5\u6210\u529F,\u53EF\u4EE5\u5F00\u59CB\u901A\u8BAF");
|
|
44
|
+
this.currentReconnectNum = 0, this.startTime = (/* @__PURE__ */ new Date()).getTime(), this.opened(this.$ws), this.startHeartbeat(), console.log(this.url + " =>websocket连接成功,可以开始通讯");
|
|
108
45
|
}
|
|
109
|
-
opened(
|
|
110
|
-
console.log(this.url + " =>websocket
|
|
46
|
+
opened(e) {
|
|
47
|
+
console.log(this.url + " =>websocket连接已打开:", e);
|
|
111
48
|
}
|
|
112
|
-
close(
|
|
49
|
+
close(e) {
|
|
113
50
|
if (this.$ws.readyState === WebSocket.CLOSED) {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
this.reconnect();
|
|
117
|
-
clearInterval(this.heartbeatInterval);
|
|
118
|
-
console.log(`${this.url}=>WebSocket\u8FDE\u63A5\u5DF2\u7ECF\u5173\u95ED,\u8FDE\u63A5\u603B\u65F6\u957F: ${endTime - this.startTime}ms`);
|
|
51
|
+
const t = (/* @__PURE__ */ new Date()).getTime();
|
|
52
|
+
this.reconnectWhenClose && this.reconnect(), clearInterval(this.heartbeatInterval), console.log(`${this.url}=>WebSocket连接已经关闭,连接总时长: ${t - this.startTime}ms`);
|
|
119
53
|
}
|
|
120
54
|
}
|
|
121
|
-
message(
|
|
122
|
-
const
|
|
123
|
-
this.afterMsg(
|
|
55
|
+
message(e) {
|
|
56
|
+
const t = typeof e.data == "object" ? e.data : JSON.parse(e.data);
|
|
57
|
+
this.afterMsg(t);
|
|
124
58
|
}
|
|
125
|
-
afterMsg(
|
|
126
|
-
console.log(this.url + "
|
|
59
|
+
afterMsg(e) {
|
|
60
|
+
console.log(this.url + " =>接收到websocket的消息:", e);
|
|
127
61
|
}
|
|
128
|
-
error(
|
|
129
|
-
|
|
130
|
-
this.reconnect();
|
|
131
|
-
return err;
|
|
62
|
+
error(e) {
|
|
63
|
+
return this.ifReconnect && this.reconnect(), e;
|
|
132
64
|
}
|
|
133
65
|
/** websocket重连 */
|
|
134
66
|
reconnect() {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.currentReconnectNum++;
|
|
139
|
-
if (this.currentReconnectNum > this.reconnectNum)
|
|
140
|
-
return;
|
|
141
|
-
this.reconnectId && clearTimeout(this.reconnectId);
|
|
142
|
-
this.reconnectId = setTimeout(() => {
|
|
143
|
-
this.initWebSocket();
|
|
144
|
-
this.lockReturn = false;
|
|
145
|
-
}, 3e3);
|
|
67
|
+
this.lockReturn || (this.lockReturn = !0, this.currentReconnectNum++, !(this.currentReconnectNum > this.reconnectNum) && (this.reconnectId && clearTimeout(this.reconnectId), this.reconnectId = setTimeout(() => {
|
|
68
|
+
this.initWebSocket(), this.lockReturn = !1;
|
|
69
|
+
}, 3e3)));
|
|
146
70
|
}
|
|
147
71
|
/** 发送消息给服务器 */
|
|
148
|
-
send(
|
|
149
|
-
|
|
150
|
-
|
|
72
|
+
send(e) {
|
|
73
|
+
var t;
|
|
74
|
+
if (((t = this.$ws) == null ? void 0 : t.readyState) !== WebSocket.OPEN) {
|
|
75
|
+
console.log(this.url + "=>websocket连接未建立,还不能发送消息");
|
|
151
76
|
return;
|
|
152
77
|
}
|
|
153
|
-
this.$ws.send(
|
|
78
|
+
this.$ws.send(e);
|
|
154
79
|
}
|
|
155
80
|
// 启动心跳检测==>30s-5分钟内随机发一次心跳保持会话(时间区间内随机是为了降低突增流量的概率)
|
|
156
81
|
startHeartbeat() {
|
|
157
82
|
this.heartbeatInterval = setInterval(() => {
|
|
158
|
-
const
|
|
159
|
-
this.send(
|
|
160
|
-
|
|
161
|
-
}, getRandomInterval(3e4, 3e5));
|
|
83
|
+
const e = "";
|
|
84
|
+
this.send(e), console.log(this.url + "=>心跳检测发送消息:", e);
|
|
85
|
+
}, g(3e4, 3e5));
|
|
162
86
|
}
|
|
163
87
|
/** 断开连接 */
|
|
164
88
|
disconnect() {
|
|
165
|
-
this.$ws.close();
|
|
166
|
-
console.log(this.url + " =>\u4E3B\u52A8\u65AD\u5F00websocket\u8FDE\u63A5");
|
|
89
|
+
this.$ws.close(), console.log(this.url + " =>主动断开websocket连接");
|
|
167
90
|
}
|
|
168
91
|
}
|
|
169
|
-
|
|
170
|
-
|
|
92
|
+
export {
|
|
93
|
+
R as socketService
|
|
94
|
+
};
|
package/with-install/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const e = (n) => (n.install = function(t) {
|
|
2
|
+
t.component(n.name, n);
|
|
3
|
+
}, n);
|
|
4
|
+
export {
|
|
5
|
+
e as withInstall
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
export { withInstall };
|