Header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <template>
  2. <!-- 顶部登录导航 -->
  3. <!-- :style="{ background: headerBg }" -->
  4. <div class="LoginNav" :class="[type == 'black' ? 'LoginNav-black' : '']">
  5. <div class="LoginNav-inner">
  6. <div class="logo">
  7. <div class="logo-name" @click="cutLoginReg">
  8. <!-- 二十一世纪英语智慧阅读平台 -->
  9. <!-- <img src="../assets/logo.png" /> -->
  10. <svg-icon icon-class="logos"></svg-icon>
  11. </div>
  12. <ul class="logo-projectlist">
  13. <li
  14. v-for="(itemI, indexI) in projectList"
  15. :key="indexI"
  16. :class="indexI == LoginNavIndex ? 'active' : ''"
  17. @click="handleCommand(indexI)"
  18. >
  19. {{ itemI.name }}
  20. <!-- <img
  21. class="active-img"
  22. v-if="indexI == LoginNavIndex"
  23. src="../assets/common/header_active.png"
  24. /> -->
  25. </li>
  26. </ul>
  27. </div>
  28. <div class="userName">
  29. <!-- <div :style="{background : userBg}" @click="handleLink('search','')"><img src="../assets/common/icon-search.png" /><label>搜索</label></div> -->
  30. <!-- <div :style="{background : userBg}"><img src="../assets/common/icon-shopping.png" /><label>购物车</label></div> -->
  31. <!-- <div :style="{background : userBg}" @click="handleLink('peraonal','like')"><img src="../assets/common/icon-like.png" /><label>收藏夹</label></div> -->
  32. <!-- <div :style="{background : userBg}" @click="handleLink('peraonal','')"><img src="../assets/common/icon-user.png" /></div> -->
  33. <div
  34. @click="handleLink('search', '')"
  35. title="搜索"
  36. class="search-btn"
  37. aria-placeholder="搜索内容"
  38. >
  39. <svg-icon icon-class="search"></svg-icon>
  40. 搜索内容
  41. </div>
  42. <!-- <div @click="handleLink('peraonal','like')" title="收藏夹"><svg-icon icon-class="like-line"></svg-icon></div> -->
  43. <div class="login" v-if="!userShow">
  44. <a @click="toLogin">登录</a>
  45. <a @click="handleLink('register', '')">注册</a>
  46. </div>
  47. <el-dropdown @command="handleChange" v-else>
  48. <span class="el-dropdown-link">
  49. <el-image
  50. :src="
  51. touxiang
  52. ? touxiang
  53. : userMessage.image_url
  54. ? userMessage.image_url
  55. : require('../assets/avatar.png')
  56. "
  57. fit="cover"
  58. style="width: 24px; height: 24px; margin: 0 8px"
  59. >
  60. </el-image>
  61. <span class="name">{{ userMessage.user_name }}</span
  62. ><i class="el-icon-arrow-down el-icon--right"></i>
  63. </span>
  64. <el-dropdown-menu slot="dropdown">
  65. <el-dropdown-item command="personal">个人中心</el-dropdown-item>
  66. <el-dropdown-item
  67. command="orgManage"
  68. v-if="userMessage.is_org_manager === 'true'"
  69. >机构管理</el-dropdown-item
  70. >
  71. <el-dropdown-item command="logout">退出登录</el-dropdown-item>
  72. </el-dropdown-menu>
  73. </el-dropdown>
  74. </div>
  75. </div>
  76. <div class="notice">
  77. <div class="notice-content">
  78. <img :src="require('../assets/notice.png')" />
  79. <span>
  80. 因附带数字阅读功能,需后台制作,智慧阅读平台数字报刊更新时间为:报纸出版<b
  81. >当周周二17:30 <svg-icon icon-class="svg-noitce"></svg-icon
  82. ></b>
  83. (寒暑假除外)。
  84. </span>
  85. </div>
  86. </div>
  87. <el-dialog
  88. :visible.sync="loginFlag"
  89. :show-close="false"
  90. :close-on-click-modal="false"
  91. :modal-append-to-body="false"
  92. width="504px"
  93. class="login-dialog"
  94. v-if="loginFlag"
  95. >
  96. <login
  97. @cancelLogin="cancelLogin"
  98. :toUrl="toUrl"
  99. :linkType="linkType"
  100. ></login>
  101. </el-dialog>
  102. </div>
  103. </template>
  104. <script>
  105. import { removeToken } from "@/utils/auth";
  106. import Cookies from "js-cookie";
  107. //import { setI18nLang } from "@/utils/i18n";
  108. import { removeSession } from "@/utils/role";
  109. import Login from "@/views/login.vue";
  110. import { getToken } from "@/utils/auth";
  111. export default {
  112. components: { Login },
  113. name: "LayoutHeader",
  114. props: [
  115. "headerBg",
  116. "headerBorder",
  117. "userBg",
  118. "LoginNavIndex",
  119. "type",
  120. "touxiang",
  121. ],
  122. data() {
  123. return {
  124. projectList: [
  125. {
  126. name: "书架",
  127. url: "/bookShelf",
  128. },
  129. {
  130. name: "商城",
  131. url: "/bookStore",
  132. },
  133. // {
  134. // name: "测评",
  135. // url: "/evaluation",
  136. // },
  137. {
  138. name: "英文词典",
  139. url: "/dictionary",
  140. },
  141. {
  142. name: "双语学生记者",
  143. url: "/reporter",
  144. },
  145. ],
  146. userMessage: getToken() ? JSON.parse(getToken()) : null,
  147. userShow: Cookies.get("HM21St_User_Token") ? true : false,
  148. loginFlag: false,
  149. toUrl: "",
  150. linkType: "",
  151. };
  152. },
  153. watch: {},
  154. computed: {},
  155. methods: {
  156. // 切换项目
  157. handleCommand(command) {
  158. this.toUrl = "";
  159. if (this.projectList[command].url === "/bookStore") {
  160. this.$router.push({
  161. path: this.projectList[command].url,
  162. });
  163. } else {
  164. if (this.userMessage) {
  165. this.$router.push({
  166. path: this.projectList[command].url,
  167. });
  168. } else {
  169. this.toUrl = this.projectList[command].url;
  170. this.loginFlag = true;
  171. }
  172. }
  173. },
  174. handleLogin(url, type) {
  175. this.toUrl = url;
  176. this.loginFlag = true;
  177. this.linkType = type;
  178. },
  179. // 切换登录的注册
  180. cutLoginReg() {
  181. window.location.href = "/";
  182. },
  183. QuitLogin() {
  184. removeToken();
  185. removeSession("SysList");
  186. Cookies.remove("registerToken");
  187. Cookies.remove("HM21St_User_Token");
  188. this.userShow = false;
  189. this.userMessage = null;
  190. window.location.href = "/";
  191. },
  192. handleLink(link, type) {
  193. let url =
  194. this.LoginNavIndex +
  195. "&&&" +
  196. this.userBg +
  197. "&&&" +
  198. this.headerBorder +
  199. "&&&" +
  200. this.headerBg;
  201. if (link !== "search") {
  202. this.$router.push({
  203. path: "/" + link,
  204. query: {
  205. headerConfig: encodeURIComponent(url),
  206. type: encodeURIComponent(type),
  207. id: link === "orgManage" ? this.userMessage.org_id : "",
  208. },
  209. });
  210. } else {
  211. if (this.userMessage) {
  212. this.$router.push({
  213. path: "/" + link,
  214. query: {
  215. headerConfig: encodeURIComponent(url),
  216. type: encodeURIComponent(type),
  217. id: link === "orgManage" ? this.userMessage.org_id : "",
  218. },
  219. });
  220. } else {
  221. this.toUrl = "/" + link;
  222. this.loginFlag = true;
  223. }
  224. }
  225. },
  226. handleChange(com) {
  227. if (com === "personal") {
  228. this.handleLink("peraonal", "");
  229. } else if (com === "logout") {
  230. this.QuitLogin();
  231. } else if (com === "orgManage") {
  232. this.handleLink("orgManage", "");
  233. }
  234. },
  235. // 去登录
  236. toLogin() {
  237. this.loginFlag = true;
  238. },
  239. // 关闭登录弹窗
  240. cancelLogin() {
  241. this.loginFlag = false;
  242. },
  243. },
  244. created() {},
  245. mounted() {},
  246. beforeDestroy() {},
  247. };
  248. </script>
  249. <style lang="scss" scoped>
  250. .LoginNav {
  251. height: 96px;
  252. // border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  253. z-index: 10;
  254. position: fixed;
  255. width: 100%;
  256. top: 0;
  257. left: 0;
  258. background: #00adef;
  259. &-inner {
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. box-sizing: border-box;
  264. padding: 0 24px;
  265. height: 64px;
  266. }
  267. .logo {
  268. display: flex;
  269. align-items: center;
  270. padding-right: 40px;
  271. .logo-name {
  272. cursor: pointer;
  273. font-size: 0;
  274. z-index: 2;
  275. .svg-icon {
  276. width: 286px;
  277. height: 35px;
  278. color: #ffffff;
  279. }
  280. }
  281. .logo-projectlist {
  282. display: flex;
  283. list-style: none;
  284. margin: 0;
  285. padding: 0;
  286. width: 100%;
  287. position: absolute;
  288. left: 0;
  289. top: 0;
  290. z-index: 1;
  291. justify-content: center;
  292. li {
  293. padding: 5px 20px;
  294. color: rgba(255, 255, 255, 0.48);
  295. font-size: 16px;
  296. line-height: 54px;
  297. cursor: pointer;
  298. white-space: nowrap;
  299. position: relative;
  300. &:hover {
  301. color: #ffffff;
  302. }
  303. &.active {
  304. color: #ffffff;
  305. font-weight: 500;
  306. }
  307. .active-img {
  308. position: absolute;
  309. bottom: -1px;
  310. left: 50%;
  311. width: 24px;
  312. margin-left: -12px;
  313. }
  314. }
  315. }
  316. }
  317. .userName {
  318. display: flex;
  319. justify-content: flex-end;
  320. align-items: center;
  321. z-index: 2;
  322. > div {
  323. cursor: pointer;
  324. display: flex;
  325. align-items: center;
  326. // background: #242424;
  327. // border-radius: 40px;
  328. height: 32px;
  329. margin-left: 16px;
  330. color: rgba(255, 255, 255, 0.88);
  331. padding: 8px;
  332. &.search-btn {
  333. border-radius: 20px;
  334. background: #0087c0;
  335. width: 221px;
  336. font-size: 12px;
  337. gap: 10px;
  338. .svg-icon {
  339. font-size: 16px;
  340. }
  341. }
  342. &.login {
  343. color: #ffffff;
  344. font-weight: 400;
  345. font-size: 14px;
  346. line-height: 22px;
  347. a {
  348. width: 60px;
  349. line-height: 32px;
  350. text-align: center;
  351. border-radius: 2px;
  352. &:hover {
  353. background: rgba(255, 255, 255, 0.12);
  354. color: rgba(255, 255, 255, 0.9);
  355. }
  356. &:focus {
  357. background: rgba(255, 255, 255, 0.08);
  358. color: rgba(255, 255, 255, 0.7);
  359. }
  360. }
  361. :first-child {
  362. margin-right: 6px;
  363. }
  364. }
  365. img {
  366. width: 16px;
  367. }
  368. label {
  369. color: #ffffff;
  370. font-size: 14px;
  371. font-weight: 400;
  372. // font-family: Harmony;
  373. margin-left: 8px;
  374. }
  375. // &:last-child {
  376. // border-radius: 20px;
  377. // width: 40px;
  378. // padding: 0 12px;
  379. // }
  380. }
  381. }
  382. .el-dropdown {
  383. color: rgba(255, 255, 255, 0.88);
  384. .el-dropdown-link {
  385. display: flex;
  386. align-items: center;
  387. }
  388. .avatar {
  389. width: 24px;
  390. height: 24px;
  391. border-radius: 2px;
  392. margin: 0 8px;
  393. }
  394. .name {
  395. font-size: 14px;
  396. line-height: 22px;
  397. }
  398. }
  399. // &-black {
  400. // border-bottom-color: #ffffff;
  401. // .svg-icon {
  402. // color: rgba(0, 0, 0, 0.88) !important;
  403. // }
  404. // .logo-projectlist li {
  405. // color: rgba(0, 0, 0, 0.56) !important;
  406. // &:hover {
  407. // color: rgba(0, 0, 0, 0.88) !important;
  408. // }
  409. // }
  410. // .el-dropdown {
  411. // color: #000000 !important;
  412. // }
  413. // }
  414. }
  415. .notice {
  416. width: 100%;
  417. background: #f8d7da;
  418. padding: 5px 0;
  419. &-content {
  420. width: 1200px;
  421. margin: 0 auto;
  422. display: flex;
  423. align-items: center;
  424. color: #721c24;
  425. gap: 10px;
  426. font-size: 16px;
  427. justify-content: center;
  428. img {
  429. width: 22px;
  430. }
  431. b {
  432. font-size: 22px;
  433. color: #ee1c24;
  434. position: relative;
  435. }
  436. .svg-icon {
  437. font-size: 40px;
  438. position: absolute;
  439. bottom: -40px;
  440. left: 50px;
  441. }
  442. }
  443. }
  444. </style>
  445. <style lang="scss">
  446. .LoginNav {
  447. .el-dropdown-menu__item {
  448. line-height: 40px;
  449. display: flex;
  450. justify-content: center;
  451. align-items: center;
  452. > span {
  453. font-family: "sourceR";
  454. font-size: 16px;
  455. }
  456. }
  457. .el-menu--horizontal > .el-menu-item {
  458. height: 64px;
  459. line-height: 68px;
  460. }
  461. .el-dropdown {
  462. display: block;
  463. > span {
  464. font-family: "sourceR";
  465. font-size: 16px;
  466. }
  467. }
  468. }
  469. .projectList {
  470. &.el-dropdown-menu__item {
  471. line-height: 40px;
  472. display: flex;
  473. align-items: center;
  474. color: #000000;
  475. > img {
  476. top: 0;
  477. }
  478. > span {
  479. line-height: 40px;
  480. font-family: "sourceR";
  481. }
  482. }
  483. &:hover {
  484. background: rgba(255, 153, 0, 0.1) !important;
  485. color: #000 !important;
  486. }
  487. &.menuActive {
  488. background: #ff9900;
  489. }
  490. }
  491. .login-dialog {
  492. .el-dialog__header,
  493. .el-dialog__body {
  494. padding: 0;
  495. }
  496. .el-dialog {
  497. border: 1px solid #e5e6eb;
  498. box-shadow: 0px 6px 30px 5px rgba(0, 0, 0, 0.05),
  499. 0px 16px 24px 2px rgba(0, 0, 0, 0.04),
  500. 0px 8px 10px -5px rgba(0, 0, 0, 0.08);
  501. border-radius: 4px;
  502. overflow: hidden;
  503. }
  504. }
  505. </style>