@ganwei-web/gw-base-components-plus 1.0.27 → 1.0.29
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/element-plus-adapter/dist/ElementPlusAdapter.css +8 -1
- package/equip-list-plus/dist/index.es.js +93 -93
- package/equip-list-plus/dist/index.umd.js +1 -1
- package/equip-list-vue2/dist/index.es.js +147 -119
- package/equip-list-vue3/dist/index.es.js +1214 -1202
- package/equip-list-vue3/dist/index.umd.js +5 -5
- package/equip-select-vue3-java/dist/index.es.js +4723 -0
- package/equip-select-vue3-java/dist/index.umd.js +6 -0
- package/equip-select-vue3-java/dist/style.css +1 -0
- package/equipProcessing/dist/index.es.js +46 -45
- package/equipProcessing/dist/index.umd.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,4723 @@
|
|
|
1
|
+
import { computed as Tt, createBlock as oe, createCommentVNode as L, createElementBlock as T, createElementVNode as x, createTextVNode as be, createVNode as S, defineComponent as Ie, mergeProps as Mt, normalizeClass as Ve, normalizeStyle as Se, onActivated as Nt, onBeforeMount as Ot, onMounted as et, onUnmounted as tt, onUpdated as xt, openBlock as E, ref as W, resolveComponent as G, toDisplayString as H, toHandlers as At, watch as Q, withCtx as P, withModifiers as _e } from "vue";
|
|
2
|
+
|
|
3
|
+
import "./style.css";
|
|
4
|
+
function Ke(i, e) {
|
|
5
|
+
let t = Object.keys(i);
|
|
6
|
+
if (Object.getOwnPropertySymbols) {
|
|
7
|
+
let s = Object.getOwnPropertySymbols(i);
|
|
8
|
+
e && (s = s.filter(function(n) {
|
|
9
|
+
return Object.getOwnPropertyDescriptor(i, n).enumerable;
|
|
10
|
+
})), t.push.apply(t, s);
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
function Z(i) {
|
|
15
|
+
for (let e = 1; e < arguments.length; e++) {
|
|
16
|
+
var t = arguments[e] != null ? arguments[e] : {};
|
|
17
|
+
e % 2 ? Ke(Object(t), !0).forEach(function(s) {
|
|
18
|
+
Rt(i, s, t[s]);
|
|
19
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(i, Object.getOwnPropertyDescriptors(t)) : Ke(Object(t)).forEach(function(s) {
|
|
20
|
+
Object.defineProperty(i, s, Object.getOwnPropertyDescriptor(t, s));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return i;
|
|
24
|
+
}
|
|
25
|
+
function It(i, e) {
|
|
26
|
+
if (!(i instanceof e)) { throw new TypeError("Cannot call a class as a function"); }
|
|
27
|
+
}
|
|
28
|
+
function We(i, e) {
|
|
29
|
+
for (let t = 0; t < e.length; t++) {
|
|
30
|
+
let s = e[t];
|
|
31
|
+
s.enumerable = s.enumerable || !1, s.configurable = !0, "value" in s && (s.writable = !0), Object.defineProperty(i, s.key, s);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function jt(i, e, t) {
|
|
35
|
+
return e && We(i.prototype, e), t && We(i, t), i;
|
|
36
|
+
}
|
|
37
|
+
function Rt(i, e, t) {
|
|
38
|
+
return e in i ? Object.defineProperty(i, e, {
|
|
39
|
+
value: t,
|
|
40
|
+
enumerable: !0,
|
|
41
|
+
configurable: !0,
|
|
42
|
+
writable: !0
|
|
43
|
+
}) : i[e] = t, i;
|
|
44
|
+
}
|
|
45
|
+
function Lt(i) {
|
|
46
|
+
return Gt(i) || Bt(i) || $t(i) || Pt();
|
|
47
|
+
}
|
|
48
|
+
function Gt(i) {
|
|
49
|
+
if (Array.isArray(i)) { return qe(i); }
|
|
50
|
+
}
|
|
51
|
+
function Bt(i) {
|
|
52
|
+
if (typeof Symbol < "u" && i[Symbol.iterator] != null || i["@@iterator"] != null) { return Array.from(i); }
|
|
53
|
+
}
|
|
54
|
+
function $t(i, e) {
|
|
55
|
+
if (i) {
|
|
56
|
+
if (typeof i == "string") { return qe(i, e); }
|
|
57
|
+
let t = Object.prototype.toString.call(i).slice(8, -1);
|
|
58
|
+
if (t === "Object" && i.constructor && (t = i.constructor.name), t === "Map" || t === "Set") { return Array.from(i); }
|
|
59
|
+
if (t === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)) { return qe(i, e); }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function qe(i, e) {
|
|
63
|
+
(e == null || e > i.length) && (e = i.length);
|
|
64
|
+
for (var t = 0, s = new Array(e); t < e; t++) { s[t] = i[t]; }
|
|
65
|
+
return s;
|
|
66
|
+
}
|
|
67
|
+
function Pt() {
|
|
68
|
+
throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
69
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
|
|
70
|
+
}
|
|
71
|
+
let z = {
|
|
72
|
+
FRONT: "FRONT",
|
|
73
|
+
// scroll up or left
|
|
74
|
+
BEHIND: "BEHIND"
|
|
75
|
+
// scroll down or right
|
|
76
|
+
}, R = {
|
|
77
|
+
INIT: "INIT",
|
|
78
|
+
FIXED: "FIXED",
|
|
79
|
+
DYNAMIC: "DYNAMIC"
|
|
80
|
+
}, He = 2, zt = /* @__PURE__ */ (function() {
|
|
81
|
+
function i(e, t) {
|
|
82
|
+
It(this, i), this.init(e, t);
|
|
83
|
+
}
|
|
84
|
+
return jt(i, [{
|
|
85
|
+
key: "init",
|
|
86
|
+
value: function(t, s) {
|
|
87
|
+
this.param = t, this.callUpdate = s, this.sizes = /* @__PURE__ */ new Map(), this.firstRangeTotalSize = 0, this.firstRangeAverageSize = 0, this.lastCalcIndex = 0, this.fixedSizeValue = 0, this.calcType = R.INIT, this.offset = 0, this.direction = "", this.range = /* @__PURE__ */ Object.create(null), t && this.checkRange(0, t.keeps - 1);
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "destroy",
|
|
91
|
+
value: function() {
|
|
92
|
+
this.init(null, null);
|
|
93
|
+
}
|
|
94
|
+
// return current render range
|
|
95
|
+
}, {
|
|
96
|
+
key: "getRange",
|
|
97
|
+
value: function() {
|
|
98
|
+
let t = /* @__PURE__ */ Object.create(null);
|
|
99
|
+
return t.start = this.range.start, t.end = this.range.end, t.padFront = this.range.padFront, t.padBehind = this.range.padBehind, t;
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "isBehind",
|
|
103
|
+
value: function() {
|
|
104
|
+
return this.direction === z.BEHIND;
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "isFront",
|
|
108
|
+
value: function() {
|
|
109
|
+
return this.direction === z.FRONT;
|
|
110
|
+
}
|
|
111
|
+
// return start index offset
|
|
112
|
+
}, {
|
|
113
|
+
key: "getOffset",
|
|
114
|
+
value: function(t) {
|
|
115
|
+
return (t < 1 ? 0 : this.getIndexOffset(t)) + this.param.slotHeaderSize;
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: "updateParam",
|
|
119
|
+
value: function(t, s) {
|
|
120
|
+
let n = this;
|
|
121
|
+
this.param && t in this.param && (t === "uniqueIds" && this.sizes.forEach(function(r, o) {
|
|
122
|
+
s.includes(o) || n.sizes.delete(o);
|
|
123
|
+
}), this.param[t] = s);
|
|
124
|
+
}
|
|
125
|
+
// save each size map by id
|
|
126
|
+
}, {
|
|
127
|
+
key: "saveSize",
|
|
128
|
+
value: function(t, s) {
|
|
129
|
+
this.sizes.set(t, s), this.calcType === R.INIT ? (this.fixedSizeValue = s, this.calcType = R.FIXED) : this.calcType === R.FIXED && this.fixedSizeValue !== s && (this.calcType = R.DYNAMIC, delete this.fixedSizeValue), this.calcType !== R.FIXED && typeof this.firstRangeTotalSize < "u" && (this.sizes.size < Math.min(this.param.keeps, this.param.uniqueIds.length) ? (this.firstRangeTotalSize = Lt(this.sizes.values()).reduce(function(n, r) {
|
|
130
|
+
return n + r;
|
|
131
|
+
}, 0), this.firstRangeAverageSize = Math.round(this.firstRangeTotalSize / this.sizes.size)) : delete this.firstRangeTotalSize);
|
|
132
|
+
}
|
|
133
|
+
// in some special situation (e.g. length change) we need to update in a row
|
|
134
|
+
// try goiong to render next range by a leading buffer according to current direction
|
|
135
|
+
}, {
|
|
136
|
+
key: "handleDataSourcesChange",
|
|
137
|
+
value: function() {
|
|
138
|
+
let t = this.range.start;
|
|
139
|
+
this.isFront() ? t = t - He : this.isBehind() && (t = t + He), t = Math.max(t, 0), this.updateRange(this.range.start, this.getEndByStart(t));
|
|
140
|
+
}
|
|
141
|
+
// when slot size change, we also need force update
|
|
142
|
+
}, {
|
|
143
|
+
key: "handleSlotSizeChange",
|
|
144
|
+
value: function() {
|
|
145
|
+
this.handleDataSourcesChange();
|
|
146
|
+
}
|
|
147
|
+
// calculating range on scroll
|
|
148
|
+
}, {
|
|
149
|
+
key: "handleScroll",
|
|
150
|
+
value: function(t) {
|
|
151
|
+
this.direction = t < this.offset ? z.FRONT : z.BEHIND, this.offset = t, this.param && (this.direction === z.FRONT ? this.handleFront() : this.direction === z.BEHIND && this.handleBehind());
|
|
152
|
+
}
|
|
153
|
+
// ----------- public method end -----------
|
|
154
|
+
}, {
|
|
155
|
+
key: "handleFront",
|
|
156
|
+
value: function() {
|
|
157
|
+
let t = this.getScrollOvers();
|
|
158
|
+
if (!(t > this.range.start)) {
|
|
159
|
+
let s = Math.max(t - this.param.buffer, 0);
|
|
160
|
+
this.checkRange(s, this.getEndByStart(s));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
key: "handleBehind",
|
|
165
|
+
value: function() {
|
|
166
|
+
let t = this.getScrollOvers();
|
|
167
|
+
t < this.range.start + this.param.buffer || this.checkRange(t, this.getEndByStart(t));
|
|
168
|
+
}
|
|
169
|
+
// return the pass overs according to current scroll offset
|
|
170
|
+
}, {
|
|
171
|
+
key: "getScrollOvers",
|
|
172
|
+
value: function() {
|
|
173
|
+
let t = this.offset - this.param.slotHeaderSize;
|
|
174
|
+
if (t <= 0) { return 0; }
|
|
175
|
+
if (this.isFixedType()) { return Math.floor(t / this.fixedSizeValue); }
|
|
176
|
+
for (var s = 0, n = 0, r = 0, o = this.param.uniqueIds.length; s <= o;) {
|
|
177
|
+
if (n = s + Math.floor((o - s) / 2), r = this.getIndexOffset(n), r === t) { return n; }
|
|
178
|
+
r < t ? s = n + 1 : r > t && (o = n - 1);
|
|
179
|
+
}
|
|
180
|
+
return s > 0 ? --s : 0;
|
|
181
|
+
}
|
|
182
|
+
// return a scroll offset from given index, can efficiency be improved more here?
|
|
183
|
+
// although the call frequency is very high, its only a superposition of numbers
|
|
184
|
+
}, {
|
|
185
|
+
key: "getIndexOffset",
|
|
186
|
+
value: function(t) {
|
|
187
|
+
if (!t) { return 0; }
|
|
188
|
+
for (var s = 0, n = 0, r = 0; r < t; r++) { n = this.sizes.get(this.param.uniqueIds[r]), s = s + (typeof n == "number" ? n : this.getEstimateSize()); }
|
|
189
|
+
return this.lastCalcIndex = Math.max(this.lastCalcIndex, t - 1), this.lastCalcIndex = Math.min(this.lastCalcIndex, this.getLastIndex()), s;
|
|
190
|
+
}
|
|
191
|
+
// is fixed size type
|
|
192
|
+
}, {
|
|
193
|
+
key: "isFixedType",
|
|
194
|
+
value: function() {
|
|
195
|
+
return this.calcType === R.FIXED;
|
|
196
|
+
}
|
|
197
|
+
// return the real last index
|
|
198
|
+
}, {
|
|
199
|
+
key: "getLastIndex",
|
|
200
|
+
value: function() {
|
|
201
|
+
return this.param.uniqueIds.length - 1;
|
|
202
|
+
}
|
|
203
|
+
// in some conditions range is broke, we need correct it
|
|
204
|
+
// and then decide whether need update to next range
|
|
205
|
+
}, {
|
|
206
|
+
key: "checkRange",
|
|
207
|
+
value: function(t, s) {
|
|
208
|
+
let n = this.param.keeps, r = this.param.uniqueIds.length;
|
|
209
|
+
r <= n ? (t = 0, s = this.getLastIndex()) : s - t < n - 1 && (t = s - n + 1), this.range.start !== t && this.updateRange(t, s);
|
|
210
|
+
}
|
|
211
|
+
// setting to a new range and rerender
|
|
212
|
+
}, {
|
|
213
|
+
key: "updateRange",
|
|
214
|
+
value: function(t, s) {
|
|
215
|
+
this.range.start = t, this.range.end = s, this.range.padFront = this.getPadFront(), this.range.padBehind = this.getPadBehind(), this.callUpdate(this.getRange());
|
|
216
|
+
}
|
|
217
|
+
// return end base on start
|
|
218
|
+
}, {
|
|
219
|
+
key: "getEndByStart",
|
|
220
|
+
value: function(t) {
|
|
221
|
+
let s = t + this.param.keeps - 1, n = Math.min(s, this.getLastIndex());
|
|
222
|
+
return n;
|
|
223
|
+
}
|
|
224
|
+
// return total front offset
|
|
225
|
+
}, {
|
|
226
|
+
key: "getPadFront",
|
|
227
|
+
value: function() {
|
|
228
|
+
return this.isFixedType() ? this.fixedSizeValue * this.range.start : this.getIndexOffset(this.range.start);
|
|
229
|
+
}
|
|
230
|
+
// return total behind offset
|
|
231
|
+
}, {
|
|
232
|
+
key: "getPadBehind",
|
|
233
|
+
value: function() {
|
|
234
|
+
let t = this.range.end, s = this.getLastIndex();
|
|
235
|
+
return this.isFixedType() ? (s - t) * this.fixedSizeValue : this.lastCalcIndex === s ? this.getIndexOffset(s) - this.getIndexOffset(t) : (s - t) * this.getEstimateSize();
|
|
236
|
+
}
|
|
237
|
+
// get the item estimate size
|
|
238
|
+
}, {
|
|
239
|
+
key: "getEstimateSize",
|
|
240
|
+
value: function() {
|
|
241
|
+
return this.isFixedType() ? this.fixedSizeValue : this.firstRangeAverageSize || this.param.estimateSize;
|
|
242
|
+
}
|
|
243
|
+
}]), i;
|
|
244
|
+
})(), Dt = {
|
|
245
|
+
dataKey: {
|
|
246
|
+
type: [String, Function],
|
|
247
|
+
required: !0
|
|
248
|
+
},
|
|
249
|
+
dataSources: {
|
|
250
|
+
type: Array,
|
|
251
|
+
required: !0,
|
|
252
|
+
default: function() {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
dataComponent: {
|
|
257
|
+
type: [Object, Function],
|
|
258
|
+
required: !0
|
|
259
|
+
},
|
|
260
|
+
keeps: {
|
|
261
|
+
type: Number,
|
|
262
|
+
default: 30
|
|
263
|
+
},
|
|
264
|
+
extraProps: {
|
|
265
|
+
type: Object
|
|
266
|
+
},
|
|
267
|
+
estimateSize: {
|
|
268
|
+
type: Number,
|
|
269
|
+
default: 50
|
|
270
|
+
},
|
|
271
|
+
direction: {
|
|
272
|
+
type: String,
|
|
273
|
+
default: "vertical"
|
|
274
|
+
// the other value is horizontal
|
|
275
|
+
},
|
|
276
|
+
start: {
|
|
277
|
+
type: Number,
|
|
278
|
+
default: 0
|
|
279
|
+
},
|
|
280
|
+
offset: {
|
|
281
|
+
type: Number,
|
|
282
|
+
default: 0
|
|
283
|
+
},
|
|
284
|
+
topThreshold: {
|
|
285
|
+
type: Number,
|
|
286
|
+
default: 0
|
|
287
|
+
},
|
|
288
|
+
bottomThreshold: {
|
|
289
|
+
type: Number,
|
|
290
|
+
default: 0
|
|
291
|
+
},
|
|
292
|
+
pageMode: {
|
|
293
|
+
type: Boolean,
|
|
294
|
+
default: !1
|
|
295
|
+
},
|
|
296
|
+
rootTag: {
|
|
297
|
+
type: String,
|
|
298
|
+
default: "div"
|
|
299
|
+
},
|
|
300
|
+
wrapTag: {
|
|
301
|
+
type: String,
|
|
302
|
+
default: "div"
|
|
303
|
+
},
|
|
304
|
+
wrapClass: {
|
|
305
|
+
type: String,
|
|
306
|
+
default: "wrap"
|
|
307
|
+
},
|
|
308
|
+
wrapStyle: {
|
|
309
|
+
type: Object
|
|
310
|
+
},
|
|
311
|
+
itemTag: {
|
|
312
|
+
type: String,
|
|
313
|
+
default: "div"
|
|
314
|
+
},
|
|
315
|
+
itemClass: {
|
|
316
|
+
type: String,
|
|
317
|
+
default: ""
|
|
318
|
+
},
|
|
319
|
+
itemClassAdd: {
|
|
320
|
+
type: Function
|
|
321
|
+
},
|
|
322
|
+
itemStyle: {
|
|
323
|
+
type: Object
|
|
324
|
+
},
|
|
325
|
+
headerTag: {
|
|
326
|
+
type: String,
|
|
327
|
+
default: "div"
|
|
328
|
+
},
|
|
329
|
+
headerClass: {
|
|
330
|
+
type: String,
|
|
331
|
+
default: ""
|
|
332
|
+
},
|
|
333
|
+
headerStyle: {
|
|
334
|
+
type: Object
|
|
335
|
+
},
|
|
336
|
+
footerTag: {
|
|
337
|
+
type: String,
|
|
338
|
+
default: "div"
|
|
339
|
+
},
|
|
340
|
+
footerClass: {
|
|
341
|
+
type: String,
|
|
342
|
+
default: ""
|
|
343
|
+
},
|
|
344
|
+
footerStyle: {
|
|
345
|
+
type: Object
|
|
346
|
+
},
|
|
347
|
+
itemScopedSlots: {
|
|
348
|
+
type: Object
|
|
349
|
+
}
|
|
350
|
+
}, Ft = {
|
|
351
|
+
index: {
|
|
352
|
+
type: Number
|
|
353
|
+
},
|
|
354
|
+
event: {
|
|
355
|
+
type: String
|
|
356
|
+
},
|
|
357
|
+
tag: {
|
|
358
|
+
type: String
|
|
359
|
+
},
|
|
360
|
+
horizontal: {
|
|
361
|
+
type: Boolean
|
|
362
|
+
},
|
|
363
|
+
source: {
|
|
364
|
+
type: Object
|
|
365
|
+
},
|
|
366
|
+
component: {
|
|
367
|
+
type: [Object, Function]
|
|
368
|
+
},
|
|
369
|
+
uniqueKey: {
|
|
370
|
+
type: [String, Number]
|
|
371
|
+
},
|
|
372
|
+
extraProps: {
|
|
373
|
+
type: Object
|
|
374
|
+
},
|
|
375
|
+
scopedSlots: {
|
|
376
|
+
type: Object
|
|
377
|
+
}
|
|
378
|
+
}, Ut = {
|
|
379
|
+
event: {
|
|
380
|
+
type: String
|
|
381
|
+
},
|
|
382
|
+
uniqueKey: {
|
|
383
|
+
type: String
|
|
384
|
+
},
|
|
385
|
+
tag: {
|
|
386
|
+
type: String
|
|
387
|
+
},
|
|
388
|
+
horizontal: {
|
|
389
|
+
type: Boolean
|
|
390
|
+
}
|
|
391
|
+
}, st = function(e, t, s) {
|
|
392
|
+
let n = null, r = Tt(function() {
|
|
393
|
+
return e.horizontal ? "offsetWidth" : "offsetHeight";
|
|
394
|
+
}), o = function() {
|
|
395
|
+
return t.value ? t.value[r.value] : 0;
|
|
396
|
+
}, a = function() {
|
|
397
|
+
let c = e.event, h = e.uniqueKey, l = e.hasInitial;
|
|
398
|
+
s(c, h, o(), l);
|
|
399
|
+
};
|
|
400
|
+
et(function() {
|
|
401
|
+
typeof ResizeObserver < "u" && (n = new ResizeObserver(function() {
|
|
402
|
+
a();
|
|
403
|
+
}), t.value && n.observe(t.value));
|
|
404
|
+
}), xt(function() {
|
|
405
|
+
a();
|
|
406
|
+
}), tt(function() {
|
|
407
|
+
n && (n.disconnect(), n = null);
|
|
408
|
+
});
|
|
409
|
+
}, Vt = Ie({
|
|
410
|
+
name: "VirtualListItem",
|
|
411
|
+
props: Ft,
|
|
412
|
+
emits: ["itemResize"],
|
|
413
|
+
setup: function(e, t) {
|
|
414
|
+
let s = t.emit, n = W(null);
|
|
415
|
+
return st(e, n, s), function() {
|
|
416
|
+
let r = e.tag, o = e.component, a = e.extraProps, u = a === void 0 ? {} : a, c = e.index, h = e.source, l = e.scopedSlots, m = l === void 0 ? {} : l, w = e.uniqueKey, v = Z(Z({}, u), {}, {
|
|
417
|
+
source: h,
|
|
418
|
+
index: c
|
|
419
|
+
});
|
|
420
|
+
return S(r, {
|
|
421
|
+
key: w,
|
|
422
|
+
ref: n
|
|
423
|
+
}, {
|
|
424
|
+
default: function() {
|
|
425
|
+
return [S(o, Z(Z({}, v), {}, {
|
|
426
|
+
scopedSlots: m
|
|
427
|
+
}), null)];
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
}), Je = Ie({
|
|
433
|
+
name: "VirtualListSlot",
|
|
434
|
+
props: Ut,
|
|
435
|
+
emits: ["slotResize"],
|
|
436
|
+
setup: function(e, t) {
|
|
437
|
+
let s = t.slots, n = t.emit, r = W(null);
|
|
438
|
+
return st(e, r, n), function() {
|
|
439
|
+
let o, a = e.tag, u = e.uniqueKey;
|
|
440
|
+
return S(a, {
|
|
441
|
+
ref: r,
|
|
442
|
+
key: u
|
|
443
|
+
}, {
|
|
444
|
+
default: function() {
|
|
445
|
+
return [(o = s.default) === null || o === void 0 ? void 0 : o.call(s)];
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}), J;
|
|
451
|
+
(function(i) {
|
|
452
|
+
i.ITEM = "itemResize", i.SLOT = "slotResize";
|
|
453
|
+
})(J || (J = {}));
|
|
454
|
+
let D;
|
|
455
|
+
(function(i) {
|
|
456
|
+
i.HEADER = "thead", i.FOOTER = "tfoot";
|
|
457
|
+
})(D || (D = {}));
|
|
458
|
+
let Kt = Ie({
|
|
459
|
+
name: "VirtualList",
|
|
460
|
+
props: Dt,
|
|
461
|
+
setup: function(e, t) {
|
|
462
|
+
let s = t.emit, n = t.slots, r = t.expose, o = e.direction === "horizontal", a = o ? "scrollLeft" : "scrollTop", u = W(null), c = W(), h = W(null), l;
|
|
463
|
+
Q(function() {
|
|
464
|
+
return e.dataSources.length;
|
|
465
|
+
}, function() {
|
|
466
|
+
l.updateParam("uniqueIds", $e()), l.handleDataSourcesChange();
|
|
467
|
+
}), Q(function() {
|
|
468
|
+
return e.keeps;
|
|
469
|
+
}, function(f) {
|
|
470
|
+
l.updateParam("keeps", f), l.handleSlotSizeChange();
|
|
471
|
+
}), Q(function() {
|
|
472
|
+
return e.start;
|
|
473
|
+
}, function(f) {
|
|
474
|
+
pe(f);
|
|
475
|
+
}), Q(function() {
|
|
476
|
+
return e.offset;
|
|
477
|
+
}, function(f) {
|
|
478
|
+
return B(f);
|
|
479
|
+
});
|
|
480
|
+
var m = function(d) {
|
|
481
|
+
return l.sizes.get(d);
|
|
482
|
+
}, w = function() {
|
|
483
|
+
return e.pageMode ? document.documentElement[a] || document.body[a] : c.value ? Math.ceil(c.value[a]) : 0;
|
|
484
|
+
}, v = function() {
|
|
485
|
+
let d = o ? "clientWidth" : "clientHeight";
|
|
486
|
+
return e.pageMode ? document.documentElement[d] || document.body[d] : c.value ? Math.ceil(c.value[d]) : 0;
|
|
487
|
+
}, I = function() {
|
|
488
|
+
let d = o ? "scrollWidth" : "scrollHeight";
|
|
489
|
+
return e.pageMode ? document.documentElement[d] || document.body[d] : c.value ? Math.ceil(c.value[d]) : 0;
|
|
490
|
+
}, St = function(d, g, b, C) {
|
|
491
|
+
s("scroll", C, l.getRange()), l.isFront() && e.dataSources.length && d - e.topThreshold <= 0 ? s("totop") : l.isBehind() && d + g + e.bottomThreshold >= b && s("tobottom");
|
|
492
|
+
}, de = function(d) {
|
|
493
|
+
let g = w(), b = v(), C = I();
|
|
494
|
+
g < 0 || g + b > C + 1 || !C || (l.handleScroll(g), St(g, b, C, d));
|
|
495
|
+
}, $e = function() {
|
|
496
|
+
let d = e.dataKey, g = e.dataSources, b = g === void 0 ? [] : g;
|
|
497
|
+
return b.map(function(C) {
|
|
498
|
+
return typeof d == "function" ? d(C) : C[d];
|
|
499
|
+
});
|
|
500
|
+
}, Ct = function(d) {
|
|
501
|
+
u.value = d;
|
|
502
|
+
}, Et = function() {
|
|
503
|
+
l = new zt({
|
|
504
|
+
slotHeaderSize: 0,
|
|
505
|
+
slotFooterSize: 0,
|
|
506
|
+
keeps: e.keeps,
|
|
507
|
+
estimateSize: e.estimateSize,
|
|
508
|
+
buffer: Math.round(e.keeps / 3),
|
|
509
|
+
// recommend for a third of keeps
|
|
510
|
+
uniqueIds: $e()
|
|
511
|
+
}, Ct), u.value = l.getRange();
|
|
512
|
+
}, pe = function(d) {
|
|
513
|
+
if (d >= e.dataSources.length - 1) { ze(); } else {
|
|
514
|
+
let g = l.getOffset(d);
|
|
515
|
+
B(g);
|
|
516
|
+
}
|
|
517
|
+
}, B = function(d) {
|
|
518
|
+
e.pageMode ? (document.body[a] = d, document.documentElement[a] = d) : c.value && (c.value[a] = d);
|
|
519
|
+
}, kt = function() {
|
|
520
|
+
for (var d = [], g = u.value, b = g.start, C = g.end, fe = e.dataSources, $ = e.dataKey, ge = e.itemClass, me = e.itemTag, ye = e.itemStyle, we = e.extraProps, Y = e.dataComponent, X = e.itemScopedSlots, N = b; N <= C; N++) {
|
|
521
|
+
let j = fe[N];
|
|
522
|
+
if (j) {
|
|
523
|
+
let U = typeof $ == "function" ? $(j) : j[$];
|
|
524
|
+
typeof U == "string" || typeof U == "number" ? d.push(S(Vt, {
|
|
525
|
+
index: N,
|
|
526
|
+
tag: me,
|
|
527
|
+
event: J.ITEM,
|
|
528
|
+
horizontal: o,
|
|
529
|
+
uniqueKey: U,
|
|
530
|
+
source: j,
|
|
531
|
+
extraProps: we,
|
|
532
|
+
component: Y,
|
|
533
|
+
scopedSlots: X,
|
|
534
|
+
style: ye,
|
|
535
|
+
class: "".concat(ge).concat(e.itemClassAdd ? " " + e.itemClassAdd(N) : ""),
|
|
536
|
+
onItemResize: vt
|
|
537
|
+
}, null)) : console.warn("Cannot get the data-key '".concat($, "' from data-sources."));
|
|
538
|
+
} else { console.warn("Cannot get the index '".concat(N, "' from data-sources.")); }
|
|
539
|
+
}
|
|
540
|
+
return d;
|
|
541
|
+
}, vt = function(d, g) {
|
|
542
|
+
l.saveSize(d, g), s("resized", d, g);
|
|
543
|
+
}, Pe = function(d, g, b) {
|
|
544
|
+
d === D.HEADER ? l.updateParam("slotHeaderSize", g) : d === D.FOOTER && l.updateParam("slotFooterSize", g), b && l.handleSlotSizeChange();
|
|
545
|
+
}, ze = function f() {
|
|
546
|
+
if (h.value) {
|
|
547
|
+
let d = h.value[o ? "offsetLeft" : "offsetTop"];
|
|
548
|
+
B(d), setTimeout(function() {
|
|
549
|
+
w() + v() < I() && f();
|
|
550
|
+
}, 3);
|
|
551
|
+
}
|
|
552
|
+
}, _t = function() {
|
|
553
|
+
if (c.value) {
|
|
554
|
+
let d = c.value.getBoundingClientRect(), g = c.value.ownerDocument.defaultView, b = o ? d.left + g.pageXOffset : d.top + g.pageYOffset;
|
|
555
|
+
l.updateParam("slotHeaderSize", b);
|
|
556
|
+
}
|
|
557
|
+
}, qt = function() {
|
|
558
|
+
return l.sizes.size;
|
|
559
|
+
};
|
|
560
|
+
return Ot(function() {
|
|
561
|
+
Et();
|
|
562
|
+
}), Nt(function() {
|
|
563
|
+
B(l.offset);
|
|
564
|
+
}), et(function() {
|
|
565
|
+
e.start ? pe(e.start) : e.offset && B(e.offset), e.pageMode && (_t(), document.addEventListener("scroll", de, {
|
|
566
|
+
passive: !1
|
|
567
|
+
}));
|
|
568
|
+
}), tt(function() {
|
|
569
|
+
l.destroy(), e.pageMode && document.removeEventListener("scroll", de);
|
|
570
|
+
}), r({
|
|
571
|
+
scrollToBottom: ze,
|
|
572
|
+
getSizes: qt,
|
|
573
|
+
getSize: m,
|
|
574
|
+
getOffset: w,
|
|
575
|
+
getScrollSize: I,
|
|
576
|
+
getClientSize: v,
|
|
577
|
+
scrollToOffset: B,
|
|
578
|
+
scrollToIndex: pe
|
|
579
|
+
}), function() {
|
|
580
|
+
let f = e.pageMode, d = e.rootTag, g = e.wrapTag, b = e.wrapClass, C = e.wrapStyle, fe = e.headerTag, $ = e.headerClass, ge = e.headerStyle, me = e.footerTag, ye = e.footerClass, we = e.footerStyle, Y = u.value, X = Y.padFront, N = Y.padBehind, j = {
|
|
581
|
+
padding: o ? "0px ".concat(N, "px 0px ").concat(X, "px") : "".concat(X, "px 0px ").concat(N, "px")
|
|
582
|
+
}, U = C ? Object.assign({}, C, j) : j, De = n.header, Fe = n.footer;
|
|
583
|
+
return S(d, {
|
|
584
|
+
ref: c,
|
|
585
|
+
onScroll: !f && de
|
|
586
|
+
}, {
|
|
587
|
+
default: function() {
|
|
588
|
+
return [De && S(Je, {
|
|
589
|
+
class: $,
|
|
590
|
+
style: ge,
|
|
591
|
+
tag: fe,
|
|
592
|
+
event: J.SLOT,
|
|
593
|
+
uniqueKey: D.HEADER,
|
|
594
|
+
onSlotResize: Pe
|
|
595
|
+
}, {
|
|
596
|
+
default: function() {
|
|
597
|
+
return [De()];
|
|
598
|
+
}
|
|
599
|
+
}), S(g, {
|
|
600
|
+
class: b,
|
|
601
|
+
style: U
|
|
602
|
+
}, {
|
|
603
|
+
default: function() {
|
|
604
|
+
return [kt()];
|
|
605
|
+
}
|
|
606
|
+
}), Fe && S(Je, {
|
|
607
|
+
class: ye,
|
|
608
|
+
style: we,
|
|
609
|
+
tag: me,
|
|
610
|
+
event: J.SLOT,
|
|
611
|
+
uniqueKey: D.FOOTER,
|
|
612
|
+
onSlotResize: Pe
|
|
613
|
+
}, {
|
|
614
|
+
default: function() {
|
|
615
|
+
return [Fe()];
|
|
616
|
+
}
|
|
617
|
+
}), S("div", {
|
|
618
|
+
ref: h,
|
|
619
|
+
style: {
|
|
620
|
+
width: o ? "0px" : "100%",
|
|
621
|
+
height: o ? "100%" : "0px"
|
|
622
|
+
}
|
|
623
|
+
}, null)];
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
class Wt {
|
|
630
|
+
// 分组节点扁平化对象、设备扁平化对象、window缓存设备扁平化对象
|
|
631
|
+
constructor(e, t, s) {
|
|
632
|
+
this.groupNodeObject = e, this.nodesMap = t, this.controlObject = s;
|
|
633
|
+
}
|
|
634
|
+
// 增加映射
|
|
635
|
+
addNodesMap(e) {
|
|
636
|
+
e && e.forEach((t) => {
|
|
637
|
+
this.nodesMap[t.key] = t;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
// 移除映射
|
|
641
|
+
removeNodesMap(e) {
|
|
642
|
+
e && e.forEach((t) => {
|
|
643
|
+
delete this.nodesMap[t.key];
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
// 回收所有分组节点缓存
|
|
647
|
+
recycleAllNodeCache(e) {
|
|
648
|
+
for (let t in this.groupNodeObject) { this.groupNodeObject[t].expand = !1, this.groupNodeObject[t].count = 0, this.recycleGroupCache(this.groupNodeObject[t].key), e && delete this.groupNodeObject[t]; }
|
|
649
|
+
}
|
|
650
|
+
// 回收分组节点内存
|
|
651
|
+
recycleGroupCache(e) {
|
|
652
|
+
if (this.groupNodeObject[e]) {
|
|
653
|
+
this.groupNodeObject[e].children = [], this.removeNodesMap(this.groupNodeObject[e].equips), this.groupNodeObject[e].equips = [], this.groupNodeObject[e].equips.length = 0, this.groupNodeObject[e].expand = !1;
|
|
654
|
+
for (let t in this.groupNodeObject) { this.groupNodeObject[t].groupId == e && this.recycleGroupCache(this.groupNodeObject[t].key); }
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
// 关闭兄弟分组节点及回收内存
|
|
658
|
+
closeBrotherNode(e) {
|
|
659
|
+
if (e && this.groupNodeObject[e]) {
|
|
660
|
+
let t = this.groupNodeObject[e].groupId;
|
|
661
|
+
for (let s in this.groupNodeObject) { this.groupNodeObject[s].groupId == t && this.groupNodeObject[s].key != e && this.groupNodeObject[s].expand && (this.groupNodeObject[s].expand = !1, this.recycleGroupCache(this.groupNodeObject[s].key)); }
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
class ue {
|
|
666
|
+
constructor() {
|
|
667
|
+
this.window = window;
|
|
668
|
+
try {
|
|
669
|
+
window.top.equipGroup, this.window = window.top;
|
|
670
|
+
} catch {
|
|
671
|
+
this.window = window;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
const it = {
|
|
676
|
+
data() {
|
|
677
|
+
return {
|
|
678
|
+
window: null
|
|
679
|
+
};
|
|
680
|
+
},
|
|
681
|
+
created() {
|
|
682
|
+
this.window = window;
|
|
683
|
+
try {
|
|
684
|
+
window.top.equipGroup, this.window = window.top;
|
|
685
|
+
} catch {
|
|
686
|
+
this.window = window;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
class Ht extends ue {
|
|
691
|
+
constructor(e, t, s, n, r, o) {
|
|
692
|
+
super(), this.equipControllObject = s, this.groupNodeObject = e, this.nodesMap = t, this.controlObject = n, this.equipCheckObject = r, this.isSearchStatus = !1, this.searchStatusGroupObject = {}, this.aliasName = o;
|
|
693
|
+
}
|
|
694
|
+
resetCheckedStatus() {
|
|
695
|
+
Object.values(this.nodesMap).forEach((e) => {
|
|
696
|
+
this.setCheckStatus(e.key, !1, !1);
|
|
697
|
+
}), Object.keys(this.equipCheckObject).forEach((e) => delete this.equipCheckObject[e]), this.updateGroupCheckStatus();
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* 搜索状态下,更新分组选中状态
|
|
702
|
+
* 新方案:直接调用 updateGroupCheckStatus 重新计算
|
|
703
|
+
*/
|
|
704
|
+
reComputedCheckNum(e) {
|
|
705
|
+
this.isSearchStatus = e, this.updateGroupCheckStatus();
|
|
706
|
+
}
|
|
707
|
+
// 根据传过来的设备选中数据、回显选中状态
|
|
708
|
+
/**
|
|
709
|
+
* 支持两种数据格式:
|
|
710
|
+
* 格式1:纯 equipNo 数组,如 [1, 2, 3],选中该设备在所有分组下的实例
|
|
711
|
+
* 格式2:{ groupId: [equipNo1, equipNo2] } 对象,如 { 2: [1, 2], 3: [5] },只选中指定分组下的设备
|
|
712
|
+
*
|
|
713
|
+
* 注意:此方法只负责将选中状态写入 equipCheckObject,不调用 updateGroupCheckStatus。
|
|
714
|
+
* 分组状态的更新由调用方在合适的时机(数据就绪后)统一调用。
|
|
715
|
+
*/
|
|
716
|
+
updateCheckedStatusWithEquips(e) {
|
|
717
|
+
Object.keys(this.equipCheckObject).forEach((s) => {
|
|
718
|
+
s.split("-").length === 2 && delete this.equipCheckObject[s];
|
|
719
|
+
});
|
|
720
|
+
let t = [];
|
|
721
|
+
Array.isArray(e) ? t = e.map((s) => ({ equipNo: s, groupId: null })) : e !== null && typeof e == "object" && Object.keys(e).forEach((s) => {
|
|
722
|
+
Array.isArray(e[s]) && e[s].forEach((n) => {
|
|
723
|
+
t.push({ equipNo: n, groupId: Number(s) });
|
|
724
|
+
});
|
|
725
|
+
});
|
|
726
|
+
for (let s = 0, n = t.length; s < n; s++) {
|
|
727
|
+
const { equipNo: r, groupId: o } = t[s];
|
|
728
|
+
if (o != null) {
|
|
729
|
+
const a = `${o}-${r}`;
|
|
730
|
+
this.setEquipCheckObject(a, !0, !1, o), this.setCheckStatus(a, !0, !1), this.updateExpandControlCheckStatus(o, r);
|
|
731
|
+
} else {
|
|
732
|
+
const a = this.window.equipCache && this.window.equipCache[r];
|
|
733
|
+
a && (a.groupIds || (a.groupId ? [a.groupId] : [])).forEach((c) => {
|
|
734
|
+
const h = `${c}-${r}`;
|
|
735
|
+
this.setEquipCheckObject(h, !0, !1, c), this.setCheckStatus(h, !0, !1), this.updateExpandControlCheckStatus(c, r);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
// 更新展开的设备控制项选中状态
|
|
741
|
+
updateExpandControlCheckStatus(e, t) {
|
|
742
|
+
let s = this.nodesMap[`${e}-${t}`];
|
|
743
|
+
s && s.settings && s.settings.length && s.settings.forEach((n) => {
|
|
744
|
+
this.nodesMap[`${e}-${t}-${n.setNo}`] && this.setCheckStatus(`${e}-${t}-${n.setNo}`, !0, !1);
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
// 根据传过来的设备控制项,回显设备分组选中状态
|
|
748
|
+
/**
|
|
749
|
+
* 注意:此方法只负责将控制项状态写入 equipControllObject/equipCheckObject,不调用 updateGroupCheckStatus。
|
|
750
|
+
* 分组状态的更新由调用方在合适的时机(数据就绪后)统一调用。
|
|
751
|
+
*/
|
|
752
|
+
updateCheckedStatusWithControls(e) {
|
|
753
|
+
for (let t = 0, s = e.length; t < s; t++) {
|
|
754
|
+
let n = e[t], r, o, a;
|
|
755
|
+
if (n !== null && typeof n == "object" && !Array.isArray(n)) { r = n.equipNo, o = n.setNo, a = n.groupId; } else {
|
|
756
|
+
let c = n.split(".");
|
|
757
|
+
r = c[0], o = c[1], a = null;
|
|
758
|
+
}
|
|
759
|
+
this.equipControllObject[r] || (this.equipControllObject[r] = []), this.equipControllObject[r].push(Number(o));
|
|
760
|
+
const u = this.window.equipCache && this.window.equipCache[r];
|
|
761
|
+
u && (a != null ? [a] : u.groupIds || (u.groupId ? [u.groupId] : [])).forEach((h) => {
|
|
762
|
+
const l = `${h}-${r}`, m = `${h}-${r}-${o}`;
|
|
763
|
+
this.nodesMap[m] && this.setCheckStatus(m, !0, !1), this.nodesMap[l] && this.setCheckStatus(l, !1, !0), this.setEquipCheckObject(l, !1, !0, h);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
// 更新分组选中状态------------------------------------------------------------------------------------
|
|
768
|
+
/**
|
|
769
|
+
* 新方案:基于 equipCheckObject 实时计算分组状态,而不是依赖中间状态
|
|
770
|
+
* 优点:状态判断准确,不会累积误差
|
|
771
|
+
*/
|
|
772
|
+
updateGroupCheckStatus() {
|
|
773
|
+
this.getSortedGroupsByLevel().forEach((t) => {
|
|
774
|
+
const s = this.computeGroupStatus(t.key);
|
|
775
|
+
this.setCheckStatus(t.key, s.checked, s.indeterminate), t.equipSelectCount = s.selectCount;
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
// 按层级排序分组(从深到浅,确保子分组先处理)
|
|
779
|
+
getSortedGroupsByLevel() {
|
|
780
|
+
return Object.values(this.groupNodeObject).sort((e, t) => t.level - e.level);
|
|
781
|
+
}
|
|
782
|
+
// 计算单个分组的选中状态
|
|
783
|
+
/**
|
|
784
|
+
* @returns {Object} { checked, indeterminate, selectCount }
|
|
785
|
+
*/
|
|
786
|
+
computeGroupStatus(e) {
|
|
787
|
+
const t = this.groupNodeObject[e];
|
|
788
|
+
if (!t) { return { checked: !1, indeterminate: !1, selectCount: 0 }; }
|
|
789
|
+
let s = this.isSearchStatus ? this.window[`group-${e}-search`] || [] : this.window[`group-${e}${this.aliasName}`] || [];
|
|
790
|
+
!this.isSearchStatus && s.length === 0 && this.aliasName && (s = this.window[`group-${e}`] || []);
|
|
791
|
+
let n = 0, r = s.length || t.equipCount || 0;
|
|
792
|
+
if (s.length > 0) {
|
|
793
|
+
s.forEach((m) => {
|
|
794
|
+
const w = m.equipNo || m.id, v = `${e}-${w}`;
|
|
795
|
+
this.equipCheckObject[v] && this.equipCheckObject[v].checked && n++;
|
|
796
|
+
});
|
|
797
|
+
} else {
|
|
798
|
+
const m = `${e}-`;
|
|
799
|
+
Object.keys(this.equipCheckObject).forEach((w) => {
|
|
800
|
+
w.startsWith(m) && w.split("-").length === 2 && this.equipCheckObject[w].checked && n++;
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
let o = 0, a = 0, u = !1, c = !1;
|
|
804
|
+
t.groups && t.groups.length > 0 && t.groups.forEach((m) => {
|
|
805
|
+
const w = this.nodesMap[m.key], v = this.groupNodeObject[m.key];
|
|
806
|
+
if (w) {
|
|
807
|
+
const I = w.count || (v ? v.equipCount : 0) || 0;
|
|
808
|
+
a += I, w.checked ? (o += I, u = !0) : w.indeterminate ? (c = !0, u = !0) : c = !0;
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
const h = n + o;
|
|
812
|
+
let l = t.count || 0;
|
|
813
|
+
return l === 0 && (l = r + a), h === 0 && !u ? { checked: !1, indeterminate: !1, selectCount: 0 } : l === 0 ? h > 0 ? { checked: !1, indeterminate: !0, selectCount: h } : { checked: !1, indeterminate: !1, selectCount: 0 } : h === 0 ? u ? { checked: !1, indeterminate: !0, selectCount: h } : { checked: !1, indeterminate: !1, selectCount: 0 } : h === l && !c ? { checked: !0, indeterminate: !1, selectCount: h } : { checked: !1, indeterminate: !0, selectCount: h };
|
|
814
|
+
}
|
|
815
|
+
// 设置设备控制项状态
|
|
816
|
+
setControlStatus(e, t, s, n) {
|
|
817
|
+
e && e.forEach((r) => {
|
|
818
|
+
this.nodesMap[`${t}-${s}-${r.setNo}`] && this.setCheckStatus(`${t}-${s}-${r.setNo}`, n, !1);
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
// 更新设备控制项选中状态
|
|
822
|
+
/**
|
|
823
|
+
* 改造点:controlObject 键格式统一为 ${groupId}-${equipNo}
|
|
824
|
+
* */
|
|
825
|
+
updateControlCheckStatus() {
|
|
826
|
+
Object.keys(this.controlObject).forEach((e) => {
|
|
827
|
+
const [t, s] = e.split("-");
|
|
828
|
+
let n = this.nodesMap[e];
|
|
829
|
+
if (n) {
|
|
830
|
+
if (n.checked) {
|
|
831
|
+
let r = n.settings;
|
|
832
|
+
this.setControlStatus(r, t, s, !0);
|
|
833
|
+
} else if (!n.checked && !n.indeterminate) {
|
|
834
|
+
let r = n.settings;
|
|
835
|
+
this.setControlStatus(r, t, s, !1);
|
|
836
|
+
} else {
|
|
837
|
+
this.equipControllObject[s] && this.equipControllObject[s].forEach((r) => {
|
|
838
|
+
let o = `${t}-${s}-${r}`;
|
|
839
|
+
this.nodesMap[o] && this.setCheckStatus(o, !0, !1);
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
// 获取选中的分组
|
|
846
|
+
getGroupChecked() {
|
|
847
|
+
let e = [];
|
|
848
|
+
return Object.keys(this.groupNodeObject).forEach((t) => {
|
|
849
|
+
this.groupNodeObject[t].checked && e.push(t);
|
|
850
|
+
}), e;
|
|
851
|
+
}
|
|
852
|
+
// 获取选中设备
|
|
853
|
+
getEquipSelectd() {
|
|
854
|
+
let e = [], t = /* @__PURE__ */ new Set();
|
|
855
|
+
return Object.keys(this.equipCheckObject).forEach((s) => {
|
|
856
|
+
if (this.equipCheckObject[s].checked) {
|
|
857
|
+
try {
|
|
858
|
+
t.add(Number(s.split("-")[1]));
|
|
859
|
+
} catch (n) {
|
|
860
|
+
console.log(n);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}), e = Array.from(t), e;
|
|
864
|
+
}
|
|
865
|
+
// 获取选中设备(携带分组)
|
|
866
|
+
getEquipGroupSelectd() {
|
|
867
|
+
let e = Object.keys(this.equipCheckObject);
|
|
868
|
+
return e.length > 0 && (e = this.returnArray(e)), e;
|
|
869
|
+
}
|
|
870
|
+
returnArray(e) {
|
|
871
|
+
const t = [];
|
|
872
|
+
return e.forEach((s) => {
|
|
873
|
+
const n = s.split("-");
|
|
874
|
+
if (n.length >= 2) {
|
|
875
|
+
const r = parseInt(n[0]), o = parseInt(n[1]);
|
|
876
|
+
!isNaN(r) && !isNaN(o) && t.push({ groupId: r, equipNo: o });
|
|
877
|
+
}
|
|
878
|
+
}), t;
|
|
879
|
+
}
|
|
880
|
+
// 解析设备数组为分组格式
|
|
881
|
+
parseEquipArrayToGroupFormat(e) {
|
|
882
|
+
const t = {};
|
|
883
|
+
return e.forEach((s) => {
|
|
884
|
+
const [n, r] = s.split("-"), o = parseInt(n);
|
|
885
|
+
isNaN(o) || (t[o] || (t[o] = []), t[o].push(parseInt(r)));
|
|
886
|
+
}), t;
|
|
887
|
+
}
|
|
888
|
+
// 获取选中的设备控制项
|
|
889
|
+
getControlSelected() {
|
|
890
|
+
let e = [];
|
|
891
|
+
return Object.keys(this.equipControllObject).forEach((t) => {
|
|
892
|
+
e.push(...this.equipControllObject[t].map((s) => `${t}.${s}`));
|
|
893
|
+
}), e;
|
|
894
|
+
}
|
|
895
|
+
// 点击选中
|
|
896
|
+
/**
|
|
897
|
+
* 1:如果是分组选择,触发分组选中事件
|
|
898
|
+
* 2:如果是设备选择,触发设备选中事件
|
|
899
|
+
* 3:如果是设备控制项选择,触发设备控制项选中事件
|
|
900
|
+
* */
|
|
901
|
+
onChecked(e, t) {
|
|
902
|
+
this.isSearchStatus = t || !1, e.isGroup && !e.isEquip ? this.selectGroup(e) : e.isEquip ? this.selectEquip(e) : e.isSetting && this.selectControl(e);
|
|
903
|
+
}
|
|
904
|
+
// 从全局映射中,设置节点选中状态
|
|
905
|
+
setCheckStatus(e, t, s, n) {
|
|
906
|
+
this.nodesMap[e] && (this.nodesMap[e].checked = t, this.nodesMap[e].isGroup && (this.nodesMap[e].indeterminate = s));
|
|
907
|
+
}
|
|
908
|
+
// 保存全局设备选中状态
|
|
909
|
+
setEquipCheckObject(e, t, s, n) {
|
|
910
|
+
this.equipCheckObject[e] || (this.equipCheckObject[e] = {}), this.equipCheckObject[e].checked = t, this.equipCheckObject[e].indeterminate = s, this.equipCheckObject[e].groupId = n, !t && !s && delete this.equipCheckObject[e];
|
|
911
|
+
}
|
|
912
|
+
// 触发分组选择
|
|
913
|
+
selectGroup(e) {
|
|
914
|
+
this.updateAllEquipStatus(e.key, e.checked), this.updateControlCheckStatus(), this.updateGroupCheckStatus();
|
|
915
|
+
}
|
|
916
|
+
// 更新分组下所有设备的选中状态
|
|
917
|
+
updateAllEquipStatus(e, t) {
|
|
918
|
+
const s = this.groupNodeObject[e];
|
|
919
|
+
if (!s) { return; }
|
|
920
|
+
let n = this.isSearchStatus ? this.window[`group-${e}-search`] || [] : this.window[`group-${e}${this.aliasName}`] || [];
|
|
921
|
+
!this.isSearchStatus && n.length === 0 && this.aliasName && (n = this.window[`group-${e}`] || []), n.forEach((r) => {
|
|
922
|
+
const o = r.equipNo || r.id, a = `${e}-${o}`;
|
|
923
|
+
this.setEquipCheckObject(a, t, !1, e), this.nodesMap[a] && this.setCheckStatus(a, t, !1);
|
|
924
|
+
}), s.groups && s.groups.length > 0 && s.groups.forEach((r) => {
|
|
925
|
+
this.updateAllEquipStatus(r.key, t);
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
// 触发设备选择
|
|
929
|
+
/**
|
|
930
|
+
* 新方案:简化逻辑,只更新设备状态,分组状态由 updateGroupCheckStatus 统一计算
|
|
931
|
+
*/
|
|
932
|
+
selectEquip(e) {
|
|
933
|
+
const t = `${e.groupId}-${e.equipNo}`;
|
|
934
|
+
this.setEquipCheckObject(t, e.checked, !1, e.groupId), this.nodesMap[t] && this.setCheckStatus(t, e.checked, !1), this.updateControlCheckStatus(), this.updateGroupCheckStatus();
|
|
935
|
+
}
|
|
936
|
+
// 更新设备控制项存储
|
|
937
|
+
updateEquipControl(e, t, s) {
|
|
938
|
+
this.equipControllObject[e] || (this.equipControllObject[e] = []), s ? this.equipControllObject[e].push(t) : this.equipControllObject[e] = this.equipControllObject[e].filter((n) => n != t);
|
|
939
|
+
}
|
|
940
|
+
// 触发控制项选择
|
|
941
|
+
/**
|
|
942
|
+
* 新方案:简化逻辑,只更新控制项和设备状态,分组状态由 updateGroupCheckStatus 统一计算
|
|
943
|
+
*/
|
|
944
|
+
selectControl(e) {
|
|
945
|
+
const t = `${e.groupId}-${e.equipNo}`, s = `${e.groupId}-${e.equipNo}-${e.setNo}`, n = this.nodesMap[t];
|
|
946
|
+
if (!n) { return; }
|
|
947
|
+
this.updateEquipControl(e.equipNo, e.setNo, e.checked), this.setCheckStatus(s, e.checked, !1);
|
|
948
|
+
const r = n.settings || [], o = this.equipControllObject[e.equipNo] || [], a = r.length, u = o.length;
|
|
949
|
+
e.checked ? u === a ? (delete this.equipControllObject[e.equipNo], this.setEquipCheckObject(t, !0, !1, e.groupId), this.setCheckStatus(t, !0, !1)) : (this.setEquipCheckObject(t, !1, !0, e.groupId), this.setCheckStatus(t, !1, !0)) : u === 0 ? (this.setEquipCheckObject(t, !1, !1, e.groupId), this.setCheckStatus(t, !1, !1)) : (this.setEquipCheckObject(t, !1, !0, e.groupId), this.setCheckStatus(t, !1, !0)), this.updateGroupCheckStatus();
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
class Jt extends ue {
|
|
953
|
+
// 分组节点扁平化对象、设备扁平化对象、window缓存设备扁平化对象
|
|
954
|
+
constructor(e, t) {
|
|
955
|
+
super(), this.aliasName = t, this.groupNodeObject = e;
|
|
956
|
+
}
|
|
957
|
+
// 重新计算分组设备数量
|
|
958
|
+
resetGroupNum(e, t, s) {
|
|
959
|
+
this.clearAllEquipNum();
|
|
960
|
+
const n = Object.keys(this.groupNodeObject).sort((r, o) => (this.groupNodeObject[o].level || 0) - (this.groupNodeObject[r].level || 0));
|
|
961
|
+
for (let r of n) {
|
|
962
|
+
let o = [];
|
|
963
|
+
e ? o = this.window[`group-${r}-search`] : o = this.window[`group-${r}${this.aliasName}`], t && o && o.length && (o = o.filter((u) => s[u.equipNo] === 2));
|
|
964
|
+
let a = o ? o.length : 0;
|
|
965
|
+
this.groupNodeObject[r].equipCount = a, this.setGroupNum(r, a);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
clearAllEquipNum() {
|
|
969
|
+
for (let e in this.groupNodeObject) { this.groupNodeObject[e].equipCount = 0, this.groupNodeObject[e].count = 0; }
|
|
970
|
+
}
|
|
971
|
+
// 设置分组设备数量
|
|
972
|
+
setGroupNum(e, t) {
|
|
973
|
+
this.groupNodeObject[e] && (this.groupNodeObject[e].count = Number(this.groupNodeObject[e].count) + Number(t), this.setGroupNum(this.groupNodeObject[e].groupId, t));
|
|
974
|
+
}
|
|
975
|
+
// 获取设备总数
|
|
976
|
+
getAllEquipsNum() {
|
|
977
|
+
let e = 0;
|
|
978
|
+
for (let t in this.groupNodeObject) { this.window[`group-${this.groupNodeObject[t].key}${this.aliasName}`] && (e = e + this.window[`group-${this.groupNodeObject[t].key}${this.aliasName}`].length); }
|
|
979
|
+
return e;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
const O = /* @__PURE__ */ Object.create(null);
|
|
983
|
+
O.open = "0";
|
|
984
|
+
O.close = "1";
|
|
985
|
+
O.ping = "2";
|
|
986
|
+
O.pong = "3";
|
|
987
|
+
O.message = "4";
|
|
988
|
+
O.upgrade = "5";
|
|
989
|
+
O.noop = "6";
|
|
990
|
+
const se = /* @__PURE__ */ Object.create(null);
|
|
991
|
+
Object.keys(O).forEach((i) => {
|
|
992
|
+
se[O[i]] = i;
|
|
993
|
+
});
|
|
994
|
+
const Oe = { type: "error", data: "parser error" }, nt = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", rt = typeof ArrayBuffer == "function", ot = (i) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(i) : i && i.buffer instanceof ArrayBuffer, je = ({ type: i, data: e }, t, s) => nt && e instanceof Blob ? t ? s(e) : Ye(e, s) : rt && (e instanceof ArrayBuffer || ot(e)) ? t ? s(e) : Ye(new Blob([e]), s) : s(O[i] + (e || "")), Ye = (i, e) => {
|
|
995
|
+
const t = new FileReader();
|
|
996
|
+
return t.onload = function() {
|
|
997
|
+
const s = t.result.split(",")[1];
|
|
998
|
+
e("b" + (s || ""));
|
|
999
|
+
}, t.readAsDataURL(i);
|
|
1000
|
+
};
|
|
1001
|
+
function Xe(i) {
|
|
1002
|
+
return i instanceof Uint8Array ? i : i instanceof ArrayBuffer ? new Uint8Array(i) : new Uint8Array(i.buffer, i.byteOffset, i.byteLength);
|
|
1003
|
+
}
|
|
1004
|
+
let Ce;
|
|
1005
|
+
function Yt(i, e) {
|
|
1006
|
+
if (nt && i.data instanceof Blob) { return i.data.arrayBuffer().then(Xe).then(e); }
|
|
1007
|
+
if (rt && (i.data instanceof ArrayBuffer || ot(i.data))) { return e(Xe(i.data)); }
|
|
1008
|
+
je(i, !1, (t) => {
|
|
1009
|
+
Ce || (Ce = new TextEncoder()), e(Ce.encode(t));
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
const Qe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", K = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
|
|
1013
|
+
for (let i = 0; i < Qe.length; i++) { K[Qe.charCodeAt(i)] = i; }
|
|
1014
|
+
const Xt = (i) => {
|
|
1015
|
+
let e = i.length * 0.75, t = i.length, s, n = 0, r, o, a, u;
|
|
1016
|
+
i[i.length - 1] === "=" && (e--, i[i.length - 2] === "=" && e--);
|
|
1017
|
+
const c = new ArrayBuffer(e), h = new Uint8Array(c);
|
|
1018
|
+
for (s = 0; s < t; s += 4) { r = K[i.charCodeAt(s)], o = K[i.charCodeAt(s + 1)], a = K[i.charCodeAt(s + 2)], u = K[i.charCodeAt(s + 3)], h[n++] = r << 2 | o >> 4, h[n++] = (o & 15) << 4 | a >> 2, h[n++] = (a & 3) << 6 | u & 63; }
|
|
1019
|
+
return c;
|
|
1020
|
+
}, Qt = typeof ArrayBuffer == "function", Re = (i, e) => {
|
|
1021
|
+
if (typeof i != "string") {
|
|
1022
|
+
return {
|
|
1023
|
+
type: "message",
|
|
1024
|
+
data: at(i, e)
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
const t = i.charAt(0);
|
|
1028
|
+
return t === "b" ? {
|
|
1029
|
+
type: "message",
|
|
1030
|
+
data: Zt(i.substring(1), e)
|
|
1031
|
+
} : se[t] ? i.length > 1 ? {
|
|
1032
|
+
type: se[t],
|
|
1033
|
+
data: i.substring(1)
|
|
1034
|
+
} : {
|
|
1035
|
+
type: se[t]
|
|
1036
|
+
} : Oe;
|
|
1037
|
+
}, Zt = (i, e) => {
|
|
1038
|
+
if (Qt) {
|
|
1039
|
+
const t = Xt(i);
|
|
1040
|
+
return at(t, e);
|
|
1041
|
+
} return { base64: !0, data: i };
|
|
1042
|
+
}, at = (i, e) => {
|
|
1043
|
+
switch (e) {
|
|
1044
|
+
case "blob":
|
|
1045
|
+
return i instanceof Blob ? i : new Blob([i]);
|
|
1046
|
+
case "arraybuffer":
|
|
1047
|
+
default:
|
|
1048
|
+
return i instanceof ArrayBuffer ? i : i.buffer;
|
|
1049
|
+
}
|
|
1050
|
+
}, ut = String.fromCharCode(30), es = (i, e) => {
|
|
1051
|
+
const t = i.length, s = new Array(t);
|
|
1052
|
+
let n = 0;
|
|
1053
|
+
i.forEach((r, o) => {
|
|
1054
|
+
je(r, !1, (a) => {
|
|
1055
|
+
s[o] = a, ++n === t && e(s.join(ut));
|
|
1056
|
+
});
|
|
1057
|
+
});
|
|
1058
|
+
}, ts = (i, e) => {
|
|
1059
|
+
const t = i.split(ut), s = [];
|
|
1060
|
+
for (let n = 0; n < t.length; n++) {
|
|
1061
|
+
const r = Re(t[n], e);
|
|
1062
|
+
if (s.push(r), r.type === "error") { break; }
|
|
1063
|
+
}
|
|
1064
|
+
return s;
|
|
1065
|
+
};
|
|
1066
|
+
function ss() {
|
|
1067
|
+
return new TransformStream({
|
|
1068
|
+
transform(i, e) {
|
|
1069
|
+
Yt(i, (t) => {
|
|
1070
|
+
const s = t.length;
|
|
1071
|
+
let n;
|
|
1072
|
+
if (s < 126) { n = new Uint8Array(1), new DataView(n.buffer).setUint8(0, s); } else if (s < 65536) {
|
|
1073
|
+
n = new Uint8Array(3);
|
|
1074
|
+
const r = new DataView(n.buffer);
|
|
1075
|
+
r.setUint8(0, 126), r.setUint16(1, s);
|
|
1076
|
+
} else {
|
|
1077
|
+
n = new Uint8Array(9);
|
|
1078
|
+
const r = new DataView(n.buffer);
|
|
1079
|
+
r.setUint8(0, 127), r.setBigUint64(1, BigInt(s));
|
|
1080
|
+
}
|
|
1081
|
+
i.data && typeof i.data != "string" && (n[0] |= 128), e.enqueue(n), e.enqueue(t);
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
let Ee;
|
|
1087
|
+
function ee(i) {
|
|
1088
|
+
return i.reduce((e, t) => e + t.length, 0);
|
|
1089
|
+
}
|
|
1090
|
+
function te(i, e) {
|
|
1091
|
+
if (i[0].length === e) { return i.shift(); }
|
|
1092
|
+
const t = new Uint8Array(e);
|
|
1093
|
+
let s = 0;
|
|
1094
|
+
for (let n = 0; n < e; n++) { t[n] = i[0][s++], s === i[0].length && (i.shift(), s = 0); }
|
|
1095
|
+
return i.length && s < i[0].length && (i[0] = i[0].slice(s)), t;
|
|
1096
|
+
}
|
|
1097
|
+
function is(i, e) {
|
|
1098
|
+
Ee || (Ee = new TextDecoder());
|
|
1099
|
+
const t = [];
|
|
1100
|
+
let s = 0, n = -1, r = !1;
|
|
1101
|
+
return new TransformStream({
|
|
1102
|
+
transform(o, a) {
|
|
1103
|
+
for (t.push(o); ;) {
|
|
1104
|
+
if (s === 0) {
|
|
1105
|
+
if (ee(t) < 1) { break; }
|
|
1106
|
+
const u = te(t, 1);
|
|
1107
|
+
r = (u[0] & 128) === 128, n = u[0] & 127, n < 126 ? s = 3 : n === 126 ? s = 1 : s = 2;
|
|
1108
|
+
} else if (s === 1) {
|
|
1109
|
+
if (ee(t) < 2) { break; }
|
|
1110
|
+
const u = te(t, 2);
|
|
1111
|
+
n = new DataView(u.buffer, u.byteOffset, u.length).getUint16(0), s = 3;
|
|
1112
|
+
} else if (s === 2) {
|
|
1113
|
+
if (ee(t) < 8) { break; }
|
|
1114
|
+
const u = te(t, 8), c = new DataView(u.buffer, u.byteOffset, u.length), h = c.getUint32(0);
|
|
1115
|
+
if (h > Math.pow(2, 53 - 32) - 1) {
|
|
1116
|
+
a.enqueue(Oe);
|
|
1117
|
+
break;
|
|
1118
|
+
}
|
|
1119
|
+
n = h * Math.pow(2, 32) + c.getUint32(4), s = 3;
|
|
1120
|
+
} else {
|
|
1121
|
+
if (ee(t) < n) { break; }
|
|
1122
|
+
const u = te(t, n);
|
|
1123
|
+
a.enqueue(Re(r ? u : Ee.decode(u), e)), s = 0;
|
|
1124
|
+
}
|
|
1125
|
+
if (n === 0 || n > i) {
|
|
1126
|
+
a.enqueue(Oe);
|
|
1127
|
+
break;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
const ht = 4;
|
|
1134
|
+
function y(i) {
|
|
1135
|
+
if (i) { return ns(i); }
|
|
1136
|
+
}
|
|
1137
|
+
function ns(i) {
|
|
1138
|
+
for (let e in y.prototype) { i[e] = y.prototype[e]; }
|
|
1139
|
+
return i;
|
|
1140
|
+
}
|
|
1141
|
+
y.prototype.on = y.prototype.addEventListener = function(i, e) {
|
|
1142
|
+
return this._callbacks = this._callbacks || {}, (this._callbacks["$" + i] = this._callbacks["$" + i] || []).push(e), this;
|
|
1143
|
+
};
|
|
1144
|
+
y.prototype.once = function(i, e) {
|
|
1145
|
+
function t() {
|
|
1146
|
+
this.off(i, t), e.apply(this, arguments);
|
|
1147
|
+
}
|
|
1148
|
+
return t.fn = e, this.on(i, t), this;
|
|
1149
|
+
};
|
|
1150
|
+
y.prototype.off = y.prototype.removeListener = y.prototype.removeAllListeners = y.prototype.removeEventListener = function(i, e) {
|
|
1151
|
+
if (this._callbacks = this._callbacks || {}, arguments.length == 0) { return this._callbacks = {}, this; }
|
|
1152
|
+
let t = this._callbacks["$" + i];
|
|
1153
|
+
if (!t) { return this; }
|
|
1154
|
+
if (arguments.length == 1) { return delete this._callbacks["$" + i], this; }
|
|
1155
|
+
for (var s, n = 0; n < t.length; n++) {
|
|
1156
|
+
if (s = t[n], s === e || s.fn === e) {
|
|
1157
|
+
t.splice(n, 1);
|
|
1158
|
+
break;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
return t.length === 0 && delete this._callbacks["$" + i], this;
|
|
1162
|
+
};
|
|
1163
|
+
y.prototype.emit = function(i) {
|
|
1164
|
+
this._callbacks = this._callbacks || {};
|
|
1165
|
+
for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + i], s = 1; s < arguments.length; s++) { e[s - 1] = arguments[s]; }
|
|
1166
|
+
if (t) {
|
|
1167
|
+
t = t.slice(0);
|
|
1168
|
+
for (var s = 0, n = t.length; s < n; ++s) { t[s].apply(this, e); }
|
|
1169
|
+
}
|
|
1170
|
+
return this;
|
|
1171
|
+
};
|
|
1172
|
+
y.prototype.emitReserved = y.prototype.emit;
|
|
1173
|
+
y.prototype.listeners = function(i) {
|
|
1174
|
+
return this._callbacks = this._callbacks || {}, this._callbacks["$" + i] || [];
|
|
1175
|
+
};
|
|
1176
|
+
y.prototype.hasListeners = function(i) {
|
|
1177
|
+
return !!this.listeners(i).length;
|
|
1178
|
+
};
|
|
1179
|
+
const he = (() => typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0))(), k = (() => typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")())(), rs = "arraybuffer";
|
|
1180
|
+
function ct(i, ...e) {
|
|
1181
|
+
return e.reduce((t, s) => (i.hasOwnProperty(s) && (t[s] = i[s]), t), {});
|
|
1182
|
+
}
|
|
1183
|
+
const os = k.setTimeout, as = k.clearTimeout;
|
|
1184
|
+
function ce(i, e) {
|
|
1185
|
+
e.useNativeTimers ? (i.setTimeoutFn = os.bind(k), i.clearTimeoutFn = as.bind(k)) : (i.setTimeoutFn = k.setTimeout.bind(k), i.clearTimeoutFn = k.clearTimeout.bind(k));
|
|
1186
|
+
}
|
|
1187
|
+
const us = 1.33;
|
|
1188
|
+
function hs(i) {
|
|
1189
|
+
return typeof i == "string" ? cs(i) : Math.ceil((i.byteLength || i.size) * us);
|
|
1190
|
+
}
|
|
1191
|
+
function cs(i) {
|
|
1192
|
+
let e = 0, t = 0;
|
|
1193
|
+
for (let s = 0, n = i.length; s < n; s++) { e = i.charCodeAt(s), e < 128 ? t += 1 : e < 2048 ? t += 2 : e < 55296 || e >= 57344 ? t += 3 : (s++, t += 4); }
|
|
1194
|
+
return t;
|
|
1195
|
+
}
|
|
1196
|
+
function lt() {
|
|
1197
|
+
return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
|
|
1198
|
+
}
|
|
1199
|
+
function ls(i) {
|
|
1200
|
+
let e = "";
|
|
1201
|
+
for (let t in i) { i.hasOwnProperty(t) && (e.length && (e += "&"), e += encodeURIComponent(t) + "=" + encodeURIComponent(i[t])); }
|
|
1202
|
+
return e;
|
|
1203
|
+
}
|
|
1204
|
+
function ds(i) {
|
|
1205
|
+
let e = {}, t = i.split("&");
|
|
1206
|
+
for (let s = 0, n = t.length; s < n; s++) {
|
|
1207
|
+
let r = t[s].split("=");
|
|
1208
|
+
e[decodeURIComponent(r[0])] = decodeURIComponent(r[1]);
|
|
1209
|
+
}
|
|
1210
|
+
return e;
|
|
1211
|
+
}
|
|
1212
|
+
class ps extends Error {
|
|
1213
|
+
constructor(e, t, s) {
|
|
1214
|
+
super(e), this.description = t, this.context = s, this.type = "TransportError";
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
class Le extends y {
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Transport abstract constructor.
|
|
1221
|
+
*
|
|
1222
|
+
* @param {Object} opts - options
|
|
1223
|
+
* @protected
|
|
1224
|
+
*/
|
|
1225
|
+
constructor(e) {
|
|
1226
|
+
super(), this.writable = !1, ce(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* Emits an error.
|
|
1231
|
+
*
|
|
1232
|
+
* @param {String} reason
|
|
1233
|
+
* @param description
|
|
1234
|
+
* @param context - the error context
|
|
1235
|
+
* @return {Transport} for chaining
|
|
1236
|
+
* @protected
|
|
1237
|
+
*/
|
|
1238
|
+
onError(e, t, s) {
|
|
1239
|
+
return super.emitReserved("error", new ps(e, t, s)), this;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* Opens the transport.
|
|
1244
|
+
*/
|
|
1245
|
+
open() {
|
|
1246
|
+
return this.readyState = "opening", this.doOpen(), this;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* Closes the transport.
|
|
1251
|
+
*/
|
|
1252
|
+
close() {
|
|
1253
|
+
return (this.readyState === "opening" || this.readyState === "open") && (this.doClose(), this.onClose()), this;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Sends multiple packets.
|
|
1258
|
+
*
|
|
1259
|
+
* @param {Array} packets
|
|
1260
|
+
*/
|
|
1261
|
+
send(e) {
|
|
1262
|
+
this.readyState === "open" && this.write(e);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* Called upon open
|
|
1267
|
+
*
|
|
1268
|
+
* @protected
|
|
1269
|
+
*/
|
|
1270
|
+
onOpen() {
|
|
1271
|
+
this.readyState = "open", this.writable = !0, super.emitReserved("open");
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* Called with data.
|
|
1276
|
+
*
|
|
1277
|
+
* @param {String} data
|
|
1278
|
+
* @protected
|
|
1279
|
+
*/
|
|
1280
|
+
onData(e) {
|
|
1281
|
+
const t = Re(e, this.socket.binaryType);
|
|
1282
|
+
this.onPacket(t);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
/**
|
|
1286
|
+
* Called with a decoded packet.
|
|
1287
|
+
*
|
|
1288
|
+
* @protected
|
|
1289
|
+
*/
|
|
1290
|
+
onPacket(e) {
|
|
1291
|
+
super.emitReserved("packet", e);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Called upon close.
|
|
1296
|
+
*
|
|
1297
|
+
* @protected
|
|
1298
|
+
*/
|
|
1299
|
+
onClose(e) {
|
|
1300
|
+
this.readyState = "closed", super.emitReserved("close", e);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Pauses the transport, in order not to lose packets during an upgrade.
|
|
1305
|
+
*
|
|
1306
|
+
* @param onPause
|
|
1307
|
+
*/
|
|
1308
|
+
pause(e) {
|
|
1309
|
+
}
|
|
1310
|
+
createUri(e, t = {}) {
|
|
1311
|
+
return e + "://" + this._hostname() + this._port() + this.opts.path + this._query(t);
|
|
1312
|
+
}
|
|
1313
|
+
_hostname() {
|
|
1314
|
+
const e = this.opts.hostname;
|
|
1315
|
+
return e.indexOf(":") === -1 ? e : "[" + e + "]";
|
|
1316
|
+
}
|
|
1317
|
+
_port() {
|
|
1318
|
+
return this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
|
|
1319
|
+
}
|
|
1320
|
+
_query(e) {
|
|
1321
|
+
const t = ls(e);
|
|
1322
|
+
return t.length ? "?" + t : "";
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
class fs extends Le {
|
|
1326
|
+
constructor() {
|
|
1327
|
+
super(...arguments), this._polling = !1;
|
|
1328
|
+
}
|
|
1329
|
+
get name() {
|
|
1330
|
+
return "polling";
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Opens the socket (triggers polling). We write a PING message to determine
|
|
1335
|
+
* when the transport is open.
|
|
1336
|
+
*
|
|
1337
|
+
* @protected
|
|
1338
|
+
*/
|
|
1339
|
+
doOpen() {
|
|
1340
|
+
this._poll();
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* Pauses polling.
|
|
1345
|
+
*
|
|
1346
|
+
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
|
1347
|
+
* @package
|
|
1348
|
+
*/
|
|
1349
|
+
pause(e) {
|
|
1350
|
+
this.readyState = "pausing";
|
|
1351
|
+
const t = () => {
|
|
1352
|
+
this.readyState = "paused", e();
|
|
1353
|
+
};
|
|
1354
|
+
if (this._polling || !this.writable) {
|
|
1355
|
+
let s = 0;
|
|
1356
|
+
this._polling && (s++, this.once("pollComplete", function() {
|
|
1357
|
+
--s || t();
|
|
1358
|
+
})), this.writable || (s++, this.once("drain", function() {
|
|
1359
|
+
--s || t();
|
|
1360
|
+
}));
|
|
1361
|
+
} else { t(); }
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
/**
|
|
1365
|
+
* Starts polling cycle.
|
|
1366
|
+
*
|
|
1367
|
+
* @private
|
|
1368
|
+
*/
|
|
1369
|
+
_poll() {
|
|
1370
|
+
this._polling = !0, this.doPoll(), this.emitReserved("poll");
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* Overloads onData to detect payloads.
|
|
1375
|
+
*
|
|
1376
|
+
* @protected
|
|
1377
|
+
*/
|
|
1378
|
+
onData(e) {
|
|
1379
|
+
const t = (s) => {
|
|
1380
|
+
if (this.readyState === "opening" && s.type === "open" && this.onOpen(), s.type === "close") { return this.onClose({ description: "transport closed by the server" }), !1; }
|
|
1381
|
+
this.onPacket(s);
|
|
1382
|
+
};
|
|
1383
|
+
ts(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* For polling, send a close packet.
|
|
1388
|
+
*
|
|
1389
|
+
* @protected
|
|
1390
|
+
*/
|
|
1391
|
+
doClose() {
|
|
1392
|
+
const e = () => {
|
|
1393
|
+
this.write([{ type: "close" }]);
|
|
1394
|
+
};
|
|
1395
|
+
this.readyState === "open" ? e() : this.once("open", e);
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
/**
|
|
1399
|
+
* Writes a packets payload.
|
|
1400
|
+
*
|
|
1401
|
+
* @param {Array} packets - data packets
|
|
1402
|
+
* @protected
|
|
1403
|
+
*/
|
|
1404
|
+
write(e) {
|
|
1405
|
+
this.writable = !1, es(e, (t) => {
|
|
1406
|
+
this.doWrite(t, () => {
|
|
1407
|
+
this.writable = !0, this.emitReserved("drain");
|
|
1408
|
+
});
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
/**
|
|
1413
|
+
* Generates uri for connection.
|
|
1414
|
+
*
|
|
1415
|
+
* @private
|
|
1416
|
+
*/
|
|
1417
|
+
uri() {
|
|
1418
|
+
const e = this.opts.secure ? "https" : "http", t = this.query || {};
|
|
1419
|
+
return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] = lt()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
let dt = !1;
|
|
1423
|
+
try {
|
|
1424
|
+
dt = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
|
|
1425
|
+
} catch {
|
|
1426
|
+
}
|
|
1427
|
+
const gs = dt;
|
|
1428
|
+
function ms() {
|
|
1429
|
+
}
|
|
1430
|
+
class ys extends fs {
|
|
1431
|
+
|
|
1432
|
+
/**
|
|
1433
|
+
* XHR Polling constructor.
|
|
1434
|
+
*
|
|
1435
|
+
* @param {Object} opts
|
|
1436
|
+
* @package
|
|
1437
|
+
*/
|
|
1438
|
+
constructor(e) {
|
|
1439
|
+
if (super(e), typeof location < "u") {
|
|
1440
|
+
const t = location.protocol === "https:";
|
|
1441
|
+
let s = location.port;
|
|
1442
|
+
s || (s = t ? "443" : "80"), this.xd = typeof location < "u" && e.hostname !== location.hostname || s !== e.port;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* Sends data.
|
|
1448
|
+
*
|
|
1449
|
+
* @param {String} data - data to send.
|
|
1450
|
+
* @param {Function} fn - called upon flush.
|
|
1451
|
+
* @private
|
|
1452
|
+
*/
|
|
1453
|
+
doWrite(e, t) {
|
|
1454
|
+
const s = this.request({
|
|
1455
|
+
method: "POST",
|
|
1456
|
+
data: e
|
|
1457
|
+
});
|
|
1458
|
+
s.on("success", t), s.on("error", (n, r) => {
|
|
1459
|
+
this.onError("xhr post error", n, r);
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
/**
|
|
1464
|
+
* Starts a poll cycle.
|
|
1465
|
+
*
|
|
1466
|
+
* @private
|
|
1467
|
+
*/
|
|
1468
|
+
doPoll() {
|
|
1469
|
+
const e = this.request();
|
|
1470
|
+
e.on("data", this.onData.bind(this)), e.on("error", (t, s) => {
|
|
1471
|
+
this.onError("xhr poll error", t, s);
|
|
1472
|
+
}), this.pollXhr = e;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
class q extends y {
|
|
1476
|
+
|
|
1477
|
+
/**
|
|
1478
|
+
* Request constructor
|
|
1479
|
+
*
|
|
1480
|
+
* @param {Object} options
|
|
1481
|
+
* @package
|
|
1482
|
+
*/
|
|
1483
|
+
constructor(e, t, s) {
|
|
1484
|
+
super(), this.createRequest = e, ce(this, s), this._opts = s, this._method = s.method || "GET", this._uri = t, this._data = s.data !== void 0 ? s.data : null, this._create();
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
/**
|
|
1488
|
+
* Creates the XHR object and sends the request.
|
|
1489
|
+
*
|
|
1490
|
+
* @private
|
|
1491
|
+
*/
|
|
1492
|
+
_create() {
|
|
1493
|
+
let e;
|
|
1494
|
+
const t = ct(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
1495
|
+
t.xdomain = !!this._opts.xd;
|
|
1496
|
+
const s = this._xhr = this.createRequest(t);
|
|
1497
|
+
try {
|
|
1498
|
+
s.open(this._method, this._uri, !0);
|
|
1499
|
+
try {
|
|
1500
|
+
if (this._opts.extraHeaders) {
|
|
1501
|
+
s.setDisableHeaderCheck && s.setDisableHeaderCheck(!0);
|
|
1502
|
+
for (let n in this._opts.extraHeaders) { this._opts.extraHeaders.hasOwnProperty(n) && s.setRequestHeader(n, this._opts.extraHeaders[n]); }
|
|
1503
|
+
}
|
|
1504
|
+
} catch {
|
|
1505
|
+
}
|
|
1506
|
+
if (this._method === "POST") {
|
|
1507
|
+
try {
|
|
1508
|
+
s.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
|
1509
|
+
} catch {
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
try {
|
|
1513
|
+
s.setRequestHeader("Accept", "*/*");
|
|
1514
|
+
} catch {
|
|
1515
|
+
}
|
|
1516
|
+
(e = this._opts.cookieJar) === null || e === void 0 || e.addCookies(s), "withCredentials" in s && (s.withCredentials = this._opts.withCredentials), this._opts.requestTimeout && (s.timeout = this._opts.requestTimeout), s.onreadystatechange = () => {
|
|
1517
|
+
let n;
|
|
1518
|
+
s.readyState === 3 && ((n = this._opts.cookieJar) === null || n === void 0 || n.parseCookies(
|
|
1519
|
+
// @ts-ignore
|
|
1520
|
+
s.getResponseHeader("set-cookie")
|
|
1521
|
+
)), s.readyState === 4 && (s.status === 200 || s.status === 1223 ? this._onLoad() : this.setTimeoutFn(() => {
|
|
1522
|
+
this._onError(typeof s.status == "number" ? s.status : 0);
|
|
1523
|
+
}, 0));
|
|
1524
|
+
}, s.send(this._data);
|
|
1525
|
+
} catch (n) {
|
|
1526
|
+
this.setTimeoutFn(() => {
|
|
1527
|
+
this._onError(n);
|
|
1528
|
+
}, 0);
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1531
|
+
typeof document < "u" && (this._index = q.requestsCount++, q.requests[this._index] = this);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Called upon error.
|
|
1536
|
+
*
|
|
1537
|
+
* @private
|
|
1538
|
+
*/
|
|
1539
|
+
_onError(e) {
|
|
1540
|
+
this.emitReserved("error", e, this._xhr), this._cleanup(!0);
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
/**
|
|
1544
|
+
* Cleans up house.
|
|
1545
|
+
*
|
|
1546
|
+
* @private
|
|
1547
|
+
*/
|
|
1548
|
+
_cleanup(e) {
|
|
1549
|
+
if (!(typeof this._xhr > "u" || this._xhr === null)) {
|
|
1550
|
+
if (this._xhr.onreadystatechange = ms, e) {
|
|
1551
|
+
try {
|
|
1552
|
+
this._xhr.abort();
|
|
1553
|
+
} catch {
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
typeof document < "u" && delete q.requests[this._index], this._xhr = null;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
/**
|
|
1561
|
+
* Called upon load.
|
|
1562
|
+
*
|
|
1563
|
+
* @private
|
|
1564
|
+
*/
|
|
1565
|
+
_onLoad() {
|
|
1566
|
+
const e = this._xhr.responseText;
|
|
1567
|
+
e !== null && (this.emitReserved("data", e), this.emitReserved("success"), this._cleanup());
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
/**
|
|
1571
|
+
* Aborts the request.
|
|
1572
|
+
*
|
|
1573
|
+
* @package
|
|
1574
|
+
*/
|
|
1575
|
+
abort() {
|
|
1576
|
+
this._cleanup();
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
q.requestsCount = 0;
|
|
1580
|
+
q.requests = {};
|
|
1581
|
+
if (typeof document < "u") {
|
|
1582
|
+
if (typeof attachEvent == "function") { attachEvent("onunload", Ze); } else if (typeof addEventListener == "function") {
|
|
1583
|
+
const i = "onpagehide" in k ? "pagehide" : "unload";
|
|
1584
|
+
addEventListener(i, Ze, !1);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
function Ze() {
|
|
1588
|
+
for (let i in q.requests) { q.requests.hasOwnProperty(i) && q.requests[i].abort(); }
|
|
1589
|
+
}
|
|
1590
|
+
const ws = (function() {
|
|
1591
|
+
const i = pt({
|
|
1592
|
+
xdomain: !1
|
|
1593
|
+
});
|
|
1594
|
+
return i && i.responseType !== null;
|
|
1595
|
+
})();
|
|
1596
|
+
class bs extends ys {
|
|
1597
|
+
constructor(e) {
|
|
1598
|
+
super(e);
|
|
1599
|
+
const t = e && e.forceBase64;
|
|
1600
|
+
this.supportsBinary = ws && !t;
|
|
1601
|
+
}
|
|
1602
|
+
request(e = {}) {
|
|
1603
|
+
return Object.assign(e, { xd: this.xd }, this.opts), new q(pt, this.uri(), e);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
function pt(i) {
|
|
1607
|
+
const e = i.xdomain;
|
|
1608
|
+
try {
|
|
1609
|
+
if (typeof XMLHttpRequest < "u" && (!e || gs)) { return new XMLHttpRequest(); }
|
|
1610
|
+
} catch {
|
|
1611
|
+
}
|
|
1612
|
+
if (!e) {
|
|
1613
|
+
try {
|
|
1614
|
+
return new k[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
1615
|
+
} catch {
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
const ft = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
|
|
1620
|
+
class Ss extends Le {
|
|
1621
|
+
get name() {
|
|
1622
|
+
return "websocket";
|
|
1623
|
+
}
|
|
1624
|
+
doOpen() {
|
|
1625
|
+
const e = this.uri(), t = this.opts.protocols, s = ft ? {} : ct(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
|
1626
|
+
this.opts.extraHeaders && (s.headers = this.opts.extraHeaders);
|
|
1627
|
+
try {
|
|
1628
|
+
this.ws = this.createSocket(e, t, s);
|
|
1629
|
+
} catch (n) {
|
|
1630
|
+
return this.emitReserved("error", n);
|
|
1631
|
+
}
|
|
1632
|
+
this.ws.binaryType = this.socket.binaryType, this.addEventListeners();
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
/**
|
|
1636
|
+
* Adds event listeners to the socket
|
|
1637
|
+
*
|
|
1638
|
+
* @private
|
|
1639
|
+
*/
|
|
1640
|
+
addEventListeners() {
|
|
1641
|
+
this.ws.onopen = () => {
|
|
1642
|
+
this.opts.autoUnref && this.ws._socket.unref(), this.onOpen();
|
|
1643
|
+
}, this.ws.onclose = (e) => this.onClose({
|
|
1644
|
+
description: "websocket connection closed",
|
|
1645
|
+
context: e
|
|
1646
|
+
}), this.ws.onmessage = (e) => this.onData(e.data), this.ws.onerror = (e) => this.onError("websocket error", e);
|
|
1647
|
+
}
|
|
1648
|
+
write(e) {
|
|
1649
|
+
this.writable = !1;
|
|
1650
|
+
for (let t = 0; t < e.length; t++) {
|
|
1651
|
+
const s = e[t], n = t === e.length - 1;
|
|
1652
|
+
je(s, this.supportsBinary, (r) => {
|
|
1653
|
+
try {
|
|
1654
|
+
this.doWrite(s, r);
|
|
1655
|
+
} catch {
|
|
1656
|
+
}
|
|
1657
|
+
n && he(() => {
|
|
1658
|
+
this.writable = !0, this.emitReserved("drain");
|
|
1659
|
+
}, this.setTimeoutFn);
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
doClose() {
|
|
1664
|
+
typeof this.ws < "u" && (this.ws.onerror = () => {
|
|
1665
|
+
}, this.ws.close(), this.ws = null);
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/**
|
|
1669
|
+
* Generates uri for connection.
|
|
1670
|
+
*
|
|
1671
|
+
* @private
|
|
1672
|
+
*/
|
|
1673
|
+
uri() {
|
|
1674
|
+
const e = this.opts.secure ? "wss" : "ws", t = this.query || {};
|
|
1675
|
+
return this.opts.timestampRequests && (t[this.opts.timestampParam] = lt()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
const ke = k.WebSocket || k.MozWebSocket;
|
|
1679
|
+
class Cs extends Ss {
|
|
1680
|
+
createSocket(e, t, s) {
|
|
1681
|
+
return ft ? new ke(e, t, s) : t ? new ke(e, t) : new ke(e);
|
|
1682
|
+
}
|
|
1683
|
+
doWrite(e, t) {
|
|
1684
|
+
this.ws.send(t);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
class Es extends Le {
|
|
1688
|
+
get name() {
|
|
1689
|
+
return "webtransport";
|
|
1690
|
+
}
|
|
1691
|
+
doOpen() {
|
|
1692
|
+
try {
|
|
1693
|
+
this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
|
|
1694
|
+
} catch (e) {
|
|
1695
|
+
return this.emitReserved("error", e);
|
|
1696
|
+
}
|
|
1697
|
+
this._transport.closed.then(() => {
|
|
1698
|
+
this.onClose();
|
|
1699
|
+
}).catch((e) => {
|
|
1700
|
+
this.onError("webtransport error", e);
|
|
1701
|
+
}), this._transport.ready.then(() => {
|
|
1702
|
+
this._transport.createBidirectionalStream().then((e) => {
|
|
1703
|
+
const t = is(Number.MAX_SAFE_INTEGER, this.socket.binaryType), s = e.readable.pipeThrough(t).getReader(), n = ss();
|
|
1704
|
+
n.readable.pipeTo(e.writable), this._writer = n.writable.getWriter();
|
|
1705
|
+
const r = () => {
|
|
1706
|
+
s.read().then(({ done: a, value: u }) => {
|
|
1707
|
+
a || (this.onPacket(u), r());
|
|
1708
|
+
}).catch((a) => {
|
|
1709
|
+
});
|
|
1710
|
+
};
|
|
1711
|
+
r();
|
|
1712
|
+
const o = { type: "open" };
|
|
1713
|
+
this.query.sid && (o.data = `{"sid":"${this.query.sid}"}`), this._writer.write(o).then(() => this.onOpen());
|
|
1714
|
+
});
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
write(e) {
|
|
1718
|
+
this.writable = !1;
|
|
1719
|
+
for (let t = 0; t < e.length; t++) {
|
|
1720
|
+
const s = e[t], n = t === e.length - 1;
|
|
1721
|
+
this._writer.write(s).then(() => {
|
|
1722
|
+
n && he(() => {
|
|
1723
|
+
this.writable = !0, this.emitReserved("drain");
|
|
1724
|
+
}, this.setTimeoutFn);
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
doClose() {
|
|
1729
|
+
let e;
|
|
1730
|
+
(e = this._transport) === null || e === void 0 || e.close();
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
const ks = {
|
|
1734
|
+
websocket: Cs,
|
|
1735
|
+
webtransport: Es,
|
|
1736
|
+
polling: bs
|
|
1737
|
+
}, vs = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, _s = [
|
|
1738
|
+
"source",
|
|
1739
|
+
"protocol",
|
|
1740
|
+
"authority",
|
|
1741
|
+
"userInfo",
|
|
1742
|
+
"user",
|
|
1743
|
+
"password",
|
|
1744
|
+
"host",
|
|
1745
|
+
"port",
|
|
1746
|
+
"relative",
|
|
1747
|
+
"path",
|
|
1748
|
+
"directory",
|
|
1749
|
+
"file",
|
|
1750
|
+
"query",
|
|
1751
|
+
"anchor"
|
|
1752
|
+
];
|
|
1753
|
+
function Ne(i) {
|
|
1754
|
+
if (i.length > 8e3) { throw "URI too long"; }
|
|
1755
|
+
const e = i, t = i.indexOf("["), s = i.indexOf("]");
|
|
1756
|
+
t != -1 && s != -1 && (i = i.substring(0, t) + i.substring(t, s).replace(/:/g, ";") + i.substring(s, i.length));
|
|
1757
|
+
let n = vs.exec(i || ""), r = {}, o = 14;
|
|
1758
|
+
for (; o--;) { r[_s[o]] = n[o] || ""; }
|
|
1759
|
+
return t != -1 && s != -1 && (r.source = e, r.host = r.host.substring(1, r.host.length - 1).replace(/;/g, ":"), r.authority = r.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), r.ipv6uri = !0), r.pathNames = qs(r, r.path), r.queryKey = Os(r, r.query), r;
|
|
1760
|
+
}
|
|
1761
|
+
function qs(i, e) {
|
|
1762
|
+
const t = /\/{2,9}/g, s = e.replace(t, "/").split("/");
|
|
1763
|
+
return (e.slice(0, 1) == "/" || e.length === 0) && s.splice(0, 1), e.slice(-1) == "/" && s.splice(s.length - 1, 1), s;
|
|
1764
|
+
}
|
|
1765
|
+
function Os(i, e) {
|
|
1766
|
+
const t = {};
|
|
1767
|
+
return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(s, n, r) {
|
|
1768
|
+
n && (t[n] = r);
|
|
1769
|
+
}), t;
|
|
1770
|
+
}
|
|
1771
|
+
const Te = typeof addEventListener == "function" && typeof removeEventListener == "function", ie = [];
|
|
1772
|
+
Te && addEventListener("offline", () => {
|
|
1773
|
+
ie.forEach((i) => i());
|
|
1774
|
+
}, !1);
|
|
1775
|
+
class A extends y {
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* Socket constructor.
|
|
1779
|
+
*
|
|
1780
|
+
* @param {String|Object} uri - uri or options
|
|
1781
|
+
* @param {Object} opts - options
|
|
1782
|
+
*/
|
|
1783
|
+
constructor(e, t) {
|
|
1784
|
+
if (super(), this.binaryType = rs, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = 1 / 0, e && typeof e == "object" && (t = e, e = null), e) {
|
|
1785
|
+
const s = Ne(e);
|
|
1786
|
+
t.hostname = s.host, t.secure = s.protocol === "https" || s.protocol === "wss", t.port = s.port, s.query && (t.query = s.query);
|
|
1787
|
+
} else { t.host && (t.hostname = Ne(t.host).host); }
|
|
1788
|
+
ce(this, t), this.secure = t.secure != null ? t.secure : typeof location < "u" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location < "u" ? location.hostname : "localhost"), this.port = t.port || (typeof location < "u" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((s) => {
|
|
1789
|
+
const n = s.prototype.name;
|
|
1790
|
+
this.transports.push(n), this._transportsByName[n] = s;
|
|
1791
|
+
}), this.opts = Object.assign({
|
|
1792
|
+
path: "/engine.io",
|
|
1793
|
+
agent: !1,
|
|
1794
|
+
withCredentials: !1,
|
|
1795
|
+
upgrade: !0,
|
|
1796
|
+
timestampParam: "t",
|
|
1797
|
+
rememberUpgrade: !1,
|
|
1798
|
+
addTrailingSlash: !0,
|
|
1799
|
+
rejectUnauthorized: !0,
|
|
1800
|
+
perMessageDeflate: {
|
|
1801
|
+
threshold: 1024
|
|
1802
|
+
},
|
|
1803
|
+
transportOptions: {},
|
|
1804
|
+
closeOnBeforeunload: !1
|
|
1805
|
+
}, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = ds(this.opts.query)), Te && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
|
|
1806
|
+
this.transport && (this.transport.removeAllListeners(), this.transport.close());
|
|
1807
|
+
}, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
|
|
1808
|
+
this._onClose("transport close", {
|
|
1809
|
+
description: "network connection lost"
|
|
1810
|
+
});
|
|
1811
|
+
}, ie.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
/**
|
|
1815
|
+
* Creates transport of the given type.
|
|
1816
|
+
*
|
|
1817
|
+
* @param {String} name - transport name
|
|
1818
|
+
* @return {Transport}
|
|
1819
|
+
* @private
|
|
1820
|
+
*/
|
|
1821
|
+
createTransport(e) {
|
|
1822
|
+
const t = Object.assign({}, this.opts.query);
|
|
1823
|
+
t.EIO = ht, t.transport = e, this.id && (t.sid = this.id);
|
|
1824
|
+
const s = Object.assign({}, this.opts, {
|
|
1825
|
+
query: t,
|
|
1826
|
+
socket: this,
|
|
1827
|
+
hostname: this.hostname,
|
|
1828
|
+
secure: this.secure,
|
|
1829
|
+
port: this.port
|
|
1830
|
+
}, this.opts.transportOptions[e]);
|
|
1831
|
+
return new this._transportsByName[e](s);
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
/**
|
|
1835
|
+
* Initializes transport to use and starts probe.
|
|
1836
|
+
*
|
|
1837
|
+
* @private
|
|
1838
|
+
*/
|
|
1839
|
+
_open() {
|
|
1840
|
+
if (this.transports.length === 0) {
|
|
1841
|
+
this.setTimeoutFn(() => {
|
|
1842
|
+
this.emitReserved("error", "No transports available");
|
|
1843
|
+
}, 0);
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
const e = this.opts.rememberUpgrade && A.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
|
|
1847
|
+
this.readyState = "opening";
|
|
1848
|
+
const t = this.createTransport(e);
|
|
1849
|
+
t.open(), this.setTransport(t);
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
/**
|
|
1853
|
+
* Sets the current transport. Disables the existing one (if any).
|
|
1854
|
+
*
|
|
1855
|
+
* @private
|
|
1856
|
+
*/
|
|
1857
|
+
setTransport(e) {
|
|
1858
|
+
this.transport && this.transport.removeAllListeners(), this.transport = e, e.on("drain", this._onDrain.bind(this)).on("packet", this._onPacket.bind(this)).on("error", this._onError.bind(this)).on("close", (t) => this._onClose("transport close", t));
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
/**
|
|
1862
|
+
* Called when connection is deemed open.
|
|
1863
|
+
*
|
|
1864
|
+
* @private
|
|
1865
|
+
*/
|
|
1866
|
+
onOpen() {
|
|
1867
|
+
this.readyState = "open", A.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
/**
|
|
1871
|
+
* Handles a packet.
|
|
1872
|
+
*
|
|
1873
|
+
* @private
|
|
1874
|
+
*/
|
|
1875
|
+
_onPacket(e) {
|
|
1876
|
+
if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
|
|
1877
|
+
switch (this.emitReserved("packet", e), this.emitReserved("heartbeat"), e.type) {
|
|
1878
|
+
case "open":
|
|
1879
|
+
this.onHandshake(JSON.parse(e.data));
|
|
1880
|
+
break;
|
|
1881
|
+
case "ping":
|
|
1882
|
+
this._sendPacket("pong"), this.emitReserved("ping"), this.emitReserved("pong"), this._resetPingTimeout();
|
|
1883
|
+
break;
|
|
1884
|
+
case "error":
|
|
1885
|
+
const t = new Error("server error");
|
|
1886
|
+
t.code = e.data, this._onError(t);
|
|
1887
|
+
break;
|
|
1888
|
+
case "message":
|
|
1889
|
+
this.emitReserved("data", e.data), this.emitReserved("message", e.data);
|
|
1890
|
+
break;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
/**
|
|
1896
|
+
* Called upon handshake completion.
|
|
1897
|
+
*
|
|
1898
|
+
* @param {Object} data - handshake obj
|
|
1899
|
+
* @private
|
|
1900
|
+
*/
|
|
1901
|
+
onHandshake(e) {
|
|
1902
|
+
this.emitReserved("handshake", e), this.id = e.sid, this.transport.query.sid = e.sid, this._pingInterval = e.pingInterval, this._pingTimeout = e.pingTimeout, this._maxPayload = e.maxPayload, this.onOpen(), this.readyState !== "closed" && this._resetPingTimeout();
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
/**
|
|
1906
|
+
* Sets and resets ping timeout timer based on server pings.
|
|
1907
|
+
*
|
|
1908
|
+
* @private
|
|
1909
|
+
*/
|
|
1910
|
+
_resetPingTimeout() {
|
|
1911
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
1912
|
+
const e = this._pingInterval + this._pingTimeout;
|
|
1913
|
+
this._pingTimeoutTime = Date.now() + e, this._pingTimeoutTimer = this.setTimeoutFn(() => {
|
|
1914
|
+
this._onClose("ping timeout");
|
|
1915
|
+
}, e), this.opts.autoUnref && this._pingTimeoutTimer.unref();
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
/**
|
|
1919
|
+
* Called on `drain` event
|
|
1920
|
+
*
|
|
1921
|
+
* @private
|
|
1922
|
+
*/
|
|
1923
|
+
_onDrain() {
|
|
1924
|
+
this.writeBuffer.splice(0, this._prevBufferLen), this._prevBufferLen = 0, this.writeBuffer.length === 0 ? this.emitReserved("drain") : this.flush();
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
/**
|
|
1928
|
+
* Flush write buffers.
|
|
1929
|
+
*
|
|
1930
|
+
* @private
|
|
1931
|
+
*/
|
|
1932
|
+
flush() {
|
|
1933
|
+
if (this.readyState !== "closed" && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
|
|
1934
|
+
const e = this._getWritablePackets();
|
|
1935
|
+
this.transport.send(e), this._prevBufferLen = e.length, this.emitReserved("flush");
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
/**
|
|
1940
|
+
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
1941
|
+
* long-polling)
|
|
1942
|
+
*
|
|
1943
|
+
* @private
|
|
1944
|
+
*/
|
|
1945
|
+
_getWritablePackets() {
|
|
1946
|
+
if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1)) { return this.writeBuffer; }
|
|
1947
|
+
let t = 1;
|
|
1948
|
+
for (let s = 0; s < this.writeBuffer.length; s++) {
|
|
1949
|
+
const n = this.writeBuffer[s].data;
|
|
1950
|
+
if (n && (t += hs(n)), s > 0 && t > this._maxPayload) { return this.writeBuffer.slice(0, s); }
|
|
1951
|
+
t += 2;
|
|
1952
|
+
}
|
|
1953
|
+
return this.writeBuffer;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
/**
|
|
1957
|
+
* Checks whether the heartbeat timer has expired but the socket has not yet been notified.
|
|
1958
|
+
*
|
|
1959
|
+
* Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
|
|
1960
|
+
* `write()` method then the message would not be buffered by the Socket.IO client.
|
|
1961
|
+
*
|
|
1962
|
+
* @return {boolean}
|
|
1963
|
+
* @private
|
|
1964
|
+
*/
|
|
1965
|
+
/* private */
|
|
1966
|
+
_hasPingExpired() {
|
|
1967
|
+
if (!this._pingTimeoutTime) { return !0; }
|
|
1968
|
+
const e = Date.now() > this._pingTimeoutTime;
|
|
1969
|
+
return e && (this._pingTimeoutTime = 0, he(() => {
|
|
1970
|
+
this._onClose("ping timeout");
|
|
1971
|
+
}, this.setTimeoutFn)), e;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
/**
|
|
1975
|
+
* Sends a message.
|
|
1976
|
+
*
|
|
1977
|
+
* @param {String} msg - message.
|
|
1978
|
+
* @param {Object} options.
|
|
1979
|
+
* @param {Function} fn - callback function.
|
|
1980
|
+
* @return {Socket} for chaining.
|
|
1981
|
+
*/
|
|
1982
|
+
write(e, t, s) {
|
|
1983
|
+
return this._sendPacket("message", e, t, s), this;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
/**
|
|
1987
|
+
* Sends a message. Alias of {@link Socket#write}.
|
|
1988
|
+
*
|
|
1989
|
+
* @param {String} msg - message.
|
|
1990
|
+
* @param {Object} options.
|
|
1991
|
+
* @param {Function} fn - callback function.
|
|
1992
|
+
* @return {Socket} for chaining.
|
|
1993
|
+
*/
|
|
1994
|
+
send(e, t, s) {
|
|
1995
|
+
return this._sendPacket("message", e, t, s), this;
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* Sends a packet.
|
|
2000
|
+
*
|
|
2001
|
+
* @param {String} type - packet type.
|
|
2002
|
+
* @param {String} data.
|
|
2003
|
+
* @param {Object} options.
|
|
2004
|
+
* @param {Function} fn - callback function.
|
|
2005
|
+
* @private
|
|
2006
|
+
*/
|
|
2007
|
+
_sendPacket(e, t, s, n) {
|
|
2008
|
+
if (typeof t == "function" && (n = t, t = void 0), typeof s == "function" && (n = s, s = null), this.readyState === "closing" || this.readyState === "closed") { return; }
|
|
2009
|
+
s = s || {}, s.compress = s.compress !== !1;
|
|
2010
|
+
const r = {
|
|
2011
|
+
type: e,
|
|
2012
|
+
data: t,
|
|
2013
|
+
options: s
|
|
2014
|
+
};
|
|
2015
|
+
this.emitReserved("packetCreate", r), this.writeBuffer.push(r), n && this.once("flush", n), this.flush();
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
/**
|
|
2019
|
+
* Closes the connection.
|
|
2020
|
+
*/
|
|
2021
|
+
close() {
|
|
2022
|
+
const e = () => {
|
|
2023
|
+
this._onClose("forced close"), this.transport.close();
|
|
2024
|
+
}, t = () => {
|
|
2025
|
+
this.off("upgrade", t), this.off("upgradeError", t), e();
|
|
2026
|
+
}, s = () => {
|
|
2027
|
+
this.once("upgrade", t), this.once("upgradeError", t);
|
|
2028
|
+
};
|
|
2029
|
+
return (this.readyState === "opening" || this.readyState === "open") && (this.readyState = "closing", this.writeBuffer.length ? this.once("drain", () => {
|
|
2030
|
+
this.upgrading ? s() : e();
|
|
2031
|
+
}) : this.upgrading ? s() : e()), this;
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
/**
|
|
2035
|
+
* Called upon transport error
|
|
2036
|
+
*
|
|
2037
|
+
* @private
|
|
2038
|
+
*/
|
|
2039
|
+
_onError(e) {
|
|
2040
|
+
if (A.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") { return this.transports.shift(), this._open(); }
|
|
2041
|
+
this.emitReserved("error", e), this._onClose("transport error", e);
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
/**
|
|
2045
|
+
* Called upon transport close.
|
|
2046
|
+
*
|
|
2047
|
+
* @private
|
|
2048
|
+
*/
|
|
2049
|
+
_onClose(e, t) {
|
|
2050
|
+
if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
|
|
2051
|
+
if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), Te && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
|
|
2052
|
+
const s = ie.indexOf(this._offlineEventListener);
|
|
2053
|
+
s !== -1 && ie.splice(s, 1);
|
|
2054
|
+
}
|
|
2055
|
+
this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
A.protocol = ht;
|
|
2060
|
+
class Ns extends A {
|
|
2061
|
+
constructor() {
|
|
2062
|
+
super(...arguments), this._upgrades = [];
|
|
2063
|
+
}
|
|
2064
|
+
onOpen() {
|
|
2065
|
+
if (super.onOpen(), this.readyState === "open" && this.opts.upgrade) {
|
|
2066
|
+
for (let e = 0; e < this._upgrades.length; e++) { this._probe(this._upgrades[e]); }
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
/**
|
|
2071
|
+
* Probes a transport.
|
|
2072
|
+
*
|
|
2073
|
+
* @param {String} name - transport name
|
|
2074
|
+
* @private
|
|
2075
|
+
*/
|
|
2076
|
+
_probe(e) {
|
|
2077
|
+
let t = this.createTransport(e), s = !1;
|
|
2078
|
+
A.priorWebsocketSuccess = !1;
|
|
2079
|
+
const n = () => {
|
|
2080
|
+
s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (l) => {
|
|
2081
|
+
if (!s) {
|
|
2082
|
+
if (l.type === "pong" && l.data === "probe") {
|
|
2083
|
+
if (this.upgrading = !0, this.emitReserved("upgrading", t), !t) { return; }
|
|
2084
|
+
A.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
|
|
2085
|
+
s || this.readyState !== "closed" && (h(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
|
|
2086
|
+
});
|
|
2087
|
+
} else {
|
|
2088
|
+
const m = new Error("probe error");
|
|
2089
|
+
m.transport = t.name, this.emitReserved("upgradeError", m);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}));
|
|
2093
|
+
};
|
|
2094
|
+
function r() {
|
|
2095
|
+
s || (s = !0, h(), t.close(), t = null);
|
|
2096
|
+
}
|
|
2097
|
+
const o = (l) => {
|
|
2098
|
+
const m = new Error("probe error: " + l);
|
|
2099
|
+
m.transport = t.name, r(), this.emitReserved("upgradeError", m);
|
|
2100
|
+
};
|
|
2101
|
+
function a() {
|
|
2102
|
+
o("transport closed");
|
|
2103
|
+
}
|
|
2104
|
+
function u() {
|
|
2105
|
+
o("socket closed");
|
|
2106
|
+
}
|
|
2107
|
+
function c(l) {
|
|
2108
|
+
t && l.name !== t.name && r();
|
|
2109
|
+
}
|
|
2110
|
+
const h = () => {
|
|
2111
|
+
t.removeListener("open", n), t.removeListener("error", o), t.removeListener("close", a), this.off("close", u), this.off("upgrading", c);
|
|
2112
|
+
};
|
|
2113
|
+
t.once("open", n), t.once("error", o), t.once("close", a), this.once("close", u), this.once("upgrading", c), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
|
|
2114
|
+
s || t.open();
|
|
2115
|
+
}, 200) : t.open();
|
|
2116
|
+
}
|
|
2117
|
+
onHandshake(e) {
|
|
2118
|
+
this._upgrades = this._filterUpgrades(e.upgrades), super.onHandshake(e);
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
/**
|
|
2122
|
+
* Filters upgrades, returning only those matching client transports.
|
|
2123
|
+
*
|
|
2124
|
+
* @param {Array} upgrades - server upgrades
|
|
2125
|
+
* @private
|
|
2126
|
+
*/
|
|
2127
|
+
_filterUpgrades(e) {
|
|
2128
|
+
const t = [];
|
|
2129
|
+
for (let s = 0; s < e.length; s++) { ~this.transports.indexOf(e[s]) && t.push(e[s]); }
|
|
2130
|
+
return t;
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
let Ts = class extends Ns {
|
|
2134
|
+
constructor(e, t = {}) {
|
|
2135
|
+
const s = typeof e == "object" ? e : t;
|
|
2136
|
+
(!s.transports || s.transports && typeof s.transports[0] == "string") && (s.transports = (s.transports || ["polling", "websocket", "webtransport"]).map((n) => ks[n]).filter((n) => !!n)), super(e, s);
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
function xs(i, e = "", t) {
|
|
2140
|
+
let s = i;
|
|
2141
|
+
t = t || typeof location < "u" && location, i == null && (i = t.protocol + "//" + t.host), typeof i == "string" && (i.charAt(0) === "/" && (i.charAt(1) === "/" ? i = t.protocol + i : i = t.host + i), /^(https?|wss?):\/\//.test(i) || (typeof t < "u" ? i = t.protocol + "//" + i : i = "https://" + i), s = Ne(i)), s.port || (/^(http|ws)$/.test(s.protocol) ? s.port = "80" : /^(http|ws)s$/.test(s.protocol) && (s.port = "443")), s.path = s.path || "/";
|
|
2142
|
+
const r = s.host.indexOf(":") !== -1 ? "[" + s.host + "]" : s.host;
|
|
2143
|
+
return s.id = s.protocol + "://" + r + ":" + s.port + e, s.href = s.protocol + "://" + r + (t && t.port === s.port ? "" : ":" + s.port), s;
|
|
2144
|
+
}
|
|
2145
|
+
const Ms = typeof ArrayBuffer == "function", As = (i) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(i) : i.buffer instanceof ArrayBuffer, gt = Object.prototype.toString, Is = typeof Blob == "function" || typeof Blob < "u" && gt.call(Blob) === "[object BlobConstructor]", js = typeof File == "function" || typeof File < "u" && gt.call(File) === "[object FileConstructor]";
|
|
2146
|
+
function Ge(i) {
|
|
2147
|
+
return Ms && (i instanceof ArrayBuffer || As(i)) || Is && i instanceof Blob || js && i instanceof File;
|
|
2148
|
+
}
|
|
2149
|
+
function ne(i, e) {
|
|
2150
|
+
if (!i || typeof i != "object") { return !1; }
|
|
2151
|
+
if (Array.isArray(i)) {
|
|
2152
|
+
for (let t = 0, s = i.length; t < s; t++) {
|
|
2153
|
+
if (ne(i[t])) { return !0; }
|
|
2154
|
+
}
|
|
2155
|
+
return !1;
|
|
2156
|
+
}
|
|
2157
|
+
if (Ge(i)) { return !0; }
|
|
2158
|
+
if (i.toJSON && typeof i.toJSON == "function" && arguments.length === 1) { return ne(i.toJSON(), !0); }
|
|
2159
|
+
for (const t in i) {
|
|
2160
|
+
if (Object.prototype.hasOwnProperty.call(i, t) && ne(i[t])) { return !0; }
|
|
2161
|
+
}
|
|
2162
|
+
return !1;
|
|
2163
|
+
}
|
|
2164
|
+
function Rs(i) {
|
|
2165
|
+
const e = [], t = i.data, s = i;
|
|
2166
|
+
return s.data = xe(t, e), s.attachments = e.length, { packet: s, buffers: e };
|
|
2167
|
+
}
|
|
2168
|
+
function xe(i, e) {
|
|
2169
|
+
if (!i) { return i; }
|
|
2170
|
+
if (Ge(i)) {
|
|
2171
|
+
const t = { _placeholder: !0, num: e.length };
|
|
2172
|
+
return e.push(i), t;
|
|
2173
|
+
} else if (Array.isArray(i)) {
|
|
2174
|
+
const t = new Array(i.length);
|
|
2175
|
+
for (let s = 0; s < i.length; s++) { t[s] = xe(i[s], e); }
|
|
2176
|
+
return t;
|
|
2177
|
+
} else if (typeof i == "object" && !(i instanceof Date)) {
|
|
2178
|
+
const t = {};
|
|
2179
|
+
for (const s in i) { Object.prototype.hasOwnProperty.call(i, s) && (t[s] = xe(i[s], e)); }
|
|
2180
|
+
return t;
|
|
2181
|
+
}
|
|
2182
|
+
return i;
|
|
2183
|
+
}
|
|
2184
|
+
function Ls(i, e) {
|
|
2185
|
+
return i.data = Me(i.data, e), delete i.attachments, i;
|
|
2186
|
+
}
|
|
2187
|
+
function Me(i, e) {
|
|
2188
|
+
if (!i) { return i; }
|
|
2189
|
+
if (i && i._placeholder === !0) {
|
|
2190
|
+
if (typeof i.num == "number" && i.num >= 0 && i.num < e.length) { return e[i.num]; }
|
|
2191
|
+
throw new Error("illegal attachments");
|
|
2192
|
+
} else if (Array.isArray(i)) {
|
|
2193
|
+
for (let t = 0; t < i.length; t++) { i[t] = Me(i[t], e); }
|
|
2194
|
+
} else if (typeof i == "object") {
|
|
2195
|
+
for (const t in i) { Object.prototype.hasOwnProperty.call(i, t) && (i[t] = Me(i[t], e)); }
|
|
2196
|
+
}
|
|
2197
|
+
return i;
|
|
2198
|
+
}
|
|
2199
|
+
const mt = [
|
|
2200
|
+
"connect",
|
|
2201
|
+
// used on the client side
|
|
2202
|
+
"connect_error",
|
|
2203
|
+
// used on the client side
|
|
2204
|
+
"disconnect",
|
|
2205
|
+
// used on both sides
|
|
2206
|
+
"disconnecting",
|
|
2207
|
+
// used on the server side
|
|
2208
|
+
"newListener",
|
|
2209
|
+
// used by the Node.js EventEmitter
|
|
2210
|
+
"removeListener"
|
|
2211
|
+
// used by the Node.js EventEmitter
|
|
2212
|
+
], Gs = 5;
|
|
2213
|
+
let p;
|
|
2214
|
+
(function(i) {
|
|
2215
|
+
i[i.CONNECT = 0] = "CONNECT", i[i.DISCONNECT = 1] = "DISCONNECT", i[i.EVENT = 2] = "EVENT", i[i.ACK = 3] = "ACK", i[i.CONNECT_ERROR = 4] = "CONNECT_ERROR", i[i.BINARY_EVENT = 5] = "BINARY_EVENT", i[i.BINARY_ACK = 6] = "BINARY_ACK";
|
|
2216
|
+
})(p || (p = {}));
|
|
2217
|
+
class Bs {
|
|
2218
|
+
|
|
2219
|
+
/**
|
|
2220
|
+
* Encoder constructor
|
|
2221
|
+
*
|
|
2222
|
+
* @param {function} replacer - custom replacer to pass down to JSON.parse
|
|
2223
|
+
*/
|
|
2224
|
+
constructor(e) {
|
|
2225
|
+
this.replacer = e;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
/**
|
|
2229
|
+
* Encode a packet as a single string if non-binary, or as a
|
|
2230
|
+
* buffer sequence, depending on packet type.
|
|
2231
|
+
*
|
|
2232
|
+
* @param {Object} obj - packet object
|
|
2233
|
+
*/
|
|
2234
|
+
encode(e) {
|
|
2235
|
+
return (e.type === p.EVENT || e.type === p.ACK) && ne(e) ? this.encodeAsBinary({
|
|
2236
|
+
type: e.type === p.EVENT ? p.BINARY_EVENT : p.BINARY_ACK,
|
|
2237
|
+
nsp: e.nsp,
|
|
2238
|
+
data: e.data,
|
|
2239
|
+
id: e.id
|
|
2240
|
+
}) : [this.encodeAsString(e)];
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
/**
|
|
2244
|
+
* Encode packet as string.
|
|
2245
|
+
*/
|
|
2246
|
+
encodeAsString(e) {
|
|
2247
|
+
let t = "" + e.type;
|
|
2248
|
+
return (e.type === p.BINARY_EVENT || e.type === p.BINARY_ACK) && (t += e.attachments + "-"), e.nsp && e.nsp !== "/" && (t += e.nsp + ","), e.id != null && (t += e.id), e.data != null && (t += JSON.stringify(e.data, this.replacer)), t;
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
/**
|
|
2252
|
+
* Encode packet as 'buffer sequence' by removing blobs, and
|
|
2253
|
+
* deconstructing packet into object with placeholders and
|
|
2254
|
+
* a list of buffers.
|
|
2255
|
+
*/
|
|
2256
|
+
encodeAsBinary(e) {
|
|
2257
|
+
const t = Rs(e), s = this.encodeAsString(t.packet), n = t.buffers;
|
|
2258
|
+
return n.unshift(s), n;
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
class Be extends y {
|
|
2262
|
+
|
|
2263
|
+
/**
|
|
2264
|
+
* Decoder constructor
|
|
2265
|
+
*/
|
|
2266
|
+
constructor(e) {
|
|
2267
|
+
super(), this.opts = Object.assign({
|
|
2268
|
+
reviver: void 0,
|
|
2269
|
+
maxAttachments: 10
|
|
2270
|
+
}, typeof e == "function" ? { reviver: e } : e);
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
/**
|
|
2274
|
+
* Decodes an encoded packet string into packet JSON.
|
|
2275
|
+
*
|
|
2276
|
+
* @param {String} obj - encoded packet
|
|
2277
|
+
*/
|
|
2278
|
+
add(e) {
|
|
2279
|
+
let t;
|
|
2280
|
+
if (typeof e == "string") {
|
|
2281
|
+
if (this.reconstructor) { throw new Error("got plaintext data when reconstructing a packet"); }
|
|
2282
|
+
t = this.decodeString(e);
|
|
2283
|
+
const s = t.type === p.BINARY_EVENT;
|
|
2284
|
+
s || t.type === p.BINARY_ACK ? (t.type = s ? p.EVENT : p.ACK, this.reconstructor = new $s(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
|
|
2285
|
+
} else if (Ge(e) || e.base64) {
|
|
2286
|
+
if (this.reconstructor) { t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t)); } else { throw new Error("got binary data when not reconstructing a packet"); }
|
|
2287
|
+
} else { throw new Error("Unknown type: " + e); }
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
/**
|
|
2291
|
+
* Decode a packet String (JSON data)
|
|
2292
|
+
*
|
|
2293
|
+
* @param {String} str
|
|
2294
|
+
* @return {Object} packet
|
|
2295
|
+
*/
|
|
2296
|
+
decodeString(e) {
|
|
2297
|
+
let t = 0;
|
|
2298
|
+
const s = {
|
|
2299
|
+
type: Number(e.charAt(0))
|
|
2300
|
+
};
|
|
2301
|
+
if (p[s.type] === void 0) { throw new Error("unknown packet type " + s.type); }
|
|
2302
|
+
if (s.type === p.BINARY_EVENT || s.type === p.BINARY_ACK) {
|
|
2303
|
+
const r = t + 1;
|
|
2304
|
+
for (; e.charAt(++t) !== "-" && t != e.length;) { }
|
|
2305
|
+
const o = e.substring(r, t);
|
|
2306
|
+
if (o != Number(o) || e.charAt(t) !== "-") { throw new Error("Illegal attachments"); }
|
|
2307
|
+
const a = Number(o);
|
|
2308
|
+
if (!yt(a) || a < 0) { throw new Error("Illegal attachments"); }
|
|
2309
|
+
if (a > this.opts.maxAttachments) { throw new Error("too many attachments"); }
|
|
2310
|
+
s.attachments = a;
|
|
2311
|
+
}
|
|
2312
|
+
if (e.charAt(t + 1) === "/") {
|
|
2313
|
+
const r = t + 1;
|
|
2314
|
+
for (; ++t && !(e.charAt(t) === "," || t === e.length);) { }
|
|
2315
|
+
s.nsp = e.substring(r, t);
|
|
2316
|
+
} else { s.nsp = "/"; }
|
|
2317
|
+
const n = e.charAt(t + 1);
|
|
2318
|
+
if (n !== "" && Number(n) == n) {
|
|
2319
|
+
const r = t + 1;
|
|
2320
|
+
for (; ++t;) {
|
|
2321
|
+
const o = e.charAt(t);
|
|
2322
|
+
if (o == null || Number(o) != o) {
|
|
2323
|
+
--t;
|
|
2324
|
+
break;
|
|
2325
|
+
}
|
|
2326
|
+
if (t === e.length) { break; }
|
|
2327
|
+
}
|
|
2328
|
+
s.id = Number(e.substring(r, t + 1));
|
|
2329
|
+
}
|
|
2330
|
+
if (e.charAt(++t)) {
|
|
2331
|
+
const r = this.tryParse(e.substr(t));
|
|
2332
|
+
if (Be.isPayloadValid(s.type, r)) { s.data = r; } else { throw new Error("invalid payload"); }
|
|
2333
|
+
}
|
|
2334
|
+
return s;
|
|
2335
|
+
}
|
|
2336
|
+
tryParse(e) {
|
|
2337
|
+
try {
|
|
2338
|
+
return JSON.parse(e, this.opts.reviver);
|
|
2339
|
+
} catch {
|
|
2340
|
+
return !1;
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
static isPayloadValid(e, t) {
|
|
2344
|
+
switch (e) {
|
|
2345
|
+
case p.CONNECT:
|
|
2346
|
+
return ae(t);
|
|
2347
|
+
case p.DISCONNECT:
|
|
2348
|
+
return t === void 0;
|
|
2349
|
+
case p.CONNECT_ERROR:
|
|
2350
|
+
return typeof t == "string" || ae(t);
|
|
2351
|
+
case p.EVENT:
|
|
2352
|
+
case p.BINARY_EVENT:
|
|
2353
|
+
return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && mt.indexOf(t[0]) === -1);
|
|
2354
|
+
case p.ACK:
|
|
2355
|
+
case p.BINARY_ACK:
|
|
2356
|
+
return Array.isArray(t);
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
/**
|
|
2361
|
+
* Deallocates a parser's resources
|
|
2362
|
+
*/
|
|
2363
|
+
destroy() {
|
|
2364
|
+
this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
class $s {
|
|
2368
|
+
constructor(e) {
|
|
2369
|
+
this.packet = e, this.buffers = [], this.reconPack = e;
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
/**
|
|
2373
|
+
* Method to be called when binary data received from connection
|
|
2374
|
+
* after a BINARY_EVENT packet.
|
|
2375
|
+
*
|
|
2376
|
+
* @param {Buffer | ArrayBuffer} binData - the raw binary data received
|
|
2377
|
+
* @return {null | Object} returns null if more binary data is expected or
|
|
2378
|
+
* a reconstructed packet object if all buffers have been received.
|
|
2379
|
+
*/
|
|
2380
|
+
takeBinaryData(e) {
|
|
2381
|
+
if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
|
|
2382
|
+
const t = Ls(this.reconPack, this.buffers);
|
|
2383
|
+
return this.finishedReconstruction(), t;
|
|
2384
|
+
}
|
|
2385
|
+
return null;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
/**
|
|
2389
|
+
* Cleans up binary packet reconstruction variables.
|
|
2390
|
+
*/
|
|
2391
|
+
finishedReconstruction() {
|
|
2392
|
+
this.reconPack = null, this.buffers = [];
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
function Ps(i) {
|
|
2396
|
+
return typeof i == "string";
|
|
2397
|
+
}
|
|
2398
|
+
const yt = Number.isInteger || function(i) {
|
|
2399
|
+
return typeof i == "number" && isFinite(i) && Math.floor(i) === i;
|
|
2400
|
+
};
|
|
2401
|
+
function zs(i) {
|
|
2402
|
+
return i === void 0 || yt(i);
|
|
2403
|
+
}
|
|
2404
|
+
function ae(i) {
|
|
2405
|
+
return Object.prototype.toString.call(i) === "[object Object]";
|
|
2406
|
+
}
|
|
2407
|
+
function Ds(i, e) {
|
|
2408
|
+
switch (i) {
|
|
2409
|
+
case p.CONNECT:
|
|
2410
|
+
return e === void 0 || ae(e);
|
|
2411
|
+
case p.DISCONNECT:
|
|
2412
|
+
return e === void 0;
|
|
2413
|
+
case p.EVENT:
|
|
2414
|
+
return Array.isArray(e) && (typeof e[0] == "number" || typeof e[0] == "string" && mt.indexOf(e[0]) === -1);
|
|
2415
|
+
case p.ACK:
|
|
2416
|
+
return Array.isArray(e);
|
|
2417
|
+
case p.CONNECT_ERROR:
|
|
2418
|
+
return typeof e == "string" || ae(e);
|
|
2419
|
+
default:
|
|
2420
|
+
return !1;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
function Fs(i) {
|
|
2424
|
+
return Ps(i.nsp) && zs(i.id) && Ds(i.type, i.data);
|
|
2425
|
+
}
|
|
2426
|
+
const Us = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2427
|
+
__proto__: null,
|
|
2428
|
+
Decoder: Be,
|
|
2429
|
+
Encoder: Bs,
|
|
2430
|
+
get PacketType() {
|
|
2431
|
+
return p;
|
|
2432
|
+
},
|
|
2433
|
+
isPacketValid: Fs,
|
|
2434
|
+
protocol: Gs
|
|
2435
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
2436
|
+
function _(i, e, t) {
|
|
2437
|
+
return i.on(e, t), function() {
|
|
2438
|
+
i.off(e, t);
|
|
2439
|
+
};
|
|
2440
|
+
}
|
|
2441
|
+
const Vs = Object.freeze({
|
|
2442
|
+
connect: 1,
|
|
2443
|
+
connect_error: 1,
|
|
2444
|
+
disconnect: 1,
|
|
2445
|
+
disconnecting: 1,
|
|
2446
|
+
// EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
|
|
2447
|
+
newListener: 1,
|
|
2448
|
+
removeListener: 1
|
|
2449
|
+
});
|
|
2450
|
+
class wt extends y {
|
|
2451
|
+
|
|
2452
|
+
/**
|
|
2453
|
+
* `Socket` constructor.
|
|
2454
|
+
*/
|
|
2455
|
+
constructor(e, t, s) {
|
|
2456
|
+
super(), this.connected = !1, this.recovered = !1, this.receiveBuffer = [], this.sendBuffer = [], this._queue = [], this._queueSeq = 0, this.ids = 0, this.acks = {}, this.flags = {}, this.io = e, this.nsp = t, s && s.auth && (this.auth = s.auth), this._opts = Object.assign({}, s), this.io._autoConnect && this.open();
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
/**
|
|
2460
|
+
* Whether the socket is currently disconnected
|
|
2461
|
+
*
|
|
2462
|
+
* @example
|
|
2463
|
+
* const socket = io();
|
|
2464
|
+
*
|
|
2465
|
+
* socket.on("connect", () => {
|
|
2466
|
+
* console.log(socket.disconnected); // false
|
|
2467
|
+
* });
|
|
2468
|
+
*
|
|
2469
|
+
* socket.on("disconnect", () => {
|
|
2470
|
+
* console.log(socket.disconnected); // true
|
|
2471
|
+
* });
|
|
2472
|
+
*/
|
|
2473
|
+
get disconnected() {
|
|
2474
|
+
return !this.connected;
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* Subscribe to open, close and packet events
|
|
2479
|
+
*
|
|
2480
|
+
* @private
|
|
2481
|
+
*/
|
|
2482
|
+
subEvents() {
|
|
2483
|
+
if (this.subs) { return; }
|
|
2484
|
+
const e = this.io;
|
|
2485
|
+
this.subs = [
|
|
2486
|
+
_(e, "open", this.onopen.bind(this)),
|
|
2487
|
+
_(e, "packet", this.onpacket.bind(this)),
|
|
2488
|
+
_(e, "error", this.onerror.bind(this)),
|
|
2489
|
+
_(e, "close", this.onclose.bind(this))
|
|
2490
|
+
];
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* Whether the Socket will try to reconnect when its Manager connects or reconnects.
|
|
2495
|
+
*
|
|
2496
|
+
* @example
|
|
2497
|
+
* const socket = io();
|
|
2498
|
+
*
|
|
2499
|
+
* console.log(socket.active); // true
|
|
2500
|
+
*
|
|
2501
|
+
* socket.on("disconnect", (reason) => {
|
|
2502
|
+
* if (reason === "io server disconnect") {
|
|
2503
|
+
* // the disconnection was initiated by the server, you need to manually reconnect
|
|
2504
|
+
* console.log(socket.active); // false
|
|
2505
|
+
* }
|
|
2506
|
+
* // else the socket will automatically try to reconnect
|
|
2507
|
+
* console.log(socket.active); // true
|
|
2508
|
+
* });
|
|
2509
|
+
*/
|
|
2510
|
+
get active() {
|
|
2511
|
+
return !!this.subs;
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
/**
|
|
2515
|
+
* "Opens" the socket.
|
|
2516
|
+
*
|
|
2517
|
+
* @example
|
|
2518
|
+
* const socket = io({
|
|
2519
|
+
* autoConnect: false
|
|
2520
|
+
* });
|
|
2521
|
+
*
|
|
2522
|
+
* socket.connect();
|
|
2523
|
+
*/
|
|
2524
|
+
connect() {
|
|
2525
|
+
return this.connected ? this : (this.subEvents(), this.io._reconnecting || this.io.open(), this.io._readyState === "open" && this.onopen(), this);
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
/**
|
|
2529
|
+
* Alias for {@link connect()}.
|
|
2530
|
+
*/
|
|
2531
|
+
open() {
|
|
2532
|
+
return this.connect();
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
/**
|
|
2536
|
+
* Sends a `message` event.
|
|
2537
|
+
*
|
|
2538
|
+
* This method mimics the WebSocket.send() method.
|
|
2539
|
+
*
|
|
2540
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
2541
|
+
*
|
|
2542
|
+
* @example
|
|
2543
|
+
* socket.send("hello");
|
|
2544
|
+
*
|
|
2545
|
+
* // this is equivalent to
|
|
2546
|
+
* socket.emit("message", "hello");
|
|
2547
|
+
*
|
|
2548
|
+
* @return self
|
|
2549
|
+
*/
|
|
2550
|
+
send(...e) {
|
|
2551
|
+
return e.unshift("message"), this.emit.apply(this, e), this;
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
/**
|
|
2555
|
+
* Override `emit`.
|
|
2556
|
+
* If the event is in `events`, it's emitted normally.
|
|
2557
|
+
*
|
|
2558
|
+
* @example
|
|
2559
|
+
* socket.emit("hello", "world");
|
|
2560
|
+
*
|
|
2561
|
+
* // all serializable datastructures are supported (no need to call JSON.stringify)
|
|
2562
|
+
* socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
|
|
2563
|
+
*
|
|
2564
|
+
* // with an acknowledgement from the server
|
|
2565
|
+
* socket.emit("hello", "world", (val) => {
|
|
2566
|
+
* // ...
|
|
2567
|
+
* });
|
|
2568
|
+
*
|
|
2569
|
+
* @return self
|
|
2570
|
+
*/
|
|
2571
|
+
emit(e, ...t) {
|
|
2572
|
+
let s, n, r;
|
|
2573
|
+
if (Vs.hasOwnProperty(e)) { throw new Error('"' + e.toString() + '" is a reserved event name'); }
|
|
2574
|
+
if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) { return this._addToQueue(t), this; }
|
|
2575
|
+
const o = {
|
|
2576
|
+
type: p.EVENT,
|
|
2577
|
+
data: t
|
|
2578
|
+
};
|
|
2579
|
+
if (o.options = {}, o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
|
|
2580
|
+
const h = this.ids++, l = t.pop();
|
|
2581
|
+
this._registerAckCallback(h, l), o.id = h;
|
|
2582
|
+
}
|
|
2583
|
+
const a = (n = (s = this.io.engine) === null || s === void 0 ? void 0 : s.transport) === null || n === void 0 ? void 0 : n.writable, u = this.connected && !(!((r = this.io.engine) === null || r === void 0) && r._hasPingExpired());
|
|
2584
|
+
return this.flags.volatile && !a || (u ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
/**
|
|
2588
|
+
* @private
|
|
2589
|
+
*/
|
|
2590
|
+
_registerAckCallback(e, t) {
|
|
2591
|
+
let s;
|
|
2592
|
+
const n = (s = this.flags.timeout) !== null && s !== void 0 ? s : this._opts.ackTimeout;
|
|
2593
|
+
if (n === void 0) {
|
|
2594
|
+
this.acks[e] = t;
|
|
2595
|
+
return;
|
|
2596
|
+
}
|
|
2597
|
+
const r = this.io.setTimeoutFn(() => {
|
|
2598
|
+
delete this.acks[e];
|
|
2599
|
+
for (let a = 0; a < this.sendBuffer.length; a++) { this.sendBuffer[a].id === e && this.sendBuffer.splice(a, 1); }
|
|
2600
|
+
t.call(this, new Error("operation has timed out"));
|
|
2601
|
+
}, n), o = (...a) => {
|
|
2602
|
+
this.io.clearTimeoutFn(r), t.apply(this, a);
|
|
2603
|
+
};
|
|
2604
|
+
o.withError = !0, this.acks[e] = o;
|
|
2605
|
+
}
|
|
2606
|
+
|
|
2607
|
+
/**
|
|
2608
|
+
* Emits an event and waits for an acknowledgement
|
|
2609
|
+
*
|
|
2610
|
+
* @example
|
|
2611
|
+
* // without timeout
|
|
2612
|
+
* const response = await socket.emitWithAck("hello", "world");
|
|
2613
|
+
*
|
|
2614
|
+
* // with a specific timeout
|
|
2615
|
+
* try {
|
|
2616
|
+
* const response = await socket.timeout(1000).emitWithAck("hello", "world");
|
|
2617
|
+
* } catch (err) {
|
|
2618
|
+
* // the server did not acknowledge the event in the given delay
|
|
2619
|
+
* }
|
|
2620
|
+
*
|
|
2621
|
+
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
2622
|
+
*/
|
|
2623
|
+
emitWithAck(e, ...t) {
|
|
2624
|
+
return new Promise((s, n) => {
|
|
2625
|
+
const r = (o, a) => o ? n(o) : s(a);
|
|
2626
|
+
r.withError = !0, t.push(r), this.emit(e, ...t);
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
/**
|
|
2631
|
+
* Add the packet to the queue.
|
|
2632
|
+
* @param args
|
|
2633
|
+
* @private
|
|
2634
|
+
*/
|
|
2635
|
+
_addToQueue(e) {
|
|
2636
|
+
let t;
|
|
2637
|
+
typeof e[e.length - 1] == "function" && (t = e.pop());
|
|
2638
|
+
const s = {
|
|
2639
|
+
id: this._queueSeq++,
|
|
2640
|
+
tryCount: 0,
|
|
2641
|
+
pending: !1,
|
|
2642
|
+
args: e,
|
|
2643
|
+
flags: Object.assign({ fromQueue: !0 }, this.flags)
|
|
2644
|
+
};
|
|
2645
|
+
e.push((n, ...r) => (this._queue[0], n !== null ? s.tryCount > this._opts.retries && (this._queue.shift(), t && t(n)) : (this._queue.shift(), t && t(null, ...r)), s.pending = !1, this._drainQueue())), this._queue.push(s), this._drainQueue();
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
/**
|
|
2649
|
+
* Send the first packet of the queue, and wait for an acknowledgement from the server.
|
|
2650
|
+
* @param force - whether to resend a packet that has not been acknowledged yet
|
|
2651
|
+
*
|
|
2652
|
+
* @private
|
|
2653
|
+
*/
|
|
2654
|
+
_drainQueue(e = !1) {
|
|
2655
|
+
if (!this.connected || this._queue.length === 0) { return; }
|
|
2656
|
+
const t = this._queue[0];
|
|
2657
|
+
t.pending && !e || (t.pending = !0, t.tryCount++, this.flags = t.flags, this.emit.apply(this, t.args));
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
/**
|
|
2661
|
+
* Sends a packet.
|
|
2662
|
+
*
|
|
2663
|
+
* @param packet
|
|
2664
|
+
* @private
|
|
2665
|
+
*/
|
|
2666
|
+
packet(e) {
|
|
2667
|
+
e.nsp = this.nsp, this.io._packet(e);
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2670
|
+
/**
|
|
2671
|
+
* Called upon engine `open`.
|
|
2672
|
+
*
|
|
2673
|
+
* @private
|
|
2674
|
+
*/
|
|
2675
|
+
onopen() {
|
|
2676
|
+
typeof this.auth == "function" ? this.auth((e) => {
|
|
2677
|
+
this._sendConnectPacket(e);
|
|
2678
|
+
}) : this._sendConnectPacket(this.auth);
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
/**
|
|
2682
|
+
* Sends a CONNECT packet to initiate the Socket.IO session.
|
|
2683
|
+
*
|
|
2684
|
+
* @param data
|
|
2685
|
+
* @private
|
|
2686
|
+
*/
|
|
2687
|
+
_sendConnectPacket(e) {
|
|
2688
|
+
this.packet({
|
|
2689
|
+
type: p.CONNECT,
|
|
2690
|
+
data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset }, e) : e
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
/**
|
|
2695
|
+
* Called upon engine or manager `error`.
|
|
2696
|
+
*
|
|
2697
|
+
* @param err
|
|
2698
|
+
* @private
|
|
2699
|
+
*/
|
|
2700
|
+
onerror(e) {
|
|
2701
|
+
this.connected || this.emitReserved("connect_error", e);
|
|
2702
|
+
}
|
|
2703
|
+
|
|
2704
|
+
/**
|
|
2705
|
+
* Called upon engine `close`.
|
|
2706
|
+
*
|
|
2707
|
+
* @param reason
|
|
2708
|
+
* @param description
|
|
2709
|
+
* @private
|
|
2710
|
+
*/
|
|
2711
|
+
onclose(e, t) {
|
|
2712
|
+
this.connected = !1, delete this.id, this.emitReserved("disconnect", e, t), this._clearAcks();
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
/**
|
|
2716
|
+
* Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
|
|
2717
|
+
* the server.
|
|
2718
|
+
*
|
|
2719
|
+
* @private
|
|
2720
|
+
*/
|
|
2721
|
+
_clearAcks() {
|
|
2722
|
+
Object.keys(this.acks).forEach((e) => {
|
|
2723
|
+
if (!this.sendBuffer.some((s) => String(s.id) === e)) {
|
|
2724
|
+
const s = this.acks[e];
|
|
2725
|
+
delete this.acks[e], s.withError && s.call(this, new Error("socket has been disconnected"));
|
|
2726
|
+
}
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
/**
|
|
2731
|
+
* Called with socket packet.
|
|
2732
|
+
*
|
|
2733
|
+
* @param packet
|
|
2734
|
+
* @private
|
|
2735
|
+
*/
|
|
2736
|
+
onpacket(e) {
|
|
2737
|
+
if (e.nsp === this.nsp) {
|
|
2738
|
+
switch (e.type) {
|
|
2739
|
+
case p.CONNECT:
|
|
2740
|
+
e.data && e.data.sid ? this.onconnect(e.data.sid, e.data.pid) : this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
|
|
2741
|
+
break;
|
|
2742
|
+
case p.EVENT:
|
|
2743
|
+
case p.BINARY_EVENT:
|
|
2744
|
+
this.onevent(e);
|
|
2745
|
+
break;
|
|
2746
|
+
case p.ACK:
|
|
2747
|
+
case p.BINARY_ACK:
|
|
2748
|
+
this.onack(e);
|
|
2749
|
+
break;
|
|
2750
|
+
case p.DISCONNECT:
|
|
2751
|
+
this.ondisconnect();
|
|
2752
|
+
break;
|
|
2753
|
+
case p.CONNECT_ERROR:
|
|
2754
|
+
this.destroy();
|
|
2755
|
+
const s = new Error(e.data.message);
|
|
2756
|
+
s.data = e.data.data, this.emitReserved("connect_error", s);
|
|
2757
|
+
break;
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
/**
|
|
2763
|
+
* Called upon a server event.
|
|
2764
|
+
*
|
|
2765
|
+
* @param packet
|
|
2766
|
+
* @private
|
|
2767
|
+
*/
|
|
2768
|
+
onevent(e) {
|
|
2769
|
+
const t = e.data || [];
|
|
2770
|
+
e.id != null && t.push(this.ack(e.id)), this.connected ? this.emitEvent(t) : this.receiveBuffer.push(Object.freeze(t));
|
|
2771
|
+
}
|
|
2772
|
+
emitEvent(e) {
|
|
2773
|
+
if (this._anyListeners && this._anyListeners.length) {
|
|
2774
|
+
const t = this._anyListeners.slice();
|
|
2775
|
+
for (const s of t) { s.apply(this, e); }
|
|
2776
|
+
}
|
|
2777
|
+
super.emit.apply(this, e), this._pid && e.length && typeof e[e.length - 1] == "string" && (this._lastOffset = e[e.length - 1]);
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
/**
|
|
2781
|
+
* Produces an ack callback to emit with an event.
|
|
2782
|
+
*
|
|
2783
|
+
* @private
|
|
2784
|
+
*/
|
|
2785
|
+
ack(e) {
|
|
2786
|
+
const t = this;
|
|
2787
|
+
let s = !1;
|
|
2788
|
+
return function(...n) {
|
|
2789
|
+
s || (s = !0, t.packet({
|
|
2790
|
+
type: p.ACK,
|
|
2791
|
+
id: e,
|
|
2792
|
+
data: n
|
|
2793
|
+
}));
|
|
2794
|
+
};
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
/**
|
|
2798
|
+
* Called upon a server acknowledgement.
|
|
2799
|
+
*
|
|
2800
|
+
* @param packet
|
|
2801
|
+
* @private
|
|
2802
|
+
*/
|
|
2803
|
+
onack(e) {
|
|
2804
|
+
const t = this.acks[e.id];
|
|
2805
|
+
typeof t == "function" && (delete this.acks[e.id], t.withError && e.data.unshift(null), t.apply(this, e.data));
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
/**
|
|
2809
|
+
* Called upon server connect.
|
|
2810
|
+
*
|
|
2811
|
+
* @private
|
|
2812
|
+
*/
|
|
2813
|
+
onconnect(e, t) {
|
|
2814
|
+
this.id = e, this.recovered = t && this._pid === t, this._pid = t, this.connected = !0, this.emitBuffered(), this._drainQueue(!0), this.emitReserved("connect");
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
/**
|
|
2818
|
+
* Emit buffered events (received and emitted).
|
|
2819
|
+
*
|
|
2820
|
+
* @private
|
|
2821
|
+
*/
|
|
2822
|
+
emitBuffered() {
|
|
2823
|
+
this.receiveBuffer.forEach((e) => this.emitEvent(e)), this.receiveBuffer = [], this.sendBuffer.forEach((e) => {
|
|
2824
|
+
this.notifyOutgoingListeners(e), this.packet(e);
|
|
2825
|
+
}), this.sendBuffer = [];
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
/**
|
|
2829
|
+
* Called upon server disconnect.
|
|
2830
|
+
*
|
|
2831
|
+
* @private
|
|
2832
|
+
*/
|
|
2833
|
+
ondisconnect() {
|
|
2834
|
+
this.destroy(), this.onclose("io server disconnect");
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
/**
|
|
2838
|
+
* Called upon forced client/server side disconnections,
|
|
2839
|
+
* this method ensures the manager stops tracking us and
|
|
2840
|
+
* that reconnections don't get triggered for this.
|
|
2841
|
+
*
|
|
2842
|
+
* @private
|
|
2843
|
+
*/
|
|
2844
|
+
destroy() {
|
|
2845
|
+
this.subs && (this.subs.forEach((e) => e()), this.subs = void 0), this.io._destroy(this);
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
/**
|
|
2849
|
+
* Disconnects the socket manually. In that case, the socket will not try to reconnect.
|
|
2850
|
+
*
|
|
2851
|
+
* If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
|
|
2852
|
+
*
|
|
2853
|
+
* @example
|
|
2854
|
+
* const socket = io();
|
|
2855
|
+
*
|
|
2856
|
+
* socket.on("disconnect", (reason) => {
|
|
2857
|
+
* // console.log(reason); prints "io client disconnect"
|
|
2858
|
+
* });
|
|
2859
|
+
*
|
|
2860
|
+
* socket.disconnect();
|
|
2861
|
+
*
|
|
2862
|
+
* @return self
|
|
2863
|
+
*/
|
|
2864
|
+
disconnect() {
|
|
2865
|
+
return this.connected && this.packet({ type: p.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
|
|
2866
|
+
}
|
|
2867
|
+
|
|
2868
|
+
/**
|
|
2869
|
+
* Alias for {@link disconnect()}.
|
|
2870
|
+
*
|
|
2871
|
+
* @return self
|
|
2872
|
+
*/
|
|
2873
|
+
close() {
|
|
2874
|
+
return this.disconnect();
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
/**
|
|
2878
|
+
* Sets the compress flag.
|
|
2879
|
+
*
|
|
2880
|
+
* @example
|
|
2881
|
+
* socket.compress(false).emit("hello");
|
|
2882
|
+
*
|
|
2883
|
+
* @param compress - if `true`, compresses the sending data
|
|
2884
|
+
* @return self
|
|
2885
|
+
*/
|
|
2886
|
+
compress(e) {
|
|
2887
|
+
return this.flags.compress = e, this;
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
/**
|
|
2891
|
+
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
|
2892
|
+
* ready to send messages.
|
|
2893
|
+
*
|
|
2894
|
+
* @example
|
|
2895
|
+
* socket.volatile.emit("hello"); // the server may or may not receive it
|
|
2896
|
+
*
|
|
2897
|
+
* @returns self
|
|
2898
|
+
*/
|
|
2899
|
+
get volatile() {
|
|
2900
|
+
return this.flags.volatile = !0, this;
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2903
|
+
/**
|
|
2904
|
+
* Sets a modifier for a subsequent event emission that the callback will be called with an error when the
|
|
2905
|
+
* given number of milliseconds have elapsed without an acknowledgement from the server:
|
|
2906
|
+
*
|
|
2907
|
+
* @example
|
|
2908
|
+
* socket.timeout(5000).emit("my-event", (err) => {
|
|
2909
|
+
* if (err) {
|
|
2910
|
+
* // the server did not acknowledge the event in the given delay
|
|
2911
|
+
* }
|
|
2912
|
+
* });
|
|
2913
|
+
*
|
|
2914
|
+
* @returns self
|
|
2915
|
+
*/
|
|
2916
|
+
timeout(e) {
|
|
2917
|
+
return this.flags.timeout = e, this;
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
/**
|
|
2921
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
2922
|
+
* callback.
|
|
2923
|
+
*
|
|
2924
|
+
* @example
|
|
2925
|
+
* socket.onAny((event, ...args) => {
|
|
2926
|
+
* console.log(`got ${event}`);
|
|
2927
|
+
* });
|
|
2928
|
+
*
|
|
2929
|
+
* @param listener
|
|
2930
|
+
*/
|
|
2931
|
+
onAny(e) {
|
|
2932
|
+
return this._anyListeners = this._anyListeners || [], this._anyListeners.push(e), this;
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
/**
|
|
2936
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
2937
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
2938
|
+
*
|
|
2939
|
+
* @example
|
|
2940
|
+
* socket.prependAny((event, ...args) => {
|
|
2941
|
+
* console.log(`got event ${event}`);
|
|
2942
|
+
* });
|
|
2943
|
+
*
|
|
2944
|
+
* @param listener
|
|
2945
|
+
*/
|
|
2946
|
+
prependAny(e) {
|
|
2947
|
+
return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(e), this;
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
/**
|
|
2951
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
2952
|
+
*
|
|
2953
|
+
* @example
|
|
2954
|
+
* const catchAllListener = (event, ...args) => {
|
|
2955
|
+
* console.log(`got event ${event}`);
|
|
2956
|
+
* }
|
|
2957
|
+
*
|
|
2958
|
+
* socket.onAny(catchAllListener);
|
|
2959
|
+
*
|
|
2960
|
+
* // remove a specific listener
|
|
2961
|
+
* socket.offAny(catchAllListener);
|
|
2962
|
+
*
|
|
2963
|
+
* // or remove all listeners
|
|
2964
|
+
* socket.offAny();
|
|
2965
|
+
*
|
|
2966
|
+
* @param listener
|
|
2967
|
+
*/
|
|
2968
|
+
offAny(e) {
|
|
2969
|
+
if (!this._anyListeners) { return this; }
|
|
2970
|
+
if (e) {
|
|
2971
|
+
const t = this._anyListeners;
|
|
2972
|
+
for (let s = 0; s < t.length; s++) {
|
|
2973
|
+
if (e === t[s]) { return t.splice(s, 1), this; }
|
|
2974
|
+
}
|
|
2975
|
+
} else { this._anyListeners = []; }
|
|
2976
|
+
return this;
|
|
2977
|
+
}
|
|
2978
|
+
|
|
2979
|
+
/**
|
|
2980
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
2981
|
+
* e.g. to remove listeners.
|
|
2982
|
+
*/
|
|
2983
|
+
listenersAny() {
|
|
2984
|
+
return this._anyListeners || [];
|
|
2985
|
+
}
|
|
2986
|
+
|
|
2987
|
+
/**
|
|
2988
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
2989
|
+
* callback.
|
|
2990
|
+
*
|
|
2991
|
+
* Note: acknowledgements sent to the server are not included.
|
|
2992
|
+
*
|
|
2993
|
+
* @example
|
|
2994
|
+
* socket.onAnyOutgoing((event, ...args) => {
|
|
2995
|
+
* console.log(`sent event ${event}`);
|
|
2996
|
+
* });
|
|
2997
|
+
*
|
|
2998
|
+
* @param listener
|
|
2999
|
+
*/
|
|
3000
|
+
onAnyOutgoing(e) {
|
|
3001
|
+
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(e), this;
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
/**
|
|
3005
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
3006
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
3007
|
+
*
|
|
3008
|
+
* Note: acknowledgements sent to the server are not included.
|
|
3009
|
+
*
|
|
3010
|
+
* @example
|
|
3011
|
+
* socket.prependAnyOutgoing((event, ...args) => {
|
|
3012
|
+
* console.log(`sent event ${event}`);
|
|
3013
|
+
* });
|
|
3014
|
+
*
|
|
3015
|
+
* @param listener
|
|
3016
|
+
*/
|
|
3017
|
+
prependAnyOutgoing(e) {
|
|
3018
|
+
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(e), this;
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
/**
|
|
3022
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
3023
|
+
*
|
|
3024
|
+
* @example
|
|
3025
|
+
* const catchAllListener = (event, ...args) => {
|
|
3026
|
+
* console.log(`sent event ${event}`);
|
|
3027
|
+
* }
|
|
3028
|
+
*
|
|
3029
|
+
* socket.onAnyOutgoing(catchAllListener);
|
|
3030
|
+
*
|
|
3031
|
+
* // remove a specific listener
|
|
3032
|
+
* socket.offAnyOutgoing(catchAllListener);
|
|
3033
|
+
*
|
|
3034
|
+
* // or remove all listeners
|
|
3035
|
+
* socket.offAnyOutgoing();
|
|
3036
|
+
*
|
|
3037
|
+
* @param [listener] - the catch-all listener (optional)
|
|
3038
|
+
*/
|
|
3039
|
+
offAnyOutgoing(e) {
|
|
3040
|
+
if (!this._anyOutgoingListeners) { return this; }
|
|
3041
|
+
if (e) {
|
|
3042
|
+
const t = this._anyOutgoingListeners;
|
|
3043
|
+
for (let s = 0; s < t.length; s++) {
|
|
3044
|
+
if (e === t[s]) { return t.splice(s, 1), this; }
|
|
3045
|
+
}
|
|
3046
|
+
} else { this._anyOutgoingListeners = []; }
|
|
3047
|
+
return this;
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
/**
|
|
3051
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
3052
|
+
* e.g. to remove listeners.
|
|
3053
|
+
*/
|
|
3054
|
+
listenersAnyOutgoing() {
|
|
3055
|
+
return this._anyOutgoingListeners || [];
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
/**
|
|
3059
|
+
* Notify the listeners for each packet sent
|
|
3060
|
+
*
|
|
3061
|
+
* @param packet
|
|
3062
|
+
*
|
|
3063
|
+
* @private
|
|
3064
|
+
*/
|
|
3065
|
+
notifyOutgoingListeners(e) {
|
|
3066
|
+
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
3067
|
+
const t = this._anyOutgoingListeners.slice();
|
|
3068
|
+
for (const s of t) { s.apply(this, e.data); }
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3072
|
+
function F(i) {
|
|
3073
|
+
i = i || {}, this.ms = i.min || 100, this.max = i.max || 1e4, this.factor = i.factor || 2, this.jitter = i.jitter > 0 && i.jitter <= 1 ? i.jitter : 0, this.attempts = 0;
|
|
3074
|
+
}
|
|
3075
|
+
F.prototype.duration = function() {
|
|
3076
|
+
let i = this.ms * Math.pow(this.factor, this.attempts++);
|
|
3077
|
+
if (this.jitter) {
|
|
3078
|
+
let e = Math.random(), t = Math.floor(e * this.jitter * i);
|
|
3079
|
+
i = Math.floor(e * 10) & 1 ? i + t : i - t;
|
|
3080
|
+
}
|
|
3081
|
+
return Math.min(i, this.max) | 0;
|
|
3082
|
+
};
|
|
3083
|
+
F.prototype.reset = function() {
|
|
3084
|
+
this.attempts = 0;
|
|
3085
|
+
};
|
|
3086
|
+
F.prototype.setMin = function(i) {
|
|
3087
|
+
this.ms = i;
|
|
3088
|
+
};
|
|
3089
|
+
F.prototype.setMax = function(i) {
|
|
3090
|
+
this.max = i;
|
|
3091
|
+
};
|
|
3092
|
+
F.prototype.setJitter = function(i) {
|
|
3093
|
+
this.jitter = i;
|
|
3094
|
+
};
|
|
3095
|
+
class Ae extends y {
|
|
3096
|
+
constructor(e, t) {
|
|
3097
|
+
let s;
|
|
3098
|
+
super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t = t || {}, t.path = t.path || "/socket.io", this.opts = t, ce(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || 1 / 0), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor((s = t.randomizationFactor) !== null && s !== void 0 ? s : 0.5), this.backoff = new F({
|
|
3099
|
+
min: this.reconnectionDelay(),
|
|
3100
|
+
max: this.reconnectionDelayMax(),
|
|
3101
|
+
jitter: this.randomizationFactor()
|
|
3102
|
+
}), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
|
|
3103
|
+
const n = t.parser || Us;
|
|
3104
|
+
this.encoder = new n.Encoder(), this.decoder = new n.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
|
|
3105
|
+
}
|
|
3106
|
+
reconnection(e) {
|
|
3107
|
+
return arguments.length ? (this._reconnection = !!e, e || (this.skipReconnect = !0), this) : this._reconnection;
|
|
3108
|
+
}
|
|
3109
|
+
reconnectionAttempts(e) {
|
|
3110
|
+
return e === void 0 ? this._reconnectionAttempts : (this._reconnectionAttempts = e, this);
|
|
3111
|
+
}
|
|
3112
|
+
reconnectionDelay(e) {
|
|
3113
|
+
let t;
|
|
3114
|
+
return e === void 0 ? this._reconnectionDelay : (this._reconnectionDelay = e, (t = this.backoff) === null || t === void 0 || t.setMin(e), this);
|
|
3115
|
+
}
|
|
3116
|
+
randomizationFactor(e) {
|
|
3117
|
+
let t;
|
|
3118
|
+
return e === void 0 ? this._randomizationFactor : (this._randomizationFactor = e, (t = this.backoff) === null || t === void 0 || t.setJitter(e), this);
|
|
3119
|
+
}
|
|
3120
|
+
reconnectionDelayMax(e) {
|
|
3121
|
+
let t;
|
|
3122
|
+
return e === void 0 ? this._reconnectionDelayMax : (this._reconnectionDelayMax = e, (t = this.backoff) === null || t === void 0 || t.setMax(e), this);
|
|
3123
|
+
}
|
|
3124
|
+
timeout(e) {
|
|
3125
|
+
return arguments.length ? (this._timeout = e, this) : this._timeout;
|
|
3126
|
+
}
|
|
3127
|
+
|
|
3128
|
+
/**
|
|
3129
|
+
* Starts trying to reconnect if reconnection is enabled and we have not
|
|
3130
|
+
* started reconnecting yet
|
|
3131
|
+
*
|
|
3132
|
+
* @private
|
|
3133
|
+
*/
|
|
3134
|
+
maybeReconnectOnOpen() {
|
|
3135
|
+
!this._reconnecting && this._reconnection && this.backoff.attempts === 0 && this.reconnect();
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
/**
|
|
3139
|
+
* Sets the current transport `socket`.
|
|
3140
|
+
*
|
|
3141
|
+
* @param {Function} fn - optional, callback
|
|
3142
|
+
* @return self
|
|
3143
|
+
* @public
|
|
3144
|
+
*/
|
|
3145
|
+
open(e) {
|
|
3146
|
+
if (~this._readyState.indexOf("open")) { return this; }
|
|
3147
|
+
this.engine = new Ts(this.uri, this.opts);
|
|
3148
|
+
const t = this.engine, s = this;
|
|
3149
|
+
this._readyState = "opening", this.skipReconnect = !1;
|
|
3150
|
+
const n = _(t, "open", function() {
|
|
3151
|
+
s.onopen(), e && e();
|
|
3152
|
+
}), r = (a) => {
|
|
3153
|
+
this.cleanup(), this._readyState = "closed", this.emitReserved("error", a), e ? e(a) : this.maybeReconnectOnOpen();
|
|
3154
|
+
}, o = _(t, "error", r);
|
|
3155
|
+
if (this._timeout !== !1) {
|
|
3156
|
+
const a = this._timeout, u = this.setTimeoutFn(() => {
|
|
3157
|
+
n(), r(new Error("timeout")), t.close();
|
|
3158
|
+
}, a);
|
|
3159
|
+
this.opts.autoUnref && u.unref(), this.subs.push(() => {
|
|
3160
|
+
this.clearTimeoutFn(u);
|
|
3161
|
+
});
|
|
3162
|
+
}
|
|
3163
|
+
return this.subs.push(n), this.subs.push(o), this;
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
/**
|
|
3167
|
+
* Alias for open()
|
|
3168
|
+
*
|
|
3169
|
+
* @return self
|
|
3170
|
+
* @public
|
|
3171
|
+
*/
|
|
3172
|
+
connect(e) {
|
|
3173
|
+
return this.open(e);
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
/**
|
|
3177
|
+
* Called upon transport open.
|
|
3178
|
+
*
|
|
3179
|
+
* @private
|
|
3180
|
+
*/
|
|
3181
|
+
onopen() {
|
|
3182
|
+
this.cleanup(), this._readyState = "open", this.emitReserved("open");
|
|
3183
|
+
const e = this.engine;
|
|
3184
|
+
this.subs.push(
|
|
3185
|
+
_(e, "ping", this.onping.bind(this)),
|
|
3186
|
+
_(e, "data", this.ondata.bind(this)),
|
|
3187
|
+
_(e, "error", this.onerror.bind(this)),
|
|
3188
|
+
_(e, "close", this.onclose.bind(this)),
|
|
3189
|
+
// @ts-ignore
|
|
3190
|
+
_(this.decoder, "decoded", this.ondecoded.bind(this))
|
|
3191
|
+
);
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
/**
|
|
3195
|
+
* Called upon a ping.
|
|
3196
|
+
*
|
|
3197
|
+
* @private
|
|
3198
|
+
*/
|
|
3199
|
+
onping() {
|
|
3200
|
+
this.emitReserved("ping");
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
/**
|
|
3204
|
+
* Called with data.
|
|
3205
|
+
*
|
|
3206
|
+
* @private
|
|
3207
|
+
*/
|
|
3208
|
+
ondata(e) {
|
|
3209
|
+
try {
|
|
3210
|
+
this.decoder.add(e);
|
|
3211
|
+
} catch (t) {
|
|
3212
|
+
this.onclose("parse error", t);
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
/**
|
|
3217
|
+
* Called when parser fully decodes a packet.
|
|
3218
|
+
*
|
|
3219
|
+
* @private
|
|
3220
|
+
*/
|
|
3221
|
+
ondecoded(e) {
|
|
3222
|
+
he(() => {
|
|
3223
|
+
this.emitReserved("packet", e);
|
|
3224
|
+
}, this.setTimeoutFn);
|
|
3225
|
+
}
|
|
3226
|
+
|
|
3227
|
+
/**
|
|
3228
|
+
* Called upon socket error.
|
|
3229
|
+
*
|
|
3230
|
+
* @private
|
|
3231
|
+
*/
|
|
3232
|
+
onerror(e) {
|
|
3233
|
+
this.emitReserved("error", e);
|
|
3234
|
+
}
|
|
3235
|
+
|
|
3236
|
+
/**
|
|
3237
|
+
* Creates a new socket for the given `nsp`.
|
|
3238
|
+
*
|
|
3239
|
+
* @return {Socket}
|
|
3240
|
+
* @public
|
|
3241
|
+
*/
|
|
3242
|
+
socket(e, t) {
|
|
3243
|
+
let s = this.nsps[e];
|
|
3244
|
+
return s ? this._autoConnect && !s.active && s.connect() : (s = new wt(this, e, t), this.nsps[e] = s), s;
|
|
3245
|
+
}
|
|
3246
|
+
|
|
3247
|
+
/**
|
|
3248
|
+
* Called upon a socket close.
|
|
3249
|
+
*
|
|
3250
|
+
* @param socket
|
|
3251
|
+
* @private
|
|
3252
|
+
*/
|
|
3253
|
+
_destroy(e) {
|
|
3254
|
+
const t = Object.keys(this.nsps);
|
|
3255
|
+
for (const s of t) {
|
|
3256
|
+
if (this.nsps[s].active) { return; }
|
|
3257
|
+
}
|
|
3258
|
+
this._close();
|
|
3259
|
+
}
|
|
3260
|
+
|
|
3261
|
+
/**
|
|
3262
|
+
* Writes a packet.
|
|
3263
|
+
*
|
|
3264
|
+
* @param packet
|
|
3265
|
+
* @private
|
|
3266
|
+
*/
|
|
3267
|
+
_packet(e) {
|
|
3268
|
+
const t = this.encoder.encode(e);
|
|
3269
|
+
for (let s = 0; s < t.length; s++) { this.engine.write(t[s], e.options); }
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
/**
|
|
3273
|
+
* Clean up transport subscriptions and packet buffer.
|
|
3274
|
+
*
|
|
3275
|
+
* @private
|
|
3276
|
+
*/
|
|
3277
|
+
cleanup() {
|
|
3278
|
+
this.subs.forEach((e) => e()), this.subs.length = 0, this.decoder.destroy();
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
/**
|
|
3282
|
+
* Close the current socket.
|
|
3283
|
+
*
|
|
3284
|
+
* @private
|
|
3285
|
+
*/
|
|
3286
|
+
_close() {
|
|
3287
|
+
this.skipReconnect = !0, this._reconnecting = !1, this.onclose("forced close");
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3290
|
+
/**
|
|
3291
|
+
* Alias for close()
|
|
3292
|
+
*
|
|
3293
|
+
* @private
|
|
3294
|
+
*/
|
|
3295
|
+
disconnect() {
|
|
3296
|
+
return this._close();
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
/**
|
|
3300
|
+
* Called when:
|
|
3301
|
+
*
|
|
3302
|
+
* - the low-level engine is closed
|
|
3303
|
+
* - the parser encountered a badly formatted packet
|
|
3304
|
+
* - all sockets are disconnected
|
|
3305
|
+
*
|
|
3306
|
+
* @private
|
|
3307
|
+
*/
|
|
3308
|
+
onclose(e, t) {
|
|
3309
|
+
let s;
|
|
3310
|
+
this.cleanup(), (s = this.engine) === null || s === void 0 || s.close(), this.backoff.reset(), this._readyState = "closed", this.emitReserved("close", e, t), this._reconnection && !this.skipReconnect && this.reconnect();
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
/**
|
|
3314
|
+
* Attempt a reconnection.
|
|
3315
|
+
*
|
|
3316
|
+
* @private
|
|
3317
|
+
*/
|
|
3318
|
+
reconnect() {
|
|
3319
|
+
if (this._reconnecting || this.skipReconnect) { return this; }
|
|
3320
|
+
const e = this;
|
|
3321
|
+
if (this.backoff.attempts >= this._reconnectionAttempts) { this.backoff.reset(), this.emitReserved("reconnect_failed"), this._reconnecting = !1; } else {
|
|
3322
|
+
const t = this.backoff.duration();
|
|
3323
|
+
this._reconnecting = !0;
|
|
3324
|
+
const s = this.setTimeoutFn(() => {
|
|
3325
|
+
e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), !e.skipReconnect && e.open((n) => {
|
|
3326
|
+
n ? (e._reconnecting = !1, e.reconnect(), this.emitReserved("reconnect_error", n)) : e.onreconnect();
|
|
3327
|
+
}));
|
|
3328
|
+
}, t);
|
|
3329
|
+
this.opts.autoUnref && s.unref(), this.subs.push(() => {
|
|
3330
|
+
this.clearTimeoutFn(s);
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
/**
|
|
3336
|
+
* Called upon successful reconnect.
|
|
3337
|
+
*
|
|
3338
|
+
* @private
|
|
3339
|
+
*/
|
|
3340
|
+
onreconnect() {
|
|
3341
|
+
const e = this.backoff.attempts;
|
|
3342
|
+
this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
const V = {};
|
|
3346
|
+
function re(i, e) {
|
|
3347
|
+
typeof i == "object" && (e = i, i = void 0), e = e || {};
|
|
3348
|
+
const t = xs(i, e.path || "/socket.io"), s = t.source, n = t.id, r = t.path, o = V[n] && r in V[n].nsps, a = e.forceNew || e["force new connection"] || e.multiplex === !1 || o;
|
|
3349
|
+
let u;
|
|
3350
|
+
return a ? u = new Ae(s, e) : (V[n] || (V[n] = new Ae(s, e)), u = V[n]), t.query && !e.query && (e.query = t.queryKey), u.socket(t.path, e);
|
|
3351
|
+
}
|
|
3352
|
+
Object.assign(re, {
|
|
3353
|
+
Manager: Ae,
|
|
3354
|
+
Socket: wt,
|
|
3355
|
+
io: re,
|
|
3356
|
+
connect: re
|
|
3357
|
+
});
|
|
3358
|
+
class bt {
|
|
3359
|
+
constructor(e, t, s = {}) {
|
|
3360
|
+
this.url = e, this.socket = null, this.reconnect = t, this.query = s, this.eventListeners = {}, this.errorCount = 0, this.isErrorShown = !1, this.maxReconnectAttempts = 5, this.currentReconnectAttempt = 0, this.reconnectDelay = 3e3;
|
|
3361
|
+
}
|
|
3362
|
+
openConnect() {
|
|
3363
|
+
return this.socket && (this.socket.disconnect(), this.socket = null), this.socket = re(this.url, {
|
|
3364
|
+
transports: ["websocket"],
|
|
3365
|
+
// 使用websocket协议
|
|
3366
|
+
autoConnect: !1,
|
|
3367
|
+
reconnection: this.reconnect || !1,
|
|
3368
|
+
timeout: 5e5,
|
|
3369
|
+
forceNew: !0,
|
|
3370
|
+
query: this.query,
|
|
3371
|
+
// 动态查询参数,由调用处传入
|
|
3372
|
+
withCredentials: !0
|
|
3373
|
+
// 跨域时携带 Cookie
|
|
3374
|
+
}), new Promise((e, t) => {
|
|
3375
|
+
this.socket.on("connect", () => {
|
|
3376
|
+
this.errorCount = 0, this.isErrorShown = !1, this.currentReconnectAttempt = 0, console.log("Socket.IO 连接成功"), e(this.socket);
|
|
3377
|
+
}), this.socket.on("connect_error", (s) => {
|
|
3378
|
+
this.errorCount++, this.isErrorShown || (console.error("Socket.IO 连接失败"), console.error("错误详情:", s.message), this.isErrorShown = !0), this.errorCount === 1 && (this.disconnect(), t(new Error(`Socket.IO 连接失败: ${s.message}`)));
|
|
3379
|
+
}), this.socket.on("disconnect", (s) => {
|
|
3380
|
+
console.log("Socket.IO 连接已断开,原因:", s), this.isErrorShown = !1, this.reconnect && s !== "io client disconnect" && (this.currentReconnectAttempt < this.maxReconnectAttempts ? (this.currentReconnectAttempt++, console.log(`准备第 ${this.currentReconnectAttempt} 次重连...`), setTimeout(() => {
|
|
3381
|
+
this.socket.connect();
|
|
3382
|
+
}, this.reconnectDelay)) : console.log("已达到最大重连次数,停止重连"));
|
|
3383
|
+
}), this.socket.connect();
|
|
3384
|
+
});
|
|
3385
|
+
}
|
|
3386
|
+
// 添加事件监听器
|
|
3387
|
+
on(e, t) {
|
|
3388
|
+
if (!this.socket) {
|
|
3389
|
+
console.error("Socket未初始化,请先调用openConnect()");
|
|
3390
|
+
return;
|
|
3391
|
+
}
|
|
3392
|
+
this.socket.on(e, t);
|
|
3393
|
+
}
|
|
3394
|
+
// 移除事件监听器
|
|
3395
|
+
off(e, t) {
|
|
3396
|
+
if (!this.socket) {
|
|
3397
|
+
console.error("Socket未初始化,请先调用openConnect()");
|
|
3398
|
+
return;
|
|
3399
|
+
}
|
|
3400
|
+
this.socket.off(e, t);
|
|
3401
|
+
}
|
|
3402
|
+
// 发送自定义事件
|
|
3403
|
+
emit(e, t) {
|
|
3404
|
+
if (!this.socket) {
|
|
3405
|
+
console.error("Socket未初始化,请先调用openConnect()");
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
this.socket.emit(e, t);
|
|
3409
|
+
}
|
|
3410
|
+
// 断开连接
|
|
3411
|
+
disconnect() {
|
|
3412
|
+
if (!this.socket) {
|
|
3413
|
+
console.error("Socket未初始化,请先调用openConnect()");
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3416
|
+
this.socket.disconnect(), this.socket = null;
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
class Ks extends ue {
|
|
3420
|
+
constructor(e, t, s, n, r) {
|
|
3421
|
+
super(), this.equipStatusObject = t, this.groupNodeObject = s, this.aleadyUpdateStatus = {}, this.isGetAllEquipStatus = !1, this.nodesMap = e, this.statusChange = n, this.openSignlr(), this.aliasName = r;
|
|
3422
|
+
}
|
|
3423
|
+
openSignlr() {
|
|
3424
|
+
const t = `${location.protocol === "https:" ? "https" : "http"}://${location.hostname}:9600`;
|
|
3425
|
+
this.equipStatusSignlr = new bt(
|
|
3426
|
+
t,
|
|
3427
|
+
!0,
|
|
3428
|
+
{ hub: "equipStatusMonitor", userName: sessionStorage.userName }
|
|
3429
|
+
), this.equipStatusSignlr.openConnect().then((s) => {
|
|
3430
|
+
s.on("connect", () => {
|
|
3431
|
+
try {
|
|
3432
|
+
s.emit("invoke", { method: "GetAllEquipStatus", data: {} }), s.emit("invoke", { method: "GetEquipChangeStatus", data: {} });
|
|
3433
|
+
} catch (n) {
|
|
3434
|
+
console.log(n);
|
|
3435
|
+
}
|
|
3436
|
+
});
|
|
3437
|
+
try {
|
|
3438
|
+
s.emit("invoke", { method: "GetAllEquipStatus", data: {} });
|
|
3439
|
+
} catch (n) {
|
|
3440
|
+
console.log(n);
|
|
3441
|
+
}
|
|
3442
|
+
this.subscribeTo(s, "GetAllEquipStatus");
|
|
3443
|
+
try {
|
|
3444
|
+
s.emit("invoke", { method: "GetEquipChangeStatus", data: {} });
|
|
3445
|
+
} catch (n) {
|
|
3446
|
+
console.log(n);
|
|
3447
|
+
}
|
|
3448
|
+
this.subscribeTo(s, "GetEquipChangeStatus");
|
|
3449
|
+
}).catch((s) => {
|
|
3450
|
+
console.error(s);
|
|
3451
|
+
});
|
|
3452
|
+
}
|
|
3453
|
+
subscribeTo(e, t) {
|
|
3454
|
+
e.off(t), e.on(t, (s) => {
|
|
3455
|
+
const n = s == null ? void 0 : s.data;
|
|
3456
|
+
n && n.isSuccess && n.data && (this[t] ? this[t](n.data) : this.notice({ func: t, data: n.data, key: n.groupId }));
|
|
3457
|
+
});
|
|
3458
|
+
}
|
|
3459
|
+
GetAllEquipStatus(e) {
|
|
3460
|
+
this.isGetAllEquipStatus = !0, this.resetGroupStatus(), this.aleadyUpdateStatus = {}, Object.keys(e).forEach((t) => {
|
|
3461
|
+
this.equipStatusObject[t] = e[t];
|
|
3462
|
+
}), Object.keys(this.groupNodeObject).forEach((t) => {
|
|
3463
|
+
this.updateByGroup(t);
|
|
3464
|
+
});
|
|
3465
|
+
}
|
|
3466
|
+
updateByGroup(e) {
|
|
3467
|
+
if (!this.aleadyUpdateStatus[e]) {
|
|
3468
|
+
let t = this.window[`group-${e}${this.aliasName}`] || [];
|
|
3469
|
+
if (t.length) {
|
|
3470
|
+
this.aleadyUpdateStatus[e] = !0;
|
|
3471
|
+
let s = !1, n = !0;
|
|
3472
|
+
t.forEach((r) => {
|
|
3473
|
+
const o = this.equipStatusObject[r.equipNo];
|
|
3474
|
+
o === 1 ? (s = !0, n = !1) : o !== 0 && (n = !1);
|
|
3475
|
+
}), n && this.setOfflineStatus(e), t.forEach((r) => {
|
|
3476
|
+
this.equipStatusObject[r.equipNo] == 2 ? this.setGroupStatus(e, !0, 2) : this.equipStatusObject[r.equipNo] == 6 && this.setGroupStatus(e, !0, 6), this.nodesMap[`${e}-${r.equipNo}`] && (this.nodesMap[`${e}-${r.equipNo}`].status = this.equipStatusObject[r.equipNo]);
|
|
3477
|
+
}), this.nodesMap[e].alarmCounts === 0 && this.nodesMap[e].backUpCounts === 0 && s && (this.nodesMap[e].status = 1, this.nodesMap[e].groupId && this.setNormalStatus(this.nodesMap[e].groupId));
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
updateGroupStatus(e) {
|
|
3482
|
+
this.isGetAllEquipStatus && this.updateByGroup(e);
|
|
3483
|
+
}
|
|
3484
|
+
GetEquipChangeStatus(e) {
|
|
3485
|
+
this.setStatus(e);
|
|
3486
|
+
}
|
|
3487
|
+
// 设置分组状态 key:扁平化数据中节点索引;type:类型(增加,减少);status:状态(报警2、双机热备6)
|
|
3488
|
+
setGroupStatus(e, t, s) {
|
|
3489
|
+
t ? s == 2 ? (this.nodesMap[e].alarmCounts = this.nodesMap[e].alarmCounts + 1, this.nodesMap[e].alarmCounts > 0 && (this.nodesMap[e].status = 2)) : (this.nodesMap[e].backUpCounts = this.nodesMap[e].backUpCounts + 1, this.nodesMap[e].alarmCounts == 0 && this.nodesMap[e].backUpCounts > 0 && (this.nodesMap[e].status = 6)) : s == 2 ? (this.nodesMap[e].alarmCounts = this.nodesMap[e].alarmCounts - 1, this.nodesMap[e].alarmCounts == 0 && (this.nodesMap[e].status = 1)) : (this.nodesMap[e].backUpCounts = this.nodesMap[e].backUpCounts - 1, this.nodesMap[e].alarmCounts == 0 && (this.nodesMap[e].backUpCounts == 0 ? this.nodesMap[e].status = 1 : this.nodesMap[e].status = 6)), this.nodesMap[e].groupId && this.setGroupStatus(this.nodesMap[e].groupId, t, s);
|
|
3490
|
+
}
|
|
3491
|
+
// 设置分组离线状态并向上冒泡(不覆盖正常、报警、双机热备状态)
|
|
3492
|
+
setOfflineStatus(e) {
|
|
3493
|
+
this.nodesMap[e].status !== 2 && this.nodesMap[e].status !== 6 && this.nodesMap[e].status !== 1 && (this.nodesMap[e].status = 0, this.nodesMap[e].groupId && this.setOfflineStatus(this.nodesMap[e].groupId));
|
|
3494
|
+
}
|
|
3495
|
+
// 设置分组正常状态并向上冒泡(不覆盖报警和双机热备状态)
|
|
3496
|
+
setNormalStatus(e) {
|
|
3497
|
+
this.nodesMap[e].status !== 2 && this.nodesMap[e].status !== 6 && (this.nodesMap[e].status = 1, this.nodesMap[e].groupId && this.setNormalStatus(this.nodesMap[e].groupId));
|
|
3498
|
+
}
|
|
3499
|
+
// 获取设备所属的所有分组ID
|
|
3500
|
+
// 优先从 groupCache 反查(按分组隔离存储,数据准确),兜底从 equipCache 获取
|
|
3501
|
+
getEquipGroupIds(e) {
|
|
3502
|
+
const t = [];
|
|
3503
|
+
if (this.window.groupCache && Object.keys(this.window.groupCache).forEach((s) => {
|
|
3504
|
+
this.window.groupCache[s] && this.window.groupCache[s][e] && t.push(Number(s));
|
|
3505
|
+
}), t.length === 0) {
|
|
3506
|
+
const s = this.window.equipCache && this.window.equipCache[e];
|
|
3507
|
+
if (s) {
|
|
3508
|
+
if (s.groupIds && s.groupIds.length > 0) { return s.groupIds; }
|
|
3509
|
+
s.groupId && t.push(s.groupId);
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
return t;
|
|
3513
|
+
}
|
|
3514
|
+
setStatus(e) {
|
|
3515
|
+
let t = this.equipStatusObject[e.equipNo];
|
|
3516
|
+
const s = this.getEquipGroupIds(e.equipNo);
|
|
3517
|
+
e.status != 3 && s.length > 0 && (s.forEach((n) => {
|
|
3518
|
+
switch (e.status) {
|
|
3519
|
+
case 0:
|
|
3520
|
+
t == 6 && this.setGroupStatus(n, !1, 6);
|
|
3521
|
+
break;
|
|
3522
|
+
case 1:
|
|
3523
|
+
t == 6 ? this.setGroupStatus(n, !1, 6) : t == 2 && this.setGroupStatus(n, !1, 2);
|
|
3524
|
+
break;
|
|
3525
|
+
case 2:
|
|
3526
|
+
t != 2 && this.setGroupStatus(n, !0, 2), t == 6 && this.setGroupStatus(n, !1, 6);
|
|
3527
|
+
break;
|
|
3528
|
+
case 6:
|
|
3529
|
+
t == 2 && this.setGroupStatus(n, !1, 2), t != 6 && this.setGroupStatus(n, !0, 6);
|
|
3530
|
+
break;
|
|
3531
|
+
}
|
|
3532
|
+
let r = `${n}-${e.equipNo}`;
|
|
3533
|
+
this.nodesMap[r] && (this.nodesMap[r].status = e.status);
|
|
3534
|
+
}), this.equipStatusObject[e.equipNo] = e.status, this.statusChange(s[0], e.equipNo, e.status));
|
|
3535
|
+
}
|
|
3536
|
+
// 重置分组状态
|
|
3537
|
+
resetGroupStatus() {
|
|
3538
|
+
for (let e in this.groupNodeObject) { this.groupNodeObject[e].alarmCounts = 0, this.groupNodeObject[e].backUpCount = 0; }
|
|
3539
|
+
}
|
|
3540
|
+
// 断开 Socket.IO 连接
|
|
3541
|
+
disconnect() {
|
|
3542
|
+
this.equipStatusSignlr && (this.equipStatusSignlr.disconnect(), this.equipStatusSignlr = null);
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
const Ws = {
|
|
3546
|
+
getSetParm(i) {
|
|
3547
|
+
if (window.AxiosBuilder.axios) {
|
|
3548
|
+
return window.AxiosBuilder.axios({
|
|
3549
|
+
method: "post",
|
|
3550
|
+
url: "/IoT/api/v3/EquipList/GetFullSetParmByEquipNo",
|
|
3551
|
+
params: i,
|
|
3552
|
+
data: i,
|
|
3553
|
+
headers: {
|
|
3554
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
3555
|
+
"Accept-Language": window.sessionStorage.languageType || "zh-CN"
|
|
3556
|
+
}
|
|
3557
|
+
});
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
}, Hs = Object.assign(
|
|
3561
|
+
{},
|
|
3562
|
+
Ws
|
|
3563
|
+
);
|
|
3564
|
+
class Js {
|
|
3565
|
+
constructor(e, t) {
|
|
3566
|
+
this.nodesMap = e, this.equipControllObject = t;
|
|
3567
|
+
}
|
|
3568
|
+
// 获取设备控制项
|
|
3569
|
+
async getSetting(e, t, s, n) {
|
|
3570
|
+
let [r, o] = String(e).split("-"), a = {
|
|
3571
|
+
equipNo: o
|
|
3572
|
+
};
|
|
3573
|
+
await Hs.getSetParm(a).then((u) => {
|
|
3574
|
+
if (u.data.code == 200) {
|
|
3575
|
+
let c = u && u.data && u.data.data && u.data.data.rows || [];
|
|
3576
|
+
this.nodesMap[e].settings || (this.nodesMap[e].settings = []), c && c.length > 0 && this.nodesMap[e] && (c.forEach((h) => {
|
|
3577
|
+
h.title = h.setNm, h.key = `${r}-${o}-${h.setNo}`, h.level = Number(s) + 1, h.checked = n || this.equipControllObject[o] && this.equipControllObject[o].includes(h.setNo), h.isSetting = !0, h.equipNo = o, h.groupId = r, h.setNo = h.setNo, h.equipName = t;
|
|
3578
|
+
}), this.nodesMap[e].settings = [...c]);
|
|
3579
|
+
}
|
|
3580
|
+
});
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
class M {
|
|
3584
|
+
static formateList(e, t) {
|
|
3585
|
+
let s = [];
|
|
3586
|
+
for (const n of e) {
|
|
3587
|
+
let r = {};
|
|
3588
|
+
r.count = 0, r.equipSelectCount = 0, r.controlSelectCount = 0, r.equipCount = n.equipCount || 0, r.title = n.name, r.key = n.id, r.isGroup = !0, r.children = [], r.status = 1, r.level = t || 1, r.expand = !t, r.equips = [], r.groupId = n.parentId, r.groups = [], r.alarmCounts = 0, r.backUpCounts = 0, r.indeterminate = !1, r.checked = !1, r.visible = !0, r.nodeEquipSelectCount = 0, r.checkedEquips = [], r.halfCheckedEquips = [], r.selectControlCount = 0, n.children && n.children.length > 0 && (r.groups = [
|
|
3589
|
+
...this.formateList(n.children, t ? t + 1 : 2)
|
|
3590
|
+
]), s.push(r);
|
|
3591
|
+
}
|
|
3592
|
+
return s;
|
|
3593
|
+
}
|
|
3594
|
+
static deepClone(e, t, s, n, r, o) {
|
|
3595
|
+
let a = [];
|
|
3596
|
+
if (e) {
|
|
3597
|
+
for (let u = 0, c = e.length; u < c; u++) {
|
|
3598
|
+
const h = e[u].id || e[u].equipNo, l = `${n}-${h}`;
|
|
3599
|
+
a.push(
|
|
3600
|
+
{
|
|
3601
|
+
isGroup: s,
|
|
3602
|
+
key: l,
|
|
3603
|
+
status: o[h] || 0,
|
|
3604
|
+
title: e[u].title,
|
|
3605
|
+
level: t,
|
|
3606
|
+
expand: !1,
|
|
3607
|
+
isEquip: !0,
|
|
3608
|
+
loading: !1,
|
|
3609
|
+
indeterminate: r[l] && r[l].indeterminate || !1,
|
|
3610
|
+
checked: r[l] && r[l].checked || !1,
|
|
3611
|
+
groupId: n,
|
|
3612
|
+
equipNo: h,
|
|
3613
|
+
visible: !0,
|
|
3614
|
+
settings: []
|
|
3615
|
+
}
|
|
3616
|
+
);
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
return a;
|
|
3620
|
+
}
|
|
3621
|
+
static copyOrigin(e) {
|
|
3622
|
+
let t = [];
|
|
3623
|
+
return e.forEach((s) => {
|
|
3624
|
+
t.push({ ...s });
|
|
3625
|
+
}), t;
|
|
3626
|
+
}
|
|
3627
|
+
// 获取分组位置
|
|
3628
|
+
static getPosition(e, t) {
|
|
3629
|
+
let s = 0;
|
|
3630
|
+
for (let n = 0, r = t.length; n < r; n++) {
|
|
3631
|
+
if (t[n].key == e) {
|
|
3632
|
+
s = n - 30;
|
|
3633
|
+
break;
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
return s;
|
|
3637
|
+
}
|
|
3638
|
+
// 扁平化
|
|
3639
|
+
static flattern(e, t) {
|
|
3640
|
+
e.forEach((s) => {
|
|
3641
|
+
if (s.isGroup) {
|
|
3642
|
+
const n = t[`${s.key}`];
|
|
3643
|
+
t[`${s.key}`] = s, n && (s.alarmCounts = n.alarmCounts, s.backUpCounts = n.backUpCounts, s.status = n.status);
|
|
3644
|
+
}
|
|
3645
|
+
s.groups && s.groups.length && this.flattern(s.groups, t);
|
|
3646
|
+
});
|
|
3647
|
+
}
|
|
3648
|
+
|
|
3649
|
+
/**
|
|
3650
|
+
* @description 生成唯一Id
|
|
3651
|
+
* @param {} 不用传参
|
|
3652
|
+
* @return {string}
|
|
3653
|
+
*/
|
|
3654
|
+
static generateUUID() {
|
|
3655
|
+
let e = (/* @__PURE__ */ new Date()).getTime();
|
|
3656
|
+
return window.performance && typeof window.performance.now == "function" && (e += performance.now()), "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(s) {
|
|
3657
|
+
let n = (e + Math.random() * 16) % 16 | 0;
|
|
3658
|
+
return e = Math.floor(e / 16), (s === "x" ? n : n & 3 | 8).toString(16);
|
|
3659
|
+
});
|
|
3660
|
+
}
|
|
3661
|
+
|
|
3662
|
+
/**
|
|
3663
|
+
* @description 将普通列表转换为树结构的列表
|
|
3664
|
+
* @param {list} 可构建树形结构的普通列表
|
|
3665
|
+
* @return {string}
|
|
3666
|
+
*/
|
|
3667
|
+
static listToTreeList(e) {
|
|
3668
|
+
const t = e, s = [], n = {};
|
|
3669
|
+
return t.forEach((r) => {
|
|
3670
|
+
n[r.id] = r;
|
|
3671
|
+
}), t.forEach((r) => {
|
|
3672
|
+
const o = n[r.parentId];
|
|
3673
|
+
o ? (o.children || (o.children = [])).push(r) : s.push(r);
|
|
3674
|
+
}), s;
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
class Ys extends ue {
|
|
3678
|
+
// 分组节点扁平化对象、设备扁平化对象、window缓存设备扁平化对象
|
|
3679
|
+
constructor(e, t, s) {
|
|
3680
|
+
super(), this.showSettings = t, this.groupNodeObject = e, this.aliasName = s;
|
|
3681
|
+
}
|
|
3682
|
+
// 触发搜索
|
|
3683
|
+
filterMethod(e) {
|
|
3684
|
+
for (let t in this.groupNodeObject) { e && this.updateBySearch(t, e); }
|
|
3685
|
+
}
|
|
3686
|
+
// 搜索状态将搜索的结果存放缓存中
|
|
3687
|
+
updateBySearch(e, t) {
|
|
3688
|
+
let s = this.window[`group-${this.groupNodeObject[e].key}${this.aliasName}`];
|
|
3689
|
+
s && (s = s.filter((n) => n.title.includes(t)), this.window[`group-${this.groupNodeObject[e].key}-search`] = M.copyOrigin(s));
|
|
3690
|
+
}
|
|
3691
|
+
}
|
|
3692
|
+
const le = (i, e) => {
|
|
3693
|
+
const t = i.__vccOpts || i;
|
|
3694
|
+
for (const [s, n] of e) { t[s] = n; }
|
|
3695
|
+
return t;
|
|
3696
|
+
}, Xs = {
|
|
3697
|
+
props: {
|
|
3698
|
+
source: {
|
|
3699
|
+
type: Object,
|
|
3700
|
+
default: () => {
|
|
3701
|
+
}
|
|
3702
|
+
},
|
|
3703
|
+
groupEditAndNew: {
|
|
3704
|
+
type: Function,
|
|
3705
|
+
default: () => {
|
|
3706
|
+
}
|
|
3707
|
+
},
|
|
3708
|
+
deleteGroup: {
|
|
3709
|
+
type: Function,
|
|
3710
|
+
default: () => {
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
}, Qs = { class: "operates" };
|
|
3715
|
+
function Zs(i, e, t, s, n, r) {
|
|
3716
|
+
const o = G("el-button"), a = G("el-button-group"), u = G("el-popover");
|
|
3717
|
+
return E(), T("div", Qs, [
|
|
3718
|
+
S(u, {
|
|
3719
|
+
placement: "bottom",
|
|
3720
|
+
trigger: "hover"
|
|
3721
|
+
}, {
|
|
3722
|
+
reference: P(() => e[6] || (e[6] = [
|
|
3723
|
+
x("i", { class: "iconfont icon-_gengduo" }, null, -1)
|
|
3724
|
+
])),
|
|
3725
|
+
default: P(() => [
|
|
3726
|
+
S(a, { class: "new-button-group setModule" }, {
|
|
3727
|
+
default: P(() => [
|
|
3728
|
+
S(o, {
|
|
3729
|
+
type: "text",
|
|
3730
|
+
size: "small",
|
|
3731
|
+
class: "elBtn",
|
|
3732
|
+
onClick: e[0] || (e[0] = _e((c) => t.groupEditAndNew(!1, t.source), ["stop"]))
|
|
3733
|
+
}, {
|
|
3734
|
+
default: P(() => [
|
|
3735
|
+
e[3] || (e[3] = x("i", { class: "iconfont icon-tubiao20_bianji" }, null, -1)),
|
|
3736
|
+
be(" " + H(i.$t("equipInfo.poverTips.rename")), 1)
|
|
3737
|
+
]),
|
|
3738
|
+
_: 1,
|
|
3739
|
+
__: [3]
|
|
3740
|
+
}),
|
|
3741
|
+
S(o, {
|
|
3742
|
+
type: "text",
|
|
3743
|
+
size: "small",
|
|
3744
|
+
class: "elBtn",
|
|
3745
|
+
onClick: e[1] || (e[1] = (c) => t.groupEditAndNew(!0, t.source))
|
|
3746
|
+
}, {
|
|
3747
|
+
default: P(() => [
|
|
3748
|
+
e[4] || (e[4] = x("i", { class: "iconfont icon-tubiao20_tianjiashebei" }, null, -1)),
|
|
3749
|
+
be(" " + H(i.$t("equipInfo.poverTips.newChildGroup")), 1)
|
|
3750
|
+
]),
|
|
3751
|
+
_: 1,
|
|
3752
|
+
__: [4]
|
|
3753
|
+
}),
|
|
3754
|
+
t.source.level != 1 ? (E(), oe(o, {
|
|
3755
|
+
key: 0,
|
|
3756
|
+
type: "text",
|
|
3757
|
+
size: "small",
|
|
3758
|
+
class: "delete-btn",
|
|
3759
|
+
onClick: e[2] || (e[2] = _e((c) => t.deleteGroup(t.source), ["stop"]))
|
|
3760
|
+
}, {
|
|
3761
|
+
default: P(() => [
|
|
3762
|
+
e[5] || (e[5] = x("i", { class: "iconfont icon-tubiao20_shanchu" }, null, -1)),
|
|
3763
|
+
be(" " + H(i.$t("publics.button.deletes")), 1)
|
|
3764
|
+
]),
|
|
3765
|
+
_: 1,
|
|
3766
|
+
__: [5]
|
|
3767
|
+
})) : L("", !0)
|
|
3768
|
+
]),
|
|
3769
|
+
_: 1
|
|
3770
|
+
})
|
|
3771
|
+
]),
|
|
3772
|
+
_: 1
|
|
3773
|
+
})
|
|
3774
|
+
]);
|
|
3775
|
+
}
|
|
3776
|
+
const ei = /* @__PURE__ */ le(Xs, [["render", Zs]]), ti = {
|
|
3777
|
+
name: "ElTreeVirtualNode",
|
|
3778
|
+
componentName: "ElTreeVirtualNode",
|
|
3779
|
+
props: {
|
|
3780
|
+
searchName: {
|
|
3781
|
+
type: String,
|
|
3782
|
+
default: ""
|
|
3783
|
+
},
|
|
3784
|
+
expanding: {
|
|
3785
|
+
type: Boolean,
|
|
3786
|
+
default: !1
|
|
3787
|
+
},
|
|
3788
|
+
aleadyLoadAll: {
|
|
3789
|
+
type: Boolean,
|
|
3790
|
+
default: !1
|
|
3791
|
+
},
|
|
3792
|
+
groupLoading: {
|
|
3793
|
+
type: Boolean,
|
|
3794
|
+
default: !1
|
|
3795
|
+
},
|
|
3796
|
+
source: {
|
|
3797
|
+
type: Object,
|
|
3798
|
+
default() {
|
|
3799
|
+
return {};
|
|
3800
|
+
}
|
|
3801
|
+
},
|
|
3802
|
+
showCheckbox: {
|
|
3803
|
+
type: Boolean,
|
|
3804
|
+
default: !1
|
|
3805
|
+
},
|
|
3806
|
+
showStatus: {
|
|
3807
|
+
type: Boolean,
|
|
3808
|
+
default: !1
|
|
3809
|
+
},
|
|
3810
|
+
showOperate: {
|
|
3811
|
+
type: Boolean,
|
|
3812
|
+
default: !1
|
|
3813
|
+
},
|
|
3814
|
+
currentSelect: {
|
|
3815
|
+
type: [Number, String],
|
|
3816
|
+
default: -1
|
|
3817
|
+
},
|
|
3818
|
+
nodeClick: {
|
|
3819
|
+
type: Function
|
|
3820
|
+
},
|
|
3821
|
+
onChecked: {
|
|
3822
|
+
type: Function
|
|
3823
|
+
},
|
|
3824
|
+
groupEditAndNew: {
|
|
3825
|
+
type: Function
|
|
3826
|
+
},
|
|
3827
|
+
deleteGroup: {
|
|
3828
|
+
type: Function
|
|
3829
|
+
},
|
|
3830
|
+
childrenResetGroupNum: {
|
|
3831
|
+
type: Function
|
|
3832
|
+
},
|
|
3833
|
+
getEquipStatus: {
|
|
3834
|
+
type: Function
|
|
3835
|
+
},
|
|
3836
|
+
colorConfig: {
|
|
3837
|
+
type: Object,
|
|
3838
|
+
default: () => {
|
|
3839
|
+
}
|
|
3840
|
+
},
|
|
3841
|
+
index: {
|
|
3842
|
+
type: Number,
|
|
3843
|
+
default: -1
|
|
3844
|
+
}
|
|
3845
|
+
},
|
|
3846
|
+
components: {
|
|
3847
|
+
oparate: ei
|
|
3848
|
+
},
|
|
3849
|
+
computed: {
|
|
3850
|
+
getColor() {
|
|
3851
|
+
return function(i) {
|
|
3852
|
+
this.colorConfig || (this.colorConfig = {
|
|
3853
|
+
noComm: "#a0a0a0",
|
|
3854
|
+
normal: "#63e03f",
|
|
3855
|
+
alarm: "#f22433",
|
|
3856
|
+
lsSet: "#bebcaa",
|
|
3857
|
+
initialize: "#289ac0",
|
|
3858
|
+
withdraw: "#ffc0cb",
|
|
3859
|
+
BackUp: "#f8901c"
|
|
3860
|
+
});
|
|
3861
|
+
let e;
|
|
3862
|
+
switch (i) {
|
|
3863
|
+
case 0:
|
|
3864
|
+
e = this.colorConfig.noComm;
|
|
3865
|
+
break;
|
|
3866
|
+
case 1:
|
|
3867
|
+
e = this.colorConfig.normal;
|
|
3868
|
+
break;
|
|
3869
|
+
case 2:
|
|
3870
|
+
e = this.colorConfig.alarm;
|
|
3871
|
+
break;
|
|
3872
|
+
case 3:
|
|
3873
|
+
e = this.colorConfig.lsSet;
|
|
3874
|
+
break;
|
|
3875
|
+
case 4:
|
|
3876
|
+
e = this.colorConfig.initialize;
|
|
3877
|
+
break;
|
|
3878
|
+
case 5:
|
|
3879
|
+
e = this.colorConfig.withdraw;
|
|
3880
|
+
break;
|
|
3881
|
+
case 6:
|
|
3882
|
+
e = this.colorConfig.BackUp;
|
|
3883
|
+
break;
|
|
3884
|
+
default:
|
|
3885
|
+
e = this.colorConfig.noComm;
|
|
3886
|
+
break;
|
|
3887
|
+
}
|
|
3888
|
+
return e;
|
|
3889
|
+
};
|
|
3890
|
+
}
|
|
3891
|
+
},
|
|
3892
|
+
data() {
|
|
3893
|
+
return {
|
|
3894
|
+
indent: 13
|
|
3895
|
+
};
|
|
3896
|
+
},
|
|
3897
|
+
methods: {
|
|
3898
|
+
clickFunction() {
|
|
3899
|
+
this.source.expand = !this.source.expand, this.nodeClick(this.source, this.index, this.source.level, this.source.checked);
|
|
3900
|
+
},
|
|
3901
|
+
checkedChange(i) {
|
|
3902
|
+
this.onChecked(this.source);
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
}, si = { class: "el-tree-node__content" }, ii = { class: "nodeContent" }, ni = {
|
|
3906
|
+
key: 1,
|
|
3907
|
+
class: "circle"
|
|
3908
|
+
}, ri = { class: "label" }, oi = {
|
|
3909
|
+
key: 2,
|
|
3910
|
+
class: "equipNumber"
|
|
3911
|
+
}, ai = {
|
|
3912
|
+
key: 4,
|
|
3913
|
+
class: "el-tree-node__loading-icon el-icon-loading"
|
|
3914
|
+
};
|
|
3915
|
+
function ui(i, e, t, s, n, r) {
|
|
3916
|
+
const o = G("el-checkbox"), a = G("oparate");
|
|
3917
|
+
return E(), T("div", {
|
|
3918
|
+
class: Ve(["el-tree-node", {
|
|
3919
|
+
parent_tag: t.source.isGroup,
|
|
3920
|
+
child_tags: !t.source.isGroup,
|
|
3921
|
+
selectedColor: t.currentSelect === t.source.key && !t.source.isGroup
|
|
3922
|
+
}]),
|
|
3923
|
+
onClick: e[2] || (e[2] = (...u) => r.clickFunction && r.clickFunction(...u))
|
|
3924
|
+
}, [
|
|
3925
|
+
x("div", si, [
|
|
3926
|
+
x("span", {
|
|
3927
|
+
class: "el-tree__indent",
|
|
3928
|
+
"aria-hidden": "true",
|
|
3929
|
+
style: Se({ width: (t.source.level - 1) * n.indent + "px" })
|
|
3930
|
+
}, null, 4),
|
|
3931
|
+
t.source.isGroup ? (E(), T("span", {
|
|
3932
|
+
key: 0,
|
|
3933
|
+
class: Ve([
|
|
3934
|
+
{
|
|
3935
|
+
"is-leaf": !t.source.isGroup,
|
|
3936
|
+
expanded: t.source.isGroup && t.source.expand
|
|
3937
|
+
},
|
|
3938
|
+
"el-tree-node__expand-icon",
|
|
3939
|
+
"iconfont icon-fangxiangL"
|
|
3940
|
+
])
|
|
3941
|
+
}, null, 2)) : L("", !0),
|
|
3942
|
+
x("div", ii, [
|
|
3943
|
+
t.showCheckbox ? (E(), oe(o, {
|
|
3944
|
+
key: 0,
|
|
3945
|
+
onClick: e[0] || (e[0] = _e(() => {
|
|
3946
|
+
}, ["stop"])),
|
|
3947
|
+
modelValue: t.source.checked,
|
|
3948
|
+
"onUpdate:modelValue": e[1] || (e[1] = (u) => t.source.checked = u),
|
|
3949
|
+
indeterminate: t.source.indeterminate,
|
|
3950
|
+
onChange: r.checkedChange
|
|
3951
|
+
}, null, 8, ["modelValue", "indeterminate", "onChange"])) : L("", !0),
|
|
3952
|
+
t.showStatus ? (E(), T("span", ni, [
|
|
3953
|
+
t.source.status != 6 ? (E(), T("span", {
|
|
3954
|
+
key: 0,
|
|
3955
|
+
class: "yd",
|
|
3956
|
+
style: Se({ backgroundColor: r.getColor(t.source.status) })
|
|
3957
|
+
}, null, 4)) : (E(), T("i", {
|
|
3958
|
+
key: 1,
|
|
3959
|
+
style: Se({ color: t.colorConfig.BackUp }),
|
|
3960
|
+
class: "iconfont icon-gw-icon-beiji2"
|
|
3961
|
+
}, null, 4))
|
|
3962
|
+
])) : L("", !0),
|
|
3963
|
+
x("span", ri, H(t.source.title), 1),
|
|
3964
|
+
t.source.isGroup && !t.source.isEquip || t.source.isGroup && !t.source.isEquip ? (E(), T("span", oi, H(t.source.count), 1)) : L("", !0),
|
|
3965
|
+
t.source.isGroup && t.showOperate ? (E(), oe(a, {
|
|
3966
|
+
key: 3,
|
|
3967
|
+
source: t.source,
|
|
3968
|
+
groupEditAndNew: t.groupEditAndNew,
|
|
3969
|
+
deleteGroup: t.deleteGroup
|
|
3970
|
+
}, null, 8, ["source", "groupEditAndNew", "deleteGroup"])) : L("", !0),
|
|
3971
|
+
t.source.loading ? (E(), T("span", ai)) : L("", !0)
|
|
3972
|
+
])
|
|
3973
|
+
])
|
|
3974
|
+
], 2);
|
|
3975
|
+
}
|
|
3976
|
+
const hi = /* @__PURE__ */ le(ti, [["render", ui]]), ci = {
|
|
3977
|
+
components: {
|
|
3978
|
+
VirtualList: Kt
|
|
3979
|
+
},
|
|
3980
|
+
mixins: [it],
|
|
3981
|
+
data() {
|
|
3982
|
+
return {
|
|
3983
|
+
itemComponent: hi,
|
|
3984
|
+
//节点组件
|
|
3985
|
+
visibleList: [],
|
|
3986
|
+
//虚拟滚动所需要的列表
|
|
3987
|
+
currentSelect: -1,
|
|
3988
|
+
//当前选中的节点(不包含分组节点)
|
|
3989
|
+
equipStatusManage: null,
|
|
3990
|
+
//设备状态管理工具
|
|
3991
|
+
cacheManage: null,
|
|
3992
|
+
//内存管理工具
|
|
3993
|
+
searchManage: null,
|
|
3994
|
+
//搜索管理工具
|
|
3995
|
+
equipNumManage: null,
|
|
3996
|
+
//设备数量管理工具
|
|
3997
|
+
requestManage: null,
|
|
3998
|
+
//请求管理工具
|
|
3999
|
+
checkStatusManage: null,
|
|
4000
|
+
//请求管理工具
|
|
4001
|
+
groupNodeObject: {},
|
|
4002
|
+
//所有分组扁平化所保存的存储的地方
|
|
4003
|
+
nodesMap: {},
|
|
4004
|
+
//所有实例化对象映射
|
|
4005
|
+
equipCheckObject: {},
|
|
4006
|
+
//设备选中状态记录 equipCheckObject:{xxx设备号:{indeterminate: false,checked: false,groupId:xxx}}
|
|
4007
|
+
equipStatusObject: {},
|
|
4008
|
+
//记录设备状态,从后台推送的初始化全量状态,增量更新需要实时维护
|
|
4009
|
+
controlObject: {},
|
|
4010
|
+
//展开的控制项,controlObject:{xxx设备号:{groupId:xxx}}用于设置当前展开设置选中,如果依赖与equipControlObject筛选设置选中,性能差
|
|
4011
|
+
isSearchStatus: !1,
|
|
4012
|
+
//是否是搜索状态
|
|
4013
|
+
equipControllObject: {},
|
|
4014
|
+
//绑定所有的已选中的设备控制项
|
|
4015
|
+
expandGroup: [],
|
|
4016
|
+
//记录已展开的分组
|
|
4017
|
+
updateJob: null,
|
|
4018
|
+
filterEquipList: []
|
|
4019
|
+
//过滤条件下新增的设备列表,由于设备开始状态都是0,因而需要单独维护
|
|
4020
|
+
};
|
|
4021
|
+
},
|
|
4022
|
+
props: {
|
|
4023
|
+
data: {
|
|
4024
|
+
//分组列表
|
|
4025
|
+
type: Array
|
|
4026
|
+
},
|
|
4027
|
+
selectEquips: {
|
|
4028
|
+
//设备选中列表,用于回显,如权限管理。支持数组格式 [equipNo] 或对象格式 { groupId: [equipNo] }
|
|
4029
|
+
type: [Array, Object],
|
|
4030
|
+
default: () => []
|
|
4031
|
+
},
|
|
4032
|
+
controllList: {
|
|
4033
|
+
//控制项选中列表,用于回显,如权限管理
|
|
4034
|
+
type: Array,
|
|
4035
|
+
default: () => []
|
|
4036
|
+
},
|
|
4037
|
+
showSettings: {
|
|
4038
|
+
//是否需要加载设备控制项,如权限管理
|
|
4039
|
+
type: Boolean,
|
|
4040
|
+
default: !1
|
|
4041
|
+
},
|
|
4042
|
+
showSelectNum: {
|
|
4043
|
+
//是否在树形结构顶部展示已选设备数量,如设备管理
|
|
4044
|
+
type: Boolean,
|
|
4045
|
+
default() {
|
|
4046
|
+
return !1;
|
|
4047
|
+
}
|
|
4048
|
+
},
|
|
4049
|
+
showCheckbox: {
|
|
4050
|
+
//是否展示checkbox
|
|
4051
|
+
type: Boolean,
|
|
4052
|
+
default: !1
|
|
4053
|
+
},
|
|
4054
|
+
showStatus: {
|
|
4055
|
+
//是否展示设备状态
|
|
4056
|
+
type: Boolean,
|
|
4057
|
+
default: !1
|
|
4058
|
+
},
|
|
4059
|
+
filterEquip: {
|
|
4060
|
+
//是否过滤
|
|
4061
|
+
type: Boolean,
|
|
4062
|
+
default: !1
|
|
4063
|
+
},
|
|
4064
|
+
showOperate: {
|
|
4065
|
+
// 是否展示操作按钮
|
|
4066
|
+
type: Boolean,
|
|
4067
|
+
default: !1
|
|
4068
|
+
},
|
|
4069
|
+
defaultExpandAll: {
|
|
4070
|
+
type: Boolean,
|
|
4071
|
+
default: !1
|
|
4072
|
+
},
|
|
4073
|
+
currentNodeKey: [String, Number],
|
|
4074
|
+
colorConfig: {
|
|
4075
|
+
type: Object,
|
|
4076
|
+
default: () => ({
|
|
4077
|
+
noComm: "#a0a0a0",
|
|
4078
|
+
normal: "#63e03f",
|
|
4079
|
+
alarm: "#f22433",
|
|
4080
|
+
lsSet: "#bebcaa",
|
|
4081
|
+
initialize: "#289ac0",
|
|
4082
|
+
withdraw: "#ffc0cb",
|
|
4083
|
+
BackUp: "#f8901c"
|
|
4084
|
+
})
|
|
4085
|
+
},
|
|
4086
|
+
treeType: {
|
|
4087
|
+
type: String,
|
|
4088
|
+
default: ""
|
|
4089
|
+
},
|
|
4090
|
+
buildTree: {
|
|
4091
|
+
type: Function,
|
|
4092
|
+
default: () => {
|
|
4093
|
+
}
|
|
4094
|
+
},
|
|
4095
|
+
filterData: {
|
|
4096
|
+
type: Function,
|
|
4097
|
+
default: () => {
|
|
4098
|
+
}
|
|
4099
|
+
},
|
|
4100
|
+
alias: {
|
|
4101
|
+
type: String,
|
|
4102
|
+
default: ""
|
|
4103
|
+
}
|
|
4104
|
+
},
|
|
4105
|
+
watch: {
|
|
4106
|
+
data(i) {
|
|
4107
|
+
i && i.length && (M.flattern(this.data, this.groupNodeObject), this.cacheManage.addNodesMap(Object.values(this.groupNodeObject).map((e) => e)), this.init());
|
|
4108
|
+
},
|
|
4109
|
+
controllList(i) {
|
|
4110
|
+
this.updateCheckedStatusWithControls();
|
|
4111
|
+
},
|
|
4112
|
+
selectEquips(i) {
|
|
4113
|
+
this.updateCheckedStatusWithEquips(), this.$nextTick(() => {
|
|
4114
|
+
this.checkStatusManage && this.checkStatusManage.updateGroupCheckStatus();
|
|
4115
|
+
});
|
|
4116
|
+
},
|
|
4117
|
+
filterEquip(i) {
|
|
4118
|
+
this.$nextTick(() => {
|
|
4119
|
+
this.visibleList = [], this.$refs.virtualList.scrollToIndex(0), this.updateTreeList(this.data), this.equipNumManage.resetGroupNum(this.isSearchStatus, i, this.equipStatusObject);
|
|
4120
|
+
});
|
|
4121
|
+
}
|
|
4122
|
+
},
|
|
4123
|
+
computed: {
|
|
4124
|
+
aliasName() {
|
|
4125
|
+
return this.alias ? `-${this.alias}` : "";
|
|
4126
|
+
}
|
|
4127
|
+
},
|
|
4128
|
+
created() {
|
|
4129
|
+
this.showCheckbox && (this.checkStatusManage = new Ht(this.groupNodeObject, this.nodesMap, this.equipControllObject, this.controlObject, this.equipCheckObject, this.aliasName)), this.cacheManage = new Wt(this.groupNodeObject, this.nodesMap, this.controlObject, this.equipCheckObject), this.searchManage = new Ys(this.groupNodeObject, this.showSettings, this.aliasName), this.equipNumManage = new Jt(this.groupNodeObject, this.aliasName), this.requestManage = new Js(this.nodesMap, this.equipControllObject);
|
|
4130
|
+
},
|
|
4131
|
+
mounted() {
|
|
4132
|
+
this.updateCheckedStatusWithControls(), this.updateCheckedStatusWithEquips(), window.addEventListener("message", (i) => {
|
|
4133
|
+
i.data.type && this[i.data.type] && this[i.data.type](i.data.data);
|
|
4134
|
+
});
|
|
4135
|
+
},
|
|
4136
|
+
methods: {
|
|
4137
|
+
// 初始化
|
|
4138
|
+
init() {
|
|
4139
|
+
this.data[0].expand = !0, this.updateTreeList(), setTimeout(() => {
|
|
4140
|
+
Object.values(this.groupNodeObject).forEach((i, e) => {
|
|
4141
|
+
!i.expand && this.expandGroup.includes(i.key) && (i.expand = !0), this.filterWithAlias(i.key), this.updateGroupEquips(i.key, !0);
|
|
4142
|
+
}), this.showCheckbox && this.checkStatusManage && this.checkStatusManage.updateGroupCheckStatus(), this.showStatus && !this.equipStatusManage && (this.equipStatusManage = new Ks(this.nodesMap, this.equipStatusObject, this.groupNodeObject, this.statusChange, this.aliasName));
|
|
4143
|
+
}, 500);
|
|
4144
|
+
},
|
|
4145
|
+
// 根据条件过滤
|
|
4146
|
+
filterWithAlias(i) {
|
|
4147
|
+
if (this.aliasName) {
|
|
4148
|
+
let e = this.window[`group-${i}`] || [];
|
|
4149
|
+
this.window[`group-${i}${this.aliasName}`] = this.filterData(e);
|
|
4150
|
+
}
|
|
4151
|
+
},
|
|
4152
|
+
// 更新当前选中
|
|
4153
|
+
updateCurrentSelect() {
|
|
4154
|
+
this.window.equipCache && this.window.equipCache[this.currentNodeKey] && (this.currentSelect = `${this.window.equipCache[this.currentNodeKey].groupId}-${this.currentNodeKey}`);
|
|
4155
|
+
},
|
|
4156
|
+
// 设备状态变化
|
|
4157
|
+
statusChange(i, e, t) {
|
|
4158
|
+
this.currentSelect == `${i}-${e}` && this.$emit("statusChange", e, t);
|
|
4159
|
+
},
|
|
4160
|
+
// 更新checkbox选中状态
|
|
4161
|
+
updateCheckWidthJob() {
|
|
4162
|
+
this.showCheckbox && (this.checkStatusManage.resetCheckedStatus(), this.updateCheckedStatusWithControls(), this.updateCheckedStatusWithEquips(), this.checkStatusManage && this.checkStatusManage.updateGroupCheckStatus());
|
|
4163
|
+
},
|
|
4164
|
+
// 通过外框更新设备
|
|
4165
|
+
updateGroupEquips(i, e) {
|
|
4166
|
+
if (!this.isSearchStatus && this.groupNodeObject[i]) {
|
|
4167
|
+
let t = this.equipNumManage.getAllEquipsNum();
|
|
4168
|
+
this.$emit("getTotal", t);
|
|
4169
|
+
}
|
|
4170
|
+
this.equipNumManage.resetGroupNum(this.isSearchStatus, this.filterEquip, this.equipStatusObject), this.groupNodeObject[i].expand && this.updateList(i, this.groupNodeObject[i].level, null, !1);
|
|
4171
|
+
},
|
|
4172
|
+
// 展开的时候从缓存中拿设备数据到equips中并更新视图
|
|
4173
|
+
updateList(i) {
|
|
4174
|
+
if (this.groupNodeObject[i]) {
|
|
4175
|
+
let e = [];
|
|
4176
|
+
this.isSearchStatus ? (e = this.window[`group-${i}-search`], this.groupNodeObject[i].equips = [...M.deepClone(e, Number(this.groupNodeObject[i].level) + 1, this.showSettings, i, this.equipCheckObject, this.equipStatusObject)]) : (e = this.window[`group-${i}${this.aliasName}`], this.groupNodeObject[i].equips = [...M.deepClone(e, Number(this.groupNodeObject[i].level) + 1, this.showSettings, i, this.equipCheckObject, this.equipStatusObject)]), this.cacheManage.addNodesMap(this.groupNodeObject[i].equips), this.cacheManage.closeBrotherNode(i), this.visibleList = [], this.updateTreeList(this.data), this.showCheckbox && this.checkStatusManage && e && e.length && this.checkStatusManage.updateGroupCheckStatus(), this.showStatus && this.equipStatusManage && this.equipStatusManage.updateGroupStatus(i), this.updateCurrentSelect();
|
|
4177
|
+
}
|
|
4178
|
+
},
|
|
4179
|
+
// 更新整个树形结构
|
|
4180
|
+
updateTreeList(i) {
|
|
4181
|
+
i && i.length > 0 && i.forEach((e) => {
|
|
4182
|
+
this.filterEquip && e.status === 2 ? this.filterEquipList.includes(e.equipNo) || this.visibleList.push(e) : this.filterEquip || this.visibleList.push(e), e.expand ? e.isEquip ? (e.children || (e.children = []), e.settings && (e.children = [...e.settings || []])) : e.children = [...e.equips || [], ...e.groups || []] : e.children = [], this.updateTreeList(e.children || []);
|
|
4183
|
+
});
|
|
4184
|
+
},
|
|
4185
|
+
// 节点点击事件
|
|
4186
|
+
nodeClick(i, e, t, s) {
|
|
4187
|
+
this.$emit("node-click", { ...i, key: i.isEquip ? i.equipNo : i.key }), i.isGroup ? i.isEquip ? this.equipClick(i, e, s) : this.groupClick(i, e, s) : this.currentSelect = i.key;
|
|
4188
|
+
},
|
|
4189
|
+
groupClick(i, e, t) {
|
|
4190
|
+
i.expand ? this.updateList(i.key, i.level, e, t) : (this.cacheManage.recycleGroupCache(i.key), this.visibleList = [], this.updateTreeList(this.data));
|
|
4191
|
+
},
|
|
4192
|
+
async equipClick(i, e, t) {
|
|
4193
|
+
this.showSettings && (i.expand ? (i.loading = !0, await this.requestManage.getSetting(i.key, i.title, i.level, t), this.controlObject[`${i.groupId}-${i.equipNo}`] = { groupId: i.groupId }, i.loading = !1, this.visibleList.splice(e + 1, 0, ...this.nodesMap[i.key].settings), this.cacheManage.addNodesMap(this.nodesMap[i.key].settings)) : (this.visibleList.splice(e + 1, this.nodesMap[i.key].settings.length), this.cacheManage.removeNodesMap(this.nodesMap[i.key].settings), this.nodesMap[i.key].settings = [], delete this.controlObject[`${i.groupId}-${i.equipNo}`]));
|
|
4194
|
+
},
|
|
4195
|
+
onChecked(i) {
|
|
4196
|
+
this.checkStatusManage && this.checkStatusManage.onChecked(i, this.isSearchStatus), this.$emit("onCheck");
|
|
4197
|
+
},
|
|
4198
|
+
groupEditAndNew(i, e) {
|
|
4199
|
+
this.$emit("groupEditAndNew", { isGroupNew: i, node: e });
|
|
4200
|
+
},
|
|
4201
|
+
deleteGroup(i) {
|
|
4202
|
+
this.$emit("deleteGroup", i);
|
|
4203
|
+
},
|
|
4204
|
+
updateCheckedStatusWithControls() {
|
|
4205
|
+
this.controllList && this.controllList.length && this.checkStatusManage && this.checkStatusManage && this.checkStatusManage.updateCheckedStatusWithControls(this.controllList);
|
|
4206
|
+
},
|
|
4207
|
+
updateCheckedStatusWithEquips() {
|
|
4208
|
+
if (!this.checkStatusManage || !this.selectEquips) { return; }
|
|
4209
|
+
(Array.isArray(this.selectEquips) ? this.selectEquips.length > 0 : Object.keys(this.selectEquips).length > 0) && (this.checkStatusManage.updateCheckedStatusWithEquips(this.selectEquips), this.checkStatusManage.updateGroupCheckStatus());
|
|
4210
|
+
},
|
|
4211
|
+
resetCheckedStatus() {
|
|
4212
|
+
this.checkStatusManage && this.checkStatusManage.resetCheckedStatus();
|
|
4213
|
+
},
|
|
4214
|
+
|
|
4215
|
+
/**
|
|
4216
|
+
* @description 获取选择的设备
|
|
4217
|
+
* @return Array
|
|
4218
|
+
*/
|
|
4219
|
+
getEquipSelectd() {
|
|
4220
|
+
return this.checkStatusManage && this.checkStatusManage.getEquipSelectd();
|
|
4221
|
+
},
|
|
4222
|
+
|
|
4223
|
+
/**
|
|
4224
|
+
* @description 获取选择的设备(携带分组)
|
|
4225
|
+
* @return Array
|
|
4226
|
+
*/
|
|
4227
|
+
getEquipGroupSelectd() {
|
|
4228
|
+
return this.checkStatusManage && this.checkStatusManage.getEquipGroupSelectd();
|
|
4229
|
+
},
|
|
4230
|
+
|
|
4231
|
+
/**
|
|
4232
|
+
* @description 获取选择的设备控制项
|
|
4233
|
+
* @return Array
|
|
4234
|
+
*/
|
|
4235
|
+
getControlSelected() {
|
|
4236
|
+
return this.checkStatusManage && this.checkStatusManage.getControlSelected();
|
|
4237
|
+
},
|
|
4238
|
+
|
|
4239
|
+
/**
|
|
4240
|
+
* @description 记录已展开的分组
|
|
4241
|
+
* @return 无
|
|
4242
|
+
*/
|
|
4243
|
+
recordExpandGroup() {
|
|
4244
|
+
this.expandGroup = [], Object.values(this.groupNodeObject).forEach((i) => {
|
|
4245
|
+
i.expand && this.expandGroup.push(i.key);
|
|
4246
|
+
});
|
|
4247
|
+
},
|
|
4248
|
+
|
|
4249
|
+
/**
|
|
4250
|
+
* @description 清除已展开的分组
|
|
4251
|
+
* @return
|
|
4252
|
+
*/
|
|
4253
|
+
removeExpandGroup() {
|
|
4254
|
+
this.$nextTick(() => {
|
|
4255
|
+
this.expandGroup = [];
|
|
4256
|
+
});
|
|
4257
|
+
},
|
|
4258
|
+
|
|
4259
|
+
/**
|
|
4260
|
+
* @description 搜索设备
|
|
4261
|
+
* 1:清除所有节点缓存
|
|
4262
|
+
2: 设置搜索状态为true,搜索状态下所有操作全部不更新
|
|
4263
|
+
3: 非搜索状态,需要清除搜索缓存
|
|
4264
|
+
* @param {searchName} 搜索名称
|
|
4265
|
+
* @return 无返回值
|
|
4266
|
+
*/
|
|
4267
|
+
filterMethod(i) {
|
|
4268
|
+
this.visibleList = [], this.cacheManage.recycleAllNodeCache(), i ? (this.isSearchStatus = !0, this.searchManage.filterMethod(i)) : this.isSearchStatus = !1, this.init(), this.$nextTick(() => {
|
|
4269
|
+
this.$refs.virtualList.scrollToIndex(0);
|
|
4270
|
+
}), this.equipNumManage.resetGroupNum(this.isSearchStatus, this.filterEquip, this.equipStatusObject), this.showCheckbox && (this.checkStatusManage && this.checkStatusManage.reComputedCheckNum(this.isSearchStatus), this.checkStatusManage && this.checkStatusManage.updateGroupCheckStatus());
|
|
4271
|
+
},
|
|
4272
|
+
// 重新构建树
|
|
4273
|
+
rebuildTree() {
|
|
4274
|
+
this.recordExpandGroup(), this.checkStatusManage && this.checkStatusManage.resetCheckedStatus(), this.cacheManage.recycleAllNodeCache(!0), this.$nextTick(() => {
|
|
4275
|
+
this.buildTree(), this.removeExpandGroup();
|
|
4276
|
+
});
|
|
4277
|
+
},
|
|
4278
|
+
// 树形结构销毁
|
|
4279
|
+
destroyTree() {
|
|
4280
|
+
this.cacheManage.recycleAllNodeCache(!0), this.visibleList = [], this.updateTreeList(this.data);
|
|
4281
|
+
},
|
|
4282
|
+
// 通过外框事件更新树形结构数据--start
|
|
4283
|
+
/**
|
|
4284
|
+
* @description 获取分组设备
|
|
4285
|
+
* @param {data} {分组Id}
|
|
4286
|
+
* @return 无返回值
|
|
4287
|
+
*/
|
|
4288
|
+
GetGroupEquips(i) {
|
|
4289
|
+
i.groupId && this.groupNodeObject[i.groupId] && !this.isSearchStatus && (this.updateGroupEquips(i.groupId, !0), this.updateJob && clearTimeout(this.updateJob), this.updateJob = setTimeout(() => {
|
|
4290
|
+
this.equipNumManage.resetGroupNum(this.isSearchStatus, this.filterEquip, this.equipStatusObject), this.updateCheckWidthJob();
|
|
4291
|
+
}, 500));
|
|
4292
|
+
},
|
|
4293
|
+
|
|
4294
|
+
/**
|
|
4295
|
+
* @description 删除设备
|
|
4296
|
+
* @param {data} {groupId,equips}
|
|
4297
|
+
* @return 无返回值
|
|
4298
|
+
*/
|
|
4299
|
+
DeleteEquip(i) {
|
|
4300
|
+
const { groupId: e, equips: t } = i || {};
|
|
4301
|
+
e && this.groupNodeObject[e] && (this.updateGroupEquips(i.groupId), this.equipNumManage.resetGroupNum(), this.checkStatusManage && this.checkStatusManage.resetCheckedStatus()), t.length && t.forEach((s) => {
|
|
4302
|
+
let n = this.nodesMap[`${e}-${s.id}`];
|
|
4303
|
+
n && (this.currentSelect.toString().includes(s.id) && this.$emit("currentDelete"), this.showStatus && (n.status == 2 ? this.equipStatusManage.setGroupStatus(e, !1, 2) : n.status == 6 && this.equipStatusManage.setGroupStatus(e, !1, 6)), delete this.nodesMap[`${e}-${s.id}`], delete this.equipCheckObject[s.id]), delete this.equipStatusObject[s.id];
|
|
4304
|
+
});
|
|
4305
|
+
},
|
|
4306
|
+
|
|
4307
|
+
/**
|
|
4308
|
+
* @description 移动设备
|
|
4309
|
+
* @param {data} {updateGroups} 需要更新的分组列表
|
|
4310
|
+
* @return 无返回值
|
|
4311
|
+
*/
|
|
4312
|
+
MoveEquips(i) {
|
|
4313
|
+
const { updateGroups: e, buildTree: t } = i || {};
|
|
4314
|
+
!t && e ? e.forEach((s) => {
|
|
4315
|
+
s && this.groupNodeObject[s] && (this.updateGroupEquips(s), this.equipNumManage.resetGroupNum(), this.checkStatusManage && this.checkStatusManage.resetCheckedStatus());
|
|
4316
|
+
}) : t && this.rebuildTree();
|
|
4317
|
+
},
|
|
4318
|
+
|
|
4319
|
+
/**
|
|
4320
|
+
* @description 删除分组
|
|
4321
|
+
* @param {data} {groupId,parentGroupId}
|
|
4322
|
+
* @return 无返回值
|
|
4323
|
+
*/
|
|
4324
|
+
DeleteEquipGroup(i) {
|
|
4325
|
+
i.forEach((e) => {
|
|
4326
|
+
e.groupId && this.nodesMap[e.groupId] && (this.isSearchStatus || this.rebuildTree());
|
|
4327
|
+
});
|
|
4328
|
+
},
|
|
4329
|
+
|
|
4330
|
+
/**
|
|
4331
|
+
* @description 新增分组
|
|
4332
|
+
* @param {data} {groupId,parentGroupId}
|
|
4333
|
+
* @return 无返回值
|
|
4334
|
+
*/
|
|
4335
|
+
AddEquipGroup(i) {
|
|
4336
|
+
const { parentGroupId: e, groupId: t } = i || {};
|
|
4337
|
+
t && this.nodesMap[e] && this.treeType && (this.isSearchStatus || this.rebuildTree());
|
|
4338
|
+
},
|
|
4339
|
+
|
|
4340
|
+
/** 编辑分组
|
|
4341
|
+
* @description 新增分组
|
|
4342
|
+
* @param {data} {groupId,parentGroupId}
|
|
4343
|
+
* @return 无返回值
|
|
4344
|
+
*/
|
|
4345
|
+
EditEquipGroup(i) {
|
|
4346
|
+
const { groupId: e, groupName: t } = i;
|
|
4347
|
+
this.nodesMap[e] && (this.nodesMap[e].title = t);
|
|
4348
|
+
},
|
|
4349
|
+
|
|
4350
|
+
/**
|
|
4351
|
+
* @description 新增分组设备
|
|
4352
|
+
* @param {data} {分组Id,设备}
|
|
4353
|
+
* @return 无返回值
|
|
4354
|
+
*/
|
|
4355
|
+
AddEquip(i) {
|
|
4356
|
+
const { groupId: e } = i || {};
|
|
4357
|
+
this.filterEquip && (this.filterEquipList = i == null ? void 0 : i.equips.map((t) => t.id)), e && this.groupNodeObject[e] && !this.isSearchStatus ? (this.updateGroupEquips(e, !0), this.updateJob && clearTimeout(this.updateJob), this.updateJob = setTimeout(() => {
|
|
4358
|
+
this.updateCheckWidthJob();
|
|
4359
|
+
}, 500)) : e && !this.isSearchStatus && this.rebuildTree();
|
|
4360
|
+
},
|
|
4361
|
+
|
|
4362
|
+
/**
|
|
4363
|
+
* @description 新增分组设备
|
|
4364
|
+
* @param {data} {分组Id,设备}
|
|
4365
|
+
* @return 无返回值
|
|
4366
|
+
*/
|
|
4367
|
+
EditEquip(i) {
|
|
4368
|
+
const { equipNo: e, groupId: t, equipName: s } = i || {};
|
|
4369
|
+
this.nodesMap[`${t}-${e}`] && (this.isSearchStatus || (this.nodesMap[`${t}-${e}`].title = s));
|
|
4370
|
+
},
|
|
4371
|
+
|
|
4372
|
+
/**
|
|
4373
|
+
* @description 重置分组数量
|
|
4374
|
+
* @param {isSearchStatus} {是否查询状态}
|
|
4375
|
+
* @return 无返回值
|
|
4376
|
+
*/
|
|
4377
|
+
childrenResetGroupNum(i) {
|
|
4378
|
+
this.equipNumManage.resetGroupNum(i, this.filterEquip, this.equipStatusObject);
|
|
4379
|
+
},
|
|
4380
|
+
|
|
4381
|
+
/**
|
|
4382
|
+
* @description 获取设备状态
|
|
4383
|
+
* @param {data} {equipNo}
|
|
4384
|
+
* @return arry[equipNo]
|
|
4385
|
+
*/
|
|
4386
|
+
getEquipStatus(i) {
|
|
4387
|
+
return this.equipStatusManage.equipStatusObject[i];
|
|
4388
|
+
}
|
|
4389
|
+
// 通过外框事件更新树形结构数据--end
|
|
4390
|
+
}
|
|
4391
|
+
}, li = {
|
|
4392
|
+
class: "gw-tree",
|
|
4393
|
+
style: { height: "100%" }
|
|
4394
|
+
}, di = {
|
|
4395
|
+
class: "tree",
|
|
4396
|
+
style: { height: "100%" }
|
|
4397
|
+
};
|
|
4398
|
+
function pi(i, e, t, s, n, r) {
|
|
4399
|
+
const o = G("virtual-list", !0);
|
|
4400
|
+
return E(), T("div", li, [
|
|
4401
|
+
x("div", di, [
|
|
4402
|
+
S(o, {
|
|
4403
|
+
ref: "virtualList",
|
|
4404
|
+
class: "virtualList",
|
|
4405
|
+
"data-key": "key",
|
|
4406
|
+
"data-sources": n.visibleList,
|
|
4407
|
+
"data-component": n.itemComponent,
|
|
4408
|
+
keeps: 40,
|
|
4409
|
+
"extra-props": {
|
|
4410
|
+
currentSelect: n.currentSelect,
|
|
4411
|
+
nodeClick: r.nodeClick,
|
|
4412
|
+
showStatus: t.showStatus,
|
|
4413
|
+
filterEquip: t.filterEquip,
|
|
4414
|
+
showSettings: t.showSettings,
|
|
4415
|
+
showCheckbox: t.showCheckbox,
|
|
4416
|
+
onChecked: r.onChecked,
|
|
4417
|
+
showOperate: t.showOperate,
|
|
4418
|
+
groupEditAndNew: r.groupEditAndNew,
|
|
4419
|
+
deleteGroup: r.deleteGroup,
|
|
4420
|
+
colorConfig: t.colorConfig,
|
|
4421
|
+
childrenResetGroupNum: r.childrenResetGroupNum,
|
|
4422
|
+
getEquipStatus: r.getEquipStatus
|
|
4423
|
+
}
|
|
4424
|
+
}, null, 8, ["data-sources", "data-component", "extra-props"])
|
|
4425
|
+
])
|
|
4426
|
+
]);
|
|
4427
|
+
}
|
|
4428
|
+
const fi = /* @__PURE__ */ le(ci, [["render", pi]]);
|
|
4429
|
+
class gi {
|
|
4430
|
+
constructor() {
|
|
4431
|
+
const t = `${location.protocol === "https:" ? "https" : "http"}://${location.hostname}:9600`;
|
|
4432
|
+
this.eGroupNotify = new bt(
|
|
4433
|
+
t,
|
|
4434
|
+
!0,
|
|
4435
|
+
{ hub: "eGroupNotify", userName: sessionStorage.userName }
|
|
4436
|
+
), this.alreadyUpdate = {}, this.notify = null, this.window = window;
|
|
4437
|
+
try {
|
|
4438
|
+
window.top.equipGroup, this.window = window.top;
|
|
4439
|
+
} catch {
|
|
4440
|
+
this.window = window;
|
|
4441
|
+
}
|
|
4442
|
+
}
|
|
4443
|
+
stop() {
|
|
4444
|
+
this.notify && this.notify.disconnect();
|
|
4445
|
+
}
|
|
4446
|
+
Init() {
|
|
4447
|
+
this.eGroupNotify.openConnect().then((e) => {
|
|
4448
|
+
this.notify = e;
|
|
4449
|
+
try {
|
|
4450
|
+
e.emit("invoke", { method: "GetEquipGroupTree", data: {} }), e.emit("invoke", { method: "GetAllEquipGroupTree", data: {} });
|
|
4451
|
+
} catch (t) {
|
|
4452
|
+
console.log(t);
|
|
4453
|
+
}
|
|
4454
|
+
this.subscribeTo(e, "GetEquipGroupTree"), this.subscribeTo(e, "AddEquipGroup"), this.subscribeTo(e, "EditEquipGroup"), this.subscribeTo(e, "DeleteEquipGroup");
|
|
4455
|
+
try {
|
|
4456
|
+
e.emit("invoke", { method: "GetGroupEquips", data: {} });
|
|
4457
|
+
} catch (t) {
|
|
4458
|
+
console.log(t);
|
|
4459
|
+
}
|
|
4460
|
+
this.subscribeTo(e, "GetGroupEquips"), this.subscribeTo(e, "AddEquip"), this.subscribeTo(e, "DeleteEquip"), this.subscribeTo(e, "EditEquip"), this.subscribeTo(e, "MoveEquips"), this.subscribeTo(e, "CopyEquips"), this.subscribeTo(e, "GetAllEquipGroupTree");
|
|
4461
|
+
}).catch((e) => {
|
|
4462
|
+
console.error(e);
|
|
4463
|
+
});
|
|
4464
|
+
}
|
|
4465
|
+
subscribeTo(e, t) {
|
|
4466
|
+
e.off(t), e.on(t, (s) => {
|
|
4467
|
+
const n = s == null ? void 0 : s.data;
|
|
4468
|
+
n && n.isSuccess && (this[t] ? this[t](n.data) : this.notice({ func: t, data: n.data, key: n.groupId }));
|
|
4469
|
+
});
|
|
4470
|
+
}
|
|
4471
|
+
// 获取分组---无权限管理的分组列表--空设备分组不展示
|
|
4472
|
+
GetEquipGroupTree(e) {
|
|
4473
|
+
this.window.groupList || (this.window.groupList = e, this.notice({ type: "GetEquipGroupTree" }));
|
|
4474
|
+
}
|
|
4475
|
+
// 获取全量分组---设备管理使用
|
|
4476
|
+
GetAllEquipGroupTree(e) {
|
|
4477
|
+
this.window.groupList_manageMent || (this.window.groupList_manageMent = e, this.notice({ type: "GetEquipGroupTreeWidthTreeType" }));
|
|
4478
|
+
}
|
|
4479
|
+
// 新增分组
|
|
4480
|
+
AddEquipGroup(e) {
|
|
4481
|
+
const { parentGroupId: t, groupId: s, groupName: n } = e || {};
|
|
4482
|
+
s && (this.window.groupList_manageMent || (this.window.groupList_manageMent = []), this.window.groupList_manageMent.push({
|
|
4483
|
+
parentId: t,
|
|
4484
|
+
id: s,
|
|
4485
|
+
name: n,
|
|
4486
|
+
equipCount: 0
|
|
4487
|
+
}), this.notice({ type: "AddEquipGroup", data: e }));
|
|
4488
|
+
}
|
|
4489
|
+
// 编辑分组
|
|
4490
|
+
EditEquipGroup(e) {
|
|
4491
|
+
const { groupId: t, groupName: s } = e;
|
|
4492
|
+
this.window.groupList && window.groupList.forEach((n) => {
|
|
4493
|
+
n.id == t && (n.name = s);
|
|
4494
|
+
}), this.window.groupList_manageMent && window.groupList_manageMent.forEach((n) => {
|
|
4495
|
+
n.id == t && (n.name = s);
|
|
4496
|
+
}), this.notice({ type: "EditEquipGroup", data: e });
|
|
4497
|
+
}
|
|
4498
|
+
deleteChildGroup(e, t) {
|
|
4499
|
+
let s = [];
|
|
4500
|
+
t.forEach((n) => {
|
|
4501
|
+
n.parentId == e && s.push(n.id);
|
|
4502
|
+
}), s.forEach((n) => {
|
|
4503
|
+
let r = t.findIndex((o) => o.id == n);
|
|
4504
|
+
r > -1 && t.splice(r, 1), this.deleteChildGroup(n, t);
|
|
4505
|
+
});
|
|
4506
|
+
}
|
|
4507
|
+
// 删除分组
|
|
4508
|
+
DeleteEquipGroup(e) {
|
|
4509
|
+
e.forEach((t) => {
|
|
4510
|
+
if (this.window.groupList) {
|
|
4511
|
+
let s = this.window.groupList.findIndex((n) => n.id == t.groupId);
|
|
4512
|
+
s > -1 && this.window.groupList.splice(s, 1), this.deleteChildGroup(t.groupId, this.window.groupList);
|
|
4513
|
+
}
|
|
4514
|
+
if (this.window.groupList_manageMent) {
|
|
4515
|
+
let s = this.window.groupList_manageMent.findIndex((n) => n.id == t.groupId);
|
|
4516
|
+
s > -1 && this.window.groupList_manageMent.splice(s, 1), this.deleteChildGroup(t.groupId, this.window.groupList_manageMent);
|
|
4517
|
+
}
|
|
4518
|
+
}), this.notice({ type: "DeleteEquipGroup", data: e });
|
|
4519
|
+
}
|
|
4520
|
+
// 获取设备
|
|
4521
|
+
GetGroupEquips(e) {
|
|
4522
|
+
const { groupId: t, equips: s } = e || {};
|
|
4523
|
+
this.alreadyUpdate[t] || (this.window.groupCache || (this.window.groupCache = {}), this.window.groupCache[t] = {}, t && s && s instanceof Array && (s.forEach((n) => {
|
|
4524
|
+
n.title = n.name, n.groupId = t, n.equipNo = n.id, this.window.equipCache || (this.window.equipCache = {}), this.window.equipCache[n.id] = n, this.window.groupCache[t][n.id] = n;
|
|
4525
|
+
}), this.window[`group-${t}`] = s, this.notice({ type: "GetGroupEquips", data: { groupId: t } }), this.alreadyUpdate[t] = !0));
|
|
4526
|
+
}
|
|
4527
|
+
// 新增设备
|
|
4528
|
+
AddEquip(e) {
|
|
4529
|
+
const { groupId: t, equips: s } = e || {};
|
|
4530
|
+
this.window[`group-${t}`] || (this.window[`group-${t}`] = []), this.window.groupCache || (this.window.groupCache = {}), this.window.groupCache[t] || (this.window.groupCache[t] = {}), this.window.equipCache || (this.window.equipCache = {});
|
|
4531
|
+
let n = this.window[`group-${t}`].length;
|
|
4532
|
+
if (t && s) {
|
|
4533
|
+
if (s.forEach((r, o) => {
|
|
4534
|
+
this.window[`group-${t}`].push(
|
|
4535
|
+
{
|
|
4536
|
+
equipNo: r.id,
|
|
4537
|
+
groupId: t,
|
|
4538
|
+
id: r.id,
|
|
4539
|
+
title: r.name
|
|
4540
|
+
}
|
|
4541
|
+
), this.window.equipCache[r.id] = this.window[`group-${t}`][n + o], this.window.groupCache[t][r.id] = this.window[`group-${t}`][n + o];
|
|
4542
|
+
}), !this.exist(t, this.window.groupList)) {
|
|
4543
|
+
let r = this.findParentList(t, this.window.groupList_manageMent);
|
|
4544
|
+
this.window.groupList.push(...r);
|
|
4545
|
+
}
|
|
4546
|
+
this.notice({ type: "AddEquip", data: e });
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
4549
|
+
MoveEquips(e) {
|
|
4550
|
+
let t = [], s = !0, n = [];
|
|
4551
|
+
const { sourceGroup: r, targetGroupId: o } = e || {};
|
|
4552
|
+
o && t.push(o), r.forEach((a) => {
|
|
4553
|
+
if (t.push(a.groupId), (!this.window[`group-${o}`] || !this.window[`group-${o}`].length) && (this.window[`group-${o}`] = [], n.push(o)), this.window.groupCache || (this.window.groupCache = {}), this.window.groupCache[o] || (this.window.groupCache[o] = {}), a.equips.forEach((u) => {
|
|
4554
|
+
if (!u.name && this.window.equipCache && this.window.equipCache[u.id] && (u.name = this.window.equipCache[u.id].title || this.window.equipCache[u.id].name), u.title = u.name || "", u.groupId = o, u.equipNo = u.id, this.window[`group-${a.groupId}`]) {
|
|
4555
|
+
let c = this.window[`group-${a.groupId}`].findIndex((h) => h.id == u.id);
|
|
4556
|
+
c > -1 && this.window[`group-${a.groupId}`].splice(c, 1);
|
|
4557
|
+
}
|
|
4558
|
+
this.window.equipCache || (this.window.equipCache = {}), this.window.equipCache[u.id] = u, this.window.groupCache[o][u.id] = u, this.window[`group-${o}`].push(u);
|
|
4559
|
+
}), !this.window[`group-${a.groupId}`].length) {
|
|
4560
|
+
let u = this.window.groupList.findIndex((c) => c.id == a.groupId);
|
|
4561
|
+
u > -1 && this.window.groupList.splice(u, 1), this.deleteChildGroup(a.groupId, this.window.groupList);
|
|
4562
|
+
}
|
|
4563
|
+
}), n.forEach((a) => {
|
|
4564
|
+
if (!this.exist(a, this.window.groupList)) {
|
|
4565
|
+
let u = this.findParentList(a, this.window.groupList_manageMent);
|
|
4566
|
+
this.window.groupList.push(...u);
|
|
4567
|
+
}
|
|
4568
|
+
}), this.notice({ type: "MoveEquips", data: { updateGroups: t, buildTree: s } });
|
|
4569
|
+
}
|
|
4570
|
+
// 复制设备(纯复制,不删除源设备)
|
|
4571
|
+
CopyEquips(e) {
|
|
4572
|
+
const { targetGroupId: t, equips: s } = e || {};
|
|
4573
|
+
if (!t || !s || !Array.isArray(s)) {
|
|
4574
|
+
console.warn("CopyEquips: 无效的数据格式", e);
|
|
4575
|
+
return;
|
|
4576
|
+
}
|
|
4577
|
+
let n = [t], r = [];
|
|
4578
|
+
this.window[`group-${t}`] || (this.window[`group-${t}`] = [], r.push(t)), this.window.groupCache || (this.window.groupCache = {}), this.window.groupCache[t] || (this.window.groupCache[t] = {}), this.window.equipCache || (this.window.equipCache = {}), s.forEach((o) => {
|
|
4579
|
+
!o.name && this.window.equipCache && this.window.equipCache[o.id] && (o.name = this.window.equipCache[o.id].title || this.window.equipCache[o.id].name);
|
|
4580
|
+
const a = {
|
|
4581
|
+
id: o.id,
|
|
4582
|
+
equipNo: o.id,
|
|
4583
|
+
groupId: t,
|
|
4584
|
+
title: o.name || "",
|
|
4585
|
+
name: o.name || ""
|
|
4586
|
+
};
|
|
4587
|
+
this.window.equipCache[o.id] = a, this.window.groupCache[t][o.id] = a, this.window[`group-${t}`].push(a);
|
|
4588
|
+
}), r.forEach((o) => {
|
|
4589
|
+
if (!this.exist(o, this.window.groupList)) {
|
|
4590
|
+
let a = this.findParentList(o, this.window.groupList_manageMent);
|
|
4591
|
+
this.window.groupList.push(...a);
|
|
4592
|
+
}
|
|
4593
|
+
}), this.notice({
|
|
4594
|
+
type: "MoveEquips",
|
|
4595
|
+
data: {
|
|
4596
|
+
updateGroups: n,
|
|
4597
|
+
buildTree: !1,
|
|
4598
|
+
targetGroupId: t,
|
|
4599
|
+
equipCount: s.length
|
|
4600
|
+
}
|
|
4601
|
+
});
|
|
4602
|
+
}
|
|
4603
|
+
exist(e, t) {
|
|
4604
|
+
return t ? t.some((s) => s.id == e) : !1;
|
|
4605
|
+
}
|
|
4606
|
+
findParentList(e, t) {
|
|
4607
|
+
let s = [];
|
|
4608
|
+
if (t) {
|
|
4609
|
+
let n = t.findIndex((r) => r.id == e);
|
|
4610
|
+
n > -1 && s.push({ ...t[n] }), t[n].parentId && !this.exist(t[n].parentId, this.window.groupList) && s.push(...this.findParentList(t[n].parentId, this.window.groupList_manageMent));
|
|
4611
|
+
}
|
|
4612
|
+
return s;
|
|
4613
|
+
}
|
|
4614
|
+
// 删除设备
|
|
4615
|
+
DeleteEquip(e) {
|
|
4616
|
+
const { groupId: t, equips: s } = e || {};
|
|
4617
|
+
if (t && s && s instanceof Array) {
|
|
4618
|
+
if (this.window[`group-${t}`]) {
|
|
4619
|
+
for (let n = 0, r = s.length; n < r; n++) {
|
|
4620
|
+
let o = this.window[`group-${t}`].findIndex((a) => a.id == s[n].id);
|
|
4621
|
+
o > -1 && this.window[`group-${t}`].splice(o, 1), delete this.window.equipCache[s[n].id], delete this.window.groupCache[t][s[n].id];
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
this.notice({ type: "DeleteEquip", data: e });
|
|
4625
|
+
}
|
|
4626
|
+
}
|
|
4627
|
+
// 编辑设备
|
|
4628
|
+
EditEquip(e) {
|
|
4629
|
+
const { equipNo: t, groupId: s, equipName: n } = e || {};
|
|
4630
|
+
s && t && (window[`group-${s}`] && (this.window.equipCache[t] = n), this.notice({ type: "EditEquip", data: e }));
|
|
4631
|
+
}
|
|
4632
|
+
notice(e) {
|
|
4633
|
+
if (this.window.hasIframe) {
|
|
4634
|
+
let t = document.getElementsByTagName("iframe");
|
|
4635
|
+
for (let s of t) { s.contentWindow.postMessage(e); }
|
|
4636
|
+
} else { window.postMessage(e, "*"); }
|
|
4637
|
+
}
|
|
4638
|
+
}
|
|
4639
|
+
const mi = {
|
|
4640
|
+
name: "treeV2",
|
|
4641
|
+
components: {
|
|
4642
|
+
tree: fi
|
|
4643
|
+
},
|
|
4644
|
+
mixins: [it],
|
|
4645
|
+
data() {
|
|
4646
|
+
return {
|
|
4647
|
+
list: [],
|
|
4648
|
+
refId: M.generateUUID(),
|
|
4649
|
+
treeKey: null,
|
|
4650
|
+
listKey: null,
|
|
4651
|
+
hasBuildTree: !1
|
|
4652
|
+
};
|
|
4653
|
+
},
|
|
4654
|
+
props: {
|
|
4655
|
+
treeType: {
|
|
4656
|
+
type: String,
|
|
4657
|
+
default: ""
|
|
4658
|
+
}
|
|
4659
|
+
},
|
|
4660
|
+
mounted() {
|
|
4661
|
+
this.treeKey = `equipGroup${this.treeType}`, this.listKey = `groupList${this.treeType}`, this.window[this.treeKey] ? this.list = M.formateList(JSON.parse(JSON.stringify(this.window[this.treeKey]))) : this.window[this.listKey] && this.buildTree(), window.executeQueue || (window.executeQueues = {}), window.executeQueues[this.refId] = this.destroyTree, window.addEventListener("message", (i) => {
|
|
4662
|
+
i && i.data && i.data.type && this[i.data.type] && this[i.data.type](i.data.data);
|
|
4663
|
+
});
|
|
4664
|
+
try {
|
|
4665
|
+
this.window.hasIframe || this.selfRequest();
|
|
4666
|
+
} catch {
|
|
4667
|
+
this.selfRequest();
|
|
4668
|
+
}
|
|
4669
|
+
},
|
|
4670
|
+
methods: {
|
|
4671
|
+
selfRequest() {
|
|
4672
|
+
new gi().Init();
|
|
4673
|
+
},
|
|
4674
|
+
GetEquipGroupTreeWidthTreeType() {
|
|
4675
|
+
this.treeType && this.window[this.listKey] && this.buildTree();
|
|
4676
|
+
},
|
|
4677
|
+
GetEquipGroupTree() {
|
|
4678
|
+
!this.treeType && this.window[this.listKey] && this.buildTree();
|
|
4679
|
+
},
|
|
4680
|
+
AddEquip(i) {
|
|
4681
|
+
const { groupId: e } = i || {};
|
|
4682
|
+
this.window[this.listKey] && (!e || !this.$refs[this.refId] || !this.$refs[this.refId].groupNodeObject[e]) && this.buildTree();
|
|
4683
|
+
},
|
|
4684
|
+
buildTree() {
|
|
4685
|
+
if (this.window[this.listKey]) {
|
|
4686
|
+
let i = M.listToTreeList(JSON.parse(JSON.stringify(this.window[this.listKey])));
|
|
4687
|
+
this.list = M.formateList(JSON.parse(JSON.stringify(i))), this.window[`equipGroup${this.treeType}`] = i, this.hasBuildTree = !0;
|
|
4688
|
+
}
|
|
4689
|
+
},
|
|
4690
|
+
filterMethod(i) {
|
|
4691
|
+
this.$refs[this.refId].filterMethod(i);
|
|
4692
|
+
},
|
|
4693
|
+
resetCheckedStatus() {
|
|
4694
|
+
this.$refs[this.refId].resetCheckedStatus();
|
|
4695
|
+
},
|
|
4696
|
+
getEquipSelectd() {
|
|
4697
|
+
return this.$refs[this.refId].getEquipSelectd();
|
|
4698
|
+
},
|
|
4699
|
+
getEquipGroupSelectd() {
|
|
4700
|
+
return this.$refs[this.refId].getEquipGroupSelectd();
|
|
4701
|
+
},
|
|
4702
|
+
getControlSelected() {
|
|
4703
|
+
return this.$refs[this.refId].getControlSelected();
|
|
4704
|
+
},
|
|
4705
|
+
destroyTree() {
|
|
4706
|
+
this.$refs[this.refId].destroyTree();
|
|
4707
|
+
}
|
|
4708
|
+
}
|
|
4709
|
+
};
|
|
4710
|
+
function yi(i, e, t, s, n, r) {
|
|
4711
|
+
const o = G("tree");
|
|
4712
|
+
return E(), oe(o, Mt({
|
|
4713
|
+
ref: n.refId,
|
|
4714
|
+
data: n.list
|
|
4715
|
+
}, { ...i.$attrs, ...i.$props }, At(i.$listeners), { buildTree: r.buildTree }), null, 16, ["data", "buildTree"]);
|
|
4716
|
+
}
|
|
4717
|
+
const ve = /* @__PURE__ */ le(mi, [["render", yi]]);
|
|
4718
|
+
ve.install = function(i) {
|
|
4719
|
+
i.component(ve.name, ve);
|
|
4720
|
+
};
|
|
4721
|
+
export {
|
|
4722
|
+
ve as default
|
|
4723
|
+
};
|