修改登录添加头像

This commit is contained in:
熊丽君
2021-08-03 14:35:04 +08:00
parent 3410256837
commit 3d0e882d1b
4 changed files with 57 additions and 34 deletions

View File

@ -10,34 +10,36 @@ const whiteList = ['/login', '/auth-redirect', '/bind', '/register'];
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start(); NProgress.start();
if (getToken()) { if (getToken()) {
// if (to.path === '/login') { if (to.path === '/login') {
// next({ path: '/' }); next({ path: '/' });
// NProgress.done(); // if current page is dashboard will not trigger afterEach hook, so manually handle it NProgress.done(); // if current page is dashboard will not trigger afterEach hook, so manually handle it
// } else { } else {
// if (store.getters.roles.length === 0) { if (store.getters.roles.length === 0) {
// store store
// .dispatch('GetInfo') .dispatch('GetInfo')
// .then(res => { .then(res => {
// // 拉取用户信息 // 拉取用户信息
// let menus = res.data.menus; let menus = res.data.menus;
// let username = res.data.username; let username = res.data.username;
// store.dispatch('GenerateRoutes', { menus, username }).then(() => { next({ ...to, replace: true });
// // 生成可访问的路由表 // store.dispatch('GenerateRoutes', { menus, username }).then(() => {
// router.addRoutes(store.getters.addRoutes); // 动态添加可访问路由表 // // 生成可访问路由表
// next({ ...to, replace: true }); // router.addRoutes(store.getters.addRoutes); // 动态添加可访问路由表
// }); // next({ ...to, replace: true });
// }) // });
// .catch(err => { })
// store.dispatch('FedLogOut').then(() => { .catch(err => {
// Message.error(err || 'Verification failed, please login again'); store.dispatch('FedLogOut').then(() => {
// next({ path: '/' }); Message.error(err || 'Verification failed, please login again');
// }); next({ path: '/' });
// }); });
// } else { });
// next(); } else {
// } next();
// } }
}
} else { } else {
console.log('无');
next(); next();
// if (whiteList.indexOf(to.path) !== -1) { // if (whiteList.indexOf(to.path) !== -1) {
// next(); // next();

View File

@ -73,6 +73,7 @@ const user = {
const avatar = !res.data.icon const avatar = !res.data.icon
? require('@/assets/image/profile.jpg') ? require('@/assets/image/profile.jpg')
: process.env.VUE_APP_BASE_API + user.icon; : process.env.VUE_APP_BASE_API + user.icon;
console.log(avatar);
if (res.roles && res.roles.length > 0) { if (res.roles && res.roles.length > 0) {
// 验证返回的roles是否是一个非空数组 // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', res.roles); commit('SET_ROLES', res.roles);

View File

@ -36,11 +36,14 @@
<div class="content"> <div class="content">
<!-- 头部 --> <!-- 头部 -->
<div class="header"> <div class="header">
<div class="login"> <div class="login_btn" v-if="2 == 3">
<el-button type="text" @click="handlePage">登录</el-button> <el-button type="text" @click="handlePage">登录</el-button>
<i class="mark">|</i> <i class="mark">|</i>
<el-button type="text" @click="handlePage">注册</el-button> <el-button type="text" @click="handlePage">注册</el-button>
</div> </div>
<div class="avatar-wrapper" v-else>
<img :src="avatar" class="user-avatar" />
</div>
<div class="img2_box"> <div class="img2_box">
<img src="@/assets/image/02.png" alt="" /> <img src="@/assets/image/02.png" alt="" />
<div class="search"> <div class="search">
@ -130,6 +133,7 @@
</template> </template>
<script> <script>
import { mapGetters } from 'vuex';
export default { export default {
name: 'home', name: 'home',
data() { data() {
@ -168,6 +172,9 @@ export default {
path: this.$route.path == '/' ? '/home' : this.$route.path path: this.$route.path == '/' ? '/home' : this.$route.path
}; };
}, },
computed: {
...mapGetters(['sidebar', 'avatar', 'device'])
},
methods: { methods: {
handlePage() { handlePage() {
this.$router.push({ path: '/login' }); this.$router.push({ path: '/login' });
@ -216,7 +223,8 @@ export default {
height: 206px; height: 206px;
padding: 0 100px; padding: 0 100px;
background-image: url(../assets/image/01.png); background-image: url(../assets/image/01.png);
.login { .login_btn {
height: 60px;
text-align: right; text-align: right;
.el-button { .el-button {
font-size: 16px; font-size: 16px;
@ -228,11 +236,22 @@ export default {
margin: 0 14px; margin: 0 14px;
} }
} }
.avatar-wrapper {
text-align: right;
.user-avatar {
vertical-align: middle;
cursor: pointer;
width: 60px;
height: 60px;
border-radius: 50%;
}
}
.img2_box { .img2_box {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
height: 63px; height: 63px;
margin-top: 75px; margin-top: 55px;
img { img {
width: 392px; width: 392px;
height: 100%; height: 100%;

View File

@ -185,8 +185,8 @@ export default {
count: '', // 初始化次数 count: '', // 初始化次数
timer: null, timer: null,
loginForm: { loginForm: {
username: '', username: '19855383805',
password: '', password: '123456',
rememberMe: false rememberMe: false
}, },
loginRules: { loginRules: {
@ -265,6 +265,7 @@ export default {
this.$store this.$store
.dispatch('Login', this.loginForm) .dispatch('Login', this.loginForm)
.then(() => { .then(() => {
// this.$router.go(-1);
this.$router.push({ path: this.redirect || '/' }); this.$router.push({ path: this.redirect || '/' });
}) })
.catch(() => { .catch(() => {
@ -274,8 +275,8 @@ export default {
this.$store this.$store
.dispatch('Register', this.loginForm) .dispatch('Register', this.loginForm)
.then(() => { .then(() => {
// this.$router.push({ path: this.redirect || '/' }); this.$router.push({ path: this.redirect || '/' });
this.$router.go(-1); // this.$router.go(-1);
}) })
.catch(() => { .catch(() => {
this.loading = false; this.loading = false;