LoginNav.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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" v-if="projectListArr.length > 0">
  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
  24. class="dropdownIcon"
  25. src="../../assets/login/dropdownIcon.png"
  26. alt=""
  27. />
  28. </span>
  29. <el-dropdown-menu slot="dropdown" style="width: 300px">
  30. <el-dropdown-item
  31. v-for="(item, i) in projectListArr"
  32. :key="i"
  33. :command="i"
  34. :class="projectDownIndex == i ? 'downsele' : ''"
  35. >
  36. <img
  37. style="position: relative; top: 5px; width: 24px"
  38. :src="item.icon_url_memu_default"
  39. alt=""
  40. />
  41. <span style="margin-left: 16px">
  42. {{ item.name }}
  43. </span>
  44. </el-dropdown-item>
  45. </el-dropdown-menu>
  46. </el-dropdown>
  47. </el-menu-item>
  48. </el-menu>
  49. </div>
  50. <div class="userName">
  51. <el-dropdown
  52. v-if="userMessage"
  53. style="margin-right: 16px"
  54. trigger="click"
  55. @command="changeLang"
  56. >
  57. <span class="el-dropdown-link" style="color: #fff; cursor: pointer">
  58. {{ lang ? lang : "中文"
  59. }}<i class="el-icon-arrow-down el-icon--right"></i>
  60. </span>
  61. <el-dropdown-menu slot="dropdown" style="width: 200px">
  62. <el-dropdown-item
  63. v-for="item in language_list"
  64. :key="item.language_type"
  65. :command="item"
  66. >{{ item.language_name }}</el-dropdown-item
  67. >
  68. </el-dropdown-menu>
  69. </el-dropdown>
  70. <div v-if="!userMessage" class="selectLoginOrRegistration">
  71. <span @click="cutLoginReg('login')">登录</span>
  72. <span> | </span>
  73. <span @click="cutLoginReg('signin')">注册</span>
  74. </div>
  75. <!-- 用户头像和用户名 -->
  76. <div class="user" v-else>
  77. <img
  78. @click="userShow = !userShow"
  79. class="headPhoto"
  80. :src="
  81. userMessage.image_url
  82. ? userMessage.image_url
  83. : require('../../assets/login/Group3214.png')
  84. "
  85. alt=""
  86. />
  87. <span @click="userShow = !userShow">{{
  88. userMessage.user_real_name
  89. }}</span>
  90. <div class="userShow" v-show="userShow">
  91. <p @click="gotoPersonalcenter">
  92. <img src="../../assets/login/project7.png" alt="" />
  93. 个人中心
  94. </p>
  95. <p @click="QuitLogin">
  96. <img src="../../assets/login/Frame77.png" alt="" />
  97. 退出登录
  98. </p>
  99. </div>
  100. </div>
  101. <!-- 消息 铃铛图片 -->
  102. <div class="message">
  103. <img
  104. @click="gotoPersonalcenter"
  105. src="../../assets/login/Vector2.png"
  106. alt=""
  107. />
  108. </div>
  109. </div>
  110. </div>
  111. </template>
  112. <script>
  113. import Cookies from "js-cookie";
  114. import { getStaticContent, getContent } from "@/api/api";
  115. import { setI18nLang } from "@/utils/i18n";
  116. import { getToken, removeToken } from "@/utils/auth";
  117. export default {
  118. props: ["type", "changeLoginReg", "FatheruserMessage", "projectList"],
  119. data() {
  120. return {
  121. activeIndex: "1",
  122. LoginNavIndex: "1",
  123. projectName: "",
  124. userMessage: null,
  125. userShow: false,
  126. projectDownIndex: 0,
  127. language_list: [],
  128. lang: "",
  129. projectListArr: [],
  130. };
  131. },
  132. watch: {
  133. FatheruserMessage(newval, oldval) {
  134. this.userMessage = null;
  135. this.userMessage = newval;
  136. },
  137. projectList: {
  138. handler: function (val, oldVal) {
  139. if (val.length > 0) {
  140. this.projectListArr = val;
  141. this.projectName = val[0].name;
  142. }
  143. },
  144. // 深度观察监听
  145. deep: true,
  146. },
  147. },
  148. methods: {
  149. // 切换导航
  150. handleSelect(key, keyPath) {
  151. this.LoginNavIndex = key;
  152. if (this.LoginNavIndex == "1") {
  153. this.$router.push("/");
  154. } else {
  155. let ulobj = document.getElementsByClassName("el-dropdown-menu")[0];
  156. ulobj.classList.add("LoginNavSeleProject");
  157. }
  158. },
  159. // 切换项目
  160. handleCommand(command) {
  161. let _this = this;
  162. _this.LoginNavIndex = "2";
  163. let userInfor = getToken();
  164. let user_code = "",
  165. user_type = "",
  166. session_id = "";
  167. if (userInfor) {
  168. userInfor = JSON.parse(getToken());
  169. user_code = userInfor.user_code;
  170. user_type = userInfor.user_type;
  171. session_id = userInfor.session_id;
  172. }
  173. if (!session_id || !user_code || !user_type || !_this.userMessage) {
  174. this.$message.warning("请先登录");
  175. this.projectName = "教学中心";
  176. return;
  177. }
  178. _this.projectDownIndex = command;
  179. let relative_path = _this.projectList[command].relative_path;
  180. location.href = relative_path;
  181. },
  182. // 切换语言
  183. async changeLang(command) {
  184. this.lang = command.language_name;
  185. let lang_type = command.language_type;
  186. console.log(lang_type);
  187. await setI18nLang(lang_type);
  188. this.$router.go(0);
  189. },
  190. // 切换登录的注册
  191. cutLoginReg(value) {
  192. this.changeLoginReg(value);
  193. },
  194. // 前往个人中心
  195. gotoPersonalcenter() {
  196. let userInfor = getToken();
  197. let user_code = "",
  198. user_type = "",
  199. session_id = "";
  200. if (userInfor) {
  201. userInfor = JSON.parse(getToken());
  202. user_code = userInfor.user_code;
  203. user_type = userInfor.user_type;
  204. session_id = userInfor.session_id;
  205. }
  206. if (!session_id) {
  207. this.$message.warning("请先登录");
  208. return;
  209. }
  210. let MethodName = "login_control-CreateAccessCode";
  211. let acsCode = "";
  212. getContent(MethodName, user_code, user_type, session_id).then((res) => {
  213. acsCode = res.access_code;
  214. location.href = `/GCLS-Personal/#/EnterSys?AccessCode=${acsCode}`;
  215. });
  216. },
  217. QuitLogin() {
  218. Cookies.remove("userMessage");
  219. Cookies.remove("session_id");
  220. Cookies.remove("user_code");
  221. Cookies.remove("user_type");
  222. removeToken();
  223. this.userShow = false;
  224. this.userMessage = null;
  225. this.changeLoginReg("login", null);
  226. },
  227. getLangList() {
  228. let MethodName = "language_manager-GetLanguageList";
  229. let data = {};
  230. getStaticContent(MethodName, data).then((res) => {
  231. this.language_list = res.language_list;
  232. for (let i = 0; i < this.language_list.length; i++) {
  233. let item = this.language_list[i];
  234. if (item.language_type == this.language_type) {
  235. this.lang = item.language_name;
  236. break;
  237. }
  238. }
  239. });
  240. },
  241. },
  242. created() {
  243. let _this = this;
  244. if (this.FatheruserMessage) {
  245. _this.userMessage = this.FatheruserMessage;
  246. } else {
  247. _this.userMessage = null;
  248. }
  249. _this.getLangList();
  250. },
  251. mounted() {
  252. // this.projectName =
  253. // this.projectList.length > 0 ? this.projectList[0].name : "";
  254. },
  255. };
  256. </script>
  257. <style lang="scss" scoped>
  258. .LoginNav {
  259. height: 64px;
  260. position: relative;
  261. display: flex;
  262. align-items: center;
  263. justify-content: space-between;
  264. padding: 0 60px 0 40px;
  265. z-index: 999;
  266. font-family: "sourceR";
  267. .logo {
  268. display: flex;
  269. align-items: center;
  270. .el-menu-demo {
  271. background: rgba(0, 0, 0, 0);
  272. // margin-left: 100px;
  273. li:hover {
  274. background: none;
  275. }
  276. li {
  277. background: none;
  278. }
  279. }
  280. .dropdownIcon {
  281. margin-left: 8px;
  282. width: 8px;
  283. height: 4px;
  284. }
  285. // 取消组件默认的样式
  286. .el-menu.el-menu--horizontal {
  287. border-bottom: none;
  288. }
  289. }
  290. .userName {
  291. display: flex;
  292. align-items: center;
  293. .seek {
  294. margin-right: 100px;
  295. position: relative;
  296. img {
  297. left: 10px;
  298. top: 11px;
  299. position: absolute;
  300. }
  301. }
  302. .flag {
  303. position: relative;
  304. top: 5px;
  305. }
  306. .headPhoto {
  307. width: 50px;
  308. height: 50px;
  309. // background: url("../assets/teacherTrain/image 4.png") no-repeat 100% 100%;
  310. // background-size: 100%;
  311. border-radius: 50%;
  312. // margin-right: 10px;
  313. }
  314. .message {
  315. position: relative;
  316. margin-left: 16px;
  317. img {
  318. width: 32px;
  319. height: 32px;
  320. cursor: pointer;
  321. }
  322. .redDot {
  323. width: 6px;
  324. height: 6px;
  325. position: absolute;
  326. display: inline-block;
  327. background: red;
  328. border-radius: 50%;
  329. right: 0;
  330. }
  331. }
  332. .selectLoginOrRegistration {
  333. display: flex;
  334. width: 161px;
  335. height: 32px;
  336. border: 1px solid #ffffff;
  337. box-sizing: border-box;
  338. border-radius: 4px;
  339. // justify-content: space-evenly;
  340. align-items: center;
  341. span {
  342. margin-left: 23px;
  343. }
  344. > :first-child {
  345. cursor: pointer;
  346. }
  347. > :last-child {
  348. cursor: pointer;
  349. }
  350. }
  351. .user {
  352. display: flex;
  353. align-items: center;
  354. cursor: pointer;
  355. position: relative;
  356. > img {
  357. width: 34px;
  358. height: 34px;
  359. }
  360. > span {
  361. padding-left: 10px;
  362. }
  363. .userShow {
  364. position: absolute;
  365. width: 156px;
  366. height: 96px;
  367. background: #ffffff;
  368. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  369. border-radius: 8px;
  370. bottom: -100px;
  371. left: 0;
  372. color: black;
  373. img {
  374. width: 24px;
  375. height: 24px;
  376. margin-right: 10px;
  377. }
  378. p {
  379. height: 40px;
  380. display: flex;
  381. align-items: center;
  382. padding-left: 20px;
  383. margin: 0;
  384. margin-top: 5px;
  385. }
  386. > p:hover {
  387. background: #f2f2f2;
  388. }
  389. }
  390. }
  391. }
  392. }
  393. </style>
  394. <style lang="scss">
  395. .downsele {
  396. background: #ff9900;
  397. }
  398. .LoginNav {
  399. .el-menu--horizontal > .el-menu-item {
  400. height: 64px;
  401. }
  402. .el-menu-item {
  403. font-size: 16px;
  404. }
  405. .is-active {
  406. font-weight: bold;
  407. line-height: 64px;
  408. }
  409. .el-menu-item i {
  410. color: white;
  411. }
  412. .el-dropdown {
  413. font-size: 16px;
  414. }
  415. }
  416. </style>