Header.vue 14 KB

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