header.vue 5.9 KB

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