headerLayout.vue 5.16 KB
<template>
    <div class="headerLayout">
        <div class="tabList">
            <div v-for="(item,index) in buttenList" :key="index" @click="change(index)">
                <el-button class="tabButton" size="mini" :class="num==index?'is-active':''">{{item}}</el-button>
            </div>
        </div>
        <h3>企业运行图谱</h3>
        <div class="time">{{nowDate | moment("YYYY/MM/DD")}} {{nowDate | moment("HH:mm:ss")}} 星期{{week | weekFilter}}</div>
             <div class="right-menu">
      <el-dropdown class="avatar-container" trigger="click">
        <div class="avatar-wrapper">
          <img src="~@/assets/img/timg.jpg" class="user-avatar">
          <i class="el-icon-caret-bottom" />
        </div>
        <el-dropdown-menu slot="dropdown" class="user-dropdown">
          <router-link to="/">
            <el-dropdown-item>
              Home
            </el-dropdown-item>
          </router-link>
          <el-dropdown-item divided @click.native="logout">
            <span style="display:block; width: 60px">Log Out</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      screenWidth: document.body.clientWidth,
      num: 0,
      nowDate: '',
      week: '',
      hour: '',
      monthData: {
        id: 'dataByMonth',
        xData: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        yData: [70, 90, 110, 108, 100, 110, 130, 140, 150, 120, 110, 98],
        colors: ['RGBA(27, 157, 247, 1)', 'RGBA(30, 201, 251, 1)']
      },
      buttenList: ['概况', '运营', '商机', '客户']
    }
  },
  filters: {
    weekFilter: function (value) {
      let nvalue = ''
      switch (value) {
        case 1:
          nvalue = '一'
          break
        case 2:
          nvalue = '二'
          break
        case 3:
          nvalue = '三'
          break
        case 4:
          nvalue = '四'
          break
        case 5:
          nvalue = '五'
          break
        case 6:
          nvalue = '六'
          break
        case 0:
          nvalue = '日'
          break
      }
      return nvalue
    }
  },
  watch: {
    screenwidth(val) {
      if(!this.timer){
        this.screenWidth = val
        this.timer = true
        let that = this
        setTimeout(function(){
          console.log(that.screenWidth)
          that.timer = false
        },400)
      }
    }
  },
  mounted () {
    this.init()
    this.getDate()
    const that = this
    window.onresize = () => {
     return(() => {
       window.screenWidth = document.body.clientWidth
       that.screenWidth = window.screenWidth
     })()
    }
  },
  methods: {
    logout() {
      this.$router.push('/login')
    },
    init () {
      this.num = sessionStorage.getItem('num')
      let user = JSON.parse(sessionStorage.getItem('user'))
      if(user.role === 1) {
        this.buttenList.push('管理端')
      }
    },
    getDate () {
      let vm = this
      this.nowDate = new Date()
      this.week = new Date().getDay()
      setTimeout(function () {
        vm.getDate()
      }, 1000)
    },
    change (index) {
      this.num = index
      sessionStorage.setItem('num', index)
      let token = sessionStorage.getItem('token')
      switch (index) {
        case 0:
          this.$router.replace('/index')
          break
        case 1:
          this.$router.replace('/content/operation/page')
          break
        case 2:
          this.$router.replace('/content/business/page')
          break
        case 3:
          this.$router.replace('/content/client/page')
          break
        // case 4:
        //   this.$router.replace('/content/organization/page')
        //   break
        // case 5:
        //   this.$router.replace('/content/organization/page')
        //   break
        case 4:
          // this.$router.replace('/http://localhost:9528/#/dashboard')
          // window.location.replace('http://localhost:9528/#/dashboard')
          window.open('http://111.203.232.175:8085/#/dashboard?token=' + token)
          // window.open('http://localhost:9528/#/dashboard?token=' + token)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
    @import '~@/assets/style/headerLayout.scss';
      .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 14px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
</style>