Header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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 { saveSession, getSession, 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. this.userShow = false;
  204. this.userMessage = null;
  205. window.location.href = "/";
  206. },
  207. getLangList() {
  208. let MethodName = "language_manager-GetLanguageList";
  209. let data = {};
  210. getStaticContent(MethodName, data).then((res) => {
  211. this.language_list = res.language_list;
  212. for (let i = 0; i < this.language_list.length; i++) {
  213. let item = this.language_list[i];
  214. if (item.language_type == this.language_type) {
  215. this.lang = item.language_name;
  216. break;
  217. }
  218. }
  219. });
  220. },
  221. async changeLang(command) {
  222. console.log(command);
  223. this.lang = command.language_name;
  224. let lang_type = command.language_type;
  225. await setI18nLang(lang_type);
  226. this.$router.go(0);
  227. },
  228. getChildSysList() {
  229. let _this = this;
  230. let MethodName = "login_control-GetChildSysList_CanEnter_PC";
  231. getContentFile(MethodName, {})
  232. .then((res) => {
  233. if (res.child_sys_list && res.child_sys_list.length > 0) {
  234. _this.projectList = res.child_sys_list;
  235. _this.projectList.forEach((item, index) => {
  236. if (item.key == "GCLS-Book") {
  237. _this.LoginNavIndex = index;
  238. }
  239. });
  240. }
  241. })
  242. .catch((err) => {
  243. console.log(err);
  244. });
  245. },
  246. //是否存在我未阅读的消息
  247. getNotReadMessage() {
  248. let MethodName = "message-message_manager-IsExistMyMessage_NotRead";
  249. let data = {};
  250. getLearnWebContent(MethodName, data).then((res) => {
  251. this.is_exist = res.is_exist;
  252. });
  253. },
  254. async _getConfig() {
  255. this.configInfor = await getConfigInfor();
  256. },
  257. },
  258. created() {
  259. let _this = this;
  260. let routePath = this.$route.path;
  261. this.routePath = routePath;
  262. let config = getConfig();
  263. if (config) {
  264. _this.configInfor = JSON.parse(config);
  265. } else {
  266. _this._getConfig();
  267. }
  268. _this.getChildSysList();
  269. },
  270. mounted() {
  271. let _this = this;
  272. let user = getToken();
  273. if (user) {
  274. _this.userMessage = JSON.parse(user);
  275. let popedom_code_list = _this.userMessage.popedom_code_list;
  276. if (popedom_code_list.indexOf(2000003) > -1) {
  277. _this.projectName = "教材管理系统";
  278. } else {
  279. _this.projectName = "学习中心";
  280. }
  281. _this.getLangList();
  282. _this.getNotReadMessage();
  283. _this.headTimer = setInterval(() => {
  284. _this.getNotReadMessage();
  285. }, 120000);
  286. }
  287. },
  288. beforeDestroy() {
  289. if (this.headTimer) {
  290. //如果定时器还在运行 或者直接关闭,不用判断
  291. clearInterval(this.headTimer); //关闭
  292. }
  293. },
  294. };
  295. </script>
  296. <style lang="scss" scoped>
  297. .LoginNav {
  298. height: 64px;
  299. position: relative;
  300. display: flex;
  301. align-items: center;
  302. justify-content: space-between;
  303. box-sizing: border-box;
  304. padding: 0px 24px;
  305. z-index: 999;
  306. background: #ffffff;
  307. box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.15);
  308. font-family: "sourceR";
  309. .logo {
  310. &-image {
  311. // width: 188px;
  312. height: 48px;
  313. cursor: pointer;
  314. }
  315. display: flex;
  316. align-items: center;
  317. .logo-projectlist {
  318. display: flex;
  319. padding: 0 24px;
  320. height: 64px;
  321. list-style: none;
  322. li {
  323. padding: 0 12px;
  324. color: rgba(0, 0, 0, 0.45);
  325. font-size: 16px;
  326. line-height: 64px;
  327. cursor: pointer;
  328. font-weight: 500;
  329. &:hover {
  330. background: #f6f6f6;
  331. }
  332. &.active {
  333. color: #ff9900;
  334. background: #ffefd6;
  335. }
  336. }
  337. }
  338. }
  339. .userName {
  340. display: flex;
  341. justify-content: flex-end;
  342. align-items: center;
  343. .seek {
  344. margin-right: 100px;
  345. position: relative;
  346. img {
  347. left: 10px;
  348. top: 11px;
  349. position: absolute;
  350. }
  351. }
  352. .flag {
  353. position: relative;
  354. top: 5px;
  355. }
  356. .headPhoto {
  357. width: 50px;
  358. height: 50px;
  359. // background: url("../assets/teacherTrain/image 4.png") no-repeat 100% 100%;
  360. // background-size: 100%;
  361. border-radius: 50%;
  362. // margin-right: 10px;
  363. }
  364. .message {
  365. height: 100%;
  366. position: relative;
  367. display: flex;
  368. justify-content: center;
  369. align-items: center;
  370. margin-left: 23px;
  371. cursor: pointer;
  372. img {
  373. width: 18px;
  374. height: 24px;
  375. }
  376. .redDot {
  377. position: absolute;
  378. top: 2px;
  379. right: -2px;
  380. width: 6px;
  381. height: 6px;
  382. display: inline-block;
  383. background: red;
  384. border-radius: 50%;
  385. }
  386. }
  387. .selectLoginOrRegistration {
  388. display: flex;
  389. height: 32px;
  390. border: 1px solid #ffffff;
  391. box-sizing: border-box;
  392. border-radius: 4px;
  393. justify-content: space-evenly;
  394. align-items: center;
  395. padding: 0 16px;
  396. > span {
  397. cursor: pointer;
  398. font-size: 16px;
  399. color: #fff;
  400. }
  401. }
  402. .user {
  403. display: flex;
  404. align-items: center;
  405. cursor: pointer;
  406. position: relative;
  407. > img {
  408. width: 34px;
  409. height: 34px;
  410. }
  411. > span {
  412. font-size: 20px;
  413. padding-left: 10px;
  414. }
  415. .userShow {
  416. position: absolute;
  417. width: 156px;
  418. height: 96px;
  419. background: #ffffff;
  420. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  421. border-radius: 8px;
  422. bottom: -100px;
  423. color: black;
  424. z-index: 9999;
  425. img {
  426. width: 24px;
  427. height: 24px;
  428. margin-right: 10px;
  429. }
  430. p {
  431. font-size: 16px;
  432. height: 40px;
  433. display: flex;
  434. align-items: center;
  435. padding-left: 20px;
  436. margin: 0;
  437. margin-top: 5px;
  438. }
  439. > p:hover {
  440. background: #f2f2f2;
  441. }
  442. }
  443. }
  444. }
  445. }
  446. </style>
  447. <style lang="scss">
  448. .LoginNav {
  449. .el-dropdown-menu__item {
  450. line-height: 40px;
  451. display: flex;
  452. justify-content: center;
  453. align-items: center;
  454. > span {
  455. font-family: "sourceR";
  456. font-size: 16px;
  457. }
  458. }
  459. .el-menu--horizontal > .el-menu-item {
  460. height: 64px;
  461. line-height: 68px;
  462. }
  463. .el-dropdown {
  464. display: block;
  465. > span {
  466. font-family: "sourceR";
  467. font-size: 16px;
  468. }
  469. }
  470. }
  471. .projectList {
  472. &.el-dropdown-menu__item {
  473. line-height: 40px;
  474. display: flex;
  475. align-items: center;
  476. color: #000000;
  477. > img {
  478. top: 0;
  479. }
  480. > span {
  481. line-height: 40px;
  482. font-family: "sourceR";
  483. }
  484. }
  485. &:hover {
  486. background: rgba(255, 153, 0, 0.1) !important;
  487. color: #000 !important;
  488. }
  489. &.menuActive {
  490. background: #ff9900;
  491. }
  492. }
  493. </style>