AvatarDropdown.vue 2.2 KB

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