Skip to content

Commit a08e539

Browse files
committed
get userinfo
1 parent 3c7f0b7 commit a08e539

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

src/App.vue

+26-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<img src="/blogv.png" style="width: 60px;" />
88
</a>
99
<div class="header-container-userinfo">
10-
<template v-if="!user.isAuthenticated">
10+
<template v-if="!sysUserName">
1111
<a
1212
@click="login"
1313
class="header-container-userinfo-login header-container-user-btn header-container-in header-container-user-size"
@@ -27,7 +27,10 @@
2727
</a>
2828
</template>
2929
<template v-else>
30-
<a href="https://ids.neters.club/" class="header-container-banner-item-btn">{{ user.name }}</a>
30+
<a
31+
href="https://ids.neters.club/"
32+
class="header-container-banner-item-btn"
33+
>{{ sysUserName }}</a>
3134
<a
3235
href="/Editor"
3336
class="header-container-user-btn header-container-hv header-container-user-size _1YbC5u"
@@ -40,7 +43,7 @@
4043
</template>
4144
</div>
4245
<div class="header-container-banner">
43-
<div class="">
46+
<div class>
4447
<div class="header-container-banner-item">
4548
<a class="header-container-banner-item-btn" href="/">首页</a>
4649
<a
@@ -54,9 +57,7 @@
5457
</div>
5558
</div>
5659
</header>
57-
<div id="nav">
58-
59-
</div>
60+
<div id="nav"></div>
6061
<router-view />
6162
</div>
6263
</template>
@@ -69,7 +70,15 @@ export default {
6970
name: "app",
7071
mixins: [userAuth],
7172
data: function() {
72-
return {};
73+
return {
74+
sysUserName: ""
75+
};
76+
},
77+
updated() {
78+
this.sysUserName = window.localStorage.getItem("USER_NAME") || "";
79+
},
80+
created() {
81+
this.sysUserName = window.localStorage.getItem("USER_NAME") || "";
7382
},
7483
watch: {
7584
$route: async function(to, from) {
@@ -88,6 +97,7 @@ export default {
8897
},
8998
async logout() {
9099
try {
100+
window.localStorage.removeItem("USER_NAME");
91101
await applicationUserManager.logout();
92102
this.$store.commit("saveToken", "");
93103
} catch (error) {
@@ -262,12 +272,14 @@ a {
262272
padding: 0 20px;
263273
cursor: pointer;
264274
}
265-
.header-container-logout{
266-
color: #007bff;
267-
margin-left: 10px;
268-
border: 1px solid transparent;
269-
padding: .375rem .75rem;
270-
border-radius: .25rem;
271-
border-color: #007bff;
275+
276+
.header-container-logout {
277+
cursor: pointer;
278+
color: #007bff;
279+
margin-left: 10px;
280+
border: 1px solid transparent;
281+
padding: 0.375rem 0.75rem;
282+
border-radius: 0.25rem;
283+
border-color: #007bff;
272284
}
273285
</style>

src/Auth/UserAuth.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const userAuth = {
1414
if (user) {
1515
this.user.name = user.profile.name;
1616
this.user.isAuthenticated = true;
17+
window.localStorage.setItem("USER_NAME", this.user.name);
1718
} else {
1819
this.user.name = "";
1920
this.user.isAuthenticated = false;

src/api/http.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ axios.interceptors.response.use(
5757
case 401:
5858
// 返回 401 清除token信息并跳转到登录页面
5959
store.commit("saveToken", "");
60-
60+
window.localStorage.removeItem("USER_NAME");
6161
applicationUserManager.login();
6262
// router.replace({
6363
// path: "/login",

src/views/LoginCallbackView.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export default {
2222
try {
2323
await applicationUserManager.signinRedirectCallback()
2424
let user = await applicationUserManager.getUser()
25-
console.log(user)
2625
this.$store.commit("saveToken", user.access_token);
26+
window.localStorage.setItem("USER_NAME", user.profile.name);
2727
this.$router.push({name: 'home'})
2828
} catch (e) {
2929
console.log(e)

0 commit comments

Comments
 (0)