Head.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="head-wrapper">
  3. <div class="head-logo">
  4. <svg-icon icon-class="zhihui-logo" />
  5. </div>
  6. <div v-for="item in headList" :key="item.path" class="nav-tag" @click="changeNavTag(item)">
  7. <div v-if="item.icon" class="icon">
  8. <svg-icon :icon-class="item.icon" />
  9. </div>
  10. <div class="name">{{ item.name }}</div>
  11. </div>
  12. <div v-show="navTagType === 2" class="nav-tag-type" @click="setNavTagType(1)">
  13. <i class="el-icon-notebook-2" style="transform: rotate(90deg);" />
  14. </div>
  15. <div v-show="navTagType === 1" class="nav-tag-type" @click="setNavTagType(2)">
  16. <i class="el-icon-notebook-2" />
  17. </div>
  18. <div v-if="userInfo" class="user-info">
  19. <a-popover placement="rightBottom" overlay-class-name="head-popover">
  20. <template #content>
  21. <div class="user-control">
  22. <div class="user-name">{{ userInfo.name }}</div>
  23. <div class="line" />
  24. <div class="user-logout">
  25. <el-button type="primary" plain size="small" @click="layout()">退出登录</el-button>
  26. </div>
  27. </div>
  28. </template>
  29. <img :src="userInfo.phoneUrl">
  30. </a-popover>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { mapGetters } from 'vuex'
  36. import routes from '@/router/newRouter'
  37. import { memberGetLoginInMemberInfoByLdap } from '@/api/projectIndex'
  38. import { logoutUrl } from '@/apiConfig/requestIP.js'
  39. export default {
  40. data() {
  41. return {
  42. headList: routes.filter(item => item.name !== '业务线'),
  43. userInfo: null
  44. }
  45. },
  46. computed: {
  47. ...mapGetters(['activeNavTag', 'navTagType'])
  48. },
  49. watch: {
  50. $route: {
  51. handler(to) {
  52. this.findRoute(to.name)
  53. },
  54. immediate: true
  55. }
  56. },
  57. created() {
  58. this.getLoginUser()
  59. },
  60. methods: {
  61. findRoute(routeName) {
  62. for (const element of routes) {
  63. if (element.name === routeName) {
  64. // 先对父元素进行查找
  65. this.$store.dispatch('global/setActiveNavTag', element.name)
  66. } else if (element.children) {
  67. const child = element.children.find(item => item.name === routeName) // 对子元素进行查找
  68. child ? this.$store.dispatch('global/setActiveNavTag', element.name) : '' // 父元素的名字设为路径
  69. }
  70. }
  71. },
  72. // 切换二级导航
  73. changeNavTag(nav) {
  74. this.$store.dispatch('global/setActiveNavTag', nav.name) // 设置二级导航的类别
  75. this.$router.push({ name: nav.name }) // 跳转
  76. },
  77. // 设置二级导航类型
  78. setNavTagType(type) {
  79. this.$store.dispatch('global/setNavTagType', type)
  80. },
  81. // 获取登录人员信息
  82. async getLoginUser() {
  83. const res = await memberGetLoginInMemberInfoByLdap()
  84. if (res && res.data) this.userInfo = res.data || null
  85. },
  86. // 退出登录
  87. layout() {
  88. window.location.href = logoutUrl
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .head-wrapper {
  95. display: flex;
  96. flex-direction: column;
  97. flex-shrink: 0;
  98. z-index: 99;
  99. width: 80px;
  100. align-items: center;
  101. background: #409eff;
  102. font-size: 20px;
  103. color: #333;
  104. padding-top: 17px;
  105. }
  106. .head-logo {
  107. height: 40px;
  108. width: 40px;
  109. margin-bottom: 42px;
  110. .svg-icon {
  111. width: 100%;
  112. height: 100%;
  113. }
  114. }
  115. .nav-tag {
  116. width: 100%;
  117. font-size: 14px;
  118. color: #ffffff;
  119. text-align: center;
  120. margin-bottom: 28px;
  121. cursor: pointer;
  122. .icon {
  123. position: relative;
  124. color: #ffffff;
  125. height: 20px;
  126. width: 20px;
  127. margin: 7px auto;
  128. font-size: 32px;
  129. }
  130. .svg-icon {
  131. position: absolute;
  132. top: 0;
  133. left: 0;
  134. width: 100%;
  135. height: 100%;
  136. }
  137. }
  138. .nav-tag-type {
  139. margin-top: auto;
  140. color: #ffffff;
  141. cursor: pointer;
  142. }
  143. .user-info {
  144. height: 30px;
  145. width: 30px;
  146. display: flex;
  147. justify-content: center;
  148. align-items: center;
  149. background-color: #fff;
  150. border-radius: 50%;
  151. overflow: hidden;
  152. margin-top: auto;
  153. margin-bottom: 30px;
  154. img {
  155. height: 30px;
  156. }
  157. }
  158. .user-control {
  159. height: 95px;
  160. width: 95px;
  161. display: flex;
  162. flex-direction: column;
  163. display: grid;
  164. grid-template-rows: 47px 1px 47px;
  165. justify-items: center;
  166. align-items: center;
  167. .line {
  168. width: 100%;
  169. height: 1px;
  170. background-color: rgba(112, 112, 112, 0.2);
  171. }
  172. }
  173. </style>
  174. <style lang="scss">
  175. .head-popover {
  176. box-shadow: 10px 0px 11px #dedede;
  177. /deep/ .ant-popover-inner-content {
  178. padding: 0;
  179. }
  180. }
  181. </style>