Header.vue 11 KB

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