jhzh
2026-01-04 9e6e9bdc3e3a4aff02022ff63bd8cb51a65e848b
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
<template>
  <div>
    <a-dropdown v-if="currentUser && currentUser.name" placement="bottomRight">
      <span class="ant-pro-account-avatar">
        <a-avatar size="small" src="https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png"
          class="antd-pro-global-header-index-avatar" />
        <span>{{ currentUser.name }}</span>
      </span>
      <template v-slot:overlay>
        <a-menu class="ant-pro-drop-down menu" :selected-keys="[]">
          <!-- <a-menu-item v-if="menu" key="center" @click="handleToCenter">
          <a-icon type="user" />
          {{ $t('menu.account.center') }}
        </a-menu-item> -->
          <a-menu-item v-if="menu" key="settings" @click="handleToSettings">
            <a-icon type="setting" />
            修改密码
          </a-menu-item>
          <a-menu-divider v-if="menu" />
          <a-menu-item key="logout" @click="handleLogout">
            <a-icon type="logout" />
            {{ $t('menu.account.logout') }}
          </a-menu-item>
        </a-menu>
      </template>
    </a-dropdown>
 
    <span v-else>
      <a-spin size="small" :style="{ marginLeft: 8, marginRight: 8 }" />
    </span>
    <span>
      <a-modal title="修改密码" :width="500" :visible="addUserdialog" :confirmLoading="addUserDialogloading"
        @ok="OkaddUserdialog" @cancel="CanceladdUserdialog">
        <a-form :form="addUserform" ref="addUserform">
          <a-form-item label="旧密码">
            <a-input placeholder="请输入旧密码"
              v-decorator="['oldPwd', { rules: [{ required: true, message: '请输入旧密码', }] }]" />
          </a-form-item>
          <a-form-item label="新密码">
            <a-input placeholder="请输入新密码"
              v-decorator="['newPwd', { rules: [{ required: true, message: '请输入新密码', }] }]" />
          </a-form-item>
        </a-form>
      </a-modal>
    </span>
  </div>
</template>
 
<script>
import { Modal } from 'ant-design-vue'
import { agentupdatePwd } from '@/api/home'
export default {
  name: 'AvatarDropdown',
  props: {
    currentUser: {
      type: Object,
      default: () => null
    },
    menu: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      addUserform: this.$form.createForm(this),
      addUserdialog: false,
      addUserDialogloading: false,
    }
  },
  methods: {
    CanceladdUserdialog() {
      this.addUserdialog = false
      const form = this.$refs.addUserform.form
      form.resetFields()
    },
    OkaddUserdialog() {
      const form = this.$refs.addUserform.form
      form.validateFields((errors, values) => {
        if (!errors) {
          this.addUserDialogloading = true
          agentupdatePwd(values).then(res => {
            if (res.status == 0) {
              this.addUserdialog = false
              this.$message.success({ content: res.msg, duration: 2 });
              form.resetFields()
            } else {
              this.$message.error({ content: res.msg });
            }
            this.addUserDialogloading = false
          })
        }
      })
    },
    handleToCenter() {
      this.$router.push({ path: '/account/center' })
    },
    handleToSettings() {
      this.addUserdialog = true
    },
    handleLogout(e) {
      Modal.confirm({
        title: this.$t('layouts.usermenu.dialog.title'),
        content: this.$t('layouts.usermenu.dialog.content'),
        onOk: () => {
          // return new Promise((resolve, reject) => {
          //   setTimeout(Math.random() > 0.5 ? resolve : reject, 1500)
          // }).catch(() => console.log('Oops errors!'))
          return this.$store.dispatch('Logout').then(() => {
            this.$router.push({ name: 'login' })
          })
        },
        onCancel() { }
      })
    }
  }
}
</script>
 
<style lang="less" scoped>
.ant-pro-drop-down {
  :deep(.action) {
    margin-right: 8px;
  }
 
  :deep(.ant-dropdown-menu-item) {
    min-width: 160px;
  }
}
</style>