Header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <!-- 顶部登录导航 -->
  3. <div class="LoginNav">
  4. <div class="logo">
  5. <template v-if="configInfor">
  6. <img
  7. :src="configInfor.logo_image_url"
  8. alt="logo"
  9. class="logo-image"
  10. @click="handleSelect"
  11. />
  12. </template>
  13. <template v-else>
  14. <span class="logo-img"> logo </span>
  15. </template>
  16. <ul class="logo-projectlist">
  17. <li
  18. v-for="(itemI, indexI) in projectList"
  19. :key="indexI"
  20. :class="indexI == LoginNavIndex ? 'active' : ''"
  21. @click="handleCommand(indexI)"
  22. >
  23. {{ itemI.name }}
  24. </li>
  25. </ul>
  26. </div>
  27. <div class="userName">
  28. <template v-if="routePath == '/GoodsDetail'">
  29. <el-dropdown
  30. style="margin-right: 16px; cursor: pointer"
  31. trigger="click"
  32. @command="changeLang"
  33. >
  34. <span class="el-dropdown-link" style="color: #000">
  35. {{ lang }}<i class="el-icon-arrow-down el-icon--right"></i>
  36. </span>
  37. <el-dropdown-menu slot="dropdown" style="width: 200px">
  38. <el-dropdown-item
  39. v-for="item in language_list"
  40. :key="item.language_type"
  41. :command="item"
  42. >{{ item.language_name }}</el-dropdown-item
  43. >
  44. </el-dropdown-menu>
  45. </el-dropdown>
  46. </template>
  47. <div v-if="!userMessage" class="selectLoginOrRegistration">
  48. <span @click="cutLoginReg">
  49. {{ routePath == "/GoodsDetail" ? $t("Key9") : "登录" }}
  50. </span>
  51. </div>
  52. <!-- 用户头像和用户名 -->
  53. <div class="user" v-else>
  54. <img
  55. @click="userShow = !userShow"
  56. class="headPhoto"
  57. :src="
  58. userMessage.image_url
  59. ? userMessage.image_url
  60. : require('../assets/login/Group3214.png')
  61. "
  62. alt=""
  63. />
  64. <span @click="userShow = !userShow">{{
  65. userMessage.user_real_name
  66. }}</span>
  67. <div class="userShow" v-show="userShow">
  68. <p @click="gopresonal">
  69. <img src="../assets/login/project7.png" alt="" />
  70. {{ routePath == "/GoodsDetail" ? $t("Key38") : "个人中心" }}
  71. </p>
  72. <p @click="QuitLogin">
  73. <img src="../assets/login/Frame77.png" alt="" />
  74. {{ routePath == "/GoodsDetail" ? $t("Key39") : "退出登录" }}
  75. </p>
  76. </div>
  77. </div>
  78. <!-- 消息 铃铛图片 -->
  79. <div class="message" @click="gopresonal">
  80. <img src="../assets/login/Vector.png" alt="" />
  81. <span class="redDot" v-if="is_exist == 'true'"></span>
  82. </div>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import { mapGetters } from "vuex";
  88. import { getToken, removeToken, getConfig } from "@/utils/auth";
  89. import Cookies from "js-cookie";
  90. import { getConfigInfor } from "@/utils/index";
  91. import {
  92. getLearnWebContent,
  93. getStaticContent,
  94. getContentFile
  95. } from "@/api/ajax";
  96. //import { setI18nLang } from "@/utils/i18n";
  97. import { removeSession } from "@/utils/role";
  98. export default {
  99. name: "LayoutHeader",
  100. props: [],
  101. data() {
  102. return {
  103. configInfor: null,
  104. activeIndex: "2", // 主导航索引
  105. LoginNavIndex: 0, //下拉框导航索引
  106. projectName: "",
  107. projectList: [],
  108. teacherProList: [
  109. //普通教师
  110. {
  111. id: 0,
  112. name: "教学中心",
  113. img: "project1"
  114. },
  115. {
  116. id: 2,
  117. name: "教培中心",
  118. img: "project3"
  119. },
  120. {
  121. id: 3,
  122. name: "教研中心",
  123. img: "project4"
  124. },
  125. {
  126. id: 4,
  127. name: "考试中心",
  128. img: "project5"
  129. },
  130. {
  131. id: 5,
  132. name: "学习中心",
  133. img: "project6"
  134. },
  135. {
  136. id: 6,
  137. name: "个人中心",
  138. img: "project7"
  139. }
  140. ],
  141. stuProList: [
  142. {
  143. id: 0,
  144. name: "教学中心",
  145. img: "project1"
  146. },
  147. {
  148. id: 5,
  149. name: "学习中心",
  150. img: "project6"
  151. },
  152. {
  153. id: 6,
  154. name: "个人中心",
  155. img: "project7"
  156. }
  157. ],
  158. userMessage: null,
  159. userShow: false,
  160. language_list: [],
  161. lang: "",
  162. is_exist: "false",
  163. headTimer: null,
  164. routePath: ""
  165. };
  166. },
  167. watch: {},
  168. computed: {
  169. ...mapGetters(["language_type"])
  170. },
  171. methods: {
  172. // 切换导航
  173. handleSelect() {
  174. window.location.href = "/";
  175. },
  176. // 切换项目
  177. handleCommand(command) {
  178. let _this = this;
  179. _this.LoginNavIndex = command;
  180. if (!_this.userMessage) {
  181. //this.$message.warning("请重新登录");
  182. window.location.href = "/";
  183. return;
  184. }
  185. _this.projectName = this.projectList[command].name;
  186. let relative_path = _this.projectList[command].relative_path;
  187. location.href = relative_path;
  188. },
  189. gopresonal() {
  190. window.location.href = `/GCLS-Personal/#/EnterSys`;
  191. },
  192. // 切换登录的注册
  193. cutLoginReg() {
  194. window.location.href = "/";
  195. },
  196. QuitLogin() {
  197. removeToken();
  198. removeSession("SysList");
  199. Cookies.remove("userMessage");
  200. Cookies.remove("session_id");
  201. Cookies.remove("user_code");
  202. Cookies.remove("user_type");
  203. sessionStorage.removeItem("useragent_root_close");
  204. this.userShow = false;
  205. this.userMessage = null;
  206. window.location.href = "/";
  207. },
  208. getLangList() {
  209. let MethodName = "language_manager-GetLanguageList";
  210. let data = {};
  211. getStaticContent(MethodName, data).then(res => {
  212. this.language_list = res.language_list;
  213. for (let i = 0; i < this.language_list.length; i++) {
  214. let item = this.language_list[i];
  215. if (item.language_type == this.language_type) {
  216. this.lang = item.language_name;
  217. break;
  218. }
  219. }
  220. });
  221. },
  222. async changeLang(command) {
  223. console.log(command);
  224. this.lang = command.language_name;
  225. let lang_type = command.language_type;
  226. await setI18nLang(lang_type);
  227. this.$router.go(0);
  228. },
  229. getChildSysList() {
  230. let _this = this;
  231. let MethodName = "login_control-GetChildSysList_CanEnter_PC";
  232. getContentFile(MethodName, {})
  233. .then(res => {
  234. if (res.child_sys_list && res.child_sys_list.length > 0) {
  235. const isNotYouth =
  236. window.location.origin !== "https://youthchinesedu.blcup.com";
  237. if (isNotYouth) {
  238. _this.projectList = res.child_sys_list;
  239. } else {
  240. let child_sys_list_youth = [];
  241. res.child_sys_list.forEach(item => {
  242. if (item.key !== "GCLS-Exercise") {
  243. child_sys_list_youth.push(item);
  244. }
  245. });
  246. _this.projectList = child_sys_list_youth;
  247. }
  248. _this.projectList.forEach((item, index) => {
  249. if (item.key == "GCLS-Book") {
  250. _this.LoginNavIndex = index;
  251. }
  252. });
  253. }
  254. })
  255. .catch(err => {
  256. console.log(err);
  257. });
  258. },
  259. //是否存在我未阅读的消息
  260. getNotReadMessage() {
  261. let MethodName = "message-message_manager-IsExistMyMessage_NotRead";
  262. let data = {};
  263. getLearnWebContent(MethodName, data).then(res => {
  264. this.is_exist = res.is_exist;
  265. });
  266. },
  267. async _getConfig() {
  268. this.configInfor = await getConfigInfor();
  269. }
  270. },
  271. created() {
  272. let _this = this;
  273. let routePath = this.$route.path;
  274. this.routePath = routePath;
  275. let config = getConfig();
  276. if (config) {
  277. _this.configInfor = JSON.parse(config);
  278. } else {
  279. _this._getConfig();
  280. }
  281. _this.getChildSysList();
  282. },
  283. mounted() {
  284. let _this = this;
  285. let user = getToken();
  286. if (user) {
  287. _this.userMessage = JSON.parse(user);
  288. let popedom_code_list = _this.userMessage.popedom_code_list;
  289. if (popedom_code_list.indexOf(2000003) > -1) {
  290. _this.projectName = "教材管理系统";
  291. } else {
  292. _this.projectName = "学习中心";
  293. }
  294. _this.getLangList();
  295. _this.getNotReadMessage();
  296. _this.headTimer = setInterval(() => {
  297. _this.getNotReadMessage();
  298. }, 120000);
  299. }
  300. },
  301. beforeDestroy() {
  302. if (this.headTimer) {
  303. //如果定时器还在运行 或者直接关闭,不用判断
  304. clearInterval(this.headTimer); //关闭
  305. }
  306. }
  307. };
  308. </script>
  309. <style lang="scss" scoped>
  310. .LoginNav {
  311. height: 64px;
  312. position: relative;
  313. display: flex;
  314. align-items: center;
  315. justify-content: space-between;
  316. box-sizing: border-box;
  317. padding: 0px 24px;
  318. z-index: 999;
  319. background: #ffffff;
  320. box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.15);
  321. font-family: "sourceR";
  322. .logo {
  323. &-image {
  324. // width: 188px;
  325. height: 48px;
  326. cursor: pointer;
  327. }
  328. display: flex;
  329. align-items: center;
  330. .logo-projectlist {
  331. display: flex;
  332. padding: 0 24px;
  333. height: 64px;
  334. list-style: none;
  335. li {
  336. padding: 0 12px;
  337. color: rgba(0, 0, 0, 0.45);
  338. font-size: 16px;
  339. line-height: 64px;
  340. cursor: pointer;
  341. font-weight: 500;
  342. white-space: nowrap;
  343. &:hover {
  344. background: #f6f6f6;
  345. }
  346. &.active {
  347. color: #ff9900;
  348. background: #ffefd6;
  349. }
  350. }
  351. }
  352. }
  353. .userName {
  354. display: flex;
  355. justify-content: flex-end;
  356. align-items: center;
  357. .seek {
  358. margin-right: 100px;
  359. position: relative;
  360. img {
  361. left: 10px;
  362. top: 11px;
  363. position: absolute;
  364. }
  365. }
  366. .flag {
  367. position: relative;
  368. top: 5px;
  369. }
  370. .headPhoto {
  371. width: 50px;
  372. height: 50px;
  373. // background: url("../assets/teacherTrain/image 4.png") no-repeat 100% 100%;
  374. // background-size: 100%;
  375. border-radius: 50%;
  376. // margin-right: 10px;
  377. }
  378. .message {
  379. height: 100%;
  380. position: relative;
  381. display: flex;
  382. justify-content: center;
  383. align-items: center;
  384. margin-left: 23px;
  385. cursor: pointer;
  386. img {
  387. width: 18px;
  388. height: 24px;
  389. }
  390. .redDot {
  391. position: absolute;
  392. top: 2px;
  393. right: -2px;
  394. width: 6px;
  395. height: 6px;
  396. display: inline-block;
  397. background: red;
  398. border-radius: 50%;
  399. }
  400. }
  401. .selectLoginOrRegistration {
  402. display: flex;
  403. height: 32px;
  404. border: 1px solid #ffffff;
  405. box-sizing: border-box;
  406. border-radius: 4px;
  407. justify-content: space-evenly;
  408. align-items: center;
  409. padding: 0 16px;
  410. > span {
  411. cursor: pointer;
  412. font-size: 16px;
  413. color: #fff;
  414. }
  415. }
  416. .user {
  417. display: flex;
  418. align-items: center;
  419. cursor: pointer;
  420. position: relative;
  421. > img {
  422. width: 34px;
  423. height: 34px;
  424. }
  425. > span {
  426. font-size: 20px;
  427. padding-left: 10px;
  428. }
  429. .userShow {
  430. position: absolute;
  431. width: 156px;
  432. height: 96px;
  433. background: #ffffff;
  434. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  435. border-radius: 8px;
  436. bottom: -100px;
  437. color: black;
  438. z-index: 9999;
  439. img {
  440. width: 24px;
  441. height: 24px;
  442. margin-right: 10px;
  443. }
  444. p {
  445. font-size: 16px;
  446. height: 40px;
  447. display: flex;
  448. align-items: center;
  449. padding-left: 20px;
  450. margin: 0;
  451. margin-top: 5px;
  452. }
  453. > p:hover {
  454. background: #f2f2f2;
  455. }
  456. }
  457. }
  458. }
  459. }
  460. </style>
  461. <style lang="scss">
  462. .LoginNav {
  463. .el-dropdown-menu__item {
  464. line-height: 40px;
  465. display: flex;
  466. justify-content: center;
  467. align-items: center;
  468. > span {
  469. font-family: "sourceR";
  470. font-size: 16px;
  471. }
  472. }
  473. .el-menu--horizontal > .el-menu-item {
  474. height: 64px;
  475. line-height: 68px;
  476. }
  477. .el-dropdown {
  478. display: block;
  479. > span {
  480. font-family: "sourceR";
  481. font-size: 16px;
  482. }
  483. }
  484. }
  485. .projectList {
  486. &.el-dropdown-menu__item {
  487. line-height: 40px;
  488. display: flex;
  489. align-items: center;
  490. color: #000000;
  491. > img {
  492. top: 0;
  493. }
  494. > span {
  495. line-height: 40px;
  496. font-family: "sourceR";
  497. }
  498. }
  499. &:hover {
  500. background: rgba(255, 153, 0, 0.1) !important;
  501. color: #000 !important;
  502. }
  503. &.menuActive {
  504. background: #ff9900;
  505. }
  506. }
  507. </style>