haoxuan
2023-11-15 ac2f57b68213b8376e3ec612432673348285f6c4
增加退出登录,安装插件js-cookie
3个文件已修改
74 ■■■■■ 已修改文件
package-lock.json 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
package.json 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/layout/components/appHeader/index.vue 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
package-lock.json
@@ -14,6 +14,7 @@
        "downloadjs": "^1.4.7",
        "element-ui": "^2.15.13",
        "faker": "^5.5.3",
        "js-cookie": "^3.0.5",
        "lodash": "^4.17.21",
        "vue": "^2.6.14",
        "vue-router": "^3.5.1",
@@ -6872,6 +6873,14 @@
        "@sideway/pinpoint": "^2.0.0"
      }
    },
    "node_modules/js-cookie": {
      "version": "3.0.5",
      "resolved": "https://registry.npmmirror.com/js-cookie/-/js-cookie-3.0.5.tgz",
      "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
      "engines": {
        "node": ">=14"
      }
    },
    "node_modules/js-message": {
      "version": "1.0.7",
      "resolved": "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz",
package.json
@@ -14,6 +14,7 @@
    "downloadjs": "^1.4.7",
    "element-ui": "^2.15.13",
    "faker": "^5.5.3",
    "js-cookie": "^3.0.5",
    "lodash": "^4.17.21",
    "vue": "^2.6.14",
    "vue-router": "^3.5.1",
src/components/layout/components/appHeader/index.vue
@@ -2,31 +2,80 @@
  <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>
      <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--right"></i></div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="logout">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown> -->
      </el-dropdown>
    </div>
  </div>
</template>
<script>
import Cookies from "js-cookie"
export default {
  name: "SalesLead",
  props: {
    headerTitle: String
  },
  data() {
    return {}
    return {
      username: ""
    }
  },
  mounted() {
    this.username = document.cookie.replace(/(?:(?:^|.*;\s*)username\s*=\s*([^;]*).*$)|^.*$/, "$1")
  },
  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.20.102:8080`
      }
      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: "已取消注销"
            })
          })
      }
    }
  }
@@ -53,9 +102,12 @@
    margin-right: 20px;
    display: flex;
    .avatar {
      margin-top: 8px;
      margin-top: 4px;
      margin-right: 10px;
    }
    .el-dropdown-link{
      cursor: pointer;
    }
  }
}
</style>