Header.vue 12 KB

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