|
|
@@ -1,12 +1,12 @@
|
|
|
<template>
|
|
|
<template v-for="item in projectMenu" :key="item.label">
|
|
|
<el-divider direction="vertical" v-if="item.type" />
|
|
|
- <MenuItem v-else :item="item" @click="handleClick(item.key)" />
|
|
|
+ <MenuItem v-else :item="item" :disabled="item?.disabled" @click="item?.onClick?.()"> </MenuItem>
|
|
|
</template>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { reactive, inject } from 'vue'
|
|
|
+import { inject, computed } from 'vue'
|
|
|
import {
|
|
|
LuUndo,
|
|
|
LuRedo,
|
|
|
@@ -24,99 +24,110 @@ import {
|
|
|
LuArrowDownToLine
|
|
|
} from 'vue-icons-plus/lu'
|
|
|
import MenuItem from './components/MenuItem.vue'
|
|
|
+import { useProjectStore } from '@/store/modules/project'
|
|
|
|
|
|
-const onMenuClick = inject<(menuKey: string) => void>('onMenuClick', () => {})
|
|
|
+import type { MenuItemType } from './components/MenuItem.vue'
|
|
|
|
|
|
-const projectMenu = reactive([
|
|
|
- {
|
|
|
- key: 'undo',
|
|
|
- label: '撤销',
|
|
|
- img: LuUndo
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'redo',
|
|
|
- label: '重做',
|
|
|
- img: LuRedo
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'divider'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignLeft',
|
|
|
- label: '左对齐',
|
|
|
- img: LuAlignStartVertical
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignHorizontal',
|
|
|
- label: '水平对齐',
|
|
|
- img: LuAlignCenterVertical
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignRight',
|
|
|
- label: '右对齐',
|
|
|
- img: LuAlignEndVertical
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignTop',
|
|
|
- label: '顶对齐',
|
|
|
- img: LuAlignStartHorizontal
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignVertical',
|
|
|
- label: '垂直居中',
|
|
|
- img: LuAlignCenterHorizontal
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignBottom',
|
|
|
- label: '底对齐',
|
|
|
- img: LuAlignEndHorizontal
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'divider'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignWidth',
|
|
|
- label: '宽度匹配',
|
|
|
- img: LuAlignHorizontalSpaceBetween
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignHeight',
|
|
|
- label: '高度匹配',
|
|
|
- img: LuAlignVerticalSpaceBetween
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'alignAll',
|
|
|
- label: '宽高匹配',
|
|
|
- img: LuLayoutGrid
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'divider'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'up',
|
|
|
- label: '上移一层',
|
|
|
- img: LuArrowUp
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'down',
|
|
|
- label: '下移一层',
|
|
|
- img: LuLayoutGrid
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'top',
|
|
|
- label: '置于顶层',
|
|
|
- img: LuArrowUpToLine
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'bottom',
|
|
|
- label: '置于底层',
|
|
|
- img: LuArrowDownToLine
|
|
|
- }
|
|
|
-])
|
|
|
+const onMenuClick = inject<(menuKey: string) => void>('onMenuClick', () => {})
|
|
|
+const projectStore = useProjectStore()
|
|
|
|
|
|
-const handleClick = (menuKey: string) => {
|
|
|
- onMenuClick?.(menuKey)
|
|
|
-}
|
|
|
+const projectMenu = computed((): MenuItemType[] => {
|
|
|
+ console.log(projectStore.history)
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ key: 'undo',
|
|
|
+ label: '撤销',
|
|
|
+ img: LuUndo,
|
|
|
+ disabled: !projectStore.canUndo,
|
|
|
+ onClick: () => {
|
|
|
+ projectStore.undo()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'redo',
|
|
|
+ label: '重做',
|
|
|
+ img: LuRedo,
|
|
|
+ disabled: !projectStore.canRedo,
|
|
|
+ onClick: () => {
|
|
|
+ projectStore.redo()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'divider'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignLeft',
|
|
|
+ label: '左对齐',
|
|
|
+ img: LuAlignStartVertical
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignHorizontal',
|
|
|
+ label: '水平对齐',
|
|
|
+ img: LuAlignCenterVertical
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignRight',
|
|
|
+ label: '右对齐',
|
|
|
+ img: LuAlignEndVertical
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignTop',
|
|
|
+ label: '顶对齐',
|
|
|
+ img: LuAlignStartHorizontal
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignVertical',
|
|
|
+ label: '垂直居中',
|
|
|
+ img: LuAlignCenterHorizontal
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignBottom',
|
|
|
+ label: '底对齐',
|
|
|
+ img: LuAlignEndHorizontal
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'divider'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignWidth',
|
|
|
+ label: '宽度匹配',
|
|
|
+ img: LuAlignHorizontalSpaceBetween
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignHeight',
|
|
|
+ label: '高度匹配',
|
|
|
+ img: LuAlignVerticalSpaceBetween
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'alignAll',
|
|
|
+ label: '宽高匹配',
|
|
|
+ img: LuLayoutGrid
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'divider'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'up',
|
|
|
+ label: '上移一层',
|
|
|
+ img: LuArrowUp
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'down',
|
|
|
+ label: '下移一层',
|
|
|
+ img: LuLayoutGrid
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'top',
|
|
|
+ label: '置于顶层',
|
|
|
+ img: LuArrowUpToLine
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'bottom',
|
|
|
+ label: '置于底层',
|
|
|
+ img: LuArrowDownToLine
|
|
|
+ }
|
|
|
+ ]
|
|
|
+})
|
|
|
</script>
|
|
|
|
|
|
<style lang="less" scoped></style>
|