header-tools.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!-- 顶栏右侧区域 -->
  2. <template>
  3. <div class="ele-admin-header-tool">
  4. <!-- 全屏切换 -->
  5. <div
  6. class="ele-admin-header-tool-item hidden-xs-only"
  7. @click="toggleFullscreen"
  8. >
  9. <i v-if="fullscreen" class="el-icon-_screen-restore"></i>
  10. <i v-else class="el-icon-_screen-full"></i>
  11. </div>
  12. <!-- 语言切换 -->
  13. <div class="ele-admin-header-tool-item">
  14. <i18n-icon />
  15. </div>
  16. <!-- 消息通知 -->
  17. <div class="ele-admin-header-tool-item">
  18. <header-notice />
  19. </div>
  20. <!-- 用户信息 -->
  21. <div class="ele-admin-header-tool-item">
  22. <el-dropdown @command="onUserDropClick">
  23. <div class="ele-admin-header-avatar">
  24. <el-avatar
  25. src="@/assets/images/default-user.png"
  26. />
  27. <!-- <span class="hidden-xs-only">{{
  28. loginUser && loginUser.nickname ? loginUser.nickname : ''
  29. }}</span> -->
  30. <i class="el-icon-arrow-down"></i>
  31. </div>
  32. <template v-slot:dropdown>
  33. <el-dropdown-menu>
  34. <el-dropdown-item command="profile" icon="el-icon-user">
  35. {{ $t('layout.header.profile') }}
  36. </el-dropdown-item>
  37. <el-dropdown-item command="password" icon="el-icon-key">
  38. {{ $t('layout.header.password') }}
  39. </el-dropdown-item>
  40. <el-dropdown-item
  41. command="logout"
  42. icon="el-icon-switch-button"
  43. divided
  44. >
  45. {{ $t('layout.header.logout') }}
  46. </el-dropdown-item>
  47. </el-dropdown-menu>
  48. </template>
  49. </el-dropdown>
  50. </div>
  51. <!-- 主题设置 -->
  52. <div class="ele-admin-header-tool-item" @click="openSetting">
  53. <i class="el-icon-_more"></i>
  54. </div>
  55. <!-- 修改密码弹窗 -->
  56. <password-modal :visible.sync="passwordVisible" />
  57. <!-- 主题设置抽屉 -->
  58. <setting-drawer :visible.sync="settingVisible" />
  59. </div>
  60. </template>
  61. <script>
  62. import HeaderNotice from './header-notice.vue';
  63. import PasswordModal from './password-modal.vue';
  64. import SettingDrawer from './setting-drawer.vue';
  65. import I18nIcon from './i18n-icon.vue';
  66. import { logout } from '@/utils/page-tab-util';
  67. import { userLogout } from '@/api/system/user';
  68. export default {
  69. components: { HeaderNotice, PasswordModal, SettingDrawer, I18nIcon },
  70. props: {
  71. // 是否是全屏
  72. fullscreen: Boolean
  73. },
  74. data () {
  75. return {
  76. // 是否显示修改密码弹窗
  77. passwordVisible: false,
  78. // 是否显示主题设置抽屉
  79. settingVisible: false
  80. };
  81. },
  82. computed: {
  83. // 当前用户信息
  84. loginUser () {
  85. return this.$store.state.user?.info;
  86. }
  87. },
  88. methods: {
  89. /* 用户信息下拉点击事件 */
  90. onUserDropClick (command) {
  91. if (command === 'password') {
  92. this.passwordVisible = true;
  93. } else if (command === 'profile') {
  94. if (this.$route.fullPath !== '/user/profile') {
  95. this.$router.push('/user/profile');
  96. }
  97. } else if (command === 'logout') {
  98. // 退出登录
  99. this.$confirm(
  100. this.$t('layout.logout.message'),
  101. this.$t('layout.logout.title'),
  102. { type: 'warning' }
  103. )
  104. .then(() => {
  105. userLogout().then((res) => {
  106. localStorage.removeItem('userId');
  107. logout();
  108. });
  109. })
  110. .catch(() => {});
  111. }
  112. },
  113. /* 全屏切换 */
  114. toggleFullscreen () {
  115. this.$emit('fullscreen');
  116. },
  117. /* 打开设置抽屉 */
  118. openSetting () {
  119. this.settingVisible = true;
  120. }
  121. }
  122. };
  123. </script>