lsc 3 年之前
父节点
当前提交
38a8d05f97
共有 4 个文件被更改,包括 85 次插入12 次删除
  1. 71 10
      src/App.vue
  2. 二进制
      src/assets/exit.png
  3. 2 0
      src/config/config.js
  4. 12 2
      src/main.js

+ 71 - 10
src/App.vue

@@ -18,6 +18,15 @@
           >CocoBlockly</span
         > -->
       </div>
+      <div class="user_head" v-if="this.$store.state.userId">
+        <span class="user_name">{{ this.$store.state.userName }}</span>
+        <div>
+          <i></i>
+          <el-button type="text" style="color: white" @click="logout"
+            >退出</el-button
+          >
+        </div>
+      </div>
     </div>
 
     <div style="background: #fff; height: calc(100% - 67.5px); width: 100%">
@@ -59,24 +68,49 @@ export default {
     },
     login() {
       //debugger;
-      console.log("1");
+      // console.log("1");
       var _this = this;
-      this.ajax
-        .get(`${this.$store.state.server}getcookieuserid`)
+      _this.ajax
+        .get(`${_this.$store.state.server}getcookieuserid`)
         .then((res) => {
-          _this.$store.commit("update", ["userId", res.data[0][0].userid]);
-          // if (res.data[0][0]) {
-          //   _this.setState({
-          //     userId: res.data[0][0].userid,
-          //   });
-          // }
+          var userid = res.data[0][0].userid;
+          var userid = "4be5e344-ce1a-11e9-a839-028edca3b798";
+          _this.$store.commit("update", ["userId", userid]);
+          _this.ajax
+            .get(
+              `${_this.$store.state.edu}admin/userinfo/userinfoById/${userid}/`
+            )
+            .then((r) => {
+              let data = r.data[0][0];
+              console.log(data);
+              _this.$store.commit("update", [
+                "userName",
+                data.alias || data.username,
+              ]);
+            });
+          if (res.data[0][0]) {
+            _this.setState({
+              userId: res.data[0][0].userid,
+            });
+          }
         })
         .catch((err) => {
           // _this.props.history.push("/login");
           // window.alert(err.response.data)
-          window.location.href="https://edu.cocorobo.cn/course/login?type=1";
+          window.location.href = "https://edu.cocorobo.cn/course/login?type=1";
         });
     },
+    logout() {
+      this.ajax
+        .post(`${this.$store.state.server}logout`)
+        .then((res) => {
+          if (res.data) {
+            window.location.href =
+              "https://edu.cocorobo.cn/course/login?type=1";
+          }
+        })
+        .catch((err) => {});
+    },
   },
 };
 </script>
@@ -110,4 +144,31 @@ body {
   margin-left: 20px;
   cursor: pointer;
 }
+.user_head {
+  display: flex;
+  align-items: center;
+  margin-left: auto;
+  margin-right: 20px;
+  font-size: 18px;
+  font-weight: 600;
+}
+.user_head .user_name {
+  color: #fff;
+  margin-right: 10px;
+}
+.user_head div {
+  display: flex;
+  align-items: center;
+  cursor: pointer;
+}
+.user_head i {
+  background-image: url("./assets/exit.png");
+  width: 25px;
+  height: 25px;
+  background-size: 100% 100%;
+  margin-top: 1px;
+  line-height: 25px;
+  vertical-align: text-top;
+  background-repeat: no-repeat;
+}
 </style>

二进制
src/assets/exit.png


+ 2 - 0
src/config/config.js

@@ -9,7 +9,9 @@ const store = new Vuex.Store({
         api: '',
         function:'',
         userId:'',
+        userName:'',
         server: 'https://beta.api.cocorobo.cn/api/',
+        edu: 'https://api.edu.cocorobo.cn/edu/',
         // server: 'http://localhost:8083/api/',
     },
 

+ 12 - 2
src/main.js

@@ -27,10 +27,20 @@ router.beforeEach((to, from, next) => {
   ajax
     .get(`${store.state.server}getcookieuserid`)
     .then((res) => {
-      store.commit("update", ["userId", res.data[0][0].userid]);
+      var userid = res.data[0][0].userid
+      store.commit("update", ["userId", userid]);
+      ajax
+        .get(
+          `${store.state.edu}admin/userinfo/userinfoById/${userid}/`
+        )
+        .then((r) => {
+          let data = r.data[0][0];
+          console.log(data);
+          store.commit("update", ["userName", data.alias || data.username]);
+        });
     })
     .catch((err) => {
-      //window.location.href = "https://edu.cocorobo.cn/course/login?type=1";
+      window.location.href = "https://edu.cocorobo.cn/course/login?type=1";
     });
   next();
 })