web-map/src/components/editor-toolbar.vue

82 lines
2.4 KiB
Vue
Raw Normal View History

2025-05-05 23:21:31 +08:00
<script setup lang="ts">
import { MapAreaType } from '@api/map';
2025-05-10 00:49:45 +08:00
import { saveSceneById } from '@api/scene';
2025-05-05 23:21:31 +08:00
import type { EditorService } from '@core/editor.service';
import { isEmpty } from 'lodash-es';
import { inject, type InjectionKey, ref, type ShallowRef, watch } from 'vue';
type Props = {
token: InjectionKey<ShallowRef<EditorService>>;
editable?: boolean;
2025-05-07 20:12:15 +08:00
id: string;
2025-05-05 23:21:31 +08:00
};
const props = defineProps<Props>();
const editor = inject(props.token)!;
2025-05-10 00:49:45 +08:00
//#region 接口
const updateScene = async () => {
const json = editor.value.save();
if (!json) return;
await saveSceneById(props.id, json);
};
//#endregion
2025-05-05 23:21:31 +08:00
const mode = ref<MapAreaType>();
watch(editor.value.mouseBrush, (v) => {
if (!mode.value) return;
const [p1, p2] = v ?? [];
if (isEmpty(p1) || isEmpty(p2)) return;
editor.value.addArea(p1, p2, mode.value);
mode.value = undefined;
});
</script>
<template>
<a-space class="toolbar" :size="0">
<a-button
class="icon-btn tool-btn"
:class="{ active: mode === MapAreaType.库区 }"
size="large"
@click="mode = MapAreaType.库区"
>
<i class="icon" :class="mode === MapAreaType.库区 ? 'area1-active' : 'area1'" />
</a-button>
<a-button
class="icon-btn tool-btn ml-12"
:class="{ active: mode === MapAreaType.互斥区 }"
size="large"
@click="mode = MapAreaType.互斥区"
>
2025-05-06 23:48:21 +08:00
<i class="icon" :class="mode === MapAreaType.互斥区 ? 'area11-active' : 'area11'" />
2025-05-05 23:21:31 +08:00
</a-button>
<a-button
class="icon-btn tool-btn ml-12"
:class="{ active: mode === MapAreaType.非互斥区 }"
size="large"
@click="mode = MapAreaType.非互斥区"
>
2025-05-06 23:48:21 +08:00
<i class="icon" :class="mode === MapAreaType.非互斥区 ? 'area12-active' : 'area12'" />
2025-05-05 23:21:31 +08:00
</a-button>
<a-divider class="size-24 mh-8" type="vertical" />
2025-05-10 00:49:45 +08:00
<a-button class="icon-btn tool-btn" size="large" @click="updateScene">
2025-05-05 23:21:31 +08:00
<i class="mask save" />
</a-button>
2025-05-07 20:12:15 +08:00
<a-button class="icon-btn tool-btn ml-12" size="large" @click="editor.undo()">
2025-05-05 23:21:31 +08:00
<i class="mask undo" />
</a-button>
2025-05-07 20:12:15 +08:00
<a-button class="icon-btn tool-btn ml-12" size="large" @click="editor.redo()">
2025-05-05 23:21:31 +08:00
<i class="mask redo" />
</a-button>
2025-05-07 20:12:15 +08:00
<a-button
class="icon-btn tool-btn ml-12"
size="large"
@click="editor.delete(undefined, true)"
:disabled="!editor.selected.value.length"
>
2025-05-05 23:21:31 +08:00
<i class="mask trash" />
</a-button>
</a-space>
</template>