<template>
  <div class="logo">
    <router-link :to="{name:'Console'}">
      <LogoSvg alt="logo" v-if="!customlogo" />
      <img v-if="customlogo" alt="logo" :src="logo" style="width: 32px;height:32px;"/>
      <h1 v-if="showTitle" style="white-space:nowrap;text-overflow:ellipsis;overflow:hidden;max-width:160px;" :title="titles">{{ this.titles }}</h1>
    </router-link>
  </div>
</template>

<script>
import LogoSvg from '@/assets/logo.svg?inline'
import { mixin, mixinDevice } from '@/utils/mixin'

export default {
  name: 'Logo',
  components: {
    LogoSvg
  },
  mixins: [mixin, mixinDevice],
  data () {
    return {
      titles: ''
    }
  },
  props: {
    logo: {
      type: String,
      default: '',
      required: false
    },
    customlogo: {
      type: Boolean,
      default: false,
      required: false
    },
    title: {
      type: String,
      default: '管理平台',
      required: false
    },
    showTitle: {
      type: Boolean,
      default: true,
      required: false
    }
  },
  created () {
    if (this.layoutMode === 'topmenu') {
      if (this.title.length > 8) {
        this.titles = this.title.substring(0, 8) + '...'
      } else {
        this.titles = this.title
      }
    } else {
      if (this.title.length > 10) {
        this.titles = this.title.substring(0, 8) + '...'
      } else {
        this.titles = this.title
      }
    }
  }
}
</script>
