Header.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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/teacherdev/headerDownlod.png"
  27. alt=""
  28. />
  29. <img
  30. v-else
  31. src="../assets/teacherdev/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/teacherdev/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. projectList: [],
  138. is_exist: "false",
  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. // let token = getToken();
  220. // if (token) {
  221. // if (JSON.parse(token).popedom_code_list.indexOf(2000006) != -1) {
  222. // this.$router.push("/teacherdevEntering");
  223. // } else {
  224. // this.$router.push({ path: "/" });
  225. // }
  226. // }
  227. }
  228. },
  229. // 切换项目
  230. handleCommand(command) {
  231. let _this = this;
  232. _this.LoginNavIndex = command;
  233. if (!_this.userMessage) {
  234. this.$message.warning("请先登录");
  235. this.projectName = "教研中心";
  236. window.location.href = "/";
  237. return;
  238. }
  239. let MethodName = "login_control-CreateAccessCode";
  240. let acsCode = null;
  241. // getContent(MethodName, UserCode, UserType, SessionID).then((res) => {
  242. // acsCode = res.access_code;
  243. // _this.projectName = this.projectList[command].name;
  244. let id = this.projectList[command].id;
  245. if (id == 0) {
  246. // 教学管理系统
  247. location.href = `/GCLS-Learn/#/EnterSys`;
  248. } else if (id == 1) {
  249. // 教材管理系统
  250. location.href = `/GCLS-Book/#/EnterSys`;
  251. } else if (id == 2) {
  252. // 教培中心
  253. location.href = `/GCLS-TRC/#/EnterSys`;
  254. } else if (id == 3) {
  255. // 教研中心
  256. location.href = `/GCLS-TC/#/EnterSys`;
  257. } else if (id == 4) {
  258. // 考试中心
  259. location.href = `/GCLS-Test/#/EnterSys`;
  260. } else if (id == 5) {
  261. // 学习中心
  262. location.href = `/GCLS-LC/#/EnterSys`;
  263. } else {
  264. // 个人中心
  265. location.href = `/GCLS-Personal/#/EnterSys`;
  266. }
  267. // });
  268. },
  269. // 切换登录的注册
  270. cutLoginReg() {
  271. window.location.href = "/";
  272. },
  273. QuitLogin() {
  274. window.location.href = "/";
  275. removeToken();
  276. Cookies.remove("JSESSIONID");
  277. this.userShow = false;
  278. this.userMessage = null;
  279. },
  280. getLangList() {
  281. let MethodName = "language_manager-GetLanguageList";
  282. let data = {};
  283. getStaticContent(MethodName, data).then((res) => {
  284. this.language_list = res.language_list;
  285. for (let i = 0; i < this.language_list.length; i++) {
  286. let item = this.language_list[i];
  287. if (item.language_type == this.language_type) {
  288. this.lang = item.language_name;
  289. break;
  290. }
  291. }
  292. });
  293. },
  294. async changeLang(command) {
  295. console.log(command);
  296. this.lang = command.language_name;
  297. let lang_type = command.language_type;
  298. await setI18nLang(lang_type);
  299. this.$router.go(0);
  300. },
  301. handleProList(list) {
  302. let projectList = [];
  303. if (list.length == 0) {
  304. let arr = [
  305. {
  306. id: 2,
  307. name: "教培中心",
  308. img: "project3",
  309. },
  310. {
  311. id: 3,
  312. name: "教研中心",
  313. img: "project6",
  314. },
  315. {
  316. id: 5,
  317. name: "学习中心",
  318. img: "project4",
  319. },
  320. {
  321. id: 6,
  322. name: "个人中心",
  323. img: "project7",
  324. },
  325. ];
  326. projectList = arr;
  327. } else {
  328. if (list.includes(2000001)) {
  329. projectList = JSON.parse(JSON.stringify(this.teacherProList));
  330. } else {
  331. for (let i = 0; i < list.length; i++) {
  332. let code = list[i];
  333. if (code == 2000002) {
  334. projectList.push({
  335. id: 0,
  336. name: "教学管理系统",
  337. img: "project1",
  338. });
  339. } else if (code == 2000003) {
  340. projectList.push({
  341. id: 1,
  342. name: "教材管理系统",
  343. img: "project2",
  344. });
  345. } else if (code == 2000004) {
  346. projectList.push({
  347. id: 2,
  348. name: "教师培训中心",
  349. img: "project3",
  350. });
  351. } else if (code == 2000005) {
  352. projectList.push({
  353. id: 4,
  354. name: "考试中心",
  355. img: "project5",
  356. });
  357. } else if (code == 2000006) {
  358. projectList.push({
  359. id: 3,
  360. name: "教研中心",
  361. img: "project4",
  362. });
  363. }
  364. }
  365. projectList.push({
  366. id: 6,
  367. // Teacher training center
  368. name: "个人中心",
  369. img: "project7",
  370. text: "您收集和购买的所有资源都可以在这里轻松找到。",
  371. });
  372. }
  373. }
  374. // 排序
  375. for (var i = 0; i < projectList.length - 1; i++) {
  376. for (var j = 0; j < projectList.length - 1 - i; j++) {
  377. // 相邻元素两两对比,元素交换,大的元素交换到后面
  378. if (projectList[j].id > projectList[j + 1].id) {
  379. var temp = projectList[j];
  380. projectList[j] = projectList[j + 1];
  381. projectList[j + 1] = temp;
  382. }
  383. }
  384. }
  385. return projectList;
  386. },
  387. getNotReadMessage() {
  388. let MethodName = "message-message_manager-IsExistMyMessage_NotRead";
  389. let data = {};
  390. getLearnWebContent(MethodName, data).then((res) => {
  391. this.is_exist = res.is_exist;
  392. });
  393. },
  394. },
  395. created() {},
  396. mounted() {
  397. let _this = this;
  398. let user = getToken();
  399. if (user) {
  400. _this.userMessage = JSON.parse(user);
  401. let popedom_code_list = _this.userMessage.popedom_code_list;
  402. if (_this.userMessage.user_type == "TEACHER") {
  403. _this.projectList = _this.handleProList(popedom_code_list);
  404. } else if (_this.userMessage.user_type == "STUDENT") {
  405. _this.projectList = _this.stuProList;
  406. }
  407. _this.projectList.forEach((item, index) => {
  408. if (item.id == 3) {
  409. _this.LoginNavIndex = index;
  410. }
  411. });
  412. }
  413. _this.getLangList();
  414. _this.getNotReadMessage();
  415. _this.headTimer = setInterval(() => {
  416. _this.getNotReadMessage();
  417. }, 120000);
  418. },
  419. beforeDestroy() {
  420. if (this.headTimer) {
  421. //如果定时器还在运行 或者直接关闭,不用判断
  422. clearInterval(this.headTimer); //关闭
  423. }
  424. },
  425. };
  426. </script>
  427. <style lang="scss" scoped>
  428. .LoginNav1 {
  429. // height: 74px;
  430. height: 64px;
  431. position: relative;
  432. display: flex;
  433. align-items: center;
  434. justify-content: space-between;
  435. box-sizing: border-box;
  436. padding: 0px 24px;
  437. z-index: 999;
  438. // background: #ffffff;
  439. // box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.15);
  440. font-family: "sourceR";
  441. .el-dropdown-link {
  442. img {
  443. width: 8px;
  444. height: 4px;
  445. vertical-align: middle;
  446. }
  447. }
  448. .logo {
  449. &-img {
  450. font-style: normal;
  451. font-weight: 600;
  452. font-size: 30px;
  453. font-variant: small-caps;
  454. // color: #000000;
  455. color: #fff;
  456. margin-right: 29px;
  457. line-height: 64px;
  458. }
  459. display: flex;
  460. align-items: center;
  461. .el-menu-demo {
  462. background: rgba(0, 0, 0, 0);
  463. // margin-left: 100px;
  464. li:hover {
  465. background: none;
  466. }
  467. li {
  468. font-size: 16px;
  469. background: none;
  470. }
  471. }
  472. // 取消组件默认的样式
  473. .el-menu.el-menu--horizontal {
  474. border-bottom: none;
  475. }
  476. }
  477. .userName {
  478. display: flex;
  479. justify-content: flex-end;
  480. align-items: center;
  481. .seek {
  482. margin-right: 100px;
  483. position: relative;
  484. img {
  485. left: 10px;
  486. top: 11px;
  487. position: absolute;
  488. }
  489. }
  490. .flag {
  491. position: relative;
  492. top: 5px;
  493. }
  494. .headPhoto {
  495. width: 50px;
  496. height: 50px;
  497. // background: url("../assets/teacherTrain/image 4.png") no-repeat 100% 100%;
  498. // background-size: 100%;
  499. border-radius: 50%;
  500. // margin-right: 10px;
  501. }
  502. .message {
  503. height: 100%;
  504. position: relative;
  505. display: flex;
  506. justify-content: center;
  507. align-items: center;
  508. margin-left: 23px;
  509. img {
  510. width: 24px;
  511. cursor: pointer;
  512. }
  513. .redDot {
  514. position: absolute;
  515. top: 2px;
  516. right: 2px;
  517. width: 6px;
  518. height: 6px;
  519. display: inline-block;
  520. background: red;
  521. border-radius: 50%;
  522. }
  523. }
  524. .selectLoginOrRegistration {
  525. display: flex;
  526. height: 32px;
  527. border: 1px solid #ffffff;
  528. box-sizing: border-box;
  529. border-radius: 4px;
  530. justify-content: space-evenly;
  531. align-items: center;
  532. padding: 0 16px;
  533. > span {
  534. cursor: pointer;
  535. font-size: 16px;
  536. color: #fff;
  537. }
  538. }
  539. .user {
  540. display: flex;
  541. align-items: center;
  542. cursor: pointer;
  543. position: relative;
  544. color: #fff;
  545. > img {
  546. width: 34px;
  547. height: 34px;
  548. }
  549. > span {
  550. font-size: 16px;
  551. padding-left: 10px;
  552. }
  553. .userShow {
  554. position: absolute;
  555. width: 156px;
  556. height: 96px;
  557. background: #ffffff;
  558. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  559. border-radius: 8px;
  560. bottom: -100px;
  561. left: -5px;
  562. color: black;
  563. img {
  564. width: 24px;
  565. height: 24px;
  566. margin-right: 10px;
  567. }
  568. p {
  569. font-size: 16px;
  570. height: 40px;
  571. display: flex;
  572. align-items: center;
  573. padding-left: 20px;
  574. margin: 0;
  575. margin-top: 5px;
  576. }
  577. > p:hover {
  578. background: #f2f2f2;
  579. }
  580. }
  581. }
  582. }
  583. }
  584. </style>
  585. <style lang="scss">
  586. .LoginNav1 {
  587. .el-dropdown-menu__item {
  588. line-height: 40px;
  589. display: flex;
  590. justify-content: center;
  591. align-items: center;
  592. > span {
  593. font-family: "sourceR";
  594. font-size: 16px;
  595. }
  596. }
  597. .el-menu--horizontal > .el-menu-item {
  598. height: 64px;
  599. line-height: 64px;
  600. }
  601. .el-dropdown {
  602. display: block;
  603. > span {
  604. font-family: "sourceR";
  605. font-size: 16px;
  606. }
  607. }
  608. .el-menu-item.is-active i {
  609. color: white;
  610. }
  611. }
  612. .projectList {
  613. &.el-dropdown-menu__item {
  614. line-height: 40px;
  615. display: flex;
  616. align-items: center;
  617. color: #000000;
  618. > img {
  619. top: 0;
  620. }
  621. > span {
  622. line-height: 40px;
  623. font-family: "sourceR";
  624. }
  625. }
  626. &:hover {
  627. background: #ff9900 !important;
  628. // background: rgba(255, 153, 0, 0.1) !important;
  629. color: #000 !important;
  630. // color: #fff;
  631. }
  632. &.menuActive {
  633. background: #ff9900;
  634. }
  635. }
  636. </style>