App.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div id="app">
  3. <div class="head">
  4. <div class="logo">
  5. <img
  6. style="height: 40px; margin-top: 10px"
  7. class="left nav-icon"
  8. src="https://x.cocorobo.cn/icons/logo.png"
  9. @click="goto()"
  10. />
  11. <!-- <span
  12. style="
  13. font-size: 28px;
  14. font-family: 'GT Walsheim Pro Trial Bold';
  15. font-weight: bold;
  16. color: #fff;
  17. "
  18. >CocoBlockly</span
  19. > -->
  20. </div>
  21. <div class="user_head" v-if="this.$store.state.userId">
  22. <span class="user_name">{{ this.$store.state.userName }}</span>
  23. <div>
  24. <i></i>
  25. <el-button type="text" style="color: white" @click="logout"
  26. >退出</el-button
  27. >
  28. </div>
  29. </div>
  30. </div>
  31. <div style="background: #e5e5e5; height: calc(100% - 88.5px); width: 100%">
  32. <!-- main 内容 -->
  33. <keep-alive v-if="$route.meta.keepAlive">
  34. <!-- 这里是会被缓存的视图组件 -->
  35. <router-view v-if="$route.meta.keepAlive" />
  36. </keep-alive>
  37. <!-- 这里是不被缓存的视图组件 -->
  38. <router-view v-if="!$route.meta.keepAlive" />
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. export default {
  44. name: "App",
  45. created() {
  46. //在页面加载时读取sessionStorage里的状态信息
  47. if (sessionStorage.getItem("store")) {
  48. this.$store.replaceState(
  49. Object.assign(
  50. {},
  51. this.$store.state,
  52. JSON.parse(sessionStorage.getItem("store"))
  53. )
  54. );
  55. }
  56. //在页面刷新时将vuex里的信息保存到sessionStorage里
  57. window.addEventListener("beforeunload", () => {
  58. sessionStorage.setItem("store", JSON.stringify(this.$store.state));
  59. });
  60. this.login();
  61. },
  62. methods: {
  63. goto() {
  64. this.$router.push("/");
  65. },
  66. login() {
  67. //debugger;
  68. // console.log("1");
  69. var _this = this;
  70. _this.ajax
  71. .get(`${_this.$store.state.server}getcookieuserid`)
  72. .then((res) => {
  73. var userid = res.data[0][0].userid;
  74. // var userid = "4be5e344-ce1a-11e9-a839-028edca3b798";
  75. _this.$store.commit("update", ["userId", userid]);
  76. _this.ajax
  77. .get(
  78. `${_this.$store.state.edu}admin/userinfo/userinfoById/${userid}/`
  79. )
  80. .then((r) => {
  81. let data = r.data[0][0];
  82. console.log(data);
  83. _this.$store.commit("update", [
  84. "userName",
  85. data.alias || data.username,
  86. ]);
  87. });
  88. })
  89. .catch((err) => {
  90. // _this.props.history.push("/login");
  91. // window.alert(err.response.data)
  92. // window.location.href = "https://edu.cocorobo.cn/course/login?type=1";
  93. });
  94. },
  95. logout() {
  96. this.ajax
  97. .post(`${this.$store.state.server}logout`)
  98. .then((res) => {
  99. if (res.data) {
  100. window.location.href =
  101. "https://edu.cocorobo.cn/course/login?type=1";
  102. }
  103. })
  104. .catch((err) => {});
  105. },
  106. },
  107. };
  108. </script>
  109. <style>
  110. * {
  111. margin: 0;
  112. padding: 0;
  113. }
  114. body {
  115. font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
  116. "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  117. }
  118. #app {
  119. height: 100%;
  120. width: 100%;
  121. /* background: #e6eaf0; */
  122. /* min-width: 1380px; */
  123. /* background: #fff; */
  124. background: #e5e5e5;
  125. min-width: 1000px;
  126. }
  127. .head {
  128. height: 67.5px;
  129. width: 100%;
  130. background-color: #2c4fcd;
  131. display: flex;
  132. align-items: center;
  133. min-width: 1000px;
  134. }
  135. .logo {
  136. margin-left: 20px;
  137. cursor: pointer;
  138. }
  139. .user_head {
  140. display: flex;
  141. align-items: center;
  142. margin-left: auto;
  143. margin-right: 20px;
  144. font-size: 18px;
  145. font-weight: 600;
  146. }
  147. .user_head .user_name {
  148. color: #fff;
  149. margin-right: 10px;
  150. }
  151. .user_head div {
  152. display: flex;
  153. align-items: center;
  154. cursor: pointer;
  155. }
  156. .user_head i {
  157. background-image: url("./assets/exit.png");
  158. width: 25px;
  159. height: 25px;
  160. background-size: 100% 100%;
  161. margin-top: 1px;
  162. line-height: 25px;
  163. vertical-align: text-top;
  164. background-repeat: no-repeat;
  165. }
  166. </style>