状态消息订阅添加图形对象查询属性,可以从外部控制查询方式,如果不提供,默认为根据code和type查询
This commit is contained in:
parent
3e1bbc92bf
commit
22fc9f8d6b
@ -24,6 +24,7 @@ import {
|
||||
WsMsgCli,
|
||||
type AppStateSubscription,
|
||||
type MessageCliOption,
|
||||
GraphicQuery,
|
||||
} from '../message';
|
||||
import { OperationRecord } from '../operation/JlOperation';
|
||||
import {
|
||||
@ -472,7 +473,10 @@ export interface IGraphicScene extends EventEmitter<GraphicAppEvents> {
|
||||
* 处理图形状态
|
||||
* @param graphicStates
|
||||
*/
|
||||
handleGraphicStates(graphicStates: GraphicState[]): void;
|
||||
handleGraphicStates(
|
||||
graphicStates: GraphicState[],
|
||||
queryer?: GraphicQuery
|
||||
): void;
|
||||
/**
|
||||
* 根据类型获取图形模板
|
||||
* @param type
|
||||
@ -1083,12 +1087,17 @@ abstract class GraphicSceneBase
|
||||
* 处理图形状态
|
||||
* @param graphicStates
|
||||
*/
|
||||
handleGraphicStates(graphicStates: GraphicState[]): void {
|
||||
handleGraphicStates(
|
||||
graphicStates: GraphicState[],
|
||||
queryer?: GraphicQuery
|
||||
): void {
|
||||
graphicStates.forEach((state) => {
|
||||
const g = this.queryStore.queryByCodeAndType(
|
||||
state.code,
|
||||
state.graphicType
|
||||
);
|
||||
let g: JlGraphic | undefined;
|
||||
if (queryer) {
|
||||
g = queryer(state, this.queryStore);
|
||||
} else {
|
||||
g = this.queryStore.queryByCodeAndType(state.code, state.graphicType);
|
||||
}
|
||||
try {
|
||||
if (!g) {
|
||||
const template = this.getGraphicTemplatesByType(state.graphicType);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import EventEmitter from 'eventemitter3';
|
||||
import { IGraphicScene } from '../app';
|
||||
import { GraphicState } from '../core';
|
||||
import { GraphicQueryStore, GraphicState, JlGraphic } from '../core';
|
||||
import {
|
||||
IMessageHandler,
|
||||
IUnsubscriptor,
|
||||
@ -146,6 +146,11 @@ export type GraphicStateMessageConvert = (
|
||||
message: Uint8Array
|
||||
) => GraphicState[];
|
||||
|
||||
export type GraphicQuery = (
|
||||
state: GraphicState,
|
||||
store: GraphicQueryStore
|
||||
) => JlGraphic | undefined;
|
||||
|
||||
// 订阅消息处理器
|
||||
export type SubscriptionMessageHandle = (message: Uint8Array) => void;
|
||||
|
||||
@ -159,6 +164,10 @@ export interface AppStateSubscription {
|
||||
* 图形状态消息转换
|
||||
*/
|
||||
messageConverter?: GraphicStateMessageConvert;
|
||||
/**
|
||||
* 根据状态查询图形对象,默认为根据code和type查询图形对象
|
||||
*/
|
||||
graphicQueryer?: GraphicQuery;
|
||||
/**
|
||||
* 订阅消息处理
|
||||
*/
|
||||
@ -187,7 +196,7 @@ class AppMessageHandler implements IMessageHandler {
|
||||
const sub = this.sub;
|
||||
if (sub.messageConverter) {
|
||||
const graphicStates = sub.messageConverter(data);
|
||||
this.app.handleGraphicStates(graphicStates);
|
||||
this.app.handleGraphicStates(graphicStates, sub.graphicQueryer);
|
||||
} else if (sub.messageHandle) {
|
||||
sub.messageHandle(data);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { defineStore } from 'pinia';
|
||||
import { destroyDrawApp, getDrawApp, initDrawApp } from 'src/examples/app';
|
||||
import { DrawAssistant, GraphicData, IDrawApp, JlGraphic } from 'src/jlgraphic';
|
||||
import { IJlCanvas } from 'src/jlgraphic/app/JlGraphicApp';
|
||||
import { markRaw } from 'vue';
|
||||
|
||||
export const useDrawStore = defineStore('draw', {
|
||||
state: () => ({
|
||||
@ -81,7 +82,7 @@ export const useDrawStore = defineStore('draw', {
|
||||
});
|
||||
app.on('graphicselected', () => {
|
||||
console.log('批量选中事件', app.selectedGraphics.length);
|
||||
this.selectedGraphics = app.selectedGraphics;
|
||||
this.selectedGraphics = markRaw(app.selectedGraphics);
|
||||
});
|
||||
this.selectedGraphics = [];
|
||||
return app;
|
||||
|
Loading…
Reference in New Issue
Block a user