header.vue 12 KB

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