Header.vue 12 KB

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