|
12 | 12 | <img :src="user.avatar || defaultAvatar" alt="头像">
|
13 | 13 | <label class="mask">
|
14 | 14 | <i class="iconfont icon-icon-test" style="font-size: 20px;"></i>
|
15 |
| - <input |
16 |
| - ref="avatarInput" |
17 |
| - type="file" |
18 |
| - accept="image/*" |
19 |
| - @change="fileChange" /> |
| 15 | + <input ref="avatarInput" type="file" accept="image/*" @change="fileChange" /> |
20 | 16 | </label>
|
21 | 17 | </div>
|
22 | 18 | <div class="text">
|
23 |
| - <div class="username">{{ nickname }}</div> |
24 |
| - <div class="desc">{{ title }}</div> |
| 19 | + <div class="username" @click="changeNickname" v-if="!nicknameChanged">{{ nickname }}</div> |
| 20 | + <el-input |
| 21 | + placeholder="请输入内容" |
| 22 | + size="small" |
| 23 | + v-else |
| 24 | + v-model="nickname" |
| 25 | + ref="input" |
| 26 | + @blur="blur"></el-input> |
25 | 27 | </div>
|
26 | 28 | <img src="../../assets/img/user/corner.png" class="corner">
|
| 29 | + <div class="info"> |
| 30 | + <div class="username">{{ username }}</div> |
| 31 | + <div class="mid">|</div> |
| 32 | + <div class="desc">{{ groupName }}</div> |
| 33 | + </div> |
27 | 34 | </div>
|
28 | 35 | <ul class="dropdown-box">
|
29 | 36 | <li class="password" @click="changePassword">
|
@@ -150,8 +157,11 @@ export default {
|
150 | 157 | }
|
151 | 158 | }
|
152 | 159 | return {
|
153 |
| - nickname: null, |
| 160 | + username: null, |
154 | 161 | dialogFormVisible: false,
|
| 162 | + nicknameChanged: false, |
| 163 | + nickname: null, |
| 164 | + groupName: null, |
155 | 165 | form: {
|
156 | 166 | old_password: '',
|
157 | 167 | new_password: '',
|
@@ -185,13 +195,6 @@ export default {
|
185 | 195 | }
|
186 | 196 | },
|
187 | 197 | computed: {
|
188 |
| - title() { |
189 |
| - const { isSuper } = this.user || {} |
190 |
| - if (isSuper) { |
191 |
| - return '超级管理员' |
192 |
| - } |
193 |
| - return '管理员' |
194 |
| - }, |
195 | 198 | ...mapGetters(['user']),
|
196 | 199 | },
|
197 | 200 | watch: {
|
@@ -263,7 +266,7 @@ export default {
|
263 | 266 |
|
264 | 267 | return this.$axios({
|
265 | 268 | method: 'post',
|
266 |
| - url: '/cms/file/', |
| 269 | + url: '/cms/file', |
267 | 270 | data: {
|
268 | 271 | file,
|
269 | 272 | },
|
@@ -302,9 +305,47 @@ export default {
|
302 | 305 | })
|
303 | 306 | })
|
304 | 307 | },
|
| 308 | + changeNickname() { |
| 309 | + this.nicknameChanged = true |
| 310 | + setTimeout(() => { |
| 311 | + this.$refs.input.focus() |
| 312 | + }, 200) |
| 313 | + }, |
| 314 | + async blur() { |
| 315 | + if (this.nickname) { |
| 316 | + const { user } = this.$store.state |
| 317 | + if (this.nickname !== user.nickname && this.nickname !== '佚名') { |
| 318 | + this.$axios({ |
| 319 | + method: 'put', |
| 320 | + url: '/cms/user', |
| 321 | + data: { |
| 322 | + nickname: this.nickname, |
| 323 | + }, |
| 324 | + params: { |
| 325 | + showBackend: true, |
| 326 | + }, |
| 327 | + }).then((res) => { |
| 328 | + if (res.error_code === 0) { |
| 329 | + this.$message({ |
| 330 | + type: 'success', |
| 331 | + message: '更新昵称成功', |
| 332 | + }) |
| 333 | + // 触发重新获取用户信息 |
| 334 | + return User.getInformation() |
| 335 | + } |
| 336 | + this.nickname = user.nickname |
| 337 | + }).then((res) => { // eslint-disable-line |
| 338 | + this.setUserAndState(res) |
| 339 | + }) |
| 340 | + } |
| 341 | + } |
| 342 | + this.nicknameChanged = false |
| 343 | + }, |
305 | 344 | init() {
|
306 | 345 | const { user } = this.$store.state
|
307 |
| - this.nickname = user ? user.nickname : '未登录' |
| 346 | + this.username = user ? user.username : '未登录' |
| 347 | + this.groupName = user.groupName ? user.groupName : '超级管理员' |
| 348 | + this.nickname = user && user.nickname ? user.nickname : '佚名' |
308 | 349 | },
|
309 | 350 | changePassword() {
|
310 | 351 | this.dialogFormVisible = true
|
@@ -372,6 +413,7 @@ export default {
|
372 | 413 |
|
373 | 414 | .user {
|
374 | 415 | height: 40px;
|
| 416 | +
|
375 | 417 | .el-dropdown-link {
|
376 | 418 | cursor: pointer;
|
377 | 419 |
|
@@ -458,13 +500,29 @@ export default {
|
458 | 500 | .username {
|
459 | 501 | margin-bottom: 10px;
|
460 | 502 | font-size: 16px;
|
| 503 | + cursor: pointer; |
461 | 504 | }
|
462 | 505 |
|
463 | 506 | .desc {
|
464 | 507 | font-size: 14px;
|
465 | 508 | color: rgba(222, 226, 230, 1);
|
466 | 509 | }
|
467 | 510 | }
|
| 511 | +
|
| 512 | + .info { |
| 513 | + position: absolute; |
| 514 | + bottom: 10px; |
| 515 | + right: 10px; |
| 516 | + display: flex; |
| 517 | + color: #fff; |
| 518 | + font-size: 14px; |
| 519 | + height: 20px; |
| 520 | + line-height: 20px; |
| 521 | +
|
| 522 | + .mid { |
| 523 | + padding: 0 5px; |
| 524 | + } |
| 525 | + } |
468 | 526 | }
|
469 | 527 |
|
470 | 528 | .dropdown-box {
|
|
0 commit comments