郑永安
2023-06-19 6ae336af4670a425ae8892aacda560ec2147d8a7
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<template>
  <div class="sidebar-logo-container">
    <router-link class="sidebar-logo-link" to="/">
      <img :src="logo" class="sidebar-logo" />
      <h1 class="sidebar-title">企业信息查询系统{{ title }}</h1>
    </router-link>
    <div class="right-menu">
      <el-dropdown class="avatar-container" trigger="click">
        <!--          <div class="avatar-wrapper">-->
        <!--            <div style="line-height:30px;cursor: pointer;">{{ username }}</div>-->
        <!--            <i class="el-icon-caret-bottom" />-->
        <!--          </div>-->
        <span class="el-dropdown-link">
           {{username}}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
        <el-dropdown-menu slot="dropdown" class="user-dropdown">
          <router-link to="/">
            <el-dropdown-item>首页</el-dropdown-item>
          </router-link>
          <router-link to="/userpermisson/user">
            <el-dropdown-item>用户管理</el-dropdown-item>
          </router-link>
          <el-dropdown-item divided>
            <span style="display:block;" @click="logout">退出</span>
          </el-dropdown-item>
          <el-dropdown-item>
            <span style="display:block;"  @click="handleEdit()">修改密码</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
 
    </div>
    <el-dialog
      :close-on-click-modal="false"
      :destroy-on-close="true"
      title="修改密码"
      :visible.sync="editDialogVisible"
      width="30%"
      :before-close="handleClose"
      :append-to-body='true'
    >
      <el-form ref="editform" :model="editFormData" :rules="editRules" label-width="80px">
        <el-form-item prop="account" label="账号">
          <el-input disabled v-model="editFormData.account" size="medium"></el-input>
        </el-form-item>
 
        <el-form-item prop="oldpassword" label="原密码">
          <el-input v-model="editFormData.oldpassword" size="medium" type="password"></el-input>
        </el-form-item>
 
        <el-form-item prop="newpassword" label="新密码">
          <el-input v-model="editFormData.newpassword" size="medium" type="password"></el-input>
        </el-form-item>
 
        <el-form-item prop="confirmnewpassword" label="确认密码">
          <el-input v-model="editFormData.confirmnewpassword" size="medium" type="password"></el-input>
        </el-form-item>
 
        <el-form-item align="center" label-width="0">
          <el-button type="primary" @click="onEditSubmit()">{{ $t('common.ok') }}</el-button>
          <el-button @click="editDialogVisible = false">{{ $t('common.cancel') }}</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
 
<script>
import { mount } from '@vue/test-utils';
import { getUser, getUserById1, updateUser } from '@/api/user';
import { rules } from '@/utils/validate';
import { deepClone } from '@/utils';
export default {
  name: 'SidebarLogo',
  props: {},
  data() {
    return {
      title: '企业信息查询系统',
      logo: require('@/assets/logo.png'),
      disabled: false,
      editDialogVisible: false,
      editFormData: {
        account: '',
        oldpassword: '',
        newpassword: '',
        confirmnewpassword: ''
      },
      editRules: {
        oldpassword: rules.empty,
        newpassword: rules.empty,
        confirmnewpassword: rules.empty
      },
      username: localStorage.getItem("name")
    };
  },
  mounted() {
    this.title = this.$store.state.park.name;
  },
  methods: {
    async logout() {
      await this.$store.dispatch('user/logout');
      this.$router.push(`/login?redirect=${this.$route.fullPath}`);
      window.location.reload();
    },
    async handleEdit() {
      this.editDialogVisible = true;
      const res = await getUserById1();
      this.editFormData.account = res.data.username;
    },
    async onEditSubmit() {
      // const res = await getUserById1();
      // if (md5(this.editFormData.oldpassword, 32) != res.data.password) {
      //     this.$message('原密码不正确,请确认', 'error');
      //     return;
      // }
 
      if (this.editFormData.newpassword != this.editFormData.confirmnewpassword) {
        this.$message('两次输入密码不一致,请确认', 'error');
        return;
      }
 
      this.$refs.editform.validate(async valid => {
        if (valid) {
          //const res1 = await findCompanyById();
          //res1.data.adminaccoutpassword = md5(this.editFormData.newpassword, 32);
          // this.editFormData.password= md5(this.editFormData.newpassword, 32)
          const res = await updateUser(this.editFormData);
          if (res.status == 200) {
            this.$message(this.$t('message.edit_success'), 'success');
          } else {
            this.$message(this.$t('message.edit_fail'), 'success');
          }
          this.editDialogVisible = false;
          this.editFormData = deepClone(EditFormData);
        }
      });
    },
    handleClose(done) {
      done();
    }
  }
};
</script>
 
<style lang="scss" scoped>
.sidebarLogoFade-enter-active {
  transition: opacity 1.5s;
}
 
.sidebarLogoFade-enter,
.sidebarLogoFade-leave-to {
  opacity: 0;
}
 
.sidebar-logo-container {
  position: fixed;
  z-index: 5;
  top:0;
  left: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
  padding-left: 40px;
  line-height: 70px;
  background: linear-gradient(to right, #11abff, #3c50fc);
  text-align: left;
 
  .sidebar-logo-link {
    height: 100%;
    display: flex;
    align-items: center;
 
    .sidebar-logo {
      width: 32px;
      height: 32px;
      margin-right: 10px;
    }
 
    .sidebar-title {
      color: #fff;
      font-weight: 600;
      font-size: 18px;
      letter-spacing: 2px;
      font-family: Avenir, Helvetica Neue, Arial, Helvetica, sans-serif;
    }
  }
 
  .right-menu {
    height: 100%;
    line-height: 70px;
    color: #fff;
    .el-dropdown-link{
      color: #fff;
      cursor: pointer;
    }
    .avatar-container {
      margin-right: 30px;
 
      .avatar-wrapper {
        margin-top: 10px;
        position: relative;
 
        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }
 
        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 10px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>