菜单报错调整

This commit is contained in:
fan 2023-07-21 10:51:15 +08:00
parent 7cb9548aaa
commit 8fffd57b5b

View File

@ -138,12 +138,8 @@ const DefaultCanvasMenu = new ContextMenu({
{ {
items: [SelectAllOptions], items: [SelectAllOptions],
}, },
{
items: [JumpStaitonOptions],
},
], ],
}); });
let drawApp: JlDrawApp | null = null; let drawApp: JlDrawApp | null = null;
export function getDrawApp(): JlDrawApp | null { export function getDrawApp(): JlDrawApp | null {
@ -161,7 +157,6 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
drawApp = new JlDrawApp(dom); drawApp = new JlDrawApp(dom);
const app = drawApp; const app = drawApp;
//根据草稿图类型加载绘图工具 //根据草稿图类型加载绘图工具
const draftType = useDrawStore().$state.draftType;
let drawAssistants: ( let drawAssistants: (
| PlatformDraw | PlatformDraw
| StationDraw | StationDraw
@ -180,6 +175,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
| AxleCountingDraw | AxleCountingDraw
| SeparatorDraw | SeparatorDraw
)[] = []; )[] = [];
const draftType = useDrawStore().$state.draftType;
if (draftType === 'Line') { if (draftType === 'Line') {
drawAssistants = [ drawAssistants = [
new PlatformDraw( new PlatformDraw(
@ -228,9 +224,26 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
} }
app.setOptions({ drawAssistants: drawAssistants }); app.setOptions({ drawAssistants: drawAssistants });
if (draftType === 'Line') {
const menuOptionsNew = {
name: '绘制-画布菜单',
groups: [
{
items: [UndoOptions, RedoOptions],
},
{
items: [SelectAllOptions],
},
{
items: [JumpStaitonOptions],
},
],
};
DefaultCanvasMenu.setOptions(menuOptionsNew);
}
// 画布右键菜单 // 画布右键菜单
app.registerMenu(DefaultCanvasMenu); app.registerMenu(DefaultCanvasMenu);
app.canvas.on('_rightclick', (e) => { app.canvas.on('_rightclick', (e) => {
if (app._drawing) return; if (app._drawing) return;
UndoOptions.disabled = !app.opRecord.hasUndo; UndoOptions.disabled = !app.opRecord.hasUndo;
@ -244,6 +257,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
SelectAllOptions.handler = () => { SelectAllOptions.handler = () => {
app.selectAllGraphics(); app.selectAllGraphics();
}; };
if (draftType === 'Line') {
const stations = app.queryStore.queryByType<Station>(Station.Type); const stations = app.queryStore.queryByType<Station>(Station.Type);
const jumpStaitonItems: MenuItemOptions[] = []; const jumpStaitonItems: MenuItemOptions[] = [];
stations.forEach((station) => { stations.forEach((station) => {
@ -265,6 +279,8 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
], ],
}; };
DefaultCanvasMenu.update(); DefaultCanvasMenu.update();
}
DefaultCanvasMenu.open(e.global); DefaultCanvasMenu.open(e.global);
}); });
app.addKeyboardListener( app.addKeyboardListener(