header-tools.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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="loginUser && loginUser.avatar ? loginUser.avatar : ''"-->
  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. import { SYSTEM_NAME } from '@/config/setting';
  69. export default {
  70. components: { HeaderNotice, PasswordModal, SettingDrawer, I18nIcon },
  71. props: {
  72. // 是否是全屏
  73. fullscreen: Boolean
  74. },
  75. data() {
  76. return {
  77. // 是否显示修改密码弹窗
  78. passwordVisible: false,
  79. // 是否显示主题设置抽屉
  80. settingVisible: false
  81. };
  82. },
  83. computed: {
  84. // 当前用户信息
  85. loginUser() {
  86. return this.$store.state.user.info;
  87. }
  88. },
  89. methods: {
  90. /* 用户信息下拉点击事件 */
  91. onUserDropClick(command) {
  92. if (command === 'password') {
  93. this.passwordVisible = true;
  94. } else if (command === 'profile') {
  95. if (this.$route.fullPath !== '/user/profile') {
  96. this.$router.push('/user/profile');
  97. }
  98. } else if (command === 'logout') {
  99. // 退出登录
  100. this.$confirm(
  101. this.$t('layout.logout.message'),
  102. this.$t('layout.logout.title'),
  103. { type: 'warning' }
  104. )
  105. .then(() => {
  106. userLogout().then((res) => {
  107. console.log(res);
  108. localStorage.removeItem(`userId-${SYSTEM_NAME}`);
  109. logout();
  110. });
  111. })
  112. .catch(() => {});
  113. }
  114. },
  115. /* 全屏切换 */
  116. toggleFullscreen() {
  117. this.$emit('fullscreen');
  118. },
  119. /* 打开设置抽屉 */
  120. openSetting() {
  121. this.settingVisible = true;
  122. }
  123. }
  124. };
  125. </script>