From 9afb470615637637ee112fa3dca17ffba9dcaa5d Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Wed, 1 Nov 2023 16:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jl-graphic/app/JlGraphicApp.ts | 13 ++++++++++--- src/jl-graphic/message/MessageBroker.ts | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/jl-graphic/app/JlGraphicApp.ts b/src/jl-graphic/app/JlGraphicApp.ts index 013b62a..99904b7 100644 --- a/src/jl-graphic/app/JlGraphicApp.ts +++ b/src/jl-graphic/app/JlGraphicApp.ts @@ -25,6 +25,7 @@ import { type AppStateSubscription, type MessageCliOption, GraphicQuery, + ICreateOnNotFound, } from '../message'; import { OperationRecord } from '../operation/JlOperation'; import { @@ -476,7 +477,7 @@ export interface IGraphicScene extends EventEmitter { handleGraphicStates( graphicStates: GraphicState[], queryer?: GraphicQuery, - createOnNotFound?: boolean + createOnNotFound?: ICreateOnNotFound ): void; /** * 根据类型获取图形模板 @@ -1094,7 +1095,7 @@ abstract class GraphicSceneBase handleGraphicStates( graphicStates: GraphicState[], queryer?: GraphicQuery, - createOnNotFound?: boolean + createOnNotFound?: ICreateOnNotFound ): void { graphicStates.forEach((state) => { let g: JlGraphic | undefined; @@ -1106,7 +1107,13 @@ abstract class GraphicSceneBase try { if (!g) { // 未找到图形对象 - if (createOnNotFound) { + if ( + createOnNotFound && + createOnNotFound.graphicTypes && + createOnNotFound.graphicTypes.findIndex( + (v) => v === state.graphicType + ) >= 0 + ) { const template = this.getGraphicTemplatesByType(state.graphicType); const g = template.new(); g.loadState(state); diff --git a/src/jl-graphic/message/MessageBroker.ts b/src/jl-graphic/message/MessageBroker.ts index 08261b8..38867ec 100644 --- a/src/jl-graphic/message/MessageBroker.ts +++ b/src/jl-graphic/message/MessageBroker.ts @@ -155,6 +155,10 @@ export type GraphicQuery = ( // 订阅消息处理器 export type SubscriptionMessageHandle = (message: Uint8Array) => void; +export interface ICreateOnNotFound { + graphicTypes?: string[]; +} + // 图形app状态订阅 export interface AppStateSubscription { /** @@ -171,8 +175,9 @@ export interface AppStateSubscription { graphicQueryer?: GraphicQuery; /** * 当未根据状态找到图形对象时是否创建新对象 + * 值为设备类型列表 */ - createOnNotFound?: boolean; + createOnNotFound?: ICreateOnNotFound; /** * 订阅消息处理 */