<template>
  <el-dropdown trigger="click" @command="handleSetSize">
    <div>
      <svg-icon class-name="size-icon" icon-class="size" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item of sizeOptions" :key="item.value" :disabled="size===item.value" :command="item.value">
        {{item.label }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  inject:['reload'],
  data() {
    return {
      sizeOptions: [
        { label: '默认', value: 'default' },
        { label: '大号', value: 'medium' },
        { label: '中号', value: 'small' },
        { label: '小号', value: 'mini' }
      ]
    }
  },
  computed: {
    size() {
      return this.$store.getters.size
    }
  },
  methods: {
    handleSetSize(size) {
      this.$ELEMENT.size = size;
      this.$store.dispatch('app/setSize', size);
      this.$message({
        message: 'Switch Size Success',
        type: 'success'
      });
      this.reload();
    },
    refreshView() {
      // In order to make the cached page re-rendered
      this.$store.dispatch('tagsView/delAllCachedViews', this.$route);
      const { fullPath } = this.$route;
      this.$nextTick(() => {
        location. reload();
        this.$router.replace({
          path: fullPath
        })
      })
    }
  }

}
</script>
