header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <template>
  2. <div class="header primary">
  3. <div class="logo">
  4. <div>
  5. <img
  6. class="logo_bg"
  7. :src="require(`@/assets/images/xinjiang/logobg_${theme}.png`)"
  8. alt=""
  9. />
  10. <img
  11. class="i_logo"
  12. @click="gotoHome"
  13. :src="require('@/assets/images/icon/logo.png')"
  14. alt=""
  15. />
  16. </div>
  17. <span @click="gotoHome"
  18. >中国人民武装警察部队<br />新疆生产建设兵团总队史馆</span
  19. >
  20. </div>
  21. <div class="nav-right">
  22. <div class="r-top">
  23. <div class="date primaryTxt" v-html="date"></div>
  24. <div class="colors">
  25. <span>主题色调</span>
  26. <ul>
  27. <li
  28. @click="changeColor(item.id)"
  29. v-for="(item, i) in colors"
  30. :key="i"
  31. >
  32. <i :style="{ background: item.color }">
  33. <i v-if="item.id == theme" :style="{ background: item.active }"></i>
  34. </i>
  35. <span :style="{color:item.id == theme?item.color:''}">{{ item.name }}</span>
  36. </li>
  37. </ul>
  38. </div>
  39. </div>
  40. <div class="line subBgColor"></div>
  41. <div class="r-bottom">
  42. <ul class="navs">
  43. <li
  44. @click="navigateTo(item)"
  45. :class="{ navActive: item.id === activeIdx }"
  46. v-for="(item, i) in navs"
  47. :key="i"
  48. >
  49. <span>{{ item.name }}</span>
  50. <img
  51. v-if="item.id === activeIdx"
  52. :src="require(`@/assets/images/xinjiang/star_${theme}.png`)"
  53. />
  54. </li>
  55. </ul>
  56. <div class="btm-right">
  57. <div class="login" @click="$bus.$emit('showLogin',true)" v-if="!userInfo.nickName">
  58. <img :src="require(`@/assets/images/xinjiang/userselect_${theme}.png`)" alt="">
  59. </div>
  60. <div class="nickname primaryTxt" v-else>
  61. <img :src="require(`@/assets/images/xinjiang/usericon_${theme}.png`)" alt="">
  62. <span>{{userInfo.nickName}}</span>
  63. <ul>
  64. <li class="pHover" @click="$router.push({path:'/userinfo'})">个人设置</li>
  65. <li class="pHover" @click="$router.push({path:'/modify'})">修改密码</li>
  66. <li @click="logout" class="pHover">登出</li>
  67. </ul>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import { mapState } from "vuex";
  76. import { formatDate } from "@/config/utils.js";
  77. import { getUserInfo,logout } from "@/config/api";
  78. const navs = [
  79. {
  80. name: "数字史馆",
  81. link: "/",
  82. id: 1,
  83. },
  84. {
  85. name: "精品典藏",
  86. link: "/collection",
  87. id: 2,
  88. },
  89. {
  90. name: "纪念祭扫",
  91. link: "/spirit",
  92. id: 3,
  93. },
  94. {
  95. name: "学习园地",
  96. link: "/dynamic/list/info/none",
  97. id: 4,
  98. },
  99. {
  100. name: "我要留言",
  101. link: "/message",
  102. id: 5,
  103. },
  104. ];
  105. const colors = [
  106. {
  107. name: "基因红",
  108. id: "jiyinhong",
  109. color: "#D32424",
  110. active:'#E4AD64'
  111. },
  112. {
  113. name: "橄榄绿",
  114. id: "ganlanlv",
  115. color: "#757034",
  116. active:'#DDDE7A'
  117. },
  118. {
  119. name: "胡杨金",
  120. id: "huyangjin",
  121. color: "#EBA348",
  122. active:'#A64A17'
  123. }
  124. ];
  125. export default {
  126. data() {
  127. return {
  128. navs,
  129. colors,
  130. keyword: "",
  131. date: "",
  132. activeIdx: this.$route.meta.id
  133. };
  134. },
  135. computed: {
  136. ...mapState({
  137. theme: (state) => state.common.theme,
  138. })
  139. },
  140. watch: {
  141. "$route.meta.id": function(newVal) {
  142. this.activeIdx = newVal;
  143. },
  144. },
  145. methods: {
  146. gotoHome() {
  147. if (this.$route.path == "/") {
  148. this.$bus.$emit("backtotop");
  149. } else {
  150. this.$router.push({ path: "/" });
  151. }
  152. },
  153. getUserInfo() {
  154. let userId = window.localStorage.getItem("webuserId");
  155. let token = window.localStorage.getItem("webtoken");
  156. if (!userId||!token) return;
  157. getUserInfo({id:userId},res=>{
  158. this.$store.dispatch("setUserInfo", res.data);
  159. this.$refs.ifr.contentWindow.postMessage({
  160. source: "userInfo",
  161. data:res.data,
  162. },'*')
  163. })
  164. },
  165. submitLogout() {
  166. logout(()=>{
  167. window.localStorage.setItem("webtoken", "");
  168. window.localStorage.setItem("webuserInfo", "");
  169. window.localStorage.setItem("webuserId", "");
  170. this.$store.dispatch("setUserInfo", {});
  171. window.location.reload();
  172. })
  173. },
  174. logout() {
  175. let res = window.confirm("是否退出登录?");
  176. res && this.submitLogout();
  177. },
  178. changeColor(id) {
  179. this.$store.dispatch("changeTheme", id);
  180. document.getElementById("app").className = "theme" + id;
  181. },
  182. navigateTo(item) {
  183. this.activeIdx = item.id;
  184. this.$router.push({
  185. path:item.link
  186. })
  187. },
  188. },
  189. mounted() {
  190. this.date = formatDate(new Date());
  191. this.getUserInfo();
  192. this.$bus.$on("logout", (data) => {
  193. this.showLogin = data;
  194. this.submitLogout()
  195. });
  196. },
  197. };
  198. </script>
  199. <style lang="less" scoped>
  200. .header {
  201. display: flex;
  202. justify-content: space-between;
  203. align-items: center;
  204. color: #fff;
  205. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.3);
  206. font-size: 0;
  207. padding-left: 30px;
  208. z-index: 99999;
  209. position: fixed;
  210. width: 100%;
  211. height: 100px;
  212. top: 0;
  213. left: 0;
  214. .logo {
  215. flex: 2;
  216. display: flex;
  217. text-align: center;
  218. justify-content: flex-start;
  219. align-items: center;
  220. font-weight: bold;
  221. font-size: 0;
  222. height: 100%;
  223. > div {
  224. position: relative;
  225. text-align: center;
  226. min-width: 118px;
  227. .logo_bg {
  228. z-index: -1;
  229. position: absolute;
  230. top: -11px;
  231. width: 100%;
  232. left: 0;
  233. }
  234. .i_logo {
  235. text-align: center;
  236. cursor: pointer;
  237. }
  238. }
  239. > span {
  240. font-size: 24px;
  241. text-align: left;
  242. letter-spacing: 2px;
  243. cursor: pointer;
  244. }
  245. }
  246. .nav-right {
  247. flex: 4;
  248. position: relative;
  249. top: 0;
  250. height: 100%;
  251. .r-top {
  252. display: flex;
  253. justify-content: flex-end;
  254. align-items: center;
  255. padding: 8px 50px;
  256. font-size: 14px;
  257. .date {
  258. margin-right: 96px;
  259. }
  260. .colors {
  261. position: relative;
  262. min-width: 80px;
  263. margin-right: 10px;
  264. > span {
  265. padding-right: 20px;
  266. cursor: pointer;
  267. &::after {
  268. position: absolute;
  269. right: 2px;
  270. top: 50%;
  271. transform: translateY(-50%);
  272. content: "";
  273. width: 0;
  274. height: 0;
  275. border-left: 6px solid transparent;
  276. border-right: 6px solid transparent;
  277. border-top: 6px solid #fff;
  278. }
  279. }
  280. ul {
  281. display: none;
  282. text-align: center;
  283. width: 120%;
  284. position: absolute;
  285. background: #fff;
  286. color: #9e9e9e;
  287. font-size: 14px;
  288. font-weight: normal;
  289. top: 22px;
  290. right: 0;
  291. z-index: 99;
  292. > li {
  293. text-align: left;
  294. padding-left: 10px;
  295. line-height: 2;
  296. font-size: 16px;
  297. cursor: pointer;
  298. >i {
  299. width: 14px;
  300. height: 14px;
  301. border-radius: 50%;
  302. display: inline-block;
  303. position: relative;
  304. >i{
  305. position: absolute;
  306. z-index: 99;
  307. width: 6px;
  308. height: 6px;
  309. display: inline-block;
  310. border-radius: 50%;
  311. top: 50%;
  312. left: 50%;
  313. transform: translate(-50%,-50%);
  314. }
  315. }
  316. span {
  317. margin-left: 10px;
  318. }
  319. }
  320. }
  321. &:hover {
  322. ul {
  323. display: block;
  324. }
  325. }
  326. }
  327. }
  328. .r-bottom {
  329. flex: 4;
  330. position: relative;
  331. .navs {
  332. width: 100%;
  333. display: flex;
  334. min-width: 800px;
  335. justify-content: flex-start;
  336. align-items: center;
  337. font-size: 18px;
  338. height: 62px;
  339. line-height: 62px;
  340. box-sizing: border-box;
  341. >li {
  342. position: relative;
  343. cursor: pointer;
  344. height: 62px;
  345. line-height: 100%;
  346. display: flex;
  347. flex-direction: column;
  348. align-items: center;
  349. justify-content: center;
  350. padding: 0 20px;
  351. margin-right: 40px;
  352. img {
  353. width: 100%;
  354. position: absolute;
  355. bottom: 0;
  356. left: 0;
  357. }
  358. span {
  359. display: block;
  360. font-size: 18px;
  361. margin-top: -8px;
  362. }
  363. .child-nav {
  364. display: none;
  365. }
  366. &:hover {
  367. .child-nav {
  368. width: calc(100% - 40px);
  369. display: block;
  370. position: absolute;
  371. background: #fff;
  372. color: #9e9e9e;
  373. font-size: 14px;
  374. font-weight: normal;
  375. top: 56px;
  376. left: 50%;
  377. transform: translateX(-50%);
  378. z-index: 99;
  379. li {
  380. line-height: 2.5;
  381. height: auto;
  382. padding: 0;
  383. margin: 0;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. .btm-right{
  390. position: absolute;
  391. top: 50%;
  392. right: 66px;
  393. transform: translateY(-50%);
  394. .nickname{
  395. display: flex;
  396. justify-content: center;
  397. align-items: center;
  398. position: relative;
  399. cursor: pointer;
  400. >img{
  401. width: 36px;
  402. }
  403. >span{
  404. display: inline-block;
  405. margin-left: 6px;
  406. }
  407. >ul{
  408. position: absolute;
  409. top: 0;
  410. z-index: 999;
  411. display: none;
  412. padding-top: 48px;
  413. >li{
  414. width: 100%;
  415. min-width: 130px;
  416. line-height: 50px;
  417. padding: 0 10px;
  418. height: 50px;
  419. background-color: #fff;
  420. color: #333333;
  421. }
  422. }
  423. &:hover{
  424. >ul{
  425. display: block;
  426. }
  427. }
  428. }
  429. .login{
  430. >img{
  431. cursor: pointer;
  432. width: 36px;
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. @media screen and (max-width: 1700px) {
  440. .header {
  441. .navs {
  442. min-width: 600px;
  443. > li {
  444. padding: 0 10px;
  445. }
  446. }
  447. .right {
  448. .colors {
  449. margin-right: 0;
  450. }
  451. }
  452. }
  453. }
  454. </style>