@meta2d/core 1.0.74 → 1.0.76
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 +5 -2
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +3 -0
- package/src/core.js +142 -42
- package/src/core.js.map +1 -1
- package/src/diagrams/svg/parse.js +3 -2
- package/src/diagrams/svg/parse.js.map +1 -1
- package/src/diagrams/video.js +5 -5
- package/src/diagrams/video.js.map +1 -1
- package/src/dialog/dialog.js +2 -0
- package/src/dialog/dialog.js.map +1 -1
- package/src/pen/model.d.ts +1 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +1 -0
- package/src/pen/render.js +7 -3
- package/src/pen/render.js.map +1 -1
- package/src/pen/text.js +2 -2
- package/src/utils/jetLinks.js +5 -1
- package/src/utils/jetLinks.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
|
@@ -182,7 +182,7 @@ export class Meta2d {
|
|
|
182
182
|
ruleColor: this.store.theme[theme].ruleColor,
|
|
183
183
|
ruleOptions: this.store.theme[theme].ruleOptions,
|
|
184
184
|
});
|
|
185
|
-
// 更新全局的主题css变量
|
|
185
|
+
// 更新全局的主题css变量
|
|
186
186
|
le5leTheme.updateCssRule(this.store.id, theme);
|
|
187
187
|
this.canvas.initGlobalStyle();
|
|
188
188
|
for (let i = 0; i < this.store.data.pens.length; i++) {
|
|
@@ -418,7 +418,10 @@ export class Meta2d {
|
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
420
|
});
|
|
421
|
-
|
|
421
|
+
let data = this.getEventData(e.list, pen);
|
|
422
|
+
if (Object.keys(data).length) {
|
|
423
|
+
data = null;
|
|
424
|
+
}
|
|
422
425
|
this.canvas.dialog.show(e.value, url, e.extend, data);
|
|
423
426
|
}
|
|
424
427
|
};
|
|
@@ -609,6 +612,7 @@ export class Meta2d {
|
|
|
609
612
|
const data = await getMeta2dData(this.store, id);
|
|
610
613
|
if (data) {
|
|
611
614
|
this.open(data);
|
|
615
|
+
this.lock(1);
|
|
612
616
|
this.fitView(true, 10);
|
|
613
617
|
}
|
|
614
618
|
}
|
|
@@ -834,7 +838,7 @@ export class Meta2d {
|
|
|
834
838
|
this.clear(false, data?.template);
|
|
835
839
|
this.canvas.autoPolylineFlag = true;
|
|
836
840
|
if (data) {
|
|
837
|
-
// 根据图纸的主题设置主题
|
|
841
|
+
// 根据图纸的主题设置主题
|
|
838
842
|
if (data.theme) {
|
|
839
843
|
this.setTheme(data.theme);
|
|
840
844
|
}
|
|
@@ -869,9 +873,9 @@ export class Meta2d {
|
|
|
869
873
|
this.canvas.opening = true;
|
|
870
874
|
}
|
|
871
875
|
this.doInitJS();
|
|
872
|
-
this.doInitFn();
|
|
873
876
|
this.initBindDatas();
|
|
874
877
|
this.initBinds();
|
|
878
|
+
this.doInitFn();
|
|
875
879
|
this.initMessageEvents();
|
|
876
880
|
this.initGlobalTriggers();
|
|
877
881
|
this.startAnimate();
|
|
@@ -1689,6 +1693,43 @@ export class Meta2d {
|
|
|
1689
1693
|
}
|
|
1690
1694
|
this.inactive();
|
|
1691
1695
|
}
|
|
1696
|
+
clearCombine(pen) {
|
|
1697
|
+
if (!pen && this.store.active) {
|
|
1698
|
+
pen = this.store.active[0];
|
|
1699
|
+
}
|
|
1700
|
+
if (!pen || !pen.children) {
|
|
1701
|
+
return;
|
|
1702
|
+
}
|
|
1703
|
+
const children = getAllChildren(pen, this.store);
|
|
1704
|
+
children.forEach((child) => {
|
|
1705
|
+
child.parentId = undefined;
|
|
1706
|
+
child.x = child.calculative.worldRect.x;
|
|
1707
|
+
child.y = child.calculative.worldRect.y;
|
|
1708
|
+
child.width = child.calculative.worldRect.width;
|
|
1709
|
+
child.height = child.calculative.worldRect.height;
|
|
1710
|
+
child.locked = LockState.None;
|
|
1711
|
+
child.calculative.active = undefined;
|
|
1712
|
+
child.calculative.hover = false;
|
|
1713
|
+
if (child.showChild !== undefined) {
|
|
1714
|
+
this.setVisible(child, true);
|
|
1715
|
+
}
|
|
1716
|
+
child.children = undefined;
|
|
1717
|
+
});
|
|
1718
|
+
const combineArr = [];
|
|
1719
|
+
children.forEach((child, index) => {
|
|
1720
|
+
if (child.name === 'combine') {
|
|
1721
|
+
child.children = undefined;
|
|
1722
|
+
combineArr.push(child);
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
this.delete(combineArr, true, false);
|
|
1726
|
+
pen.children = undefined;
|
|
1727
|
+
if (this.isCombine(pen)) {
|
|
1728
|
+
this.delete([pen], true, false);
|
|
1729
|
+
}
|
|
1730
|
+
//未考虑历史记录
|
|
1731
|
+
this.inactive();
|
|
1732
|
+
}
|
|
1692
1733
|
appendChild(pens = this.store.active) {
|
|
1693
1734
|
if (!pens) {
|
|
1694
1735
|
return;
|
|
@@ -2085,44 +2126,15 @@ export class Meta2d {
|
|
|
2085
2126
|
const { networks } = this.store.data;
|
|
2086
2127
|
const https = [];
|
|
2087
2128
|
if (networks) {
|
|
2088
|
-
let mqttIndex = 0;
|
|
2129
|
+
let mqttIndex = 0, httpIndex = 0, websocketIndex = 0, sseIndex = 0;
|
|
2089
2130
|
this.mqttClients = [];
|
|
2090
|
-
let websocketIndex = 0;
|
|
2091
|
-
let sseIndex = 0;
|
|
2092
|
-
let sqlIndex = 0;
|
|
2093
2131
|
this.websockets = [];
|
|
2094
2132
|
this.eventSources = [];
|
|
2095
2133
|
networks.forEach(async (net) => {
|
|
2096
2134
|
// if (net.type === 'subscribe') {
|
|
2097
2135
|
if (net.protocol === 'mqtt') {
|
|
2098
2136
|
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
|
-
}
|
|
2137
|
+
this.connectNetMqtt(net);
|
|
2126
2138
|
mqttIndex += 1;
|
|
2127
2139
|
}
|
|
2128
2140
|
else if (net.protocol === 'websocket') {
|
|
@@ -2152,6 +2164,7 @@ export class Meta2d {
|
|
|
2152
2164
|
websocketIndex += 1;
|
|
2153
2165
|
}
|
|
2154
2166
|
else if (net.protocol === 'http') {
|
|
2167
|
+
net.index = httpIndex;
|
|
2155
2168
|
https.push({
|
|
2156
2169
|
url: net.url,
|
|
2157
2170
|
interval: net.interval,
|
|
@@ -2159,6 +2172,7 @@ export class Meta2d {
|
|
|
2159
2172
|
method: net.method,
|
|
2160
2173
|
body: net.body,
|
|
2161
2174
|
});
|
|
2175
|
+
httpIndex += 1;
|
|
2162
2176
|
}
|
|
2163
2177
|
else if (net.protocol === 'ADIIOT') {
|
|
2164
2178
|
connectJetLinks(this, net);
|
|
@@ -2174,6 +2188,41 @@ export class Meta2d {
|
|
|
2174
2188
|
this.connectIot();
|
|
2175
2189
|
this.connectSqls();
|
|
2176
2190
|
}
|
|
2191
|
+
reconnectNetwork(index) {
|
|
2192
|
+
const net = this.store.data.networks[index];
|
|
2193
|
+
if (net.protocol === 'mqtt') {
|
|
2194
|
+
this.mqttClients && this.mqttClients[net.index]?.end();
|
|
2195
|
+
this.connectNetMqtt(net);
|
|
2196
|
+
}
|
|
2197
|
+
else if (net.protocol === 'websocket') {
|
|
2198
|
+
if (this.websockets && this.websockets[net.index]) {
|
|
2199
|
+
this.websockets[net.index].onclose = undefined;
|
|
2200
|
+
this.websockets[net.index].close();
|
|
2201
|
+
this.websockets[net.index] = undefined;
|
|
2202
|
+
}
|
|
2203
|
+
this.connectNetWebSocket(net);
|
|
2204
|
+
}
|
|
2205
|
+
else if (net.protocol === 'http') {
|
|
2206
|
+
if (this.updateTimerList) {
|
|
2207
|
+
clearInterval(this.updateTimerList[net.index]);
|
|
2208
|
+
this.updateTimerList[net.index] = undefined;
|
|
2209
|
+
}
|
|
2210
|
+
const http = deepClone(net);
|
|
2211
|
+
if (!this.store.data.cancelFirstConnect) {
|
|
2212
|
+
this.requestHttp(http);
|
|
2213
|
+
}
|
|
2214
|
+
this.updateTimerList[net.index] = setInterval(async () => {
|
|
2215
|
+
this.requestHttp(http);
|
|
2216
|
+
}, http.interval || 1000);
|
|
2217
|
+
}
|
|
2218
|
+
else if (net.protocol === 'SSE') {
|
|
2219
|
+
if (this.eventSources) {
|
|
2220
|
+
this.eventSources[net.index]?.close();
|
|
2221
|
+
this.eventSources[net.index] = undefined;
|
|
2222
|
+
}
|
|
2223
|
+
this.connectSSE(net);
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2177
2226
|
iotMqttClient;
|
|
2178
2227
|
iotTimer;
|
|
2179
2228
|
iotWebsocketClient;
|
|
@@ -2215,7 +2264,7 @@ export class Meta2d {
|
|
|
2215
2264
|
// token
|
|
2216
2265
|
// );
|
|
2217
2266
|
// this.iotWebsocketClient.onmessage = (e) => {
|
|
2218
|
-
// this.socketCallback(e.data, { type: 'iot', method: 'websocket' });
|
|
2267
|
+
// this.socketCallback(e.data, { type: 'iot', method: 'websocket' });
|
|
2219
2268
|
// };
|
|
2220
2269
|
// this.iotWebsocketClient.onerror = (error) => {
|
|
2221
2270
|
// this.store.emitter.emit('error', { type: 'websocket', error });
|
|
@@ -2257,13 +2306,60 @@ export class Meta2d {
|
|
|
2257
2306
|
}
|
|
2258
2307
|
});
|
|
2259
2308
|
}
|
|
2309
|
+
connectNetMqtt(net) {
|
|
2310
|
+
if (net.options.clientId && !net.options.customClientId) {
|
|
2311
|
+
net.options.clientId = s8();
|
|
2312
|
+
}
|
|
2313
|
+
let url = net.url;
|
|
2314
|
+
if (url.indexOf('${') > -1) {
|
|
2315
|
+
let keys = url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2316
|
+
if (keys) {
|
|
2317
|
+
keys.forEach((key) => {
|
|
2318
|
+
url = url.replace(`\${${key}}`, this.getDynamicParam(key));
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
net.times = 0;
|
|
2323
|
+
this.mqttClients[net.index] = mqtt.connect(url, net.options);
|
|
2324
|
+
this.mqttClients[net.index].on('message', (topic, message) => {
|
|
2325
|
+
this.socketCallback(message.toString(), {
|
|
2326
|
+
topic,
|
|
2327
|
+
type: 'mqtt',
|
|
2328
|
+
url: net.url,
|
|
2329
|
+
});
|
|
2330
|
+
});
|
|
2331
|
+
this.mqttClients[net.index].on('error', (error) => {
|
|
2332
|
+
this.store.emitter.emit('error', { type: 'mqtt', error });
|
|
2333
|
+
});
|
|
2334
|
+
this.mqttClients[net.index].on('close', () => {
|
|
2335
|
+
if (this.store.options.reconnetTimes) {
|
|
2336
|
+
net.times++;
|
|
2337
|
+
if (net.times >= this.store.options.reconnetTimes) {
|
|
2338
|
+
net.times = 0;
|
|
2339
|
+
this.mqttClients && this.mqttClients[net.index]?.end();
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
});
|
|
2343
|
+
if (net.topics) {
|
|
2344
|
+
this.mqttClients[net.index].subscribe(net.topics.split(','));
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2260
2347
|
connectNetWebSocket(net) {
|
|
2261
2348
|
if (this.websockets[net.index]) {
|
|
2262
2349
|
this.websockets[net.index].onclose = undefined;
|
|
2263
2350
|
this.websockets[net.index]?.close();
|
|
2264
2351
|
this.websockets[net.index] = undefined;
|
|
2265
2352
|
}
|
|
2266
|
-
|
|
2353
|
+
let url = net.url;
|
|
2354
|
+
if (url.indexOf('${') > -1) {
|
|
2355
|
+
let keys = url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2356
|
+
if (keys) {
|
|
2357
|
+
keys.forEach((key) => {
|
|
2358
|
+
url = url.replace(`\${${key}}`, this.getDynamicParam(key));
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
this.websockets[net.index] = new WebSocket(url, net.protocols || undefined);
|
|
2267
2363
|
this.websockets[net.index].onmessage = (e) => {
|
|
2268
2364
|
this.socketCallback(e.data, { type: 'websocket', url: net.url });
|
|
2269
2365
|
};
|
|
@@ -2553,7 +2649,7 @@ export class Meta2d {
|
|
|
2553
2649
|
//获取动态参数
|
|
2554
2650
|
getDynamicParam(key) {
|
|
2555
2651
|
let params = queryURLParams();
|
|
2556
|
-
let value = params[key] || localStorage[key] || getCookie(key) || '';
|
|
2652
|
+
let value = params[key] || localStorage[key] || getCookie(key) || globalThis[key] || '';
|
|
2557
2653
|
return value;
|
|
2558
2654
|
}
|
|
2559
2655
|
onNetworkConnect(https) {
|
|
@@ -3818,8 +3914,10 @@ export class Meta2d {
|
|
|
3818
3914
|
this.store.data.fits?.forEach((fit) => {
|
|
3819
3915
|
let pens = [];
|
|
3820
3916
|
fit.children.forEach((id) => {
|
|
3821
|
-
this.store.pens[id]
|
|
3822
|
-
|
|
3917
|
+
if (this.store.pens[id]) {
|
|
3918
|
+
this.store.pens[id].locked = LockState.None;
|
|
3919
|
+
pens.push(this.store.pens[id]);
|
|
3920
|
+
}
|
|
3823
3921
|
});
|
|
3824
3922
|
let r = wGap / 2;
|
|
3825
3923
|
if (fit.left && fit.right) {
|
|
@@ -3912,8 +4010,10 @@ export class Meta2d {
|
|
|
3912
4010
|
this.store.data.fits?.forEach((fit) => {
|
|
3913
4011
|
let pens = [];
|
|
3914
4012
|
fit.children.forEach((id) => {
|
|
3915
|
-
this.store.pens[id]
|
|
3916
|
-
|
|
4013
|
+
if (this.store.pens[id]) {
|
|
4014
|
+
this.store.pens[id].locked = LockState.None;
|
|
4015
|
+
pens.push(this.store.pens[id]);
|
|
4016
|
+
}
|
|
3917
4017
|
});
|
|
3918
4018
|
let r = hGap / 2;
|
|
3919
4019
|
if (fit.top && fit.bottom) {
|