AvatarDropdown.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <a-dropdown v-if="currentUser && currentUser.name" placement="bottomRight">
  3. <span class="ant-pro-account-avatar">
  4. <a-avatar
  5. size="small"
  6. src="https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png"
  7. class="antd-pro-global-header-index-avatar" />
  8. <span>{{ currentUser.name }}</span>
  9. </span>
  10. <template v-slot:overlay>
  11. <a-menu class="ant-pro-drop-down menu" :selected-keys="[]">
  12. <!-- <a-menu-item v-if="menu" key="center" @click="handleToCenter">
  13. <a-icon type="user" />
  14. {{ $t('menu.account.center') }}
  15. </a-menu-item> -->
  16. <a-menu-item v-if="menu" key="settings" @click="handleToSettings">
  17. <a-icon type="setting" />
  18. {{ $t('menu.account.settings') }}
  19. </a-menu-item>
  20. <a-menu-divider v-if="menu" />
  21. <a-menu-item key="logout" @click="handleLogout">
  22. <a-icon type="logout" />
  23. {{ $t('menu.account.logout') }}
  24. </a-menu-item>
  25. </a-menu>
  26. </template>
  27. </a-dropdown>
  28. <span v-else>
  29. <a-spin size="small" :style="{ marginLeft: 8, marginRight: 8 }" />
  30. </span>
  31. </template>
  32. <script>
  33. import { Modal } from 'ant-design-vue'
  34. export default {
  35. name: 'AvatarDropdown',
  36. props: {
  37. currentUser: {
  38. type: Object,
  39. default: () => null
  40. },
  41. menu: {
  42. type: Boolean,
  43. default: true
  44. }
  45. },
  46. methods: {
  47. handleToCenter () {
  48. this.$router.push({ path: '/account/center' })
  49. },
  50. handleToSettings () {
  51. this.$router.push({ path: '/account/settings' })
  52. },
  53. handleLogout (e) {
  54. Modal.confirm({
  55. title: this.$t('layouts.usermenu.dialog.title'),
  56. content: this.$t('layouts.usermenu.dialog.content'),
  57. onOk: () => {
  58. // return new Promise((resolve, reject) => {
  59. // setTimeout(Math.random() > 0.5 ? resolve : reject, 1500)
  60. // }).catch(() => console.log('Oops errors!'))
  61. return this.$store.dispatch('Logout').then(() => {
  62. this.$router.push({ name: 'login' })
  63. })
  64. },
  65. onCancel () { }
  66. })
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="less" scoped>
  72. .ant-pro-drop-down {
  73. :deep(.action) {
  74. margin-right: 8px;
  75. }
  76. :deep(.ant-dropdown-menu-item) {
  77. min-width: 160px;
  78. }
  79. }
  80. </style>