header.vue 11 KB

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