Navbar.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div class="navbar">
  3. <hamburger
  4. id="hamburger-container"
  5. :is-active="sidebar.opened"
  6. class="hamburger-container"
  7. @toggleClick="toggleSideBar"
  8. />
  9. <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
  10. <div class="right-menu">
  11. <template v-if="device !== 'mobile'">
  12. <!-- <search id="header-search" class="right-menu-item" /> -->
  13. <!-- <notice-todo v-if="userIdentity === 1 && openSoket" /> -->
  14. <!-- <error-log class="errLog-container right-menu-item hover-effect" /> -->
  15. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  16. </template>
  17. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  18. <div class="avatar-wrapper">
  19. <!-- <img src="https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif" class="user-avatar"> -->
  20. <span>{{ userName }}</span>
  21. <i class="el-icon-caret-bottom" />
  22. </div>
  23. <el-dropdown-menu slot="dropdown">
  24. <template v-if="userIdentity === 2">
  25. <router-link to="/vip/vip-open">
  26. <el-dropdown-item>会员中心</el-dropdown-item>
  27. </router-link>
  28. <router-link to="/personal/info">
  29. <el-dropdown-item divided>个人资料</el-dropdown-item>
  30. </router-link>
  31. <router-link to="/personal/account">
  32. <el-dropdown-item>绑定登录账号</el-dropdown-item>
  33. </router-link>
  34. <router-link to="/password/edit">
  35. <el-dropdown-item>修改密码</el-dropdown-item>
  36. </router-link>
  37. <el-dropdown-item v-if="proxyState" divided @click.native="proxyLogout">
  38. 退出代理
  39. </el-dropdown-item>
  40. <el-dropdown-item v-else divided @click.native="logout">
  41. <span style="display:block;">退出登录</span>
  42. </el-dropdown-item>
  43. </template>
  44. <template v-else>
  45. <router-link to="/password/edit">
  46. <el-dropdown-item>修改密码</el-dropdown-item>
  47. </router-link>
  48. <el-dropdown-item divided @click.native="logout">
  49. <span style="display:block;">退出登录</span>
  50. </el-dropdown-item>
  51. </template>
  52. </el-dropdown-menu>
  53. </el-dropdown>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import { mapGetters } from 'vuex'
  59. import Breadcrumb from '@/components/Breadcrumb'
  60. import Hamburger from '@/components/Hamburger'
  61. // import ErrorLog from '@/components/ErrorLog'
  62. import Screenfull from '@/components/Screenfull'
  63. // import Search from '@/components/HeaderSearch'
  64. // import NoticeTodo from './NoticeTodo'
  65. export default {
  66. components: {
  67. Breadcrumb,
  68. Hamburger,
  69. // ErrorLog,
  70. Screenfull
  71. // NoticeTodo
  72. // Search
  73. },
  74. computed: {
  75. ...mapGetters(['sidebar', 'device', 'name', 'userIdentity', 'openSoket', 'proxyState']),
  76. userName() {
  77. return this.name
  78. }
  79. },
  80. methods: {
  81. toggleSideBar() {
  82. this.$store.dispatch('app/toggleSideBar')
  83. },
  84. async logout() {
  85. this.$message.success('已退出当前账号')
  86. setTimeout(() => {
  87. // 退出登录重置用户信息
  88. this.$store.dispatch('user/logout').then(() => {
  89. // 重置相关state
  90. this.$router.replace('/login')
  91. })
  92. }, 500)
  93. },
  94. proxyLogout() {
  95. this.$message.success('已退出代理操作')
  96. setTimeout(() => {
  97. // 切换到真实登录用户的数据
  98. this.$store.dispatch('user/proxyLogout')
  99. this.$store.commit('proxy/CLOSE_PROXY')
  100. this.$router.replace('/proxy')
  101. }, 500)
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .navbar {
  108. height: 50px;
  109. overflow: hidden;
  110. position: relative;
  111. background: #fff;
  112. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  113. .hamburger-container {
  114. line-height: 46px;
  115. height: 100%;
  116. float: left;
  117. cursor: pointer;
  118. transition: background 0.3s;
  119. -webkit-tap-highlight-color: transparent;
  120. &:hover {
  121. background: rgba(0, 0, 0, 0.025);
  122. }
  123. }
  124. .breadcrumb-container {
  125. float: left;
  126. }
  127. .errLog-container {
  128. display: inline-block;
  129. vertical-align: top;
  130. }
  131. .right-menu {
  132. float: right;
  133. height: 100%;
  134. line-height: 50px;
  135. &:focus {
  136. outline: none;
  137. }
  138. .right-menu-item {
  139. display: inline-block;
  140. padding: 0 8px;
  141. height: 100%;
  142. font-size: 18px;
  143. color: #5a5e66;
  144. vertical-align: text-bottom;
  145. &.hover-effect {
  146. cursor: pointer;
  147. transition: background 0.3s;
  148. &:hover {
  149. background: rgba(0, 0, 0, 0.025);
  150. }
  151. }
  152. }
  153. .avatar-container {
  154. margin-right: 30px;
  155. .avatar-wrapper {
  156. // margin-top: 5px;
  157. position: relative;
  158. .user-avatar {
  159. cursor: pointer;
  160. width: 40px;
  161. height: 40px;
  162. border-radius: 10px;
  163. vertical-align: middle;
  164. }
  165. span {
  166. margin-left: 10px;
  167. }
  168. .el-icon-caret-bottom {
  169. cursor: pointer;
  170. position: absolute;
  171. right: -20px;
  172. top: 25px;
  173. font-size: 12px;
  174. }
  175. }
  176. }
  177. }
  178. }
  179. </style>