Header.vue 17 KB

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