Header.vue 13 KB

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