Head.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <header class="header navbar">
  3. <ul class="menu-list">
  4. <li class="logo" @click="onMenu(0)">
  5. <img src="@/assets/images/logo.png"/>
  6. <!-- <img src="@/assets/images/logo_m.png" @click="onMenu(0)"/> -->
  7. </li>
  8. <li class="nav-item header-item" :class="!activeId ? 'active' : ''" @click="onMenu(0)">
  9. <i class="iconfont icon-shouye"></i>首页
  10. </li>
  11. <li class="nav-item header-item" v-for="item of menus" :key="item.menuId" :class="activeId === item.menuId ? 'active' : ''" @click="onMenu(item.menuId , item.menuName)">
  12. <i :class="'iconfont '+ item.imageUrl" style="vertical-align: middle;"></i>{{item.menuName}}
  13. </li>
  14. </ul>
  15. <div class="menu-right">
  16. <i class="iconfont icon-xiaoxi"></i>
  17. <div class="portrait">
  18. <img src="@/assets/images/headPortrait.png" >
  19. <p>
  20. <span class="portrait-name">{{userName}}</span>
  21. <span class="portrait-role">{{roleName}}</span>
  22. </p>
  23. </div>
  24. <div class="sign-out" @click="signOut">
  25. <i class="iconfont icon-084tuichu"></i><span class="sign-out-text">退出</span>
  26. </div>
  27. </div>
  28. <!-- 确认退出 -->
  29. <Modal
  30. v-model="signOutModal"
  31. title="退出"
  32. width="400"
  33. ref="modalGragSign"
  34. draggable
  35. reset-drag-position
  36. :mask-closable="false"
  37. class-name="common-modal">
  38. <Icon type="ios-information-circle" class="modal-icon" style="color: #ff8432;"></Icon>
  39. <span class="modal-text">确认退出</span>
  40. <div slot="footer">
  41.     <Button @click="signOutCancel">取消</Button>
  42.     <Button type="primary" @click="signOutOk">确定</Button>
  43.   </div>
  44. </Modal>
  45. </header>
  46. </template>
  47. <script>
  48. import utils from '../../libs/utils';
  49. export default {
  50. name: "Head",
  51. components:{
  52. },
  53. data() {
  54. return {
  55. menus: [],
  56. roleName: '',
  57. userName: utils.storage('sw_user').user,
  58. activeId: 0,
  59. signOutModal: false,
  60. menuNameArr: []
  61. };
  62. },
  63. watch: {
  64. '$route' (to, from) {
  65. // 菜单头部浏览器前进或后退
  66. let arr = utils.storage('sw_user').menus;
  67. arr.forEach((item,i) => {
  68. if (item.childMenus) {
  69. item.childMenus.forEach((val,index)=> {
  70. if (val.linkUrl == to.path) {
  71. this.activeId = val.parentMenuId
  72. this.$emit('listenMenuId', this.activeId);
  73. sessionStorage.setItem('routname', to.path);
  74. this.$router.push( to.path );
  75. }
  76. })
  77. }
  78. })
  79. // 菜单头部浏览器前进或后退首页选中首页菜单
  80. if (to.path == '/mainPage') {
  81. this.activeId = 0
  82. }
  83. }
  84. },
  85. mounted() {
  86. this.menus = utils.storage('sw_user').menus
  87. this.roleName = this.getCookie('role_name')
  88. const ID = sessionStorage.getItem('id')
  89. this.activeId = parseInt(ID)
  90. this.$emit('listenMenuId', parseInt(ID));
  91. },
  92. methods: {
  93. // 获取cookie里某个参数的值
  94. getCookie(name) {
  95. let cookieValue = null;
  96. if (document.cookie && document.cookie !== '') {
  97. let cookies = document.cookie.split(';');
  98. for (let i = 0; i < cookies.length; i++) {
  99. let cookie = cookies[i].trim();
  100. // 判断这个cookie的参数名是不是我们想要的
  101. if (cookie.substring(0, name.length + 1) === (name + '=')) {
  102. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  103. break;
  104. }
  105. }
  106. }
  107. return cookieValue;
  108. },
  109. onMenu: function(id,menuName) {
  110. let menuNameArr = []
  111. menuNameArr[0] = menuName
  112. if(this.activeId === id) {
  113. return ;
  114. }
  115. this.activeId = id;
  116. const { currRouterName } = utils.toRouter(id);
  117. this.$emit('listenMenuId', id);
  118. this.menus.forEach((item)=> {
  119. if (item.menuId == id) {
  120. menuNameArr[1] = item.childMenus[0].menuName
  121. }
  122. })
  123. sessionStorage.setItem('routname', currRouterName);
  124. sessionStorage.setItem('menuNameArr',JSON.stringify(menuNameArr));
  125. this.$router.push( currRouterName );
  126. },
  127. signOut () {
  128. this.signOutModal = true
  129. },
  130. signOutOk () {
  131. utils.removeSessionData();
  132. this.$router.push('/');
  133. this.signOutModal = false
  134. },
  135. signOutCancel () {
  136. this.signOutModal = false
  137. },
  138. },
  139. };
  140. </script>
  141. <style scoped lang="stylus">
  142. .header {
  143. width: 100%;
  144. height: 90px;
  145. background: linear-gradient(180deg, #06215F, #0D429E);
  146. display: flex;
  147. }
  148. .menu-list {
  149. height: 100%;
  150. display: flex;
  151. flex: 1;
  152. align-items: center;
  153. }
  154. .logo {
  155. height: 100%;
  156. display: flex;
  157. align-items: center;
  158. margin-right: 30px;
  159. }
  160. .nav-item {
  161. width: 96px;
  162. height: 100%;
  163. display: flex;
  164. flex-direction: column;
  165. align-items: center;
  166. justify-content: center;
  167. font-size: 14px;
  168. font-weight: bold;
  169. color: #F1F1F1;
  170. cursor: pointer;
  171. }
  172. .active {
  173. background: linear-gradient(0deg, rgba(1, 133, 234, 0.6), rgba(21, 51, 107, 0.06));
  174. border-bottom: 3px solid #259FF8;
  175. }
  176. .menu-right {
  177. display: flex;
  178. align-items: center;
  179. color: #FFFFFF;
  180. }
  181. .portrait {
  182. display: flex;
  183. align-items: center;
  184. height: 100%;
  185. padding-left: 12px;
  186. p {
  187. display: flex;
  188. flex-direction: column;
  189. margin-left: 12px;
  190. .portrait-name {
  191. font-size: 16px;
  192. }
  193. .portrait-role {
  194. font-size: 12px;
  195. }
  196. }
  197. }
  198. .sign-out {
  199. height: 100%;
  200. display: flex;
  201. align-items: center;
  202. padding: 0 35px;
  203. cursor: pointer;
  204. }
  205. .sign-out-text {
  206. font-size: 16px;
  207. padding-left: 12px;
  208. }
  209. >>> .iconfont {
  210. font-size: 30px;
  211. color: #F1F1F1;
  212. }
  213. </style>