Header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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" @click="handleSelect"> 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>
  29. <el-dropdown
  30. style="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">{{ $t("Key9") }}</span>
  49. </div>
  50. <!-- 用户头像和用户名 -->
  51. <div class="user" v-else>
  52. <img
  53. @click="userShow = !userShow"
  54. class="headPhoto"
  55. :src="
  56. userMessage.image_url
  57. ? userMessage.image_url
  58. : require('../../assets/login/Group3214.png')
  59. "
  60. alt=""
  61. />
  62. <span @click="userShow = !userShow">{{
  63. userMessage.user_real_name
  64. }}</span>
  65. <div class="userShow" v-show="userShow">
  66. <p @click="gotoPersonalcenter">
  67. <img src="../../assets/login/project7.png" alt="" />
  68. <!-- 个人中心 -->
  69. {{ $t("Key38") }}
  70. </p>
  71. <p @click="QuitLogin">
  72. <img src="../../assets/login/Frame77.png" alt="" />
  73. <!-- 退出登录 -->
  74. {{ $t("Key39") }}
  75. </p>
  76. </div>
  77. </div>
  78. <!-- 消息 铃铛图片 -->
  79. <div class="message">
  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, setToken, removeToken, getConfig } from "@/utils/auth";
  89. import { getContent, getStaticContent, getLearnWebContent } from "@/api/ajax";
  90. import { setI18nLang } from "@/utils/i18n";
  91. import { saveSession, getSession, removeSession } from "@/utils/role";
  92. export default {
  93. name: "LayoutHeader",
  94. props: [],
  95. data() {
  96. return {
  97. activeIndex: "2", // 主导航索引
  98. LoginNavIndex: 0, //下拉框导航索引
  99. projectName: "个人中心",
  100. projectList: [],
  101. teacherProList: [
  102. //普通教师
  103. {
  104. id: 0,
  105. name: "教学中心",
  106. img: "project1",
  107. },
  108. {
  109. id: 2,
  110. name: "教培中心",
  111. img: "project3",
  112. },
  113. {
  114. id: 3,
  115. name: "教研中心",
  116. img: "project4",
  117. },
  118. {
  119. id: 4,
  120. name: "考试中心",
  121. img: "project5",
  122. },
  123. {
  124. id: 5,
  125. name: "学习中心",
  126. img: "project6",
  127. },
  128. {
  129. id: 6,
  130. name: "个人中心",
  131. img: "project7",
  132. },
  133. ],
  134. stuProList: [
  135. {
  136. id: 0,
  137. name: "教学中心",
  138. img: "project1",
  139. },
  140. {
  141. id: 5,
  142. name: "学习中心",
  143. img: "project6",
  144. },
  145. {
  146. id: 6,
  147. name: "个人中心",
  148. img: "project7",
  149. },
  150. ],
  151. userMessage: null,
  152. userShow: false,
  153. language_list: [],
  154. lang: "",
  155. configInfor: null,
  156. };
  157. },
  158. watch: {},
  159. computed: {
  160. ...mapGetters(["language_type", "is_exist"]),
  161. },
  162. methods: {
  163. // 前往个人中心
  164. gotoPersonalcenter() {
  165. if (!this.userMessage) {
  166. this.$message.warning("请先登录");
  167. return;
  168. }
  169. location.href = `/GCLS-Personal/#/EnterSys`;
  170. },
  171. //是否存在我未阅读的消息
  172. getNotReadMessage() {
  173. let MethodName = "message-message_manager-IsExistMyMessage_NotRead";
  174. let data = {};
  175. getLearnWebContent(MethodName, data).then((res) => {
  176. // this.is_exist = res.is_exist;
  177. this.$store.dispatch("message/updateIsExist", res.is_exist);
  178. });
  179. },
  180. // 切换导航
  181. handleSelect() {
  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. removeToken();
  204. sessionStorage.removeItem("useragent_root_close");
  205. this.userShow = false;
  206. this.userMessage = null;
  207. window.location.href = "/";
  208. },
  209. getLangList() {
  210. let MethodName = "language_manager-GetLanguageList";
  211. let data = {};
  212. getStaticContent(MethodName, data).then((res) => {
  213. this.language_list = res.language_list;
  214. for (let i = 0; i < this.language_list.length; i++) {
  215. let item = this.language_list[i];
  216. if (item.language_type == this.language_type) {
  217. this.lang = item.language_name;
  218. break;
  219. }
  220. }
  221. });
  222. },
  223. async changeLang(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. getContent(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-Personal") {
  238. _this.LoginNavIndex = index;
  239. }
  240. });
  241. saveSession("SysList", this.projectList);
  242. }
  243. })
  244. .catch((err) => {
  245. console.log(err);
  246. });
  247. },
  248. },
  249. created() {
  250. let _this = this;
  251. let config = getConfig();
  252. if (config) {
  253. _this.configInfor = JSON.parse(config);
  254. }
  255. _this.getChildSysList();
  256. },
  257. mounted() {
  258. let _this = this;
  259. let user = getToken();
  260. if (user) {
  261. _this.userMessage = JSON.parse(user);
  262. _this.getNotReadMessage();
  263. setInterval(() => {
  264. _this.getNotReadMessage();
  265. }, 120000);
  266. }
  267. _this.getLangList();
  268. },
  269. };
  270. </script>
  271. <style lang="scss" scoped>
  272. .LoginNav {
  273. height: 64px;
  274. position: relative;
  275. display: flex;
  276. align-items: center;
  277. justify-content: space-between;
  278. box-sizing: border-box;
  279. padding: 0px 24px;
  280. z-index: 999;
  281. background: #ffffff;
  282. box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.15);
  283. font-family: "sourceR";
  284. .logo {
  285. &-image {
  286. height: 48px;
  287. cursor: pointer;
  288. }
  289. display: flex;
  290. align-items: center;
  291. .logo-projectlist {
  292. display: flex;
  293. padding: 0 24px;
  294. height: 64px;
  295. li {
  296. padding: 0 12px;
  297. color: rgba(0, 0, 0, 0.45);
  298. font-size: 16px;
  299. line-height: 64px;
  300. font-weight: 500;
  301. cursor: pointer;
  302. white-space: nowrap;
  303. &:hover {
  304. background: #f6f6f6;
  305. }
  306. &.active {
  307. color: #ff9900;
  308. background: #ffefd6;
  309. }
  310. }
  311. }
  312. }
  313. .userName {
  314. display: flex;
  315. justify-content: flex-end;
  316. align-items: center;
  317. .seek {
  318. margin-right: 100px;
  319. position: relative;
  320. img {
  321. left: 10px;
  322. top: 11px;
  323. position: absolute;
  324. }
  325. }
  326. .flag {
  327. position: relative;
  328. top: 5px;
  329. }
  330. .headPhoto {
  331. width: 50px;
  332. height: 50px;
  333. // background: url("../assets/teacherTrain/image 4.png") no-repeat 100% 100%;
  334. // background-size: 100%;
  335. border-radius: 50%;
  336. // margin-right: 10px;
  337. }
  338. .message {
  339. height: 100%;
  340. position: relative;
  341. display: flex;
  342. justify-content: center;
  343. align-items: center;
  344. // margin-left: 23px;
  345. img {
  346. width: 18px;
  347. height: 24px;
  348. }
  349. .redDot {
  350. position: absolute;
  351. top: 2px;
  352. right: -2px;
  353. width: 6px;
  354. height: 6px;
  355. display: inline-block;
  356. background: red;
  357. border-radius: 50%;
  358. }
  359. }
  360. .selectLoginOrRegistration {
  361. display: flex;
  362. height: 32px;
  363. border: 1px solid #ffffff;
  364. box-sizing: border-box;
  365. border-radius: 4px;
  366. justify-content: space-evenly;
  367. align-items: center;
  368. padding: 0 16px;
  369. > span {
  370. cursor: pointer;
  371. font-size: 16px;
  372. color: #fff;
  373. }
  374. }
  375. .user {
  376. display: flex;
  377. align-items: center;
  378. cursor: pointer;
  379. position: relative;
  380. margin: 0 23px 0 16px;
  381. > img {
  382. width: 34px;
  383. height: 34px;
  384. }
  385. > span {
  386. font-size: 20px;
  387. padding-left: 10px;
  388. padding-right: 10px;
  389. }
  390. .userShow {
  391. position: absolute;
  392. width: 156px;
  393. height: 96px;
  394. background: #ffffff;
  395. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  396. border-radius: 8px;
  397. bottom: -100px;
  398. color: black;
  399. img {
  400. width: 24px;
  401. height: 24px;
  402. margin-right: 10px;
  403. }
  404. p {
  405. font-size: 16px;
  406. height: 40px;
  407. display: flex;
  408. align-items: center;
  409. padding-left: 20px;
  410. margin: 0;
  411. margin-top: 5px;
  412. }
  413. > p:hover {
  414. background: #f2f2f2;
  415. }
  416. }
  417. }
  418. }
  419. }
  420. </style>
  421. <style lang="scss">
  422. .LoginNav {
  423. .el-dropdown-menu__item {
  424. line-height: 40px;
  425. display: flex;
  426. justify-content: center;
  427. align-items: center;
  428. > span {
  429. font-family: "sourceR";
  430. font-size: 16px;
  431. }
  432. }
  433. .el-menu--horizontal > .el-menu-item {
  434. height: 64px;
  435. line-height: 64px;
  436. }
  437. .el-dropdown {
  438. display: block;
  439. > span {
  440. font-family: "sourceR";
  441. font-size: 16px;
  442. }
  443. }
  444. }
  445. .projectList {
  446. &.el-dropdown-menu__item {
  447. line-height: 40px;
  448. display: flex;
  449. align-items: center;
  450. color: #000000;
  451. > img {
  452. top: 0;
  453. }
  454. > span {
  455. line-height: 40px;
  456. font-family: "sourceR";
  457. }
  458. }
  459. &:hover {
  460. background: rgba(255, 153, 0, 0.1) !important;
  461. color: #000 !important;
  462. }
  463. &.menuActive {
  464. background: #ff9900;
  465. }
  466. }
  467. </style>