@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.
Files changed (131) hide show
  1. package/api-services/index.d.ts +1 -0
  2. package/api-services/index.js +3 -19845
  3. package/api-services/modules/app-manage.d.ts +2 -0
  4. package/api-services/modules/app-manage.js +5 -6
  5. package/api-services/modules/authentication.d.ts +2 -0
  6. package/api-services/modules/authentication.js +5 -6
  7. package/api-services/modules/bems.d.ts +6 -0
  8. package/api-services/modules/bems.js +8 -10
  9. package/api-services/modules/contract.d.ts +2 -0
  10. package/api-services/modules/contract.js +5 -6
  11. package/api-services/modules/duty-manage.d.ts +7 -0
  12. package/api-services/modules/duty-manage.js +9 -10
  13. package/api-services/modules/enterpriseright.d.ts +2 -0
  14. package/api-services/modules/enterpriseright.js +5 -6
  15. package/api-services/modules/file.d.ts +36 -0
  16. package/api-services/modules/file.js +449 -354
  17. package/api-services/modules/gateway-edge.d.ts +2 -0
  18. package/api-services/modules/gateway-edge.js +5 -6
  19. package/api-services/modules/index.d.ts +21 -0
  20. package/api-services/modules/index.js +501 -435
  21. package/api-services/modules/iot.d.ts +15 -0
  22. package/api-services/modules/iot.js +17 -18
  23. package/api-services/modules/justauth.d.ts +3 -0
  24. package/api-services/modules/justauth.js +6 -7
  25. package/api-services/modules/knowledge.d.ts +2 -0
  26. package/api-services/modules/knowledge.js +5 -6
  27. package/api-services/modules/link.d.ts +2 -0
  28. package/api-services/modules/link.js +5 -6
  29. package/api-services/modules/permission.d.ts +2 -0
  30. package/api-services/modules/permission.js +5 -6
  31. package/api-services/modules/platformManage.d.ts +14 -0
  32. package/api-services/modules/platformManage.js +12 -13
  33. package/api-services/modules/portal.d.ts +2 -0
  34. package/api-services/modules/portal.js +5 -6
  35. package/api-services/modules/space-manage.d.ts +2 -0
  36. package/api-services/modules/space-manage.js +5 -6
  37. package/api-services/modules/super-admin.d.ts +8 -0
  38. package/api-services/modules/super-admin.js +8 -9
  39. package/api-services/modules/supplier.d.ts +6 -0
  40. package/api-services/modules/supplier.js +7 -8
  41. package/api-services/modules/supplychain-manage.d.ts +2 -0
  42. package/api-services/modules/supplychain-manage.js +5 -6
  43. package/api-services/modules/systemConfiguration.d.ts +2 -0
  44. package/api-services/modules/systemConfiguration.js +5 -6
  45. package/api-services/modules/tool.d.ts +2 -0
  46. package/api-services/modules/tool.js +5 -6
  47. package/api-services/src/create-service.d.ts +2 -0
  48. package/api-services/src/create-service.js +3119 -19726
  49. package/api-services/src/sso.d.ts +29 -0
  50. package/api-services/src/sso.js +1547 -156
  51. package/api-services/src/util.d.ts +1 -0
  52. package/api-services/src/util.js +1462 -19
  53. package/atob/index.d.ts +2 -0
  54. package/atob/index.js +9 -10
  55. package/common-info/getIframeUrl.d.ts +9 -0
  56. package/common-info/getIframeUrl.js +9 -11
  57. package/common-info/index.d.ts +42 -0
  58. package/common-info/index.js +138 -272
  59. package/common-info/setInfoFromUrl.d.ts +8 -0
  60. package/common-info/setInfoFromUrl.js +60 -128
  61. package/common-tools/arr-tools.d.ts +15 -0
  62. package/common-tools/arr-tools.js +6 -13
  63. package/common-tools/date-format.d.ts +7 -0
  64. package/common-tools/date-format.js +18 -21
  65. package/common-tools/get-url-params.d.ts +33 -0
  66. package/common-tools/get-url-params.js +48 -88
  67. package/common-tools/handle-data.d.ts +6 -0
  68. package/common-tools/handle-data.js +3 -4
  69. package/common-tools/index.d.ts +7 -0
  70. package/common-tools/index.js +7 -213
  71. package/common-tools/nest-tree-format.d.ts +30 -0
  72. package/common-tools/nest-tree-format.js +22 -49
  73. package/common-tools/obj-tools.d.ts +7 -0
  74. package/common-tools/obj-tools.js +17 -18
  75. package/common-tools/setHtmlMinWH.d.ts +5 -0
  76. package/common-tools/setHtmlMinWH.js +6 -10
  77. package/common-tools/throttled.d.ts +7 -0
  78. package/common-tools/throttled.js +7 -16
  79. package/config/index.d.ts +2 -0
  80. package/config/index.js +8 -25
  81. package/curring-http/index.d.ts +11 -0
  82. package/curring-http/index.js +5150 -17289
  83. package/directive/auth.d.ts +8 -0
  84. package/directive/auth.js +54 -104
  85. package/directive/clickOutside.d.ts +5 -0
  86. package/directive/clickOutside.js +23 -49
  87. package/directive/hoverInside.d.ts +5 -0
  88. package/directive/hoverInside.js +16 -35
  89. package/directive/index.d.ts +3 -0
  90. package/directive/index.js +7 -182
  91. package/directive/utils.d.ts +7 -0
  92. package/directive/utils.js +6 -11
  93. package/dom-check-in/index.d.ts +6 -0
  94. package/dom-check-in/index.js +7 -15
  95. package/dom-watcher/index.d.ts +25 -0
  96. package/dom-watcher/index.js +7 -8
  97. package/hooks/popup-manager/use-zindex.d.ts +5 -0
  98. package/hooks/popup-manager/use-zindex.js +17 -36
  99. package/index.d.ts +2 -0
  100. package/index.js +2 -215
  101. package/load-js/index.d.ts +3 -0
  102. package/load-js/index.js +10 -20
  103. package/oss/index.d.ts +2 -0
  104. package/oss/index.js +11 -15
  105. package/package.json +8 -13
  106. package/pinyin-first-character/index.d.ts +2 -0
  107. package/pinyin-first-character/index.js +25011 -12217
  108. package/process-engine-info/index.d.ts +10 -0
  109. package/process-engine-info/index.js +8 -10
  110. package/pure-image-src/index.d.ts +2 -0
  111. package/pure-image-src/index.js +3 -29
  112. package/set-personal-info/index.d.ts +5 -0
  113. package/set-personal-info/index.js +1460 -16
  114. package/size-watcher/index.d.ts +6 -0
  115. package/size-watcher/index.js +17 -24
  116. package/style/index.d.ts +2 -0
  117. package/style/index.js +62 -103
  118. package/style/math.d.ts +9 -0
  119. package/style/math.js +16 -31
  120. package/style/style.d.ts +30 -0
  121. package/style/style.js +49 -72
  122. package/token-tools/index.d.ts +18 -0
  123. package/token-tools/index.js +72 -149
  124. package/vue/hooks/use-model-value.d.ts +3 -0
  125. package/vue/hooks/use-model-value.js +9 -10
  126. package/vue/index.d.ts +1 -0
  127. package/vue/index.js +3 -10
  128. package/webSocket-service/index.d.ts +40 -0
  129. package/webSocket-service/index.js +62 -138
  130. package/with-install/index.d.ts +10 -0
  131. package/with-install/index.js +5 -7
