@das-fed/utils 1.0.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.
Files changed (66) hide show
  1. package/api-services/index.js +19846 -0
  2. package/api-services/modules/app-manage.js +6 -0
  3. package/api-services/modules/authentication.js +6 -0
  4. package/api-services/modules/bems.js +11 -0
  5. package/api-services/modules/contract.js +6 -0
  6. package/api-services/modules/duty-manage.js +15 -0
  7. package/api-services/modules/enterpriseright.js +6 -0
  8. package/api-services/modules/file.js +409 -0
  9. package/api-services/modules/gateway-edge.js +6 -0
  10. package/api-services/modules/index.js +494 -0
  11. package/api-services/modules/iot.js +19 -0
  12. package/api-services/modules/justauth.js +7 -0
  13. package/api-services/modules/knowledge.js +6 -0
  14. package/api-services/modules/link.js +6 -0
  15. package/api-services/modules/permission.js +6 -0
  16. package/api-services/modules/platformManage.js +14 -0
  17. package/api-services/modules/portal.js +6 -0
  18. package/api-services/modules/space-manage.js +6 -0
  19. package/api-services/modules/super-admin.js +9 -0
  20. package/api-services/modules/supplier.js +8 -0
  21. package/api-services/modules/supplychain-manage.js +6 -0
  22. package/api-services/modules/systemConfiguration.js +6 -0
  23. package/api-services/modules/tool.js +6 -0
  24. package/api-services/src/create-service.js +19846 -0
  25. package/api-services/src/sso.js +200 -0
  26. package/api-services/src/util.js +23 -0
  27. package/atob/index.js +12 -0
  28. package/common-info/getIframeUrl.js +13 -0
  29. package/common-info/index.js +311 -0
  30. package/common-info/setInfoFromUrl.js +156 -0
  31. package/common-tools/arr-tools.js +15 -0
  32. package/common-tools/date-format.js +22 -0
  33. package/common-tools/get-url-params.js +92 -0
  34. package/common-tools/handle-data.js +5 -0
  35. package/common-tools/index.js +213 -0
  36. package/common-tools/nest-tree-format.js +53 -0
  37. package/common-tools/obj-tools.js +21 -0
  38. package/common-tools/setHtmlMinWH.js +11 -0
  39. package/common-tools/throttled.js +19 -0
  40. package/config/index.js +26 -0
  41. package/curring-http/index.js +17310 -0
  42. package/directive/auth.js +114 -0
  43. package/directive/clickOutside.js +53 -0
  44. package/directive/hoverInside.js +40 -0
  45. package/directive/index.js +183 -0
  46. package/directive/utils.js +12 -0
  47. package/dom-check-in/index.js +16 -0
  48. package/dom-watcher/index.js +10 -0
  49. package/hooks/popup-manager/use-zindex.js +41 -0
  50. package/index.js +215 -0
  51. package/load-js/index.js +23 -0
  52. package/oss/index.js +16 -0
  53. package/package.json +44 -0
  54. package/pinyin-first-character/index.js +12223 -0
  55. package/process-engine-info/index.js +12 -0
  56. package/pure-image-src/index.js +30 -0
  57. package/set-personal-info/index.js +24 -0
  58. package/size-watcher/index.js +27 -0
  59. package/style/index.js +115 -0
  60. package/style/math.js +32 -0
  61. package/style/style.js +84 -0
  62. package/token-tools/index.js +179 -0
  63. package/vue/hooks/use-model-value.js +11 -0
  64. package/vue/index.js +11 -0
  65. package/webSocket-service/index.js +170 -0
  66. package/with-install/index.js +8 -0
@@ -0,0 +1,170 @@
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 {
30
+ constructor({
31
+ url,
32
+ params = {},
33
+ opened,
34
+ close,
35
+ error,
36
+ message,
37
+ ifReconnect,
38
+ reconnectNum,
39
+ reconnectWhenClose
40
+ }) {
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) {
74
+ 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();
83
+ }
84
+ 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 = () => {
90
+ 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);
100
+ };
101
+ }
102
+ 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");
108
+ }
109
+ opened(ws) {
110
+ console.log(this.url + " =>websocket\u8FDE\u63A5\u5DF2\u6253\u5F00:", ws);
111
+ }
112
+ close(event) {
113
+ 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`);
119
+ }
120
+ }
121
+ message(event) {
122
+ const msgContent = typeof event.data == "object" ? event.data : JSON.parse(event.data);
123
+ this.afterMsg(msgContent);
124
+ }
125
+ afterMsg(msg) {
126
+ console.log(this.url + " =>\u63A5\u6536\u5230websocket\u7684\u6D88\u606F:", msg);
127
+ }
128
+ error(err) {
129
+ if (this.ifReconnect)
130
+ this.reconnect();
131
+ return err;
132
+ }
133
+ /** websocket重连 */
134
+ 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);
146
+ }
147
+ /** 发送消息给服务器 */
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");
151
+ return;
152
+ }
153
+ this.$ws.send(message);
154
+ }
155
+ // 启动心跳检测==>30s-5分钟内随机发一次心跳保持会话(时间区间内随机是为了降低突增流量的概率)
156
+ startHeartbeat() {
157
+ 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));
162
+ }
163
+ /** 断开连接 */
164
+ disconnect() {
165
+ this.$ws.close();
166
+ console.log(this.url + " =>\u4E3B\u52A8\u65AD\u5F00websocket\u8FDE\u63A5");
167
+ }
168
+ }
169
+
170
+ export { socketService };
@@ -0,0 +1,8 @@
1
+ const withInstall = (comp) => {
2
+ comp.install = function(app) {
3
+ app.component(comp.name, comp);
4
+ };
5
+ return comp;
6
+ };
7
+
8
+ export { withInstall };