Header.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <template>
  2. <!-- 顶部登录导航 -->
  3. <div class="LoginNav1">
  4. <div class="logo">
  5. <span class="logo-img"> logo </span>
  6. <el-menu
  7. :default-active="activeIndex"
  8. class="el-menu-demo"
  9. mode="horizontal"
  10. @select="handleSelect"
  11. text-color="#fff"
  12. active-text-color="#FF9900"
  13. >
  14. <el-menu-item index="1">主页</el-menu-item>
  15. <el-menu-item index="2">
  16. <template v-if="projectList.length > 1">
  17. <el-dropdown trigger="click" @command="handleCommand">
  18. <span
  19. class="el-dropdown-link"
  20. :style="{ color: activeIndex == 2 ? '#FF9900' : '#fff' }"
  21. >
  22. {{ projectName }}
  23. <!-- SYSTEM -->
  24. <img
  25. v-if="activeIndex == 2"
  26. src="../assets/learncenter/headerDownlod.png"
  27. alt=""
  28. />
  29. <img
  30. v-else
  31. src="../assets/learncenter/headerDownlod2.png"
  32. alt=""
  33. />
  34. </span>
  35. <el-dropdown-menu slot="dropdown" style="min-width: 278px">
  36. <el-dropdown-item
  37. :class="i == LoginNavIndex ? 'menuActive' : ''"
  38. :command="i"
  39. :key="i"
  40. class="projectList"
  41. v-for="(item, i) in projectList"
  42. >
  43. <img
  44. style="position: relative; width: 24px"
  45. :src="require('../assets/login/' + item.img + '.png')"
  46. alt=""
  47. />
  48. <span style="margin-left: 16px">
  49. {{ item.name }}
  50. </span>
  51. </el-dropdown-item>
  52. </el-dropdown-menu>
  53. </el-dropdown>
  54. </template>
  55. <template v-else>{{
  56. projectList.length > 0 && projectList[0].name
  57. }}</template>
  58. </el-menu-item>
  59. </el-menu>
  60. </div>
  61. <div class="userName">
  62. <template>
  63. <el-dropdown
  64. style="margin-right: 16px; cursor: pointer"
  65. trigger="click"
  66. @command="changeLang"
  67. >
  68. <span class="el-dropdown-link" style="color: #fff">
  69. {{ lang }}
  70. <img src="../assets/learncenter/headerDownlod2.png" alt="" />
  71. </span>
  72. <el-dropdown-menu slot="dropdown" style="width: 200px">
  73. <el-dropdown-item
  74. v-for="item in language_list"
  75. :key="item.language_type"
  76. :command="item"
  77. >{{ item.language_name }}</el-dropdown-item
  78. >
  79. </el-dropdown-menu>
  80. </el-dropdown>
  81. </template>
  82. <div v-if="!userMessage" class="selectLoginOrRegistration">
  83. <span @click="cutLoginReg">登录</span>
  84. </div>
  85. <!-- 用户头像和用户名 -->
  86. <div class="user" v-else>
  87. <img
  88. @click="userShow = !userShow"
  89. class="headPhoto"
  90. :src="
  91. userMessage.image_url
  92. ? userMessage.image_url
  93. : require('../assets/login/Group3214.png')
  94. "
  95. alt=""
  96. />
  97. <span @click="userShow = !userShow">{{
  98. userMessage.user_real_name
  99. }}</span>
  100. <div class="userShow" v-show="userShow">
  101. <p @click="gotoPersonalcenter">
  102. <img src="../assets/login/project7.png" alt="" />
  103. 个人中心
  104. </p>
  105. <p @click="QuitLogin">
  106. <img src="../assets/login/Frame77.png" alt="" />
  107. 退出登录
  108. </p>
  109. </div>
  110. </div>
  111. <!-- 消息 铃铛图片 -->
  112. <div class="message">
  113. <img
  114. @click="gotoPersonalcenter"
  115. src="../assets/login/Vector2.png"
  116. alt=""
  117. />
  118. <span class="redDot" v-if="is_exist == 'true'"></span>
  119. </div>
  120. </div>
  121. </div>
  122. </template>
  123. <script>
  124. import { mapGetters } from "vuex";
  125. import { getToken, removeToken } from "@/utils/auth";
  126. import Cookies from "js-cookie";
  127. import { getContent, getStaticContent, getLearnWebContent } from "@/api/api";
  128. import { setI18nLang } from "@/utils/i18n";
  129. export default {
  130. name: "LayoutHeader",
  131. props: [],
  132. data() {
  133. return {
  134. activeIndex: "2", // 主导航索引
  135. LoginNavIndex: 0, //下拉框导航索引
  136. projectName: "学习中心",
  137. is_exist: "false",
  138. projectList: [],
  139. teacherProList: [
  140. //普通教师
  141. {
  142. id: 0,
  143. name: "教学中心",
  144. img: "project1",
  145. },
  146. {
  147. id: 2,
  148. name: "教培中心",
  149. img: "project3",
  150. },
  151. {
  152. id: 3,
  153. name: "教研中心",
  154. img: "project4",
  155. },
  156. {
  157. id: 4,
  158. name: "考试中心",
  159. img: "project5",
  160. },
  161. {
  162. id: 5,
  163. name: "学习中心",
  164. img: "project6",
  165. },
  166. {
  167. id: 6,
  168. name: "个人中心",
  169. img: "project7",
  170. },
  171. ],
  172. stuProList: [
  173. {
  174. id: 0,
  175. name: "教学中心",
  176. img: "project1",
  177. },
  178. {
  179. id: 5,
  180. name: "学习中心",
  181. img: "project6",
  182. },
  183. {
  184. id: 6,
  185. name: "个人中心",
  186. img: "project7",
  187. },
  188. ],
  189. userMessage: null,
  190. userShow: false,
  191. language_list: [],
  192. lang: "",
  193. headTimer: null,
  194. };
  195. },
  196. watch: {},
  197. computed: {
  198. ...mapGetters(["language_type"]),
  199. },
  200. methods: {
  201. // 前往个人中心
  202. gotoPersonalcenter() {
  203. if (!this.userMessage) {
  204. this.$message.warning("请先登录");
  205. return;
  206. }
  207. // let MethodName = "login_control-CreateAccessCode";
  208. // let acsCode = "";
  209. // getContent(MethodName, UserCode, UserType, SessionID).then((res) => {
  210. // acsCode = res.access_code;
  211. location.href = `/GCLS-Personal/#/EnterSys`;
  212. // });
  213. },
  214. // 切换导航
  215. handleSelect(key, keyPath) {
  216. this.activeIndex = key;
  217. if (this.activeIndex == 1) {
  218. window.location.href = "/";
  219. }
  220. },
  221. // 切换项目
  222. handleCommand(command) {
  223. let _this = this;
  224. _this.LoginNavIndex = command;
  225. if (!_this.userMessage) {
  226. this.$message.warning("请先登录");
  227. this.projectName = "学习中心";
  228. window.location.href = "/";
  229. return;
  230. }
  231. let MethodName = "login_control-CreateAccessCode";
  232. let acsCode = null;
  233. // getContent(MethodName, UserCode, UserType, SessionID).then((res) => {
  234. // acsCode = res.access_code;
  235. _this.projectName = this.projectList[command].name;
  236. let id = this.projectList[command].id;
  237. if (id == 0) {
  238. // 教学管理系统
  239. location.href = `/GCLS-Learn/#/EnterSys`;
  240. } else if (id == 1) {
  241. // 教材管理系统
  242. location.href = `/GCLS-Book/#/EnterSys`;
  243. } else if (id == 2) {
  244. // 教培中心
  245. location.href = `/GCLS-TRC/#/EnterSys`;
  246. } else if (id == 3) {
  247. // 教研中心
  248. location.href = `/GCLS-TC/#/EnterSys`;
  249. } else if (id == 4) {
  250. // 考试中心
  251. location.href = `/GCLS-Test/#/EnterSys`;
  252. } else if (id == 5) {
  253. // 学习中心
  254. location.href = `/GCLS-LC/#/EnterSys`;
  255. } else {
  256. // 个人中心
  257. location.href = `/GCLS-Personal/#/EnterSys`;
  258. }
  259. // });
  260. },
  261. // 切换登录的注册
  262. cutLoginReg() {
  263. window.location.href = "/";
  264. },
  265. QuitLogin() {
  266. window.location.href = "/";
  267. removeToken();
  268. Cookies.remove("JSESSIONID");
  269. this.userShow = false;
  270. this.userMessage = null;
  271. },
  272. getLangList() {
  273. let MethodName = "language_manager-GetLanguageList";
  274. let data = {};
  275. getStaticContent(MethodName, data).then((res) => {
  276. this.language_list = res.language_list;
  277. for (let i = 0; i < this.language_list.length; i++) {
  278. let item = this.language_list[i];
  279. if (item.language_type == this.language_type) {
  280. this.lang = item.language_name;
  281. break;
  282. }
  283. }
  284. });
  285. },
  286. async changeLang(command) {
  287. console.log(command);
  288. this.lang = command.language_name;
  289. let lang_type = command.language_type;
  290. await setI18nLang(lang_type);
  291. this.$router.go(0);
  292. },
  293. handleProList(list) {
  294. let projectList = [];
  295. if (list.length == 0) {
  296. let arr = [
  297. {
  298. id: 2,
  299. name: "教培中心",
  300. img: "project3",
  301. },
  302. {
  303. id: 3,
  304. name: "教研中心",
  305. img: "project6",
  306. },
  307. {
  308. id: 5,
  309. name: "学习中心",
  310. img: "project4",
  311. },
  312. {
  313. id: 6,
  314. name: "个人中心",
  315. img: "project7",
  316. },
  317. ];
  318. projectList = arr;
  319. } else {
  320. if (list.includes(2000001)) {
  321. projectList = JSON.parse(JSON.stringify(this.teacherProList));
  322. for (let i = 0; i < list.length; i++) {
  323. let code = list[i];
  324. if (code == 2000003) {
  325. projectList.push({
  326. id: 1,
  327. name: "教材管理系统",
  328. img: "project1-1",
  329. selectImg: "project1-1-1",
  330. });
  331. }
  332. if (code == 2000005) {
  333. projectList.push({
  334. id: 4,
  335. name: "考试中心",
  336. img: "project5",
  337. });
  338. }
  339. }
  340. } else {
  341. for (let i = 0; i < list.length; i++) {
  342. let code = list[i];
  343. if (code == 2000002) {
  344. projectList.push({
  345. id: 0,
  346. name: "教学管理系统",
  347. img: "project1",
  348. });
  349. } else if (code == 2000003) {
  350. projectList.push({
  351. id: 1,
  352. name: "教材管理系统",
  353. img: "project2",
  354. });
  355. } else if (code == 2000004) {
  356. projectList.push({
  357. id: 2,
  358. name: "教师培训中心",
  359. img: "project3",
  360. });
  361. } else if (code == 2000005) {
  362. projectList.push({
  363. id: 4,
  364. name: "考试中心",
  365. img: "project5",
  366. });
  367. } else if (code == 2000006) {
  368. projectList.push({
  369. id: 3,
  370. name: "教研中心",
  371. img: "project4",
  372. });
  373. }
  374. }
  375. projectList.push({
  376. id: 6,
  377. // Teacher training center
  378. name: "个人中心",
  379. img: "project7",
  380. text: "您收集和购买的所有资源都可以在这里轻松找到。",
  381. });
  382. }
  383. }
  384. // 排序
  385. for (var i = 0; i < projectList.length - 1; i++) {
  386. for (var j = 0; j < projectList.length - 1 - i; j++) {
  387. // 相邻元素两两对比,元素交换,大的元素交换到后面
  388. if (projectList[j].id > projectList[j + 1].id) {
  389. var temp = projectList[j];
  390. projectList[j] = projectList[j + 1];
  391. projectList[j + 1] = temp;
  392. }
  393. }
  394. }
  395. console.log(projectList);
  396. return projectList;
  397. },
  398. getNotReadMessage() {
  399. let MethodName = "message-message_manager-IsExistMyMessage_NotRead";
  400. let data = {};
  401. getLearnWebContent(MethodName, data).then((res) => {
  402. this.is_exist = res.is_exist;
  403. });
  404. },
  405. },
  406. created() {},
  407. mounted() {
  408. let _this = this;
  409. let user = getToken();
  410. if (user) {
  411. _this.userMessage = JSON.parse(user);
  412. let popedom_code_list = _this.userMessage.popedom_code_list;
  413. if (_this.userMessage.user_type == "TEACHER") {
  414. _this.projectList = _this.handleProList(popedom_code_list);
  415. } else if (_this.userMessage.user_type == "STUDENT") {
  416. _this.projectList = _this.stuProList;
  417. }
  418. _this.projectList.forEach((item, index) => {
  419. if (item.id == 5) {
  420. _this.LoginNavIndex = index;
  421. }
  422. });
  423. }
  424. _this.getLangList();
  425. _this.headTimer = _this.getNotReadMessage();
  426. setInterval(() => {
  427. _this.getNotReadMessage();
  428. }, 120000);
  429. },
  430. beforeDestroy() {
  431. if (this.headTimer) {
  432. //如果定时器还在运行 或者直接关闭,不用判断
  433. clearInterval(this.headTimer); //关闭
  434. }
  435. },
  436. };
  437. </script>
  438. <style lang="scss" scoped>
  439. .LoginNav1 {
  440. // height: 74px;
  441. height: 64px;
  442. position: relative;
  443. display: flex;
  444. align-items: center;
  445. justify-content: space-between;
  446. box-sizing: border-box;
  447. padding: 0px 24px;
  448. z-index: 999;
  449. // background: #ffffff;
  450. // box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.15);
  451. font-family: "sourceR";
  452. .logo {
  453. &-img {
  454. font-style: normal;
  455. font-weight: 600;
  456. font-size: 30px;
  457. font-variant: small-caps;
  458. // color: #000000;
  459. color: #fff;
  460. margin-right: 29px;
  461. line-height: 64px;
  462. }
  463. display: flex;
  464. align-items: center;
  465. .el-menu-demo {
  466. background: rgba(0, 0, 0, 0);
  467. // margin-left: 100px;
  468. li:hover {
  469. background: none;
  470. }
  471. li {
  472. font-size: 16px;
  473. background: none;
  474. height: 64px;
  475. line-height: 64px;
  476. }
  477. }
  478. // 取消组件默认的样式
  479. .el-menu.el-menu--horizontal {
  480. border-bottom: none;
  481. }
  482. }
  483. .el-dropdown-link {
  484. img {
  485. width: 8px;
  486. height: 4px;
  487. vertical-align: middle;
  488. }
  489. }
  490. .userName {
  491. display: flex;
  492. justify-content: flex-end;
  493. align-items: center;
  494. .seek {
  495. margin-right: 100px;
  496. position: relative;
  497. img {
  498. left: 10px;
  499. top: 11px;
  500. position: absolute;
  501. }
  502. }
  503. .flag {
  504. position: relative;
  505. top: 5px;
  506. }
  507. .headPhoto {
  508. width: 50px;
  509. height: 50px;
  510. // background: url("../assets/teacherTrain/image 4.png") no-repeat 100% 100%;
  511. // background-size: 100%;
  512. border-radius: 50%;
  513. // margin-right: 10px;
  514. }
  515. .message {
  516. height: 100%;
  517. position: relative;
  518. display: flex;
  519. justify-content: center;
  520. align-items: center;
  521. margin-left: 23px;
  522. cursor: pointer;
  523. img {
  524. width: 24px;
  525. }
  526. .redDot {
  527. position: absolute;
  528. top: 2px;
  529. right: 2px;
  530. width: 6px;
  531. height: 6px;
  532. display: inline-block;
  533. background: red;
  534. border-radius: 50%;
  535. }
  536. }
  537. .selectLoginOrRegistration {
  538. display: flex;
  539. height: 32px;
  540. border: 1px solid #ffffff;
  541. box-sizing: border-box;
  542. border-radius: 4px;
  543. justify-content: space-evenly;
  544. align-items: center;
  545. padding: 0 16px;
  546. > span {
  547. cursor: pointer;
  548. font-size: 16px;
  549. color: #fff;
  550. }
  551. }
  552. .user {
  553. display: flex;
  554. align-items: center;
  555. cursor: pointer;
  556. position: relative;
  557. color: #fff;
  558. > img {
  559. width: 34px;
  560. height: 34px;
  561. }
  562. > span {
  563. font-size: 16px;
  564. padding-left: 10px;
  565. }
  566. .userShow {
  567. position: absolute;
  568. width: 156px;
  569. height: 96px;
  570. background: #ffffff;
  571. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  572. border-radius: 8px;
  573. bottom: -100px;
  574. left: -5px;
  575. color: black;
  576. img {
  577. width: 24px;
  578. height: 24px;
  579. margin-right: 10px;
  580. }
  581. p {
  582. font-size: 16px;
  583. height: 40px;
  584. display: flex;
  585. align-items: center;
  586. padding-left: 20px;
  587. margin: 0;
  588. margin-top: 5px;
  589. }
  590. > p:hover {
  591. background: #f2f2f2;
  592. }
  593. }
  594. }
  595. }
  596. }
  597. </style>
  598. <style lang="scss">
  599. .LoginNav1 {
  600. .el-dropdown-menu__item {
  601. line-height: 40px;
  602. display: flex;
  603. justify-content: center;
  604. align-items: center;
  605. > span {
  606. font-family: "sourceR";
  607. font-size: 16px;
  608. }
  609. }
  610. .el-menu--horizontal > .el-menu-item {
  611. height: 60px;
  612. line-height: 60px;
  613. }
  614. .el-dropdown {
  615. display: block;
  616. > span {
  617. font-family: "sourceR";
  618. font-size: 16px;
  619. }
  620. }
  621. }
  622. .projectList {
  623. &.el-dropdown-menu__item {
  624. line-height: 40px;
  625. display: flex;
  626. align-items: center;
  627. color: #000000;
  628. > img {
  629. top: 0;
  630. }
  631. > span {
  632. line-height: 40px;
  633. font-family: "sourceR";
  634. }
  635. }
  636. &:hover {
  637. background: #ff9900 !important;
  638. // background: rgba(255, 153, 0, 0.1) !important;
  639. color: #000 !important;
  640. // color: #fff;
  641. }
  642. &.menuActive {
  643. background: #ff9900;
  644. }
  645. }
  646. </style>