diff --git a/UI2.0/src/js/login.js b/UI2.0/src/js/login.js index 601660e832c8447867c4e8356a17f642f745f252..a27cbdff60eaad6825e482e6447b23675be81866 100644 --- a/UI2.0/src/js/login.js +++ b/UI2.0/src/js/login.js @@ -27,6 +27,7 @@ export default defineComponent({ name: res.user_name, userId: res.user_id, }) + localStorage.setItem("token", res.token) this.$router.push({ path: "/user", }); diff --git a/UI2.0/src/js/loginlayout.js b/UI2.0/src/js/loginlayout.js index 5c729bb3868832c53e778b284b4bbc4c11998303..d12c95bc95864d6a8a0048d40f1b7ffcf3920877 100644 --- a/UI2.0/src/js/loginlayout.js +++ b/UI2.0/src/js/loginlayout.js @@ -1,16 +1,33 @@ import { defineComponent, ref } from "vue"; +import axios from "./utils/AxiosConfig"; export default defineComponent({ name: "LoginLayout", components: {}, methods: { - onItemClick() { - }, onMainClick() { this.$router.push({ path: "/", }); }, + verifyToken() { + if(this.$store.state.User.userInfo.userId == 0 || !localStorage.getItem("token")){ + return + } + axios("/v1/UI/user/userVerify", { + userId: this.$store.state.User.userInfo.userId + },"get").then(res => { + res = JSON.parse(res) + if(res.vaild) { + this.$router.push({ + path: "/user" + }) + } + }) + }, + }, + mounted() { + this.verifyToken() }, setup() { }, }); \ No newline at end of file diff --git a/UI2.0/src/js/mainlayout.js b/UI2.0/src/js/mainlayout.js index 1b7860b56ac1cf9223d7321ac50396b6a4822005..b6d7f341e600e284a1596b6a0df1f70ccc52b244 100644 --- a/UI2.0/src/js/mainlayout.js +++ b/UI2.0/src/js/mainlayout.js @@ -2,6 +2,7 @@ import EssentialLink from "components/EssentialLink.vue"; import { defineComponent, ref } from "vue"; import axios from "./utils/AxiosConfig"; + const linksList = [ { title: "Docs", @@ -22,6 +23,7 @@ export default defineComponent({ }, mounted() { this.connectDatabase() + this.verifyToken() }, methods: { onItemClick() { @@ -62,6 +64,22 @@ export default defineComponent({ }).catch(err => { console.log(err) }) + }, + verifyToken() { + if(this.$store.state.User.userInfo.userId == 0 || !localStorage.getItem("token")){ + return + } + axios("/v1/UI/user/userVerify", { + userId: this.$store.state.User.userInfo.userId + },"get").then(res => { + res = JSON.parse(res) + console.log(res) + if(res.vaild) { + this.$router.push({ + path: "/user" + }) + } + }) } }, setup() { diff --git a/UI2.0/src/js/userlayout.js b/UI2.0/src/js/userlayout.js index 68367248823f5d40261692ba6795e3e4ccfa13aa..060fa10442eead8bcba5679c9f471f094d69cb42 100644 --- a/UI2.0/src/js/userlayout.js +++ b/UI2.0/src/js/userlayout.js @@ -1,4 +1,5 @@ import { defineComponent, ref } from "vue"; +import axios from "./utils/AxiosConfig"; export default defineComponent({ name: "MainLayout", @@ -6,10 +7,8 @@ export default defineComponent({ components: {}, methods: { - onItemClick() { - console.log("Clicked."); - }, onMainClick() { + localStorage.clear() this.$router.push({ path: "/", }); @@ -44,11 +43,6 @@ export default defineComponent({ path: "/user", }); }, - onLoginClick() { - this.$router.push({ - path: "/login", - }); - }, onPersonalClick() { this.$router.push({ path: "/personal", @@ -57,9 +51,29 @@ export default defineComponent({ showSearchInput() { document.getElementById("search-input").style.display = "block"; }, + verifyToken() { + if(this.$store.state.User.userInfo.userId == 0 || !localStorage.getItem("token")){ + this.$router.push({ + path: "/" + }) + return + } + axios("/v1/UI/user/userVerify", { + userId: this.$store.state.User.userInfo.userId + },"get").then(res => { + res = JSON.parse(res) + console.log(res) + if(!res.vaild) { + this.$router.push({ + path: "/" + }) + } + }) + }, }, mounted() { this.$store.dispatch("getUserInfoFromBackend") + this.verifyToken() }, setup() { return { diff --git a/UI2.0/src/js/utils/AxiosConfig.js b/UI2.0/src/js/utils/AxiosConfig.js index 55e64c96941f238b8ff2177999cb91efb9a93bb9..b68c2d13824deb782d8992f70fff6d6e4f66e675 100644 --- a/UI2.0/src/js/utils/AxiosConfig.js +++ b/UI2.0/src/js/utils/AxiosConfig.js @@ -9,7 +9,7 @@ axios.defaults.timeout = 10000; axios.interceptors.request.use( config => { - const token = sessionStorage.getItem("access_token"); + const token = localStorage.getItem("token"); config.headers.authorization = token; return config; }, diff --git a/UI2.0/src/layouts/UserLayout.vue b/UI2.0/src/layouts/UserLayout.vue index 7297988a75a62726b95f9409fb13be6a19de15ec..1b301de7977d2b67c2aab15df716f43db9304161 100644 --- a/UI2.0/src/layouts/UserLayout.vue +++ b/UI2.0/src/layouts/UserLayout.vue @@ -59,18 +59,17 @@ dropdown-icon="expand_more" > - + 个人中心 - + - 退出登录 diff --git a/UI2.0/src/pages/Personal.vue b/UI2.0/src/pages/Personal.vue index 7070670e23a07d0ebff06a795f9facca7a98d057..2989ffc9196b5b46ecb4a2f87e459ae82212a748 100644 --- a/UI2.0/src/pages/Personal.vue +++ b/UI2.0/src/pages/Personal.vue @@ -197,7 +197,7 @@