@@ -1,179 +1,102 @@
1
- import { tokenStorage } from '@das-fed/utils/api-services/src/sso';
2
- import { setProcessEngineToken } from '@das-fed/utils/process-engine-info';
3
- import { setPersonalInfo } from '@das-fed/utils/set-personal-info';
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
- /* eslint-disable no-var */
7
- function assign (target) {
8
- for (var i = 1; i < arguments.length; i++) {
9
- var source = arguments[i];
10
- for (var key in source) {
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 target
11
+ return o;
15
12
  }
16
- /* eslint-enable no-var */
17
-
18
- /* eslint-disable no-var */
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 (value) {
27
- return encodeURIComponent(value).replace(
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
- /* eslint-enable no-var */
34
-
35
- /* eslint-disable no-var */
36
-
37
- function init (converter, defaultAttributes) {
38
- function set (name, value, attributes) {
39
- if (typeof document === 'undefined') {
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
- function get (name) {
83
- if (typeof document === 'undefined' || (arguments.length && !name)) {
84
- return
85
- }
86
-
87
- // To prevent the for loop in the first place assign an empty array
88
- // in case there are no cookies at all.
89
- var cookies = document.cookie ? document.cookie.split('; ') : [];
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
- } catch (e) {}
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 (name, attributes) {
113
- set(
114
- name,
115
- '',
116
- assign({}, attributes, {
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 (attributes) {
122
- return init(this.converter, assign({}, this.attributes, attributes))
61
+ withAttributes: function(n) {
62
+ return m(this.converter, u({}, this.attributes, n));
123
63
  },
124
- withConverter: function (converter) {
125
- return init(assign({}, this.converter, converter), this.attributes)
64
+ withConverter: function(n) {
65
+ return m(u({}, this.converter, n), this.attributes);
126
66
  }
127
67
  },
128
68
  {
129
- attributes: { value: Object.freeze(defaultAttributes) },
130
- converter: { value: Object.freeze(converter) }
69
+ attributes: { value: Object.freeze(t) },
70
+ converter: { value: Object.freeze(o) }
131
71
  }
132
- )
72
+ );
133
73
  }
134
-
135
- var api = init(defaultConverter, { path: '/' });
136
-
137
- const KEY = "accessToken", INFOKEY = "accessTokenInfo";
138
- const getAccessToken = () => {
139
- const cookieToken = api.get(KEY) ?? "";
140
- let sessionToken = "";
141
- if (tokenStorage().getData()?.info && JSON.stringify(tokenStorage().getData()?.info) !== "{}") {
142
- sessionToken = tokenStorage().getData()?.info?.access_token ?? tokenStorage().getData()?.info?.accessToken ?? "";
143
- }
144
- if (cookieToken && !sessionToken) {
145
- const cookieTokenInfo = getAccessTokenInfo();
146
- if (cookieTokenInfo && JSON.stringify(cookieTokenInfo) !== "{}") {
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
- tokenStorage().save(tokenData);
155
- setPersonalInfo(access_token);
156
- setProcessEngineToken(tokenData);
88
+ k().save(l), D(g), C(l);
157
89
  }
158
90
  }
159
- return api.get(KEY) ?? tokenStorage().getData()?.accessToken ?? "";
160
- };
161
- const getAccessTokenInfo = () => {
162
- if (api.get(INFOKEY)) {
163
- return JSON.parse(api.get(INFOKEY));
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
- const removeAccessToken = () => {
174
- api.remove(KEY);
175
- if (api.get(INFOKEY))
176
- api.remove(INFOKEY);
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 };
@@ -0,0 +1,3 @@
1
+ /** 简化组件内使用modelValue时的watch过程 */
2
+ declare const useModelValue: (props: any, propKey: string) => Ref;
3
+ export { useModelValue };
@@ -1,11 +1,10 @@
1
- import { ref, watchEffect } from 'vue';
2
-
3
- const useModelValue = (props, propKey) => {
4
- const modelValue = ref(props[propKey]);
5
- watchEffect(() => {
6
- modelValue.value = props[propKey];
7
- });
8
- return modelValue;
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 { ref, watchEffect } from 'vue';
2
-
3
- const useModelValue = (props, propKey) => {
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 '@das-fed/utils/config';
2
- import { getToken } from '@das-fed/utils/common-info';
3
- import { objectToUrlparams } from '@das-fed/utils/common-tools';
4
-
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
11
- const config = getConfig();
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
- /** websocket实例 */
42
- __publicField(this, "$ws", null);
43
- /** websocket地址 */
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
- } else {
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 === "undefined")
86
- throw new Error("\u60A8\u7684\u6D4F\u89C8\u5668\u4E0D\u652F\u6301websocket");
87
- const url = getUrl(this.url, this.params);
88
- this.$ws = new WebSocket(url);
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
- this.$ws.onclose = (event) => {
93
- this.close(event);
94
- };
95
- this.$ws.onmessage = (event) => {
96
- this.message(event);
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(ws) {
110
- console.log(this.url + " =>websocket\u8FDE\u63A5\u5DF2\u6253\u5F00:", ws);
46
+ opened(e) {
47
+ console.log(this.url + " =>websocket连接已打开:", e);
111
48
  }
112
- close(event) {
49
+ close(e) {
113
50
  if (this.$ws.readyState === WebSocket.CLOSED) {
114
- const endTime = (/* @__PURE__ */ new Date()).getTime();
115
- if (this.reconnectWhenClose)
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(event) {
122
- const msgContent = typeof event.data == "object" ? event.data : JSON.parse(event.data);
123
- this.afterMsg(msgContent);
55
+ message(e) {
56
+ const t = typeof e.data == "object" ? e.data : JSON.parse(e.data);
57
+ this.afterMsg(t);
124
58
  }
125
- afterMsg(msg) {
126
- console.log(this.url + " =>\u63A5\u6536\u5230websocket\u7684\u6D88\u606F:", msg);
59
+ afterMsg(e) {
60
+ console.log(this.url + " =>接收到websocket的消息:", e);
127
61
  }
128
- error(err) {
129
- if (this.ifReconnect)
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
- if (this.lockReturn)
136
- return;
137
- this.lockReturn = true;
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(message) {
149
- if (this.$ws?.readyState !== WebSocket.OPEN) {
150
- console.log(this.url + "=>websocket\u8FDE\u63A5\u672A\u5EFA\u7ACB\uFF0C\u8FD8\u4E0D\u80FD\u53D1\u9001\u6D88\u606F");
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(message);
78
+ this.$ws.send(e);
154
79
  }
155
80
  // 启动心跳检测==>30s-5分钟内随机发一次心跳保持会话(时间区间内随机是为了降低突增流量的概率)
156
81
  startHeartbeat() {
157
82
  this.heartbeatInterval = setInterval(() => {
158
- const randomMessage = "";
159
- this.send(randomMessage);
160
- console.log(this.url + "=>\u5FC3\u8DF3\u68C0\u6D4B\u53D1\u9001\u6D88\u606F:", randomMessage);
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
- export { socketService };
92
+ export {
93
+ R as socketService
94
+ };
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'vue';
2
+ /**
3
+ * 组件外部使用use时执行install,然后将组件注册为全局
4
+ */
5
+ export type SFCWithInstall<T> = T & Plugin;
6
+ /**
7
+ * 定义一个withInstall方法处理以下组件类型问题
8
+ * @param comp
9
+ */
10
+ export declare const withInstall: <T>(comp: T) => any;
@@ -1,8 +1,6 @@
1
- const withInstall = (comp) => {
2
- comp.install = function(app) {
3
- app.component(comp.name, comp);
4
- };
5
- return comp;
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 };