@meta2d/core 1.0.74 → 1.0.75
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/package.json +1 -1
- package/src/canvas/canvas.js +4 -2
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +3 -0
- package/src/core.js +133 -37
- package/src/core.js.map +1 -1
- package/src/pen/render.js +2 -3
- package/src/pen/render.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -188,6 +188,7 @@ export declare class Meta2d {
|
|
|
188
188
|
*/
|
|
189
189
|
combine(pens?: Pen[], showChild?: number, active?: boolean): any;
|
|
190
190
|
uncombine(pen?: Pen): void;
|
|
191
|
+
clearCombine(pen?: Pen): void;
|
|
191
192
|
appendChild(pens?: Pen[]): void;
|
|
192
193
|
/***
|
|
193
194
|
* 修改子图元大小,更新整个组合图元
|
|
@@ -248,6 +249,7 @@ export declare class Meta2d {
|
|
|
248
249
|
updateTimerList: any[];
|
|
249
250
|
sqlTimerList: any[];
|
|
250
251
|
connectNetwork(): void;
|
|
252
|
+
reconnectNetwork(index: number): void;
|
|
251
253
|
iotMqttClient: MqttClient;
|
|
252
254
|
iotTimer: any;
|
|
253
255
|
iotWebsocketClient: WebSocket;
|
|
@@ -255,6 +257,7 @@ export declare class Meta2d {
|
|
|
255
257
|
connectSqls(): void;
|
|
256
258
|
connectSSE(net: Network): void;
|
|
257
259
|
closeSSE(): void;
|
|
260
|
+
connectNetMqtt(net: Network): void;
|
|
258
261
|
connectNetWebSocket(net: Network): void;
|
|
259
262
|
getMqttUrl(): Promise<string>;
|
|
260
263
|
getIotToken(devices: any, type: number): Promise<any>;
|
package/src/core.js
CHANGED
|
@@ -1689,6 +1689,43 @@ export class Meta2d {
|
|
|
1689
1689
|
}
|
|
1690
1690
|
this.inactive();
|
|
1691
1691
|
}
|
|
1692
|
+
clearCombine(pen) {
|
|
1693
|
+
if (!pen && this.store.active) {
|
|
1694
|
+
pen = this.store.active[0];
|
|
1695
|
+
}
|
|
1696
|
+
if (!pen || !pen.children) {
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
const children = getAllChildren(pen, this.store);
|
|
1700
|
+
children.forEach((child) => {
|
|
1701
|
+
child.parentId = undefined;
|
|
1702
|
+
child.x = child.calculative.worldRect.x;
|
|
1703
|
+
child.y = child.calculative.worldRect.y;
|
|
1704
|
+
child.width = child.calculative.worldRect.width;
|
|
1705
|
+
child.height = child.calculative.worldRect.height;
|
|
1706
|
+
child.locked = LockState.None;
|
|
1707
|
+
child.calculative.active = undefined;
|
|
1708
|
+
child.calculative.hover = false;
|
|
1709
|
+
if (child.showChild !== undefined) {
|
|
1710
|
+
this.setVisible(child, true);
|
|
1711
|
+
}
|
|
1712
|
+
child.children = undefined;
|
|
1713
|
+
});
|
|
1714
|
+
const combineArr = [];
|
|
1715
|
+
children.forEach((child, index) => {
|
|
1716
|
+
if (child.name === 'combine') {
|
|
1717
|
+
child.children = undefined;
|
|
1718
|
+
combineArr.push(child);
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
this.delete(combineArr, true, false);
|
|
1722
|
+
pen.children = undefined;
|
|
1723
|
+
if (this.isCombine(pen)) {
|
|
1724
|
+
this.delete([pen], true, false);
|
|
1725
|
+
}
|
|
1726
|
+
//未考虑历史记录
|
|
1727
|
+
this.inactive();
|
|
1728
|
+
}
|
|
1692
1729
|
appendChild(pens = this.store.active) {
|
|
1693
1730
|
if (!pens) {
|
|
1694
1731
|
return;
|
|
@@ -2085,44 +2122,15 @@ export class Meta2d {
|
|
|
2085
2122
|
const { networks } = this.store.data;
|
|
2086
2123
|
const https = [];
|
|
2087
2124
|
if (networks) {
|
|
2088
|
-
let mqttIndex = 0;
|
|
2125
|
+
let mqttIndex = 0, httpIndex = 0, websocketIndex = 0, sseIndex = 0;
|
|
2089
2126
|
this.mqttClients = [];
|
|
2090
|
-
let websocketIndex = 0;
|
|
2091
|
-
let sseIndex = 0;
|
|
2092
|
-
let sqlIndex = 0;
|
|
2093
2127
|
this.websockets = [];
|
|
2094
2128
|
this.eventSources = [];
|
|
2095
2129
|
networks.forEach(async (net) => {
|
|
2096
2130
|
// if (net.type === 'subscribe') {
|
|
2097
2131
|
if (net.protocol === 'mqtt') {
|
|
2098
2132
|
net.index = mqttIndex;
|
|
2099
|
-
|
|
2100
|
-
net.options.clientId = s8();
|
|
2101
|
-
}
|
|
2102
|
-
net.times = 0;
|
|
2103
|
-
this.mqttClients[mqttIndex] = mqtt.connect(net.url, net.options);
|
|
2104
|
-
this.mqttClients[mqttIndex].on('message', (topic, message) => {
|
|
2105
|
-
this.socketCallback(message.toString(), {
|
|
2106
|
-
topic,
|
|
2107
|
-
type: 'mqtt',
|
|
2108
|
-
url: net.url,
|
|
2109
|
-
});
|
|
2110
|
-
});
|
|
2111
|
-
this.mqttClients[mqttIndex].on('error', (error) => {
|
|
2112
|
-
this.store.emitter.emit('error', { type: 'mqtt', error });
|
|
2113
|
-
});
|
|
2114
|
-
this.mqttClients[mqttIndex].on('close', () => {
|
|
2115
|
-
if (this.store.options.reconnetTimes) {
|
|
2116
|
-
net.times++;
|
|
2117
|
-
if (net.times >= this.store.options.reconnetTimes) {
|
|
2118
|
-
net.times = 0;
|
|
2119
|
-
this.mqttClients && this.mqttClients[net.index]?.end();
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
});
|
|
2123
|
-
if (net.topics) {
|
|
2124
|
-
this.mqttClients[mqttIndex].subscribe(net.topics.split(','));
|
|
2125
|
-
}
|
|
2133
|
+
this.connectNetMqtt(net);
|
|
2126
2134
|
mqttIndex += 1;
|
|
2127
2135
|
}
|
|
2128
2136
|
else if (net.protocol === 'websocket') {
|
|
@@ -2152,6 +2160,7 @@ export class Meta2d {
|
|
|
2152
2160
|
websocketIndex += 1;
|
|
2153
2161
|
}
|
|
2154
2162
|
else if (net.protocol === 'http') {
|
|
2163
|
+
net.index = httpIndex;
|
|
2155
2164
|
https.push({
|
|
2156
2165
|
url: net.url,
|
|
2157
2166
|
interval: net.interval,
|
|
@@ -2159,6 +2168,7 @@ export class Meta2d {
|
|
|
2159
2168
|
method: net.method,
|
|
2160
2169
|
body: net.body,
|
|
2161
2170
|
});
|
|
2171
|
+
httpIndex += 1;
|
|
2162
2172
|
}
|
|
2163
2173
|
else if (net.protocol === 'ADIIOT') {
|
|
2164
2174
|
connectJetLinks(this, net);
|
|
@@ -2174,6 +2184,41 @@ export class Meta2d {
|
|
|
2174
2184
|
this.connectIot();
|
|
2175
2185
|
this.connectSqls();
|
|
2176
2186
|
}
|
|
2187
|
+
reconnectNetwork(index) {
|
|
2188
|
+
const net = this.store.data.networks[index];
|
|
2189
|
+
if (net.protocol === 'mqtt') {
|
|
2190
|
+
this.mqttClients && this.mqttClients[net.index]?.end();
|
|
2191
|
+
this.connectNetMqtt(net);
|
|
2192
|
+
}
|
|
2193
|
+
else if (net.protocol === 'websocket') {
|
|
2194
|
+
if (this.websockets && this.websockets[net.index]) {
|
|
2195
|
+
this.websockets[net.index].onclose = undefined;
|
|
2196
|
+
this.websockets[net.index].close();
|
|
2197
|
+
this.websockets[net.index] = undefined;
|
|
2198
|
+
}
|
|
2199
|
+
this.connectNetWebSocket(net);
|
|
2200
|
+
}
|
|
2201
|
+
else if (net.protocol === 'http') {
|
|
2202
|
+
if (this.updateTimerList) {
|
|
2203
|
+
clearInterval(this.updateTimerList[net.index]);
|
|
2204
|
+
this.updateTimerList[net.index] = undefined;
|
|
2205
|
+
}
|
|
2206
|
+
const http = deepClone(net);
|
|
2207
|
+
if (!this.store.data.cancelFirstConnect) {
|
|
2208
|
+
this.requestHttp(http);
|
|
2209
|
+
}
|
|
2210
|
+
this.updateTimerList[net.index] = setInterval(async () => {
|
|
2211
|
+
this.requestHttp(http);
|
|
2212
|
+
}, http.interval || 1000);
|
|
2213
|
+
}
|
|
2214
|
+
else if (net.protocol === 'SSE') {
|
|
2215
|
+
if (this.eventSources) {
|
|
2216
|
+
this.eventSources[net.index]?.close();
|
|
2217
|
+
this.eventSources[net.index] = undefined;
|
|
2218
|
+
}
|
|
2219
|
+
this.connectSSE(net);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2177
2222
|
iotMqttClient;
|
|
2178
2223
|
iotTimer;
|
|
2179
2224
|
iotWebsocketClient;
|
|
@@ -2257,13 +2302,60 @@ export class Meta2d {
|
|
|
2257
2302
|
}
|
|
2258
2303
|
});
|
|
2259
2304
|
}
|
|
2305
|
+
connectNetMqtt(net) {
|
|
2306
|
+
if (net.options.clientId && !net.options.customClientId) {
|
|
2307
|
+
net.options.clientId = s8();
|
|
2308
|
+
}
|
|
2309
|
+
let url = net.url;
|
|
2310
|
+
if (url.indexOf('${') > -1) {
|
|
2311
|
+
let keys = url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2312
|
+
if (keys) {
|
|
2313
|
+
keys.forEach((key) => {
|
|
2314
|
+
url = url.replace(`\${${key}}`, this.getDynamicParam(key));
|
|
2315
|
+
});
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
net.times = 0;
|
|
2319
|
+
this.mqttClients[net.index] = mqtt.connect(url, net.options);
|
|
2320
|
+
this.mqttClients[net.index].on('message', (topic, message) => {
|
|
2321
|
+
this.socketCallback(message.toString(), {
|
|
2322
|
+
topic,
|
|
2323
|
+
type: 'mqtt',
|
|
2324
|
+
url: net.url,
|
|
2325
|
+
});
|
|
2326
|
+
});
|
|
2327
|
+
this.mqttClients[net.index].on('error', (error) => {
|
|
2328
|
+
this.store.emitter.emit('error', { type: 'mqtt', error });
|
|
2329
|
+
});
|
|
2330
|
+
this.mqttClients[net.index].on('close', () => {
|
|
2331
|
+
if (this.store.options.reconnetTimes) {
|
|
2332
|
+
net.times++;
|
|
2333
|
+
if (net.times >= this.store.options.reconnetTimes) {
|
|
2334
|
+
net.times = 0;
|
|
2335
|
+
this.mqttClients && this.mqttClients[net.index]?.end();
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
if (net.topics) {
|
|
2340
|
+
this.mqttClients[net.index].subscribe(net.topics.split(','));
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2260
2343
|
connectNetWebSocket(net) {
|
|
2261
2344
|
if (this.websockets[net.index]) {
|
|
2262
2345
|
this.websockets[net.index].onclose = undefined;
|
|
2263
2346
|
this.websockets[net.index]?.close();
|
|
2264
2347
|
this.websockets[net.index] = undefined;
|
|
2265
2348
|
}
|
|
2266
|
-
|
|
2349
|
+
let url = net.url;
|
|
2350
|
+
if (url.indexOf('${') > -1) {
|
|
2351
|
+
let keys = url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2352
|
+
if (keys) {
|
|
2353
|
+
keys.forEach((key) => {
|
|
2354
|
+
url = url.replace(`\${${key}}`, this.getDynamicParam(key));
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
this.websockets[net.index] = new WebSocket(url, net.protocols || undefined);
|
|
2267
2359
|
this.websockets[net.index].onmessage = (e) => {
|
|
2268
2360
|
this.socketCallback(e.data, { type: 'websocket', url: net.url });
|
|
2269
2361
|
};
|
|
@@ -2553,7 +2645,7 @@ export class Meta2d {
|
|
|
2553
2645
|
//获取动态参数
|
|
2554
2646
|
getDynamicParam(key) {
|
|
2555
2647
|
let params = queryURLParams();
|
|
2556
|
-
let value = params[key] || localStorage[key] || getCookie(key) || '';
|
|
2648
|
+
let value = params[key] || localStorage[key] || getCookie(key) || globalThis[key] || '';
|
|
2557
2649
|
return value;
|
|
2558
2650
|
}
|
|
2559
2651
|
onNetworkConnect(https) {
|
|
@@ -3818,8 +3910,10 @@ export class Meta2d {
|
|
|
3818
3910
|
this.store.data.fits?.forEach((fit) => {
|
|
3819
3911
|
let pens = [];
|
|
3820
3912
|
fit.children.forEach((id) => {
|
|
3821
|
-
this.store.pens[id]
|
|
3822
|
-
|
|
3913
|
+
if (this.store.pens[id]) {
|
|
3914
|
+
this.store.pens[id].locked = LockState.None;
|
|
3915
|
+
pens.push(this.store.pens[id]);
|
|
3916
|
+
}
|
|
3823
3917
|
});
|
|
3824
3918
|
let r = wGap / 2;
|
|
3825
3919
|
if (fit.left && fit.right) {
|
|
@@ -3912,8 +4006,10 @@ export class Meta2d {
|
|
|
3912
4006
|
this.store.data.fits?.forEach((fit) => {
|
|
3913
4007
|
let pens = [];
|
|
3914
4008
|
fit.children.forEach((id) => {
|
|
3915
|
-
this.store.pens[id]
|
|
3916
|
-
|
|
4009
|
+
if (this.store.pens[id]) {
|
|
4010
|
+
this.store.pens[id].locked = LockState.None;
|
|
4011
|
+
pens.push(this.store.pens[id]);
|
|
4012
|
+
}
|
|
3917
4013
|
});
|
|
3918
4014
|
let r = hGap / 2;
|
|
3919
4015
|
if (fit.top && fit.bottom) {
|