LoginNav.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <template>
  2. <!-- 顶部登录导航 -->
  3. <div class="LoginNav" :style="{ color: type == 'Live' ? 'black' : 'white' }">
  4. <div class="logo">
  5. <!-- <span> logo </span> -->
  6. <el-menu
  7. :default-active="activeIndex"
  8. class="el-menu-demo"
  9. mode="horizontal"
  10. @select="handleSelect"
  11. text-color="#fff"
  12. active-text-color="#FF9900"
  13. >
  14. <el-menu-item index="1">首页</el-menu-item>
  15. <el-menu-item index="2">
  16. <el-dropdown trigger="click" @command="handleCommand">
  17. <span
  18. class="el-dropdown-link"
  19. :style="{ color: LoginNavIndex == 2 ? '#FF9900' : '#fff' }"
  20. >
  21. {{ projectName }}
  22. <!-- SYSTEM -->
  23. <img class="dropdownIcon" src="../../assets/login/dropdownIcon.png" alt="">
  24. <!-- <i class="el-icon-arrow-down el-icon--right"></i> -->
  25. </span>
  26. <el-dropdown-menu slot="dropdown" style="width: 300px">
  27. <el-dropdown-item
  28. v-for="(item, i) in projectList"
  29. :key="i"
  30. :command="i"
  31. :class="projectDownIndex == i ? 'downsele' : ''"
  32. >
  33. <img
  34. style="position: relative; top: 5px; width: 24px"
  35. :src="require('../../assets/login/' + item.img + '.png')"
  36. alt=""
  37. />
  38. <span style="margin-left: 16px">
  39. {{ item.name }}
  40. </span>
  41. </el-dropdown-item>
  42. <!-- <el-dropdown-item command="LEARING CENTER">
  43. Learning Center
  44. </el-dropdown-item>
  45. <el-dropdown-item command="TESTING CENTER"
  46. >Testing Center</el-dropdown-item
  47. >
  48. <el-dropdown-item command="TEACHER CENTER"
  49. >Teacher Center</el-dropdown-item
  50. > -->
  51. </el-dropdown-menu>
  52. </el-dropdown>
  53. </el-menu-item>
  54. </el-menu>
  55. </div>
  56. <div class="userName">
  57. <!-- <div class="headPhoto"></div> -->
  58. <el-dropdown
  59. v-if="userMessage"
  60. style="margin-right: 16px"
  61. trigger="click"
  62. @command="changeLang"
  63. >
  64. <span class="el-dropdown-link" style="color: #fff; cursor: pointer">
  65. {{ lang ? lang : "中文"
  66. }}<i class="el-icon-arrow-down el-icon--right"></i>
  67. </span>
  68. <el-dropdown-menu slot="dropdown" style="width: 200px">
  69. <el-dropdown-item
  70. v-for="item in language_list"
  71. :key="item.language_type"
  72. :command="item"
  73. >{{ item.language_name }}</el-dropdown-item
  74. >
  75. </el-dropdown-menu>
  76. </el-dropdown>
  77. <div v-if="!userMessage" class="selectLoginOrRegistration">
  78. <span @click="cutLoginReg('login')">登录</span>
  79. <span> | </span>
  80. <span @click="cutLoginReg('signin')">注册</span>
  81. </div>
  82. <!-- 用户头像和用户名 -->
  83. <div class="user" v-else>
  84. <!-- :src="
  85. userMessage.image_url
  86. ? userMessage.image_url
  87. : require('../../assets/login/Group3214.png')+
  88. "
  89. src="../../assets/login/Group3214.png"
  90. -->
  91. <img
  92. @click="userShow = !userShow"
  93. class="headPhoto"
  94. :src="
  95. userMessage.image_url
  96. ? userMessage.image_url
  97. : require('../../assets/login/Group3214.png')
  98. "
  99. alt=""
  100. />
  101. <span @click="userShow = !userShow">{{
  102. userMessage.user_real_name
  103. }}</span>
  104. <div class="userShow" v-show="userShow">
  105. <p @click="gotoPersonalcenter">
  106. <img src="../../assets/login/project7.png" alt="" />
  107. 个人中心
  108. </p>
  109. <p @click="QuitLogin">
  110. <img src="../../assets/login/Frame77.png" alt="" />
  111. 退出登录
  112. </p>
  113. </div>
  114. </div>
  115. <!-- 消息 铃铛图片 -->
  116. <div class="message">
  117. <img
  118. @click="gotoPersonalcenter"
  119. src="../../assets/login/Vector2.png"
  120. alt=""
  121. />
  122. <!-- <span class="redDot"></span> -->
  123. </div>
  124. </div>
  125. </div>
  126. </template>
  127. <script>
  128. import Cookies from "js-cookie";
  129. import { getAcsCode, getStaticContent, getContent } from "@/api/api";
  130. import { setI18nLang } from "@/utils/i18n";
  131. import { mapGetters } from "vuex";
  132. import { getToken, removeToken } from "@/utils/auth";
  133. export default {
  134. props: ["type", "changeLoginReg", "FatheruserMessage"],
  135. data() {
  136. return {
  137. activeIndex: "1",
  138. LoginNavIndex: "1",
  139. projectName: "",
  140. userMessage: null,
  141. userShow: false,
  142. projectDownIndex: 0,
  143. projectList: [
  144. {
  145. id: 0,
  146. name: "教学中心",
  147. img: "project1",
  148. },
  149. {
  150. id: 2,
  151. name: "教培中心",
  152. img: "project3",
  153. },
  154. {
  155. id: 3,
  156. name: "教研中心",
  157. img: "project6",
  158. },
  159. {
  160. id: 5,
  161. name: "学习中心",
  162. img: "project4",
  163. },
  164. {
  165. id: 6,
  166. name: "个人中心",
  167. img: "project7",
  168. },
  169. {
  170. id: 4,
  171. name: "考试中心",
  172. img: "project5",
  173. },
  174. ],
  175. teacherProList: [
  176. //普通教师
  177. {
  178. id: 0,
  179. name: "教学中心",
  180. img: "project1",
  181. },
  182. {
  183. id: 2,
  184. name: "教培中心",
  185. img: "project3",
  186. },
  187. {
  188. id: 3,
  189. name: "教研中心",
  190. img: "project6",
  191. },
  192. {
  193. id: 5,
  194. name: "学习中心",
  195. img: "project4",
  196. },
  197. {
  198. id: 6,
  199. name: "个人中心",
  200. img: "project7",
  201. },
  202. ],
  203. stuProList: [
  204. {
  205. id: 0,
  206. name: "教学中心",
  207. img: "project1",
  208. },
  209. {
  210. id: 5,
  211. name: "学习中心",
  212. img: "project4",
  213. },
  214. {
  215. id: 6,
  216. name: "个人中心",
  217. img: "project7",
  218. },
  219. ],
  220. language_list: [],
  221. lang: "",
  222. };
  223. },
  224. watch: {
  225. FatheruserMessage(newval, oldval) {
  226. this.userMessage = null;
  227. this.userMessage = newval;
  228. if (this.userMessage) {
  229. let popedom_code_list = this.userMessage.popedom_code_list;
  230. if (this.userMessage.user_type == "TEACHER") {
  231. this.projectList = this.handleProList(popedom_code_list);
  232. } else if (this.userMessage.user_type == "STUDENT") {
  233. this.projectList = this.stuProList;
  234. }
  235. this.projectList.forEach((item, index) => {
  236. if (item.id == 4) {
  237. this.LoginNavIndex = index;
  238. }
  239. });
  240. } else {
  241. this.projectList = this.teacherProList;
  242. }
  243. },
  244. },
  245. methods: {
  246. // 切换导航
  247. handleSelect(key, keyPath) {
  248. this.LoginNavIndex = key;
  249. if (this.LoginNavIndex == "1") {
  250. this.$router.push("/");
  251. } else {
  252. let ulobj = document.getElementsByClassName("el-dropdown-menu")[0];
  253. ulobj.classList.add("LoginNavSeleProject");
  254. }
  255. },
  256. // 切换项目
  257. handleCommand(command) {
  258. let _this = this;
  259. _this.LoginNavIndex = "2";
  260. let userInfor = getToken();
  261. let user_code = "",
  262. user_type = "",
  263. session_id = "";
  264. if (userInfor) {
  265. userInfor = JSON.parse(getToken());
  266. user_code = userInfor.user_code;
  267. user_type = userInfor.user_type;
  268. session_id = userInfor.session_id;
  269. }
  270. if (!session_id || !user_code || !user_type || !_this.userMessage) {
  271. this.$message.warning("请先登录");
  272. this.projectName = "教学中心";
  273. // window.location.href = "/";
  274. return;
  275. }
  276. _this.projectDownIndex = command;
  277. let MethodName = "login_control-CreateAccessCode";
  278. let acsCode = null;
  279. getContent(MethodName, user_code, user_type, session_id).then((res) => {
  280. acsCode = res.access_code;
  281. _this.projectName = this.projectList[command].name;
  282. let id = this.projectList[command].id;
  283. if (id == 0) {
  284. // 教学管理系统
  285. location.href = `/GCLS-Learn/#/EnterSys?AccessCode=${acsCode}`;
  286. } else if (id == 1) {
  287. // 教材管理系统
  288. location.href = `/GCLS-Book/#/EnterSys?AccessCode=${acsCode}`;
  289. } else if (id == 2) {
  290. // 教培中心
  291. location.href = `/GCLS-TRC/#/EnterSys?AccessCode=${acsCode}`;
  292. } else if (id == 3) {
  293. // 教研中心
  294. location.href = `/GCLS-TC/#/EnterSys?AccessCode=${acsCode}`;
  295. } else if (id == 4) {
  296. // 考试中心
  297. location.href = `/GCLS-Test/#/EnterSys?AccessCode=${acsCode}`;
  298. } else if (id == 5) {
  299. // 学习中心
  300. location.href = `/GCLS-LC/#/EnterSys?AccessCode=${acsCode}`;
  301. } else {
  302. // 个人中心
  303. location.href = `/GCLS-Personal/#/EnterSys?AccessCode=${acsCode}`;
  304. }
  305. });
  306. },
  307. // 切换语言
  308. async changeLang(command) {
  309. this.lang = command.language_name;
  310. let lang_type = command.language_type;
  311. console.log(lang_type);
  312. await setI18nLang(lang_type);
  313. this.$router.go(0);
  314. },
  315. // 切换登录的注册
  316. cutLoginReg(value) {
  317. this.changeLoginReg(value);
  318. },
  319. // 前往个人中心
  320. gotoPersonalcenter() {
  321. let userInfor = getToken();
  322. let user_code = "",
  323. user_type = "",
  324. session_id = "";
  325. if (userInfor) {
  326. userInfor = JSON.parse(getToken());
  327. user_code = userInfor.user_code;
  328. user_type = userInfor.user_type;
  329. session_id = userInfor.session_id;
  330. }
  331. if (!session_id) {
  332. this.$message.warning("请先登录");
  333. return;
  334. }
  335. let MethodName = "login_control-CreateAccessCode";
  336. let acsCode = "";
  337. getContent(MethodName, user_code, user_type, session_id).then((res) => {
  338. acsCode = res.access_code;
  339. location.href = `/GCLS-Personal/#/EnterSys?AccessCode=${acsCode}`;
  340. });
  341. },
  342. QuitLogin() {
  343. Cookies.remove("userMessage");
  344. Cookies.remove("session_id");
  345. Cookies.remove("user_code");
  346. Cookies.remove("user_type");
  347. removeToken();
  348. this.userShow = false;
  349. this.userMessage = null;
  350. this.changeLoginReg("", null);
  351. },
  352. getLangList() {
  353. let MethodName = "language_manager-GetLanguageList";
  354. let data = {};
  355. getStaticContent(MethodName, data).then((res) => {
  356. this.language_list = res.language_list;
  357. for (let i = 0; i < this.language_list.length; i++) {
  358. let item = this.language_list[i];
  359. if (item.language_type == this.language_type) {
  360. this.lang = item.language_name;
  361. break;
  362. }
  363. }
  364. });
  365. },
  366. handleProList(list) {
  367. let projectList = [];
  368. if (list.length == 0) {
  369. let arr = [
  370. {
  371. id: 2,
  372. name: "教培中心",
  373. img: "project3",
  374. },
  375. {
  376. id: 3,
  377. name: "教研中心",
  378. img: "project6",
  379. },
  380. {
  381. id: 5,
  382. name: "学习中心",
  383. img: "project4",
  384. },
  385. {
  386. id: 6,
  387. name: "个人中心",
  388. img: "project7",
  389. },
  390. ];
  391. projectList = arr;
  392. } else if (list.includes(2000001)) {
  393. projectList = JSON.parse(JSON.stringify(this.teacherProList));
  394. for (let i = 0; i < list.length; i++) {
  395. let code = list[i];
  396. if (code == 2000003) {
  397. projectList.push({
  398. id: 1,
  399. name: "教材管理系统",
  400. img: "project2",
  401. });
  402. }
  403. if (code == 2000005) {
  404. projectList.push({
  405. id: 4,
  406. name: "考试中心",
  407. img: "project5",
  408. });
  409. }
  410. }
  411. } else {
  412. for (let i = 0; i < list.length; i++) {
  413. let code = list[i];
  414. if (code == 2000002) {
  415. projectList.push({
  416. id: 0,
  417. name: "教学管理系统",
  418. img: "project1",
  419. });
  420. } else if (code == 2000003) {
  421. projectList.push({
  422. id: 1,
  423. name: "教材管理系统",
  424. img: "project2",
  425. });
  426. } else if (code == 2000004) {
  427. projectList.push({
  428. id: 2,
  429. name: "教师培训中心",
  430. img: "project3",
  431. });
  432. } else if (code == 2000005) {
  433. projectList.push({
  434. id: 4,
  435. name: "考试中心",
  436. img: "project5",
  437. });
  438. } else if (code == 2000006) {
  439. projectList.push({
  440. id: 3,
  441. name: "教研中心",
  442. img: "project4",
  443. });
  444. }
  445. }
  446. projectList.push({
  447. id: 6,
  448. // Teacher training center
  449. name: "个人中心",
  450. img: "project7",
  451. text: "您收集和购买的所有资源都可以在这里轻松找到。",
  452. });
  453. }
  454. // 排序
  455. for (var i = 0; i < projectList.length - 1; i++) {
  456. for (var j = 0; j < projectList.length - 1 - i; j++) {
  457. // 相邻元素两两对比,元素交换,大的元素交换到后面
  458. if (projectList[j].id > projectList[j + 1].id) {
  459. var temp = projectList[j];
  460. projectList[j] = projectList[j + 1];
  461. projectList[j + 1] = temp;
  462. }
  463. }
  464. }
  465. this.projectName = projectList[0].name;
  466. return projectList;
  467. },
  468. },
  469. created() {
  470. let _this = this;
  471. if (this.FatheruserMessage) {
  472. _this.userMessage = this.FatheruserMessage;
  473. } else {
  474. _this.userMessage = null;
  475. }
  476. // let user = Cookies.get("userMessage");
  477. // if (user) {
  478. // _this.userMessage = JSON.parse(user);
  479. // let popedom_code_list = _this.userMessage.popedom_code_list;
  480. // if (_this.userMessage.user_type == "TEACHER") {
  481. // _this.projectList = _this.handleProList(popedom_code_list);
  482. // } else if (_this.userMessage.user_type == "STUDENT") {
  483. // _this.projectList = _this.stuProList;
  484. // }
  485. // _this.projectList.forEach((item, index) => {
  486. // if (item.id == 0) {
  487. // _this.LoginNavIndex = index;
  488. // }
  489. // });
  490. // } else {
  491. // _this.userMessage = null;
  492. // this.projectName = this.projectList[0].name;
  493. // }
  494. this.projectName = this.projectList[0].name;
  495. _this.getLangList();
  496. },
  497. };
  498. </script>
  499. <style lang="scss" scoped>
  500. .LoginNav {
  501. height: 65px;
  502. position: relative;
  503. display: flex;
  504. align-items: center;
  505. justify-content: space-between;
  506. padding: 0 60px 0 40px;
  507. z-index: 999;
  508. font-family: "sourceR";
  509. .logo {
  510. display: flex;
  511. align-items: center;
  512. .el-menu-demo {
  513. background: rgba(0, 0, 0, 0);
  514. // margin-left: 100px;
  515. li:hover {
  516. background: none;
  517. }
  518. li {
  519. background: none;
  520. }
  521. }
  522. .dropdownIcon{
  523. margin-left: 8px;
  524. width: 8px;
  525. height: 4px;
  526. }
  527. // 取消组件默认的样式
  528. .el-menu.el-menu--horizontal {
  529. border-bottom: none;
  530. }
  531. }
  532. .userName {
  533. display: flex;
  534. align-items: center;
  535. .seek {
  536. margin-right: 100px;
  537. position: relative;
  538. img {
  539. left: 10px;
  540. top: 11px;
  541. position: absolute;
  542. }
  543. }
  544. .flag {
  545. position: relative;
  546. top: 5px;
  547. }
  548. .headPhoto {
  549. width: 50px;
  550. height: 50px;
  551. // background: url("../assets/teacherTrain/image 4.png") no-repeat 100% 100%;
  552. // background-size: 100%;
  553. border-radius: 50%;
  554. // margin-right: 10px;
  555. }
  556. .message {
  557. position: relative;
  558. margin-left: 16px;
  559. img {
  560. width: 32px;
  561. height: 32px;
  562. cursor: pointer;
  563. }
  564. .redDot {
  565. width: 6px;
  566. height: 6px;
  567. position: absolute;
  568. display: inline-block;
  569. background: red;
  570. border-radius: 50%;
  571. right: 0;
  572. }
  573. }
  574. .selectLoginOrRegistration {
  575. display: flex;
  576. width: 161px;
  577. height: 32px;
  578. border: 1px solid #ffffff;
  579. box-sizing: border-box;
  580. border-radius: 4px;
  581. // justify-content: space-evenly;
  582. align-items: center;
  583. span {
  584. margin-left: 23px;
  585. }
  586. > :first-child {
  587. cursor: pointer;
  588. }
  589. > :last-child {
  590. cursor: pointer;
  591. }
  592. }
  593. .user {
  594. display: flex;
  595. align-items: center;
  596. cursor: pointer;
  597. position: relative;
  598. > img {
  599. width: 34px;
  600. height: 34px;
  601. }
  602. > span {
  603. padding-left: 10px;
  604. }
  605. .userShow {
  606. position: absolute;
  607. width: 156px;
  608. height: 96px;
  609. background: #ffffff;
  610. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  611. border-radius: 8px;
  612. bottom: -100px;
  613. left: 0;
  614. color: black;
  615. img {
  616. width: 24px;
  617. height: 24px;
  618. margin-right: 10px;
  619. }
  620. p {
  621. height: 40px;
  622. display: flex;
  623. align-items: center;
  624. padding-left: 20px;
  625. margin: 0;
  626. margin-top: 5px;
  627. }
  628. > p:hover {
  629. background: #f2f2f2;
  630. }
  631. }
  632. }
  633. }
  634. }
  635. </style>
  636. <style lang="scss">
  637. .downsele {
  638. background: #ff9900;
  639. }
  640. .LoginNav {
  641. .el-menu-item {
  642. font-size: 16px;
  643. }
  644. .is-active{
  645. font-weight: bold;
  646. }
  647. .el-menu-item i {
  648. color: white;
  649. }
  650. }
  651. </style>