添加强制重新加载接口和切换场景接口
添加绑定dom和取消绑定dom时暂停和恢复相关资源
This commit is contained in:
parent
7e9c9eb311
commit
df9615fe48
@ -445,9 +445,13 @@ export interface IGraphicScene extends EventEmitter<GraphicAppEvents> {
|
|||||||
*/
|
*/
|
||||||
toCanvasCoordinates(p: Point): Point;
|
toCanvasCoordinates(p: Point): Point;
|
||||||
/**
|
/**
|
||||||
* 加载/重新加载数据
|
* 加载/重新加载数据(若已经加载过,则不会重新加载)
|
||||||
*/
|
*/
|
||||||
reload(): Promise<void>;
|
reload(): Promise<void>;
|
||||||
|
/**
|
||||||
|
* 强制重新加载,无论是否已经加载过
|
||||||
|
*/
|
||||||
|
forceReload(): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* 绑定到dom
|
* 绑定到dom
|
||||||
* @param dom
|
* @param dom
|
||||||
@ -534,6 +538,7 @@ abstract class GraphicSceneBase
|
|||||||
pixi: Application; // Pixi 渲染器
|
pixi: Application; // Pixi 渲染器
|
||||||
viewport: Viewport; // 视口
|
viewport: Viewport; // 视口
|
||||||
canvas: JlCanvas; // 画布
|
canvas: JlCanvas; // 画布
|
||||||
|
_loaded = false; // 是否已经加载
|
||||||
_dom?: HTMLElement; // 场景绑定到的dom节点
|
_dom?: HTMLElement; // 场景绑定到的dom节点
|
||||||
_viewportResizer?: NodeJS.Timeout; // 自动根据dom大小变化调整视口尺寸
|
_viewportResizer?: NodeJS.Timeout; // 自动根据dom大小变化调整视口尺寸
|
||||||
graphicTemplateMap: Map<string, GraphicTemplate> = new Map<
|
graphicTemplateMap: Map<string, GraphicTemplate> = new Map<
|
||||||
@ -630,11 +635,7 @@ abstract class GraphicSceneBase
|
|||||||
return this.queryStore.getAllGraphics().filter((g) => g.selected);
|
return this.queryStore.getAllGraphics().filter((g) => g.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private async load(): Promise<void> {
|
||||||
* 重新加载数据
|
|
||||||
*/
|
|
||||||
async reload(): Promise<void> {
|
|
||||||
this.graphicStore.clear();
|
|
||||||
if (this._options.dataLoader) {
|
if (this._options.dataLoader) {
|
||||||
const storage = await this._options.dataLoader();
|
const storage = await this._options.dataLoader();
|
||||||
if (storage.canvasProperty) {
|
if (storage.canvasProperty) {
|
||||||
@ -644,6 +645,25 @@ abstract class GraphicSceneBase
|
|||||||
await this.loadGraphic(storage.datas);
|
await this.loadGraphic(storage.datas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this._loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重新加载数据
|
||||||
|
*/
|
||||||
|
async reload(): Promise<void> {
|
||||||
|
if (!this._loaded) {
|
||||||
|
this.graphicStore.clear();
|
||||||
|
await this.load();
|
||||||
|
} else {
|
||||||
|
console.debug('场景已经加载过数据,不重新加载', this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async forceReload(): Promise<void> {
|
||||||
|
console.debug('场景强制重新加载数据', this);
|
||||||
|
this.graphicStore.clear();
|
||||||
|
await this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -712,6 +732,28 @@ abstract class GraphicSceneBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停
|
||||||
|
*/
|
||||||
|
private pause() {
|
||||||
|
// 暂停动画
|
||||||
|
this.animationManager.pause();
|
||||||
|
// 取消消息订阅
|
||||||
|
this.wsMsgBroker.unsubscribeAll();
|
||||||
|
// 关闭所有上下文菜单
|
||||||
|
this.menuPlugin.closeAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 恢复
|
||||||
|
*/
|
||||||
|
private resume() {
|
||||||
|
// 恢复动画
|
||||||
|
this.animationManager.resume();
|
||||||
|
// 重新订阅
|
||||||
|
this.wsMsgBroker.resubscribeAll();
|
||||||
|
}
|
||||||
|
|
||||||
bindDom(dom: HTMLElement): void {
|
bindDom(dom: HTMLElement): void {
|
||||||
this._dom = dom;
|
this._dom = dom;
|
||||||
this.pixi.resizeTo = dom;
|
this.pixi.resizeTo = dom;
|
||||||
@ -726,8 +768,8 @@ abstract class GraphicSceneBase
|
|||||||
// );
|
// );
|
||||||
this.updateViewport(dom.clientWidth, dom.clientHeight);
|
this.updateViewport(dom.clientWidth, dom.clientHeight);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
// 恢复动画
|
// 恢复
|
||||||
this.animationManager.resume();
|
this.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
unbindDom(): void {
|
unbindDom(): void {
|
||||||
@ -735,8 +777,8 @@ abstract class GraphicSceneBase
|
|||||||
clearInterval(this._viewportResizer);
|
clearInterval(this._viewportResizer);
|
||||||
this._dom.removeChild(this.pixi.view as unknown as Node);
|
this._dom.removeChild(this.pixi.view as unknown as Node);
|
||||||
this._dom = undefined;
|
this._dom = undefined;
|
||||||
// 暂停动画
|
// 暂停
|
||||||
this.animationManager.pause();
|
this.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -1096,6 +1138,11 @@ export interface IGraphicApp extends IGraphicScene {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getScene(code: string): IGraphicScene;
|
getScene(code: string): IGraphicScene;
|
||||||
|
/**
|
||||||
|
* 切换场景
|
||||||
|
* @param dom
|
||||||
|
*/
|
||||||
|
switchScene(code: string, dom: HTMLElement): void;
|
||||||
/**
|
/**
|
||||||
* 移除指定code场景
|
* 移除指定code场景
|
||||||
* @param code
|
* @param code
|
||||||
@ -1197,6 +1244,18 @@ export class GraphicApp extends GraphicSceneBase implements IGraphicApp {
|
|||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switchScene(code: string, dom: HTMLElement): void {
|
||||||
|
const scene = this.getScene(code);
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
for (const [_code, pre] of this.scenes) {
|
||||||
|
if (pre.dom === dom) {
|
||||||
|
pre.unbindDom();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scene.bindDom(dom);
|
||||||
|
}
|
||||||
|
|
||||||
removeScene(code: string): void {
|
removeScene(code: string): void {
|
||||||
const scene = this.scenes.get(code);
|
const scene = this.scenes.get(code);
|
||||||
if (scene) {
|
if (scene) {
|
||||||
|
@ -222,17 +222,23 @@ export class AppWsMsgBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsbuscribeAll() {
|
unsubscribeAll() {
|
||||||
this.subscriptions.forEach((record, destination) => {
|
this.subscriptions.forEach((record, destination) => {
|
||||||
this.unsbuscribe(destination);
|
this.unsbuscribe(destination);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resubscribeAll() {
|
||||||
|
this.subscriptions.forEach((handler, destination) => {
|
||||||
|
WsMsgCli.registerSubscription(destination, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取消所有订阅,从通用Stomp客户端移除此消息代理
|
* 取消所有订阅,从通用Stomp客户端移除此消息代理
|
||||||
*/
|
*/
|
||||||
close() {
|
close() {
|
||||||
WsMsgCli.removeAppMsgBroker(this);
|
WsMsgCli.removeAppMsgBroker(this);
|
||||||
this.unsbuscribeAll();
|
this.unsubscribeAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ import { IGraphicScene } from '../app';
|
|||||||
import { JlGraphic } from '../core';
|
import { JlGraphic } from '../core';
|
||||||
import { KeyListener } from './KeyboardPlugin';
|
import { KeyListener } from './KeyboardPlugin';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图形复制插件
|
||||||
|
*/
|
||||||
export class GraphicCopyPlugin {
|
export class GraphicCopyPlugin {
|
||||||
container: Container;
|
container: Container;
|
||||||
scene: IGraphicScene;
|
scene: IGraphicScene;
|
||||||
|
@ -91,6 +91,14 @@ export class ContextMenuPlugin {
|
|||||||
this.app.pixi.stage.removeChild(menu);
|
this.app.pixi.stage.removeChild(menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 关闭所有菜单
|
||||||
|
*/
|
||||||
|
closeAll() {
|
||||||
|
this.contextMenuMap.forEach((cm) => {
|
||||||
|
this.close(cm);
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 越界检查
|
* 越界检查
|
||||||
* @param menu
|
* @param menu
|
||||||
|
Loading…
Reference in New Issue
Block a user