yangfeng
2023-11-08 b23188df0c4343d51cbc777121d4a138c5a5a1f4
增加显示用户名及退出优化
1个文件已修改
84 ■■■■ 已修改文件
src/components/layout/components/appHeader/index.vue 84 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/layout/components/appHeader/index.vue
@@ -4,7 +4,7 @@
    <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--right"></i></div>
        <div class="el-dropdown-link">{{ username }}<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>
@@ -21,27 +21,33 @@
    headerTitle: String
  },
  data() {
    return {}
    return {
      username: ""
    }
  },
  mounted() {
    this.username = document.cookie.replace(/(?:(?:^|.*;\s*)username\s*=\s*([^;]*).*$)|^.*$/, "$1")
  },
  methods: {
    environmentType(){
    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'
      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'
        type = "prod"
      }
      return type
    },
    getApsPage(){
    getApsPage() {
      // 首页部署在各个环境的端口
      const loginPathMap = {
          prod:`//${window.location.hostname}:9080`,
          test:`//192.168.20.119:9080`,
          // 想跳到本地启动的登录页的话需要把dev改成你本地项目路径
          dev: `//192.168.8.112:8082`
        prod: `//${window.location.hostname}:9080`,
        test: `//192.168.20.119:9080`,
        // 想跳到本地启动的登录页的话需要把dev改成你本地项目路径
        dev: `//192.168.20.102:8080`
      }
      return loginPathMap[this.environmentType()]
    },
@@ -49,25 +55,27 @@
      console.log(command)
      if (command === "logout") {
        // 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: '已取消注销'
          });
        });
        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: "已取消注销"
            })
          })
      }
    }
  }
@@ -79,16 +87,14 @@
.sales-lead {
  display: flex;
  height: 50px;
  line-height: 50px;
  flex-shrink: 0;
  box-sizing: border-box;
  background-color: transparent;
  line-height: 50px;
  background-color: $color-bg;
  border: 1px solid #ccc;
  align-items: center;
  .header-title {
    margin-left: 16px;
    padding-left: 16px;
    font-size: 18px;
    font-weight: 700;
    font-weight: bold;
    color: #171718;
  }
  .header-user-info {
@@ -96,7 +102,7 @@
    margin-right: 20px;
    display: flex;
    .avatar {
      margin-top: 8px;
      margin-top: 4px;
      margin-right: 10px;
    }
  }