zuozhengqing
2023-11-06 2fb4239e828bcfa9711ce4cecc4b942767621d62
src/components/layout/components/appHeader/index.vue
@@ -1,19 +1,20 @@
<template>
  <div class="sales-lead">
    <div class="header-title">{{ headerTitle }}</div>
<!--    <div class="header-user-info">-->
<!--      <div class="avatar"><el-avatar icon="el-icon-user-solid"></el-avatar></div>-->
<!--      <el-dropdown @command="handleCommand">-->
<!--        <div class="el-dropdown-link">用户名<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i></div>-->
<!--        <el-dropdown-menu slot="dropdown">-->
<!--          <el-dropdown-item command="logout">退出</el-dropdown-item>-->
<!--        </el-dropdown-menu>-->
<!--      </el-dropdown>-->
<!--    </div>-->
   <div class="header-user-info">
     <div class="avatar"><el-avatar icon="el-icon-user-solid"></el-avatar></div>
     <el-dropdown @command="handleCommand">
       <div class="el-dropdown-link">用户名<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i></div>
       <el-dropdown-menu slot="dropdown">
         <el-dropdown-item command="logout">退出</el-dropdown-item>
       </el-dropdown-menu>
     </el-dropdown>
   </div>
  </div>
</template>
<script>
import Cookies from "js-cookie"
export default {
  name: "SalesLead",
  props: {
@@ -23,10 +24,51 @@
    return {}
  },
  methods: {
    environmentType(){
      let type
      if (location.href.includes('192.168.20.119')) {
          type = 'test'
      } else if (location.href.includes('192.168') || location.href.includes('localhost')) {
          type = 'dev'
      } else {
          type = 'prod'
      }
      return type
    },
    getApsPage(){
      // 首页部署在各个环境的端口
      const loginPathMap = {
          prod:`//${window.location.hostname}:9080`,
          test:`//192.168.20.119:9080`,
          // 想跳到本地启动的登录页的话需要把dev改成你本地项目路径
          dev: `//192.168.8.112:8081`
      }
      return loginPathMap[this.environmentType()]
    },
    handleCommand(command) {
      console.log(command)
      if (command === "logout") {
        this.$router.push({ path: "/login" })
        // this.$router.push({ path: "/login" })
        document.cookie = "cookieName=; path=/;";
        this.$confirm('确定要注销当前用户吗?', '注销用户', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          Cookies.remove('token')
          // window.location.href = 'http://localhost:8080/login'; //本地的智慧工厂-登录页
          window.location.href = 'http:'+this.getApsPage()+'/login';
          this.$message({
            type: 'success',
            message: '注销成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消注销'
          });
        });
      }
    }
  }