yxuse 3.0.42 → 3.0.44
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/README.md +14 -568
- package/lib/api.cjs.js +1 -1
- package/lib/api.es.js +4 -4
- package/lib/dayjs.min.cjs.js +1 -1
- package/lib/dayjs.min.cjs.js.map +1 -1
- package/lib/dayjs.min.es.js +32 -2
- package/lib/dayjs.min.es.js.gz +0 -0
- package/lib/dayjs.min.es.js.map +1 -1
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.cjs11.js.map +1 -1
- package/lib/index.cjs12.js +1 -7
- package/lib/index.cjs12.js.gz +0 -0
- package/lib/index.cjs12.js.map +1 -1
- package/lib/index.cjs13.js +1 -1
- package/lib/index.cjs13.js.map +1 -1
- package/lib/index.cjs2.js +1 -1
- package/lib/index.cjs2.js.map +1 -1
- package/lib/index.cjs3.js +1 -1
- package/lib/index.cjs4.js +1 -1
- package/lib/index.cjs5.js +10 -4
- package/lib/index.cjs5.js.gz +0 -0
- package/lib/index.cjs5.js.map +1 -1
- package/lib/index.cjs6.js +2 -2
- package/lib/index.cjs6.js.gz +0 -0
- package/lib/index.cjs6.js.map +1 -1
- package/lib/index.es.js.map +1 -1
- package/lib/index.es11.js.map +1 -1
- package/lib/index.es12.js +36 -2249
- package/lib/index.es12.js.gz +0 -0
- package/lib/index.es12.js.map +1 -1
- package/lib/index.es13.js +20 -230
- package/lib/index.es13.js.map +1 -1
- package/lib/index.es2.js +330 -3
- package/lib/index.es2.js.map +1 -1
- package/lib/index.es3.js +1 -1
- package/lib/index.es4.js +2 -2
- package/lib/index.es5.js +2220 -13
- package/lib/index.es5.js.gz +0 -0
- package/lib/index.es5.js.map +1 -1
- package/lib/index.es6.js +65 -53
- package/lib/index.es6.js.gz +0 -0
- package/lib/index.es6.js.map +1 -1
- package/lib/index.es7.js +1 -1
- package/lib/index.es7.js.gz +0 -0
- package/lib/index.es8.js +1 -1
- package/lib/mqtt.min.cjs.js +2 -0
- package/lib/mqtt.min.cjs.js.gz +0 -0
- package/lib/mqtt.min.cjs.js.map +1 -0
- package/lib/mqtt.min.es.js +7066 -0
- package/lib/mqtt.min.es.js.gz +0 -0
- package/lib/mqtt.min.es.js.map +1 -0
- package/lib/style.css +1 -1
- package/lib/style.css.gz +0 -0
- package/lib/theme.cjs.js +1 -1
- package/lib/theme.es.js +11 -10
- package/lib/theme.es.js.map +1 -1
- package/lib/translate.cjs.js +1 -1
- package/lib/translate.es.js +4 -3
- package/lib/translate.es.js.map +1 -1
- package/lib/utils.cjs.js +1 -1
- package/lib/utils.es.js +8 -4
- package/lib/utils.es.js.map +1 -1
- package/lib/yxIcon.cjs.js +1 -1
- package/lib/yxIcon.es.js +1 -1
- package/package.json +4 -3
- package/types/api/auth/index.d.ts +1 -2
- package/types/components/Toolbar/src/utils/mounted.d.ts +1 -0
- package/types/components/YxForm/index.vue.d.ts +10 -6
- package/types/components/YxForm/type.d.ts +11 -8
- package/types/components/YxIcon/type.d.ts +1 -0
- package/types/components/YxTable/index.vue.d.ts +1 -5
- package/types/components/YxTable/type.d.ts +5 -3
- package/types/utils/common/index.d.ts +1 -1
- package/types/utils/fecth/index.d.ts +8 -0
- package/types/utils/fecth/interface.d.ts +8 -0
- package/types/utils/index.d.ts +3 -0
- package/types/utils/mqtt/index.d.ts +16 -0
- package/types/utils/mqtt/interface.d.ts +17 -0
- package/types/utils/socket/index.d.ts +36 -0
- package/types/utils/socket/interface.d.ts +16 -0
- package/lib/_commonjsHelpers.cjs.js +0 -2
- package/lib/_commonjsHelpers.cjs.js.map +0 -1
- package/lib/_commonjsHelpers.es.js +0 -34
- package/lib/_commonjsHelpers.es.js.map +0 -1
- package/lib/index.cjs14.js +0 -2
- package/lib/index.cjs14.js.map +0 -1
- package/lib/index.es14.js +0 -23
- package/lib/index.es14.js.map +0 -1
package/lib/index.es13.js
CHANGED
|
@@ -1,233 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
const getSelectOptions = (arr, labelKey, valueKey, isValueToNumber) => {
|
|
18
|
-
if (!Array.isArray(arr)) return [];
|
|
19
|
-
return arr.map((item) => {
|
|
20
|
-
return {
|
|
21
|
-
label: item == null ? void 0 : item[labelKey],
|
|
22
|
-
value: isValueToNumber ? +item[valueKey] : item[valueKey]
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
const enumToArray = (enumObject) => {
|
|
27
|
-
const result = [];
|
|
28
|
-
for (const key in enumObject) {
|
|
29
|
-
if (isNaN(Number(key))) {
|
|
30
|
-
result.push({ label: key, value: enumObject[key] });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
const isDarkColor = (color) => {
|
|
36
|
-
const parseColor = (color2) => {
|
|
37
|
-
let r2 = 0, g2 = 0, b2 = 0, a = 1;
|
|
38
|
-
if (color2.startsWith("#")) {
|
|
39
|
-
color2 = color2.slice(1);
|
|
40
|
-
if (color2.length === 3) {
|
|
41
|
-
r2 = parseInt(color2[0] + color2[0], 16);
|
|
42
|
-
g2 = parseInt(color2[1] + color2[1], 16);
|
|
43
|
-
b2 = parseInt(color2[2] + color2[2], 16);
|
|
44
|
-
} else if (color2.length === 6) {
|
|
45
|
-
r2 = parseInt(color2.slice(0, 2), 16);
|
|
46
|
-
g2 = parseInt(color2.slice(2, 4), 16);
|
|
47
|
-
b2 = parseInt(color2.slice(4, 6), 16);
|
|
48
|
-
} else {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
} else if (color2.startsWith("rgb")) {
|
|
52
|
-
const rgbaMatch = color2.match(/(\d+(\.\d+)?)/g);
|
|
53
|
-
if (rgbaMatch) {
|
|
54
|
-
r2 = parseFloat(rgbaMatch[0]);
|
|
55
|
-
g2 = parseFloat(rgbaMatch[1]);
|
|
56
|
-
b2 = parseFloat(rgbaMatch[2]);
|
|
57
|
-
if (rgbaMatch.length > 3) {
|
|
58
|
-
a = parseFloat(rgbaMatch[3]);
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return [r2, g2, b2, a];
|
|
67
|
-
};
|
|
68
|
-
const colorComponents = parseColor(color);
|
|
69
|
-
if (!colorComponents) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
const [r, g, b, _] = colorComponents;
|
|
73
|
-
const normalizedR = r / 255;
|
|
74
|
-
const normalizedG = g / 255;
|
|
75
|
-
const normalizedB = b / 255;
|
|
76
|
-
const max = Math.max(normalizedR, normalizedG, normalizedB);
|
|
77
|
-
const min = Math.min(normalizedR, normalizedG, normalizedB);
|
|
78
|
-
let l = (max + min) / 2;
|
|
79
|
-
return l < 0.5;
|
|
80
|
-
};
|
|
81
|
-
const areColorsSimilar = (color1, color2, threshold = 100) => {
|
|
82
|
-
const getColorComponents = (color) => {
|
|
83
|
-
let r, g, b, a = 1;
|
|
84
|
-
if (color.startsWith("#")) {
|
|
85
|
-
color = color.slice(1);
|
|
86
|
-
if (color.length === 3) {
|
|
87
|
-
r = parseInt(color[0] + color[0], 16);
|
|
88
|
-
g = parseInt(color[1] + color[1], 16);
|
|
89
|
-
b = parseInt(color[2] + color[2], 16);
|
|
90
|
-
} else if (color.length === 6) {
|
|
91
|
-
r = parseInt(color.slice(0, 2), 16);
|
|
92
|
-
g = parseInt(color.slice(2, 4), 16);
|
|
93
|
-
b = parseInt(color.slice(4, 6), 16);
|
|
94
|
-
} else {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
} else if (color.startsWith("rgb")) {
|
|
98
|
-
const rgbaMatch = color.match(/(\d+(\.\d+)?)/g);
|
|
99
|
-
r = parseFloat(rgbaMatch[0]);
|
|
100
|
-
g = parseFloat(rgbaMatch[1]);
|
|
101
|
-
b = parseFloat(rgbaMatch[2]);
|
|
102
|
-
if (rgbaMatch.length > 3) {
|
|
103
|
-
a = parseFloat(rgbaMatch[3]);
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
return [r, g, b, a];
|
|
109
|
-
};
|
|
110
|
-
const color1Components = getColorComponents(color1);
|
|
111
|
-
const color2Components = getColorComponents(color2);
|
|
112
|
-
if (!color1Components || !color2Components) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
const euclideanDistance = Math.sqrt(
|
|
116
|
-
Math.pow(color1Components[0] - color2Components[0], 2) + Math.pow(color1Components[1] - color2Components[1], 2) + Math.pow(color1Components[2] - color2Components[2], 2) + Math.pow(color1Components[3] - color2Components[3], 2)
|
|
117
|
-
);
|
|
118
|
-
return euclideanDistance <= threshold;
|
|
119
|
-
};
|
|
120
|
-
const isColorEqual = (color1, color2) => {
|
|
121
|
-
function toRGBA(color) {
|
|
122
|
-
if (color.toLowerCase().startsWith("rgba")) {
|
|
123
|
-
return color.toLowerCase();
|
|
124
|
-
} else if (color.toLowerCase().startsWith("rgb")) {
|
|
125
|
-
return color.replace("rgb", "rgba").replace(")", ", 1)");
|
|
126
|
-
} else if (color.length === 7) {
|
|
127
|
-
const r = parseInt(color.substring(1, 3), 16);
|
|
128
|
-
const g = parseInt(color.substring(3, 5), 16);
|
|
129
|
-
const b = parseInt(color.substring(5, 7), 16);
|
|
130
|
-
return `rgba(${r}, ${g}, ${b}, 1)`;
|
|
131
|
-
} else if (color.length === 9 && color.toLowerCase().startsWith("rrggbbaa")) {
|
|
132
|
-
const r = parseInt(color.substring(1, 3), 16);
|
|
133
|
-
const g = parseInt(color.substring(3, 5), 16);
|
|
134
|
-
const b = parseInt(color.substring(5, 7), 16);
|
|
135
|
-
const a = Math.round(parseInt(color.substring(7, 9), 16) / 255 * 100) / 100;
|
|
136
|
-
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
137
|
-
} else {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const rgbaColor1 = toRGBA(convertShortHexToLongHex(color1));
|
|
142
|
-
const rgbaColor2 = toRGBA(convertShortHexToLongHex(color2));
|
|
143
|
-
if (!rgbaColor1 || !rgbaColor2) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
return rgbaColor1 === rgbaColor2;
|
|
147
|
-
};
|
|
148
|
-
const convertShortHexToLongHex = (shortHex) => {
|
|
149
|
-
if (shortHex.length === 4 && shortHex[0] === "#") {
|
|
150
|
-
const r = shortHex[1];
|
|
151
|
-
const g = shortHex[2];
|
|
152
|
-
const b = shortHex[3];
|
|
153
|
-
const longHex = `#${r}${r}${g}${g}${b}${b}`;
|
|
154
|
-
return longHex;
|
|
155
|
-
} else {
|
|
156
|
-
return shortHex;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const yxMessage = (data, callback, isShowError = true) => {
|
|
160
|
-
if (data.isSuccess) {
|
|
161
|
-
ElMessage.success(data.resultMsg || "操作成功");
|
|
162
|
-
callback && callback();
|
|
163
|
-
} else {
|
|
164
|
-
if (isShowError) {
|
|
165
|
-
ElMessage.error(data.resultMsg || "操作失败");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
const copyText = (text) => {
|
|
170
|
-
const textField = document.createElement("textarea");
|
|
171
|
-
textField.innerText = text;
|
|
172
|
-
document.body.appendChild(textField);
|
|
173
|
-
textField.select();
|
|
174
|
-
document.execCommand("copy");
|
|
175
|
-
textField.remove();
|
|
176
|
-
ElMessage.success("路径已成功复制到剪贴板");
|
|
177
|
-
};
|
|
178
|
-
const getCownDownTime = (time) => {
|
|
179
|
-
const diffTimeSecond = dayjs(time).diff(dayjs(), "second");
|
|
180
|
-
let formattedTime = "00:00:00";
|
|
181
|
-
if (diffTimeSecond > 0) {
|
|
182
|
-
const hours = Math.floor(diffTimeSecond / 3600);
|
|
183
|
-
const minutes = Math.floor(diffTimeSecond % 3600 / 60);
|
|
184
|
-
const seconds = diffTimeSecond % 60;
|
|
185
|
-
formattedTime = `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
186
|
-
}
|
|
187
|
-
return formattedTime;
|
|
188
|
-
};
|
|
189
|
-
class YxSubscribe {
|
|
190
|
-
constructor() {
|
|
191
|
-
__publicField(this, "subscribers");
|
|
192
|
-
this.subscribers = {};
|
|
193
|
-
}
|
|
194
|
-
subscribe(sub, fn) {
|
|
195
|
-
if (!this.subscribers[sub]) {
|
|
196
|
-
this.subscribers[sub] = [];
|
|
197
|
-
}
|
|
198
|
-
this.subscribers[sub].push(fn);
|
|
199
|
-
}
|
|
200
|
-
unsubscribe(sub, fn) {
|
|
201
|
-
const subscribers = this.subscribers[sub];
|
|
202
|
-
if (!fn) return this.subscribers[sub] = [];
|
|
203
|
-
if (subscribers) {
|
|
204
|
-
const index = subscribers.indexOf(fn);
|
|
205
|
-
if (index !== -1) {
|
|
206
|
-
subscribers.splice(index, 1);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
publish(message) {
|
|
211
|
-
const subscribers = this.subscribers[message.type];
|
|
212
|
-
if (subscribers) {
|
|
213
|
-
subscribers.forEach((fn) => {
|
|
214
|
-
fn(message.data);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
const yxSubscribe = new YxSubscribe();
|
|
1
|
+
import { a as http, U as URL } from "./index.es12.js";
|
|
2
|
+
const uploadResourceApi = (params, config) => http.post(`${URL["ttc"].INTEGRATED_BASE_URL}/file/upload`, params, config);
|
|
3
|
+
const getGroupListApi = () => http.get(
|
|
4
|
+
`${URL["ttc"].INTEGRATED_BASE_URL}/resource/group/list`,
|
|
5
|
+
{},
|
|
6
|
+
{
|
|
7
|
+
headers: { noLoading: true }
|
|
8
|
+
}
|
|
9
|
+
);
|
|
10
|
+
const getResourceListApi = (groupUuid, sign) => http.get(`${URL["ttc"].INTEGRATED_BASE_URL}/resource/file/list/${sign}/${groupUuid}`, {}, { headers: { noLoading: true } });
|
|
11
|
+
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
12
|
+
__proto__: null,
|
|
13
|
+
getGroupListApi,
|
|
14
|
+
getResourceListApi,
|
|
15
|
+
uploadResourceApi
|
|
16
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
220
17
|
export {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
enumToArray as e,
|
|
226
|
-
yxSubscribe as f,
|
|
227
|
-
getCownDownTime as g,
|
|
228
|
-
isColorEqual as i,
|
|
229
|
-
notifyMessageToSystems as n,
|
|
230
|
-
receiveMessage as r,
|
|
231
|
-
yxMessage as y
|
|
18
|
+
getResourceListApi as a,
|
|
19
|
+
getGroupListApi as g,
|
|
20
|
+
index as i,
|
|
21
|
+
uploadResourceApi as u
|
|
232
22
|
};
|
|
233
23
|
//# sourceMappingURL=index.es13.js.map
|
package/lib/index.es13.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es13.js","sources":["../packages/utils/common/index.ts","../packages/utils/subscribe/index.ts"],"sourcesContent":["/*\n * @Author: WangXin\n * @Date: 2023-09-13 16:21:13\n * @LastEditors: WangXin\n * @LastEditTime: 2025-02-17 16:09:23\n * @FilePath: /yxuse/packages/utils/common/index.ts\n * @Description:\n *\n * Copyright (c) 2023 by YuXing, All Rights Reserved.\n */\nimport { ElMessage } from \"element-plus\";\nimport dayjs from \"dayjs\";\n/**\n * @description 给各分系统发送消息\n * @param data 发送的消息\n */\ninterface Message {\n\ttype: string; //消息类型\n\tdata: any; //消息data\n}\nexport const notifyMessageToSystems = (message: Message) => {\n\tconst themeBc = new BroadcastChannel(\"YXUSE_BC\");\n\tthemeBc.postMessage(message);\n};\n/**\n * @description 接收系统消息\n * @param callback 接收后的回调\n */\nexport const receiveMessage = (callback: Function) => {\n\tconst themeBc = new BroadcastChannel(\"YXUSE_BC\");\n\tthemeBc.onmessage = () => {\n\t\tcallback();\n\t};\n};\n\n/**\n * @param arr 处理的参数\n * @param labelKey label的key\n * @param valueKey value的key\n * @param isValueToNumber 是否将value转为number\n * @return [{label:\"\",value:\"\"}]\n */\nexport const getSelectOptions = (\n\tarr: [],\n\tlabelKey: string,\n\tvalueKey: string,\n\tisValueToNumber?: boolean\n): { label: string; value: string | number }[] => {\n\tif (!Array.isArray(arr)) return [];\n\treturn arr.map(item => {\n\t\treturn {\n\t\t\tlabel: item?.[labelKey],\n\t\t\tvalue: isValueToNumber ? +item[valueKey] : item[valueKey]\n\t\t};\n\t});\n};\n\n/**\n * @param enumObject 处理的枚举类\n */\nexport const enumToArray = <T extends Record<string, string | number>>(\n\tenumObject: T\n): { label: string; value: string | number }[] => {\n\tconst result: { label: string; value: string | number }[] = [];\n\tfor (const key in enumObject) {\n\t\tif (isNaN(Number(key))) {\n\t\t\tresult.push({ label: key, value: enumObject[key] });\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * @description 判断该色值是否是深色\n * @param color 色值\n */\nexport const isDarkColor = (color: string) => {\n\tconst parseColor = (color: string): [number, number, number, number] | null => {\n\t\tlet r = 0,\n\t\t\tg = 0,\n\t\t\tb = 0,\n\t\t\ta = 1;\n\t\tif (color.startsWith(\"#\")) {\n\t\t\t// 解析十六进制颜色值\n\t\t\tcolor = color.slice(1);\n\t\t\tif (color.length === 3) {\n\t\t\t\tr = parseInt(color[0] + color[0], 16);\n\t\t\t\tg = parseInt(color[1] + color[1], 16);\n\t\t\t\tb = parseInt(color[2] + color[2], 16);\n\t\t\t} else if (color.length === 6) {\n\t\t\t\tr = parseInt(color.slice(0, 2), 16);\n\t\t\t\tg = parseInt(color.slice(2, 4), 16);\n\t\t\t\tb = parseInt(color.slice(4, 6), 16);\n\t\t\t} else {\n\t\t\t\t// 非法的颜色值\n\t\t\t\treturn null;\n\t\t\t}\n\t\t} else if (color.startsWith(\"rgb\")) {\n\t\t\t// 解析 RGB 或 RGBA 格式的颜色值\n\t\t\tconst rgbaMatch = color.match(/(\\d+(\\.\\d+)?)/g);\n\t\t\tif (rgbaMatch) {\n\t\t\t\tr = parseFloat(rgbaMatch[0]);\n\t\t\t\tg = parseFloat(rgbaMatch[1]);\n\t\t\t\tb = parseFloat(rgbaMatch[2]);\n\t\t\t\tif (rgbaMatch.length > 3) {\n\t\t\t\t\ta = parseFloat(rgbaMatch[3]);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t} else {\n\t\t\treturn null; // 非法的颜色值\n\t\t}\n\t\treturn [r, g, b, a];\n\t};\n\n\tconst colorComponents = parseColor(color);\n\n\tif (!colorComponents) {\n\t\treturn null; // 非法的颜色值\n\t}\n\n\tconst [r, g, b, _] = colorComponents;\n\n\t// 转换为 HSL 颜色空间\n\tconst normalizedR = r / 255;\n\tconst normalizedG = g / 255;\n\tconst normalizedB = b / 255;\n\tconst max = Math.max(normalizedR, normalizedG, normalizedB);\n\tconst min = Math.min(normalizedR, normalizedG, normalizedB);\n\tlet h,\n\t\ts,\n\t\tl = (max + min) / 2;\n\n\tif (max === min) {\n\t\th = s = 0; // 灰色\n\t} else {\n\t\tconst d = max - min;\n\t\ts = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n\t\tswitch (max) {\n\t\t\tcase normalizedR:\n\t\t\t\th = (normalizedG - normalizedB) / d + (normalizedG < normalizedB ? 6 : 0);\n\t\t\t\tbreak;\n\t\t\tcase normalizedG:\n\t\t\t\th = (normalizedB - normalizedR) / d + 2;\n\t\t\t\tbreak;\n\t\t\tcase normalizedB:\n\t\t\t\th = (normalizedR - normalizedG) / d + 4;\n\t\t\t\tbreak;\n\t\t}\n\t\th /= 6;\n\t}\n\n\t// 根据亮度判断是深色还是浅色\n\treturn l < 0.5; // 深色为 true,浅色为 false\n};\n\n/**\n * @description 判断两个色值是否为相近色\n * @param color1 第一个色值\n * @param color2 第二个色值\n * @param threshold 阈值,用于判断两个颜色是否相近\n */\nexport const areColorsSimilar = (color1: string, color2: string, threshold: number = 100): boolean => {\n\tconst getColorComponents = (color: string): [number, number, number, number] | null => {\n\t\tlet r,\n\t\t\tg,\n\t\t\tb,\n\t\t\ta = 1;\n\t\tif (color.startsWith(\"#\")) {\n\t\t\tcolor = color.slice(1);\n\t\t\tif (color.length === 3) {\n\t\t\t\tr = parseInt(color[0] + color[0], 16);\n\t\t\t\tg = parseInt(color[1] + color[1], 16);\n\t\t\t\tb = parseInt(color[2] + color[2], 16);\n\t\t\t} else if (color.length === 6) {\n\t\t\t\tr = parseInt(color.slice(0, 2), 16);\n\t\t\t\tg = parseInt(color.slice(2, 4), 16);\n\t\t\t\tb = parseInt(color.slice(4, 6), 16);\n\t\t\t} else {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t} else if (color.startsWith(\"rgb\")) {\n\t\t\tconst rgbaMatch = color.match(/(\\d+(\\.\\d+)?)/g);\n\t\t\tr = parseFloat(rgbaMatch[0]);\n\t\t\tg = parseFloat(rgbaMatch[1]);\n\t\t\tb = parseFloat(rgbaMatch[2]);\n\t\t\tif (rgbaMatch.length > 3) {\n\t\t\t\ta = parseFloat(rgbaMatch[3]);\n\t\t\t}\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t\treturn [r, g, b, a];\n\t};\n\n\tconst color1Components = getColorComponents(color1);\n\tconst color2Components = getColorComponents(color2);\n\n\tif (!color1Components || !color2Components) {\n\t\treturn false; // 非法的颜色值\n\t}\n\n\tconst euclideanDistance = Math.sqrt(\n\t\tMath.pow(color1Components[0] - color2Components[0], 2) +\n\t\t\tMath.pow(color1Components[1] - color2Components[1], 2) +\n\t\t\tMath.pow(color1Components[2] - color2Components[2], 2) +\n\t\t\tMath.pow(color1Components[3] - color2Components[3], 2)\n\t);\n\tconsole.log(euclideanDistance);\n\n\treturn euclideanDistance <= threshold;\n};\n\n//判断两个色值是否相等\nexport const isColorEqual = (color1, color2) => {\n\tfunction toRGBA(color) {\n\t\tif (color.toLowerCase().startsWith(\"rgba\")) {\n\t\t\t// 如果是 RGBA 格式,则直接返回\n\t\t\treturn color.toLowerCase();\n\t\t} else if (color.toLowerCase().startsWith(\"rgb\")) {\n\t\t\t// 如果是 RGB 格式,则转换为 RGBA 格式,alpha 默认为 1\n\t\t\treturn color.replace(\"rgb\", \"rgba\").replace(\")\", \", 1)\");\n\t\t} else if (color.length === 7) {\n\t\t\t// 如果是十六进制格式,则转换为 RGBA 格式,alpha 默认为 1\n\t\t\tconst r = parseInt(color.substring(1, 3), 16);\n\t\t\tconst g = parseInt(color.substring(3, 5), 16);\n\t\t\tconst b = parseInt(color.substring(5, 7), 16);\n\t\t\treturn `rgba(${r}, ${g}, ${b}, 1)`;\n\t\t} else if (color.length === 9 && color.toLowerCase().startsWith(\"rrggbbaa\")) {\n\t\t\t// 如果是 RRGGBBAA 十六进制格式,则转换为 RGBA 格式\n\t\t\tconst r = parseInt(color.substring(1, 3), 16);\n\t\t\tconst g = parseInt(color.substring(3, 5), 16);\n\t\t\tconst b = parseInt(color.substring(5, 7), 16);\n\t\t\tconst a = Math.round((parseInt(color.substring(7, 9), 16) / 255) * 100) / 100; // 转换 alpha 值\n\t\t\treturn `rgba(${r}, ${g}, ${b}, ${a})`;\n\t\t} else {\n\t\t\t// 其他情况视为无效颜色值\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tconst rgbaColor1 = toRGBA(convertShortHexToLongHex(color1));\n\tconst rgbaColor2 = toRGBA(convertShortHexToLongHex(color2));\n\t// 如果转换失败,则返回 false\n\tif (!rgbaColor1 || !rgbaColor2) {\n\t\treturn false;\n\t}\n\n\t// 比较两个 RGBA 格式的颜色值是否相等\n\treturn rgbaColor1 === rgbaColor2;\n};\n\nconst convertShortHexToLongHex = (shortHex: string) => {\n\tif (shortHex.length === 4 && shortHex[0] === \"#\") {\n\t\t// 提取每个字符\n\t\tconst r = shortHex[1];\n\t\tconst g = shortHex[2];\n\t\tconst b = shortHex[3];\n\t\t// 转换为6位十六进制表示\n\t\tconst longHex = `#${r}${r}${g}${g}${b}${b}`;\n\t\treturn longHex;\n\t} else {\n\t\t// 如果不是3位十六进制表示,直接返回原始值\n\t\treturn shortHex;\n\t}\n};\n\n/**\n * @param data //后端返回的数据\n * @param isShowError //是否显示后端服务的报错信息\n * @param callback //回调\n * @description 消息提示\n */\n\nexport const yxMessage = (data: any, callback?: Function, isShowError = true) => {\n\tif (data.isSuccess) {\n\t\tElMessage.success(data.resultMsg || \"操作成功\");\n\t\tcallback && callback();\n\t} else {\n\t\tif (isShowError) {\n\t\t\tElMessage.error(data.resultMsg || \"操作失败\");\n\t\t}\n\t}\n};\n\n/**\n * @param text 要复制的文本\n * @description 复制文本到剪贴板\n * @return void\n */\nexport const copyText = (text: string) => {\n\tconst textField = document.createElement(\"textarea\");\n\ttextField.innerText = text;\n\tdocument.body.appendChild(textField);\n\ttextField.select();\n\tdocument.execCommand(\"copy\");\n\ttextField.remove();\n\tElMessage.success(\"路径已成功复制到剪贴板\");\n};\n\n/**\n * @param time 时间\n * @description 将传入的时间转为距离当前时间的 时 分 秒 的字符串\n * @return void\n */\nexport const getCownDownTime = (time: string) => {\n\tconst diffTimeSecond = dayjs(time).diff(dayjs(), \"second\");\n\tlet formattedTime = \"00:00:00\";\n\tif (diffTimeSecond > 0) {\n\t\tconst hours = Math.floor(diffTimeSecond / 3600);\n\t\tconst minutes = Math.floor((diffTimeSecond % 3600) / 60);\n\t\tconst seconds = diffTimeSecond % 60;\n\t\tformattedTime = `${hours.toString().padStart(2, \"0\")}:${minutes.toString().padStart(2, \"0\")}:${seconds\n\t\t\t.toString()\n\t\t\t.padStart(2, \"0\")}`;\n\t}\n\n\treturn formattedTime;\n};\n","/*\n * @Author: WangXin\n * @Date: 2024-01-01 10:33:25\n * @LastEditors: WangXin\n * @LastEditTime: 2024-01-03 10:59:31\n * @FilePath: \\yxUse\\packages\\utils\\subscribe\\index.ts\n * @Description:\n *\n * Copyright (c) 2024 by YuXing, All Rights Reserved.\n */\ninterface Message {\n\ttype: string;\n\tdata: any;\n}\ninterface Subscribe {\n\t[key: string]: Function[];\n}\nclass YxSubscribe {\n\tprivate subscribers: Subscribe;\n\tconstructor() {\n\t\tthis.subscribers = {};\n\t}\n\tsubscribe(sub: string, fn: Function) {\n\t\tif (!this.subscribers[sub]) {\n\t\t\tthis.subscribers[sub] = [];\n\t\t}\n\t\tthis.subscribers[sub].push(fn);\n\t}\n\tunsubscribe(sub: string, fn?: Function) {\n\t\tconst subscribers = this.subscribers[sub];\n\t\tif (!fn) return (this.subscribers[sub] = []);\n\t\tif (subscribers) {\n\t\t\tconst index = subscribers.indexOf(fn);\n\t\t\tif (index !== -1) {\n\t\t\t\tsubscribers.splice(index, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublish(message: Message) {\n\t\tconst subscribers = this.subscribers[message.type];\n\t\tif (subscribers) {\n\t\t\tsubscribers.forEach(fn => {\n\t\t\t\tfn(message.data);\n\t\t\t});\n\t\t}\n\t}\n}\n\nexport default new YxSubscribe();\n"],"names":["color","r","g","b"],"mappings":";;;;;;AAoBa,MAAA,yBAAyB,CAAC,YAAqB;AACrD,QAAA,UAAU,IAAI,iBAAiB,UAAU;AAC/C,UAAQ,YAAY,OAAO;AAC5B;AAKa,MAAA,iBAAiB,CAAC,aAAuB;AAC/C,QAAA,UAAU,IAAI,iBAAiB,UAAU;AAC/C,UAAQ,YAAY,MAAM;AAChB,aAAA;AAAA,EACV;AACD;AASO,MAAM,mBAAmB,CAC/B,KACA,UACA,UACA,oBACiD;AACjD,MAAI,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;AAC1B,SAAA,IAAI,IAAI,CAAQ,SAAA;AACf,WAAA;AAAA,MACN,O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D;AAAA,EAGD,QAAQ,SAAkB;AACzB,UAAM,cAAc,KAAK,YAAY,QAAQ,IAAI;AACjD,QAAI,aAAa;AAChB,kBAAY,QAAQ,CAAM,OAAA;AACzB,WAAG,QAAQ,IAAI;AAAA,MAAA,CACf;AAAA,IAAA;AAAA,EACF;AAEF;AAEA,MAAe,cAAA,IAAI,YAAY;"}
|
|
1
|
+
{"version":3,"file":"index.es13.js","sources":["../packages/api/modules/assets/index.ts"],"sourcesContent":["/*\n * @Author: WangXin\n * @Date: 2024-04-11 11:09:04\n * @LastEditors: WangXin\n * @LastEditTime: 2024-08-16 10:16:23\n * @FilePath: /yxuse/packages/api/modules/assets/index.ts\n * @Description:\n *\n * Copyright (c) 2024 by YuXing, All Rights Reserved.\n */\nimport http from \"@packages/utils/http\";\nimport { URL } from \"@packages/config\";\n\nexport const uploadResourceApi = (params: FormData, config?: Object) =>\n\thttp.post(`${URL[\"ttc\"].INTEGRATED_BASE_URL}/file/upload`, params, config);\n\n//获取资源分组\nexport const getGroupListApi = () =>\n\thttp.get(\n\t\t`${URL[\"ttc\"].INTEGRATED_BASE_URL}/resource/group/list`,\n\t\t{},\n\t\t{\n\t\t\theaders: { noLoading: true }\n\t\t}\n\t);\n//获取icon的配置\nexport const getResourceListApi = (groupUuid: string, sign: number) =>\n\thttp.get(`${URL[\"ttc\"].INTEGRATED_BASE_URL}/resource/file/list/${sign}/${groupUuid}`, {}, { headers: { noLoading: true } });\n"],"names":[],"mappings":";AAaO,MAAM,oBAAoB,CAAC,QAAkB,WACnD,KAAK,KAAK,GAAG,IAAI,KAAK,EAAE,mBAAmB,gBAAgB,QAAQ,MAAM;AAG7D,MAAA,kBAAkB,MAC9B,KAAK;AAAA,EACJ,GAAG,IAAI,KAAK,EAAE,mBAAmB;AAAA,EACjC,CAAC;AAAA,EACD;AAAA,IACC,SAAS,EAAE,WAAW,KAAK;AAAA,EAAA;AAE7B;AAEY,MAAA,qBAAqB,CAAC,WAAmB,SACrD,KAAK,IAAI,GAAG,IAAI,KAAK,EAAE,mBAAmB,uBAAuB,IAAI,IAAI,SAAS,IAAI,CAAA,GAAI,EAAE,SAAS,EAAE,WAAW,OAAQ,CAAA;;;;;;;"}
|
package/lib/index.es2.js
CHANGED
|
@@ -1,7 +1,330 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
import { g as getToken, s as showFullScreenLoading, h as hideFullScreenLoading, c as checkStatus, a as http } from "./index.es12.js";
|
|
39
|
+
import { m as mqtt_minExports, a as areColorsSimilar, c as copyText, e as enumToArray, g as getCownDownTime, b as getSelectOptions, i as isColorEqual, d as isDarkColor, n as notifyMessageToSystems, r as receiveMessage, y as yxMessage, f as yxSubscribe } from "./mqtt.min.es.js";
|
|
40
|
+
import "element-plus";
|
|
41
|
+
function buildQuery(params) {
|
|
42
|
+
if (!params) return "";
|
|
43
|
+
const query = new URLSearchParams();
|
|
44
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
45
|
+
if (value !== void 0 && value !== null) {
|
|
46
|
+
query.append(key, String(value));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return `?${query.toString()}`;
|
|
50
|
+
}
|
|
51
|
+
function baseRequest(_0, _1, _2) {
|
|
52
|
+
return __async(this, arguments, function* (url, method, data, config = {}) {
|
|
53
|
+
const { headers = {}, responseType = "json", signal, noAuth = false } = config;
|
|
54
|
+
const fullUrl = method === "GET" ? `${url}${buildQuery(data)}` : `${url}`;
|
|
55
|
+
const token = getToken();
|
|
56
|
+
if (!config.noLoading) {
|
|
57
|
+
showFullScreenLoading();
|
|
58
|
+
}
|
|
59
|
+
const res = yield fetch(fullUrl, {
|
|
60
|
+
method,
|
|
61
|
+
headers: __spreadValues(__spreadValues({
|
|
62
|
+
"Content-Type": "application/json"
|
|
63
|
+
}, token && !noAuth ? { token } : ""), headers),
|
|
64
|
+
body: method !== "GET" && data ? JSON.stringify(data) : void 0,
|
|
65
|
+
signal
|
|
66
|
+
});
|
|
67
|
+
hideFullScreenLoading();
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
let errorMessage = "";
|
|
70
|
+
try {
|
|
71
|
+
const errorData = yield res.json();
|
|
72
|
+
if (errorData == null ? void 0 : errorData.resultMsg) {
|
|
73
|
+
errorMessage = errorData.resultMsg;
|
|
74
|
+
}
|
|
75
|
+
} catch (_) {
|
|
76
|
+
}
|
|
77
|
+
checkStatus(res.status, errorMessage);
|
|
78
|
+
throw new Error(errorMessage);
|
|
79
|
+
}
|
|
80
|
+
switch (responseType) {
|
|
81
|
+
case "text":
|
|
82
|
+
return res.text();
|
|
83
|
+
case "blob":
|
|
84
|
+
return res.blob();
|
|
85
|
+
default:
|
|
86
|
+
return res.json();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const yxFecth = {
|
|
91
|
+
get: (url, params, config) => baseRequest(url, "GET", params, config),
|
|
92
|
+
post: (url, data, config) => baseRequest(url, "POST", data, config),
|
|
93
|
+
put: (url, data, config) => baseRequest(url, "PUT", data, config),
|
|
94
|
+
delete: (url, data, config) => baseRequest(url, "DELETE", data, config)
|
|
95
|
+
};
|
|
96
|
+
const clientOptions = {
|
|
97
|
+
mqttVersion: 5,
|
|
98
|
+
clean: true,
|
|
99
|
+
// true: 清除会话, false: 保留会话
|
|
100
|
+
connectTimeout: 4e3,
|
|
101
|
+
// 超时时间
|
|
102
|
+
keepAlive: 60,
|
|
103
|
+
// 认证信息
|
|
104
|
+
clientId: "mqttjs_" + Date.now(),
|
|
105
|
+
// username: "xxxx",
|
|
106
|
+
// password: "xxxx",
|
|
107
|
+
qos: 1
|
|
108
|
+
};
|
|
109
|
+
const subscribeMap = /* @__PURE__ */ new Map();
|
|
110
|
+
class MQ {
|
|
111
|
+
constructor(url, options) {
|
|
112
|
+
__publicField(this, "client");
|
|
113
|
+
this.client = null;
|
|
114
|
+
this.subscribe = this.subscribe;
|
|
115
|
+
this.unsubscribe = this.unsubscribe;
|
|
116
|
+
this.publish = this.publish;
|
|
117
|
+
this.destroyed = this.destroyed;
|
|
118
|
+
this.createClient(url, __spreadValues(__spreadValues({}, clientOptions), options));
|
|
119
|
+
}
|
|
120
|
+
createClient(url, options) {
|
|
121
|
+
this.client = mqtt_minExports.connect(url, options);
|
|
122
|
+
this.client.on("connect", this.onConnect);
|
|
123
|
+
this.client.on("reconnect", this.onReconnect);
|
|
124
|
+
this.client.on("error", this.onError);
|
|
125
|
+
this.client.on("message", this.onMessage);
|
|
126
|
+
}
|
|
127
|
+
publish(topic, message) {
|
|
128
|
+
this.client.publish(topic, message, { qos: clientOptions.qos }, (e) => {
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
subscribe(topic, callback) {
|
|
132
|
+
this.client.subscribe(topic, (error) => {
|
|
133
|
+
if (!error) {
|
|
134
|
+
subscribeMap.set(topic, callback);
|
|
135
|
+
} else {
|
|
136
|
+
throw new Error(error);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
unsubscribe(topic) {
|
|
141
|
+
this.client.unsubscribe(topic, {}, (error) => {
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
onConnect(e) {
|
|
145
|
+
}
|
|
146
|
+
onReconnect(error) {
|
|
147
|
+
}
|
|
148
|
+
onError(error) {
|
|
149
|
+
}
|
|
150
|
+
onMessage(topic, message) {
|
|
151
|
+
const data = message.toString();
|
|
152
|
+
subscribeMap.get(topic)(JSON.parse(data));
|
|
153
|
+
}
|
|
154
|
+
destroyed() {
|
|
155
|
+
if (this.client.end) this.client.end();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
class Ws {
|
|
159
|
+
constructor(options, protocols) {
|
|
160
|
+
__publicField(this, "url");
|
|
161
|
+
__publicField(this, "protocols");
|
|
162
|
+
__publicField(this, "webSocketState");
|
|
163
|
+
__publicField(this, "isCustomClose");
|
|
164
|
+
__publicField(this, "reconnectTime");
|
|
165
|
+
__publicField(this, "heartBeatTime");
|
|
166
|
+
__publicField(this, "waitBeatTime");
|
|
167
|
+
__publicField(this, "callback");
|
|
168
|
+
__publicField(this, "HEART_KEY");
|
|
169
|
+
__publicField(this, "HEART_VALUE");
|
|
170
|
+
__publicField(this, "ws");
|
|
171
|
+
__publicField(this, "isReconnectionLoading");
|
|
172
|
+
__publicField(this, "timeId");
|
|
173
|
+
__publicField(this, "eventCenter");
|
|
174
|
+
__publicField(this, "errorStack");
|
|
175
|
+
__publicField(this, "heartMessage");
|
|
176
|
+
__publicField(this, "msgDataPreHandler");
|
|
177
|
+
this.url = options.url;
|
|
178
|
+
this.protocols = protocols;
|
|
179
|
+
this.webSocketState = false;
|
|
180
|
+
this.isCustomClose = true;
|
|
181
|
+
this.reconnectTime = options.reconnectTime;
|
|
182
|
+
this.heartBeatTime = options.heartBeatTime;
|
|
183
|
+
this.waitBeatTime = options.waitBeatTime;
|
|
184
|
+
this.callback = options.callback;
|
|
185
|
+
if (options.msgDataPreHandler) {
|
|
186
|
+
this.msgDataPreHandler = options.msgDataPreHandler;
|
|
187
|
+
}
|
|
188
|
+
this.onmessage = this.onmessage;
|
|
189
|
+
this.heartMessage = options.heartMessage;
|
|
190
|
+
this.HEART_KEY = options.HEART_KEY;
|
|
191
|
+
this.HEART_VALUE = options.HEART_VALUE;
|
|
192
|
+
this.ws = null;
|
|
193
|
+
this.isReconnectionLoading = false;
|
|
194
|
+
this.createWs();
|
|
195
|
+
}
|
|
196
|
+
createWs() {
|
|
197
|
+
if ("WebSocket" in window) {
|
|
198
|
+
this.ws = null;
|
|
199
|
+
this.ws = new WebSocket(this.url, this.protocols);
|
|
200
|
+
this.onopen();
|
|
201
|
+
this.onerror();
|
|
202
|
+
this.onclose();
|
|
203
|
+
this.onmessage();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// 监听成功
|
|
207
|
+
onopen() {
|
|
208
|
+
this.ws.onopen = () => {
|
|
209
|
+
this.webSocketState = true;
|
|
210
|
+
this.startHeartBeat(this.heartBeatTime);
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
startHeartBeat(time) {
|
|
214
|
+
setTimeout(() => {
|
|
215
|
+
this.heartMessage && (this.heartMessage.data = (/* @__PURE__ */ new Date()).getTime() + "");
|
|
216
|
+
this.send(this.heartMessage ? this.heartMessage : this.HEART_KEY);
|
|
217
|
+
this.waitingServer();
|
|
218
|
+
}, time);
|
|
219
|
+
}
|
|
220
|
+
//延时等待服务端响应,通过webSocketState判断是否连线成功
|
|
221
|
+
waitingServer() {
|
|
222
|
+
this.webSocketState = false;
|
|
223
|
+
setTimeout(() => {
|
|
224
|
+
if (this.webSocketState) {
|
|
225
|
+
this.startHeartBeat(this.heartBeatTime);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
this.close();
|
|
230
|
+
if (this.ws) {
|
|
231
|
+
this.start();
|
|
232
|
+
}
|
|
233
|
+
} catch (e) {
|
|
234
|
+
}
|
|
235
|
+
}, this.waitBeatTime);
|
|
236
|
+
}
|
|
237
|
+
// 监听错误
|
|
238
|
+
onerror() {
|
|
239
|
+
if (!this.ws) return;
|
|
240
|
+
this.ws.onerror = (err) => {
|
|
241
|
+
this.isCustomClose = false;
|
|
242
|
+
this.isReconnectionLoading = false;
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
// 监听关闭
|
|
246
|
+
onclose() {
|
|
247
|
+
if (!this.ws) return;
|
|
248
|
+
this.ws.onclose = () => {
|
|
249
|
+
if (this.isCustomClose) return;
|
|
250
|
+
if (this.ws) {
|
|
251
|
+
this.reconnection();
|
|
252
|
+
this.isReconnectionLoading = false;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
// 接收 WebSocket 消息,增加二进制数据支持
|
|
257
|
+
onmessage() {
|
|
258
|
+
return __async(this, null, function* () {
|
|
259
|
+
if (!this.ws) return;
|
|
260
|
+
this.ws.onmessage = (event) => __async(this, null, function* () {
|
|
261
|
+
try {
|
|
262
|
+
let rawData = event.data;
|
|
263
|
+
if (this.msgDataPreHandler) {
|
|
264
|
+
yield this.msgDataPreHandler(rawData);
|
|
265
|
+
}
|
|
266
|
+
if (rawData === this.HEART_VALUE) {
|
|
267
|
+
this.webSocketState = true;
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const data = JSON.parse(rawData);
|
|
271
|
+
this.callback(data);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
this.callback(event.data);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
// 重连
|
|
279
|
+
reconnection() {
|
|
280
|
+
if (this.isReconnectionLoading) return;
|
|
281
|
+
this.isReconnectionLoading = true;
|
|
282
|
+
clearTimeout(this.timeId);
|
|
283
|
+
this.timeId = null;
|
|
284
|
+
this.timeId = setTimeout(() => {
|
|
285
|
+
this.createWs();
|
|
286
|
+
}, this.reconnectTime);
|
|
287
|
+
}
|
|
288
|
+
// 发送消息
|
|
289
|
+
send(message) {
|
|
290
|
+
if (this.webSocketState && this.ws) {
|
|
291
|
+
this.ws.send(message);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// 手动关闭
|
|
295
|
+
close() {
|
|
296
|
+
var _a;
|
|
297
|
+
this.isCustomClose = true;
|
|
298
|
+
this.isReconnectionLoading = false;
|
|
299
|
+
if (this.ws && this.ws.close) (_a = this.ws) == null ? void 0 : _a.close();
|
|
300
|
+
}
|
|
301
|
+
// 手动开启
|
|
302
|
+
start() {
|
|
303
|
+
this.isCustomClose = false;
|
|
304
|
+
this.reconnection();
|
|
305
|
+
}
|
|
306
|
+
// 订阅
|
|
307
|
+
subscribe(eventName, cb) {
|
|
308
|
+
this.eventCenter.on(eventName, cb);
|
|
309
|
+
}
|
|
310
|
+
// 取消订阅
|
|
311
|
+
unsubscribe(eventName, cb) {
|
|
312
|
+
this.eventCenter.off(eventName, cb);
|
|
313
|
+
}
|
|
314
|
+
// 销毁
|
|
315
|
+
destroy() {
|
|
316
|
+
clearTimeout(this.timeId);
|
|
317
|
+
this.close();
|
|
318
|
+
this.ws = null;
|
|
319
|
+
this.errorStack = null;
|
|
320
|
+
this.eventCenter = null;
|
|
321
|
+
this.webSocketState = false;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
3
324
|
const utils2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4
325
|
__proto__: null,
|
|
326
|
+
MQ,
|
|
327
|
+
WS: Ws,
|
|
5
328
|
areColorsSimilar,
|
|
6
329
|
copyText,
|
|
7
330
|
enumToArray,
|
|
@@ -12,10 +335,14 @@ const utils2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
|
|
|
12
335
|
isDarkColor,
|
|
13
336
|
notifyMessageToSystems,
|
|
14
337
|
receiveMessage,
|
|
338
|
+
yxFecth,
|
|
15
339
|
yxMessage,
|
|
16
340
|
yxSubscribe
|
|
17
341
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
18
342
|
export {
|
|
19
|
-
|
|
343
|
+
MQ as M,
|
|
344
|
+
Ws as W,
|
|
345
|
+
utils2 as u,
|
|
346
|
+
yxFecth as y
|
|
20
347
|
};
|
|
21
348
|
//# sourceMappingURL=index.es2.js.map
|