header.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div class="header primary">
  3. <div class="h-content">
  4. <div class="logo">
  5. <span @click="gotoHome">川陕苏区税收文物陈列展</span>
  6. </div>
  7. <ul class="navs">
  8. <li
  9. @click="navigateTo(item)"
  10. :class="{ navActive: item.id === activeIdx }"
  11. v-for="(item, i) in navs"
  12. :key="i"
  13. >
  14. <span>{{ item.name }}</span>
  15. </li>
  16. </ul>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. import { mapState } from "vuex";
  22. const navs = [
  23. {
  24. name: "首页",
  25. link: { path: "/" },
  26. id: 1,
  27. },
  28. {
  29. name: "三维场景",
  30. link: { path: "/digital" },
  31. id: 2,
  32. },
  33. {
  34. name: "藏品鉴赏",
  35. link: { name: "collection", params: { type: 0 } },
  36. id: 3,
  37. },
  38. {
  39. name: "资料文库",
  40. link: { path: "/spirit" },
  41. id: 4,
  42. },
  43. {
  44. name: "影音内容",
  45. link: { path: "/dynamic" },
  46. id: 5,
  47. },
  48. ];
  49. const navsId = {
  50. home: 1,
  51. dynamic: 2,
  52. spirit: 3,
  53. collection: 4,
  54. digital: 5,
  55. message: 6,
  56. };
  57. const colors = [
  58. {
  59. name: "酒红",
  60. id: "juhong",
  61. color: "#b9412e",
  62. },
  63. {
  64. name: "橄榄绿",
  65. id: "ganlanlv",
  66. color: "#548550",
  67. },
  68. {
  69. name: "暗黄",
  70. id: "anhuang",
  71. color: "#c48f48",
  72. },
  73. {
  74. name: "天蓝",
  75. id: "tianlan",
  76. color: "#09bce1",
  77. },
  78. ];
  79. export default {
  80. data() {
  81. return {
  82. navs,
  83. colors,
  84. showSearch: false,
  85. keyword: "",
  86. date: "",
  87. activeIdx: this.$route.meta.id,
  88. };
  89. },
  90. computed: {
  91. // activeIdx: {
  92. // get: function () {
  93. // return this.$route.meta.id
  94. // },
  95. // set: function () {
  96. // }
  97. // },
  98. userName() {
  99. let condition = window.localStorage.getItem("webuserInfo");
  100. let userInfo =
  101. (condition &&
  102. condition != "undefined" &&
  103. JSON.parse(window.localStorage.getItem("webuserInfo"))) ||
  104. "";
  105. return userInfo.userName;
  106. },
  107. ...mapState({
  108. theme: (state) => state.common.theme,
  109. }),
  110. },
  111. watch: {
  112. "$route.meta.id": function(newVal) {
  113. this.activeIdx = newVal;
  114. },
  115. "$route.path": function() {
  116. this.showSearch = false;
  117. },
  118. showSearch() {
  119. this.keyword = "";
  120. },
  121. },
  122. methods: {
  123. gotoHome() {
  124. if (this.$route.path == "/") {
  125. this.$bus.$emit("backtotop");
  126. } else {
  127. this.$router.push({ path: "/" });
  128. }
  129. },
  130. navigateTo(item) {
  131. this.$router.push(item.link);
  132. this.activeIdx = item.id;
  133. },
  134. },
  135. mounted() {
  136. this.$bus.$on("activeId", (data) => {
  137. this.activeIdx = navsId[data];
  138. });
  139. },
  140. };
  141. </script>
  142. <style lang="less" scoped>
  143. .header {
  144. color: #fff;
  145. box-shadow: 0 0.08rem 0.42rem rgba(0, 0, 0, 0.8);
  146. font-size: 0;
  147. padding: 0;
  148. z-index: 99999;
  149. position: fixed;
  150. width: 100%;
  151. top: 0;
  152. left: 0;
  153. .h-content {
  154. display: flex;
  155. justify-content: space-around;
  156. align-items: center;
  157. width: 90%;
  158. margin: 0 auto;
  159. .logo {
  160. flex: 1;
  161. display: flex;
  162. text-align: center;
  163. justify-content: flex-start;
  164. align-items: center;
  165. font-weight: bold;
  166. letter-spacing: 0.08rem;
  167. > img {
  168. cursor: pointer;
  169. }
  170. > span {
  171. font-size: 1.75rem;
  172. cursor: pointer;
  173. }
  174. }
  175. .navs {
  176. flex: 1;
  177. display: flex;
  178. justify-content: flex-end;
  179. align-items: center;
  180. height: 3.4375rem;
  181. line-height: 3.4375rem;
  182. box-sizing: border-box;
  183. li {
  184. position: relative;
  185. cursor: pointer;
  186. height: 3.4375rem;
  187. line-height: 100%;
  188. display: flex;
  189. flex-direction: column;
  190. align-items: center;
  191. justify-content: center;
  192. margin: 0 10px;
  193. width: 20%;
  194. img {
  195. margin-top: 0.5rem;
  196. width: 1.38rem;
  197. }
  198. span {
  199. display: block;
  200. font-size: .875rem;
  201. }
  202. .child-nav {
  203. display: none;
  204. }
  205. &:hover {
  206. .child-nav {
  207. width: calc(100% - 1.67rem);
  208. display: block;
  209. position: absolute;
  210. background: #fff;
  211. color: #9e9e9e;
  212. font-size: 0.58rem;
  213. font-weight: normal;
  214. top: 2.33rem;
  215. left: 50%;
  216. transform: translateX(-50%);
  217. z-index: 99;
  218. li {
  219. line-height: 2.5;
  220. height: auto;
  221. padding: 0;
  222. margin: 0;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. @media screen and (max-width: 70.83rem) {
  231. .header {
  232. .h-content {
  233. width: 90%;
  234. }
  235. .navs {
  236. min-width: 25rem;
  237. > li {
  238. padding: 0 0.42rem;
  239. }
  240. }
  241. .right {
  242. .colors {
  243. margin-right: 0;
  244. }
  245. }
  246. }
  247. }
  248. </style>