ActionBar.vue 1.9 KB
Newer Older
L
LeoKu 已提交
1 2 3 4 5 6 7 8
<template>
  <div class="action-menu">
    <div
      v-for="ac in actions"
      :key="ac.type"
      class="menu-item"
      :class="{ disabled: ac.disabled }"
      :title="ac.tip"
L
LeoKu 已提交
9
      @click="emit('action', ac.type)"
L
LeoKu 已提交
10
    >
L
LeoKu 已提交
11
      <img :src="ac.icon" :alt="ac.tip" />
L
LeoKu 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'

import IconBack from '@/assets/icons/icon-back.svg'
import IconCode from '@/assets/icons/icon-code.svg'
import IconFlip from '@/assets/icons/icon-flip.svg'
import IconNext from '@/assets/icons/icon-next.svg'
import { ActionType } from '@/enums'
import { useStore } from '@/store'

const emit = defineEmits<{
L
LeoKu 已提交
28
  (e: 'action', actionType: ActionType): void
L
LeoKu 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
}>()

const { t } = useI18n()

const store = useStore()

const canUndo = computed(() => store.state.history.past.length > 0)
const canRedo = computed(() => store.state.history.future.length > 0)

const actions = computed(() => [
  {
    type: ActionType.Undo,
    icon: IconBack,
    tip: t('action.undo'),
    disabled: !canUndo.value,
  },
  {
    type: ActionType.Redo,
    icon: IconNext,
    tip: t('action.redo'),
    disabled: !canRedo.value,
  },
  {
    type: ActionType.Flip,
    icon: IconFlip,
    tip: t('action.flip'),
  },
  {
    type: ActionType.Code,
    icon: IconCode,
    tip: t('action.code'),
  },
])
</script>

<style lang="scss" scoped>
.action-menu {
  display: flex;
  align-items: center;
  margin-top: 5rem;
  padding: 0.5rem;
  background-color: $color-gray;
  border-radius: 2rem;

  .menu-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    margin: 0 0.5rem;
    background-color: lighten($color-gray, 10);
    border-radius: 50%;
    cursor: pointer;
    transition: opacity 0.2s;

    &.disabled {
      cursor: default;
      opacity: 0.6;
    }
  }
}
</style>