Header.vue 10 KB

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