LayoutHeader.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <!-- 顶部登录导航 -->
  3. <div class="LoginNav">
  4. <div class="logo">
  5. <span class="logo-img">
  6. <el-image :src="$store.state.app.config.logo_image_url" />
  7. </span>
  8. <ul class="logo-projectlist">
  9. <li
  10. v-for="({ name }, i) in projectList"
  11. :key="i"
  12. :class="i === LoginNavIndex ? 'active' : ''"
  13. @click="handleCommand(i)"
  14. >
  15. {{ name }}
  16. </li>
  17. </ul>
  18. </div>
  19. <div class="userName">
  20. <el-dropdown style="margin-right: 16px" trigger="click" @command="changeLang">
  21. <span class="el-dropdown-link"> {{ lang }}<i class="el-icon-arrow-down el-icon--right" /> </span>
  22. <el-dropdown-menu slot="dropdown" style="width: 200px">
  23. <el-dropdown-item v-for="item in language_list" :key="item.language_type" :command="item">
  24. {{ item.language_name }}
  25. </el-dropdown-item>
  26. </el-dropdown-menu>
  27. </el-dropdown>
  28. <div v-if="!userMessage" class="selectLoginOrRegistration">
  29. <span @click="cutLoginReg">{{ $t('Key9') }}</span>
  30. </div>
  31. <!-- 用户头像和用户名 -->
  32. <el-dropdown v-else style="margin-right: 16px" trigger="click" class="user">
  33. <span class="el-dropdown-link">
  34. <img
  35. class="headPhoto"
  36. :src="userMessage.image_url ? userMessage.image_url : require('../../assets/login/Group3214.png')"
  37. alt="head portrait"
  38. >
  39. <span class="real_name">{{ userMessage.user_real_name }}</span>
  40. </span>
  41. <el-dropdown-menu slot="dropdown" class="user-menu">
  42. <el-dropdown-item @click.native="goPersonal">
  43. <img src="../../assets/login/project7.png"><span>{{ $t('Key8') }}</span>
  44. </el-dropdown-item>
  45. <el-dropdown-item @click.native="QuitLogin">
  46. <img src="../../assets/login/Frame77.png"><span>{{ $t('Key39') }}</span>
  47. </el-dropdown-item>
  48. </el-dropdown-menu>
  49. </el-dropdown>
  50. <!-- 消息 铃铛图片 -->
  51. <div class="message" @click="goPersonal">
  52. <img src="../../assets/login/Vector.png">
  53. <span v-show="isNotRead" class="redDot" />
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import { mapGetters } from 'vuex';
  60. import { getToken, removeToken } from '@/utils/auth';
  61. import { GetLanguageList, GetChildSysList_CanEnter_PC } from '@/api/app';
  62. import { setI18nLang } from '@/utils/i18n';
  63. import { IsExistMyMessage_NotRead } from '@/api/user';
  64. export default {
  65. name: 'LayoutHeader',
  66. data() {
  67. return {
  68. activeIndex: '2', // 主导航索引
  69. loginNav: 'GCLS-Learn',
  70. LoginNavIndex: 0, // 下拉框导航索引
  71. projectName: '教学中心',
  72. projectList: [],
  73. userMessage: null,
  74. userShow: false,
  75. language_list: [],
  76. isNotRead: false,
  77. lang: ''
  78. };
  79. },
  80. computed: {
  81. ...mapGetters(['language_type'])
  82. },
  83. created() {
  84. this.getChildSysList();
  85. this.updateWordPack({
  86. word_key_list: ['Key2', 'Key8', 'Key9', 'Key39', 'Key573']
  87. });
  88. const { token, isHas } = getToken();
  89. if (isHas) {
  90. this.userMessage = token;
  91. let interval = setInterval(() => {
  92. IsExistMyMessage_NotRead()
  93. .then(({ is_exist }) => {
  94. this.isNotRead = JSON.parse(is_exist);
  95. })
  96. .catch(() => {
  97. clearInterval(interval);
  98. });
  99. }, 120000);
  100. this.getLangList();
  101. }
  102. },
  103. methods: {
  104. // 切换导航
  105. handleSelect(key) {
  106. this.activeIndex = key;
  107. if (this.activeIndex === '1') {
  108. window.location.href = '/';
  109. }
  110. },
  111. // 改变下拉框导航索引
  112. changeLoginNavIndex(key) {
  113. console.log(key);
  114. if (!key) return;
  115. console.log(this.LoginNavIndex);
  116. console.log(this.projectList);
  117. this.loginNav = key;
  118. this.LoginNavIndex = this.projectList.findIndex(item => item.key === key);
  119. console.log(this.LoginNavIndex);
  120. },
  121. // 切换项目
  122. handleCommand(command) {
  123. this.LoginNavIndex = command;
  124. if (!this.userMessage) {
  125. this.$message.warning(this.$i18n.t('Key573'));
  126. this.projectName = this.$i18n.t('Key2');
  127. window.location.href = '/';
  128. return;
  129. }
  130. this.projectName = this.projectList[command].name;
  131. let relative_path = this.projectList[command].relative_path;
  132. location.href = relative_path;
  133. },
  134. goPersonal() {
  135. window.location.href = `/GCLS-Personal/#/EnterSys`;
  136. },
  137. // 切换登录的注册
  138. cutLoginReg() {
  139. window.location.href = '/';
  140. },
  141. QuitLogin() {
  142. removeToken();
  143. this.userShow = false;
  144. this.userMessage = null;
  145. window.location.href = '/';
  146. },
  147. getLangList() {
  148. GetLanguageList().then(({ language_list }) => {
  149. this.language_list = language_list;
  150. let curLang = language_list.find(el => el.language_type === this.language_type);
  151. this.lang = curLang ? curLang.language_name : '中文';
  152. });
  153. },
  154. async changeLang({ language_name, language_type }) {
  155. this.lang = language_name;
  156. await setI18nLang(language_type);
  157. this.$router.go(0);
  158. },
  159. getChildSysList() {
  160. GetChildSysList_CanEnter_PC()
  161. .then(({ child_sys_list }) => {
  162. if (child_sys_list && child_sys_list.length > 0) {
  163. this.projectList = child_sys_list;
  164. if (this.LoginNavIndex) return;
  165. this.projectList.forEach((item, index) => {
  166. if (item.key === this.loginNav) {
  167. this.LoginNavIndex = index;
  168. }
  169. });
  170. }
  171. })
  172. .catch(err => {
  173. console.log(err);
  174. });
  175. }
  176. }
  177. };
  178. </script>
  179. <style lang="scss" scoped>
  180. .LoginNav {
  181. position: relative;
  182. z-index: 999;
  183. box-sizing: border-box;
  184. display: flex;
  185. align-items: center;
  186. justify-content: space-between;
  187. height: $header-h;
  188. padding: 0 24px;
  189. font-family: 'sourceR';
  190. background: #fff;
  191. box-shadow: 0 1px 0 rgba(0, 0, 0, 15%);
  192. .logo {
  193. display: flex;
  194. align-items: center;
  195. &-img {
  196. min-width: 242px;
  197. }
  198. &-projectlist {
  199. display: flex;
  200. height: 64px;
  201. padding: 0 24px;
  202. li {
  203. padding: 0 12px;
  204. font-weight: 500;
  205. line-height: $header-h;
  206. color: rgba(0, 0, 0, 45%);
  207. white-space: nowrap;
  208. cursor: pointer;
  209. &:hover {
  210. background: #f6f6f6;
  211. }
  212. &.active {
  213. color: $basic-color;
  214. background: #ffefd6;
  215. }
  216. }
  217. }
  218. }
  219. .userName {
  220. display: flex;
  221. align-items: center;
  222. justify-content: flex-end;
  223. .seek {
  224. position: relative;
  225. margin-right: 100px;
  226. img {
  227. position: absolute;
  228. top: 11px;
  229. left: 10px;
  230. }
  231. }
  232. .flag {
  233. position: relative;
  234. top: 5px;
  235. }
  236. .headPhoto {
  237. width: 34px;
  238. height: 34px;
  239. border-radius: 50%;
  240. }
  241. .message {
  242. position: relative;
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. height: 100%;
  247. margin-left: 23px;
  248. img {
  249. width: 18px;
  250. height: 24px;
  251. }
  252. .redDot {
  253. position: absolute;
  254. top: 2px;
  255. right: -2px;
  256. display: inline-block;
  257. width: 6px;
  258. height: 6px;
  259. background-color: #f00;
  260. border-radius: 50%;
  261. }
  262. }
  263. .selectLoginOrRegistration {
  264. box-sizing: border-box;
  265. display: flex;
  266. align-items: center;
  267. justify-content: space-evenly;
  268. height: 32px;
  269. padding: 0 16px;
  270. border: 1px solid #fff;
  271. border-radius: 4px;
  272. > span {
  273. font-size: 16px;
  274. color: #fff;
  275. cursor: pointer;
  276. }
  277. }
  278. .user {
  279. cursor: pointer;
  280. .real_name {
  281. display: inline-block;
  282. padding-left: 10px;
  283. font-size: 20px;
  284. vertical-align: super;
  285. }
  286. }
  287. }
  288. }
  289. </style>
  290. <style lang="scss">
  291. .LoginNav {
  292. .el-dropdown-menu__item {
  293. display: flex;
  294. align-items: center;
  295. justify-content: center;
  296. line-height: 40px;
  297. > span {
  298. font-family: 'sourceR';
  299. font-size: 16px;
  300. }
  301. }
  302. .el-menu--horizontal > .el-menu-item {
  303. height: $header-h;
  304. line-height: $header-h;
  305. }
  306. .el-dropdown-link {
  307. color: #000;
  308. }
  309. .el-dropdown {
  310. display: block;
  311. cursor: pointer;
  312. > span {
  313. font-family: 'sourceR';
  314. font-size: 16px;
  315. }
  316. }
  317. }
  318. .projectList {
  319. &.el-dropdown-menu__item {
  320. display: flex;
  321. align-items: center;
  322. line-height: 40px;
  323. color: #000;
  324. > img {
  325. top: 0;
  326. }
  327. > span {
  328. font-family: 'sourceR';
  329. line-height: 40px;
  330. }
  331. }
  332. &:hover {
  333. color: #000 !important;
  334. background: rgba(255, 153, 0, 10%) !important;
  335. }
  336. &.menuActive {
  337. background: #f90;
  338. }
  339. }
  340. </style>
  341. <style lang="scss">
  342. .user-menu {
  343. min-width: 156px;
  344. .el-dropdown-menu__item {
  345. display: flex;
  346. align-items: center;
  347. font-size: 16px;
  348. color: #000;
  349. img {
  350. width: 24px;
  351. height: 24px;
  352. margin-right: 10px;
  353. }
  354. }
  355. }
  356. </style>