header.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class="header primary">
  3. <div class="logo">
  4. <div>
  5. <img class="logo_bg" :src="require(`@/assets/images/icon/logo_dec.png`)" alt="" />
  6. <img class="i_logo" @click="gotoHome" :src="require('@/assets/images/icon/logo.png')" alt="" />
  7. </div>
  8. <span @click="gotoHome">武警北京市总队执勤第十四支队数字史馆</span>
  9. </div>
  10. <div class="nav-right">
  11. <ul class="navs">
  12. <li @click="navigateTo(item)" :class="{ navActive: item.id === activeIdx }" v-for="(item, i) in navs" :key="i">
  13. <img v-if="item.id === activeIdx" :src="require(`@/assets/images/xinjiang/qiji.png`)" />
  14. <span>{{ item.name }}</span>
  15. <div class="line"></div>
  16. </li>
  17. </ul>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import { mapState } from "vuex";
  23. import { formatDate } from "@/config/utils.js";
  24. import { getUserInfo, logout } from "@/config/api";
  25. const navs = [
  26. {
  27. name: "数字史馆",
  28. link: "/",
  29. id: 1,
  30. },
  31. {
  32. name: "数字荣誉室",
  33. link: "/honor",
  34. id: 2,
  35. },
  36. {
  37. name: "精品典藏",
  38. link: "/collection",
  39. id: 3,
  40. },
  41. {
  42. name: "我要留言",
  43. link: "/message",
  44. id: 4,
  45. },
  46. ];
  47. const colors = [
  48. {
  49. name: "海军蓝",
  50. id: "huyangjin",
  51. color: "#0194DD",
  52. active: "#1E4786",
  53. },
  54. {
  55. name: "基因红",
  56. id: "jiyinhong",
  57. color: "#CB0000",
  58. active: "#E4AD64",
  59. },
  60. {
  61. name: "橄榄绿",
  62. id: "ganlanlv",
  63. color: "#757034",
  64. active: "#CCC460",
  65. },
  66. ];
  67. export default {
  68. data() {
  69. return {
  70. navs,
  71. colors,
  72. keyword: "",
  73. date: "",
  74. activeIdx: this.$route.meta.id,
  75. };
  76. },
  77. computed: {
  78. ...mapState({
  79. theme: (state) => state.common.theme,
  80. }),
  81. },
  82. watch: {
  83. "$route.meta.id": function(newVal) {
  84. this.activeIdx = newVal;
  85. },
  86. },
  87. methods: {
  88. gotoHome() {
  89. if (this.$route.path == "/") {
  90. this.$bus.$emit("backtotop");
  91. } else {
  92. this.$router.push({ path: "/" });
  93. }
  94. },
  95. getUserInfo() {
  96. let userId = window.localStorage.getItem("webuserId");
  97. let token = window.localStorage.getItem("webtoken");
  98. if (!userId || !token) return;
  99. getUserInfo({ id: userId }, (res) => {
  100. this.$store.dispatch("setUserInfo", res.data);
  101. this.$refs.ifr &&
  102. this.$refs.ifr.contentWindow.postMessage(
  103. {
  104. source: "userInfo",
  105. data: res.data,
  106. },
  107. "*"
  108. );
  109. });
  110. },
  111. submitLogout() {
  112. logout(() => {
  113. window.localStorage.setItem("webtoken", "");
  114. window.localStorage.setItem("webuserInfo", "");
  115. window.localStorage.setItem("webuserId", "");
  116. this.$store.dispatch("setUserInfo", {});
  117. window.location.reload();
  118. });
  119. },
  120. logout() {
  121. let res = window.confirm("是否退出登录?");
  122. res && this.submitLogout();
  123. },
  124. changeColor(id) {
  125. this.$store.dispatch("changeTheme", id);
  126. document.getElementById("app").className = "theme" + id;
  127. },
  128. navigateTo(item) {
  129. this.activeIdx = item.id;
  130. this.$router.push({
  131. path: item.link,
  132. });
  133. },
  134. },
  135. mounted() {
  136. this.date = formatDate(new Date());
  137. this.getUserInfo();
  138. this.$bus.$on("logout", (data) => {
  139. this.showLogin = data;
  140. this.submitLogout();
  141. });
  142. // window.onunload = ()=>{
  143. // this.submitLogout()
  144. // }
  145. },
  146. };
  147. </script>
  148. <style lang="less" scoped>
  149. .header {
  150. display: flex;
  151. justify-content: space-between;
  152. align-items: center;
  153. color: #fff;
  154. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.3);
  155. font-size: 0;
  156. padding-left: 30px;
  157. z-index: 99999;
  158. position: fixed;
  159. width: 100%;
  160. height: 80px;
  161. top: 0;
  162. left: 0;
  163. .logo {
  164. flex: 2;
  165. display: flex;
  166. text-align: center;
  167. justify-content: flex-start;
  168. align-items: center;
  169. font-weight: bold;
  170. font-size: 0;
  171. height: 100%;
  172. > div {
  173. position: relative;
  174. text-align: center;
  175. width: 100px;
  176. .logo_bg {
  177. z-index: -1;
  178. position: absolute;
  179. top: -6px;
  180. left: 0;
  181. width: 100%;
  182. }
  183. .i_logo {
  184. text-align: center;
  185. cursor: pointer;
  186. width: 74%;
  187. }
  188. }
  189. > span {
  190. font-size: 24px;
  191. text-align: left;
  192. letter-spacing: 2px;
  193. cursor: pointer;
  194. }
  195. }
  196. .nav-right {
  197. display: flex;
  198. flex: 4;
  199. padding: 0 50px;
  200. height: 100%;
  201. align-items: center;
  202. justify-content: space-between;
  203. .navs {
  204. width: 100%;
  205. display: flex;
  206. justify-content: flex-start;
  207. align-items: center;
  208. font-size: 18px;
  209. height: 80px;
  210. line-height: 80px;
  211. box-sizing: border-box;
  212. > li {
  213. position: relative;
  214. cursor: pointer;
  215. height: 100%;
  216. line-height: 100%;
  217. width: 180px;
  218. display: flex;
  219. align-items: center;
  220. justify-content: center;
  221. padding: 0 20px;
  222. margin-right: 20px;
  223. img {
  224. width: 40px;
  225. margin-right: 10px;
  226. position: absolute;
  227. left: 14px;
  228. top: 50%;
  229. transform: translateY(-50%);
  230. }
  231. span {
  232. display: inline-block;
  233. font-size: 18px;
  234. min-width: 140px;
  235. padding-left: 50px;
  236. }
  237. }
  238. }
  239. }
  240. }
  241. @media screen and (max-width: 1700px) {
  242. .header {
  243. .navs {
  244. min-width: 600px;
  245. > li {
  246. padding: 0 10px;
  247. }
  248. }
  249. .right {
  250. .colors {
  251. margin-right: 0;
  252. }
  253. }
  254. }
  255. }
  256. </style>