yangfeng
2024-02-28 7979474ca5570945126d7f087fa4363272d964b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<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">你好  {{ 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-item @click.native="updatePwd">
            <d2-icon name="unlock" class="d2-mr-5" />
            修改密码
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <UpdatePassWord :editCommonConfig="editConfig"></UpdatePassWord>
    </div>
  </div>
</template>
 
<script>
import Cookies from "js-cookie"
import UpdatePassWord from "./components/updatePassWord"
export default {
  name: "SalesLeads",
  props: {
    headerTitle: {
      type:String,
      default:''
    }
  },
  components:{
    UpdatePassWord,
  },
  data() {
    return {
      username: "",
      editConfig:{
        dialogVisible:false,
        userId:"",
      }
    }
  },
  created(){
    const userObj = Cookies.get('userObj');  
    if (userObj) {   
      let userInfo = JSON.parse(userObj); 
      this.editConfig.userId=userInfo.id
      this.username=userInfo.nickName
    } else {  
      console.log('Object not found in cookie');  
    }  
  },
  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.8.113:8080`
      }
      return loginPathMap[this.environmentType()]
    },
    handleCommand(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: "已取消注销"
            })
          })
      }
    },
    updatePwd(){
      this.editConfig.dialogVisible=true
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.sales-lead {
  display: flex;
  height: 50px;
  box-sizing: border-box;
  line-height: 50px;
  background-color: $color-bg;
  border: 1px solid #ccc;
  .header-title {
    padding-left: 16px;
    font-size: 18px;
    font-weight: bold;
    color: #171718;
  }
  .header-user-info {
    margin-left: auto;
    margin-right: 20px;
    display: flex;
    .avatar {
      margin-top: 4px;
      margin-right: 10px;
    }
  }
}
</style>