Header.vue 13 KB

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