Header.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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: 5,
  158. name: "学习中心",
  159. img: "project6",
  160. },
  161. {
  162. id: 4,
  163. name: "考试中心",
  164. img: "project5",
  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: 4,
  314. name: "考试中心",
  315. img: "project5",
  316. },
  317. {
  318. id: 6,
  319. name: "个人中心",
  320. img: "project7",
  321. },
  322. ];
  323. projectList = arr;
  324. } else if (list.includes(2000001)) {
  325. projectList = JSON.parse(JSON.stringify(this.teacherProList));
  326. for (let i = 0; i < list.length; i++) {
  327. let code = list[i];
  328. if (code == 2000003) {
  329. projectList.push({
  330. id: 1,
  331. name: "教材管理系统",
  332. img: "project1-1",
  333. selectImg: "project1-1-1",
  334. });
  335. }
  336. if (code == 2000005) {
  337. projectList.push({
  338. id: 4,
  339. name: "考试中心",
  340. img: "project5",
  341. });
  342. }
  343. }
  344. } else {
  345. for (let i = 0; i < list.length; i++) {
  346. let code = list[i];
  347. if (code == 2000002) {
  348. projectList.push({
  349. id: 0,
  350. name: "教学管理系统",
  351. img: "project1",
  352. });
  353. } else if (code == 2000003) {
  354. projectList.push({
  355. id: 1,
  356. name: "教材管理系统",
  357. img: "project2",
  358. });
  359. } else if (code == 2000004) {
  360. projectList.push({
  361. id: 2,
  362. name: "教师培训中心",
  363. img: "project3",
  364. });
  365. } else if (code == 2000005) {
  366. projectList.push({
  367. id: 4,
  368. name: "考试中心",
  369. img: "project5",
  370. });
  371. } else if (code == 2000006) {
  372. projectList.push({
  373. id: 3,
  374. name: "教研中心",
  375. img: "project4",
  376. });
  377. }
  378. }
  379. projectList.push({
  380. id: 6,
  381. // Teacher training center
  382. name: "个人中心",
  383. img: "project7",
  384. text: "您收集和购买的所有资源都可以在这里轻松找到。",
  385. });
  386. }
  387. // 排序
  388. for (var i = 0; i < projectList.length - 1; i++) {
  389. for (var j = 0; j < projectList.length - 1 - i; j++) {
  390. // 相邻元素两两对比,元素交换,大的元素交换到后面
  391. if (projectList[j].id > projectList[j + 1].id) {
  392. var temp = projectList[j];
  393. projectList[j] = projectList[j + 1];
  394. projectList[j + 1] = temp;
  395. }
  396. }
  397. }
  398. console.log(projectList);
  399. return projectList;
  400. },
  401. getNotReadMessage() {
  402. let MethodName = "message-message_manager-IsExistMyMessage_NotRead";
  403. let data = {};
  404. getLearnWebContent(MethodName, data).then((res) => {
  405. this.is_exist = res.is_exist;
  406. });
  407. },
  408. },
  409. created() {},
  410. mounted() {
  411. let _this = this;
  412. let user = getToken();
  413. if (user) {
  414. _this.userMessage = JSON.parse(user);
  415. let popedom_code_list = _this.userMessage.popedom_code_list;
  416. if (_this.userMessage.user_type == "TEACHER") {
  417. _this.projectList = _this.handleProList(popedom_code_list);
  418. } else if (_this.userMessage.user_type == "STUDENT") {
  419. _this.projectList = _this.stuProList;
  420. }
  421. _this.projectList.forEach((item, index) => {
  422. if (item.id == 5) {
  423. _this.LoginNavIndex = index;
  424. }
  425. });
  426. }
  427. _this.getLangList();
  428. _this.headTimer = _this.getNotReadMessage();
  429. setInterval(() => {
  430. _this.getNotReadMessage();
  431. }, 120000);
  432. },
  433. beforeDestroy() {
  434. if (this.headTimer) {
  435. //如果定时器还在运行 或者直接关闭,不用判断
  436. clearInterval(this.headTimer); //关闭
  437. }
  438. },
  439. };
  440. </script>
  441. <style lang="scss" scoped>
  442. .LoginNav1 {
  443. // height: 74px;
  444. height: 64px;
  445. position: relative;
  446. display: flex;
  447. align-items: center;
  448. justify-content: space-between;
  449. box-sizing: border-box;
  450. padding: 0px 24px;
  451. z-index: 999;
  452. // background: #ffffff;
  453. // box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.15);
  454. font-family: "sourceR";
  455. .logo {
  456. &-img {
  457. font-style: normal;
  458. font-weight: 600;
  459. font-size: 30px;
  460. font-variant: small-caps;
  461. // color: #000000;
  462. color: #fff;
  463. margin-right: 29px;
  464. line-height: 64px;
  465. }
  466. display: flex;
  467. align-items: center;
  468. .el-menu-demo {
  469. background: rgba(0, 0, 0, 0);
  470. // margin-left: 100px;
  471. li:hover {
  472. background: none;
  473. }
  474. li {
  475. font-size: 16px;
  476. background: none;
  477. height: 64px;
  478. line-height: 64px;
  479. }
  480. }
  481. // 取消组件默认的样式
  482. .el-menu.el-menu--horizontal {
  483. border-bottom: none;
  484. }
  485. }
  486. .el-dropdown-link {
  487. img {
  488. width: 8px;
  489. height: 4px;
  490. vertical-align: middle;
  491. }
  492. }
  493. .userName {
  494. display: flex;
  495. justify-content: flex-end;
  496. align-items: center;
  497. .seek {
  498. margin-right: 100px;
  499. position: relative;
  500. img {
  501. left: 10px;
  502. top: 11px;
  503. position: absolute;
  504. }
  505. }
  506. .flag {
  507. position: relative;
  508. top: 5px;
  509. }
  510. .headPhoto {
  511. width: 50px;
  512. height: 50px;
  513. // background: url("../assets/teacherTrain/image 4.png") no-repeat 100% 100%;
  514. // background-size: 100%;
  515. border-radius: 50%;
  516. // margin-right: 10px;
  517. }
  518. .message {
  519. height: 100%;
  520. position: relative;
  521. display: flex;
  522. justify-content: center;
  523. align-items: center;
  524. margin-left: 23px;
  525. cursor: pointer;
  526. img {
  527. width: 24px;
  528. }
  529. .redDot {
  530. position: absolute;
  531. top: 2px;
  532. right: 2px;
  533. width: 6px;
  534. height: 6px;
  535. display: inline-block;
  536. background: red;
  537. border-radius: 50%;
  538. }
  539. }
  540. .selectLoginOrRegistration {
  541. display: flex;
  542. height: 32px;
  543. border: 1px solid #ffffff;
  544. box-sizing: border-box;
  545. border-radius: 4px;
  546. justify-content: space-evenly;
  547. align-items: center;
  548. padding: 0 16px;
  549. > span {
  550. cursor: pointer;
  551. font-size: 16px;
  552. color: #fff;
  553. }
  554. }
  555. .user {
  556. display: flex;
  557. align-items: center;
  558. cursor: pointer;
  559. position: relative;
  560. color: #fff;
  561. > img {
  562. width: 34px;
  563. height: 34px;
  564. }
  565. > span {
  566. font-size: 16px;
  567. padding-left: 10px;
  568. }
  569. .userShow {
  570. position: absolute;
  571. width: 156px;
  572. height: 96px;
  573. background: #ffffff;
  574. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  575. border-radius: 8px;
  576. bottom: -100px;
  577. left: -5px;
  578. color: black;
  579. img {
  580. width: 24px;
  581. height: 24px;
  582. margin-right: 10px;
  583. }
  584. p {
  585. font-size: 16px;
  586. height: 40px;
  587. display: flex;
  588. align-items: center;
  589. padding-left: 20px;
  590. margin: 0;
  591. margin-top: 5px;
  592. }
  593. > p:hover {
  594. background: #f2f2f2;
  595. }
  596. }
  597. }
  598. }
  599. }
  600. </style>
  601. <style lang="scss">
  602. .LoginNav1 {
  603. .el-dropdown-menu__item {
  604. line-height: 40px;
  605. display: flex;
  606. justify-content: center;
  607. align-items: center;
  608. > span {
  609. font-family: "sourceR";
  610. font-size: 16px;
  611. }
  612. }
  613. .el-menu--horizontal > .el-menu-item {
  614. height: 60px;
  615. line-height: 60px;
  616. }
  617. .el-dropdown {
  618. display: block;
  619. > span {
  620. font-family: "sourceR";
  621. font-size: 16px;
  622. }
  623. }
  624. }
  625. .projectList {
  626. &.el-dropdown-menu__item {
  627. line-height: 40px;
  628. display: flex;
  629. align-items: center;
  630. color: #000000;
  631. > img {
  632. top: 0;
  633. }
  634. > span {
  635. line-height: 40px;
  636. font-family: "sourceR";
  637. }
  638. }
  639. &:hover {
  640. background: #ff9900 !important;
  641. // background: rgba(255, 153, 0, 0.1) !important;
  642. color: #000 !important;
  643. // color: #fff;
  644. }
  645. &.menuActive {
  646. background: #ff9900;
  647. }
  648. }
  649. </style>