Browse Source

Merge branch 'dev'

master
taylor 8 years ago
parent
commit
9da6caee42
  1. 17
      src/App.vue
  2. 4
      src/main.js
  3. 2
      src/mockdata/user.js
  4. 17
      src/pages/Home.vue
  5. 8
      src/pages/Login.vue

17
src/App.vue

@ -12,9 +12,20 @@
name: 'app', name: 'app',
components: { components: {
}, },
created: function () {
this.$router.replace('/login')
}
// beforeCreate: function () {
// let user = JSON.parse(localStorage.getItem('user'));
// if (!user) {
// this.$router.replace('/login')
// }
// }
watch: {
'$route'(to, from) {//
let user = JSON.parse(sessionStorage.getItem('user'));
if (!user) {
this.$router.replace('/login')
}
}
},
} }
</script> </script>

4
src/main.js

@ -86,6 +86,10 @@ const router = new VueRouter({
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start(); NProgress.start();
let user = JSON.parse(sessionStorage.getItem('user'));
if (!user && to.path != '/login') {
next({ path: '/login' })
}
next() next()
}) })

2
src/mockdata/user.js

@ -4,7 +4,7 @@ const LoginUsers = [
id: 1, id: 1,
username: 'admin', username: 'admin',
password: '123456', password: '123456',
avatar: '',
avatar: 'https://raw.githubusercontent.com/taylorchen709/markdown-images/master/vueadmin/user.png',
name: '张某某' name: '张某某'
} }
]; ];

17
src/pages/Home.vue

@ -7,7 +7,7 @@
</el-col> </el-col>
<el-col :span="4" class="rightbar"> <el-col :span="4" class="rightbar">
<el-dropdown trigger="click"> <el-dropdown trigger="click">
<span class="el-dropdown-link" style="color:#c0ccda;cursor: pointer;"><img src="../assets/user.png" class="head"> 张某某
<span class="el-dropdown-link" style="color:#c0ccda;cursor: pointer;"><img :src="this.sysUserAvatar" class="head"> {{sysUserName}}
</span> </span>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item>我的消息</el-dropdown-item> <el-dropdown-item>我的消息</el-dropdown-item>
@ -82,6 +82,8 @@
currentPath: '/table', currentPath: '/table',
currentPathName: 'Table', currentPathName: 'Table',
currentPathNameParent: '导航一', currentPathNameParent: '导航一',
sysUserName: '',
sysUserAvatar: '',
form: { form: {
name: '', name: '',
region: '', region: '',
@ -119,12 +121,25 @@
this.$confirm('确认退出吗?', '提示', { this.$confirm('确认退出吗?', '提示', {
//type: 'warning' //type: 'warning'
}).then(() => { }).then(() => {
sessionStorage.removeItem('user');
_this.$router.replace('/login'); _this.$router.replace('/login');
}).catch(() => { }).catch(() => {
}); });
}
},
mounted() {
this.currentPath = this.$route.path;
this.currentPathName = this.$route.name;
this.currentPathNameParent = this.$route.matched[0].name;
var user = sessionStorage.getItem('user');
if (user) {
user = JSON.parse(user);
this.sysUserName = user.name || '';
this.sysUserAvatar = user.avatar || '';
} }
} }
} }

8
src/pages/Login.vue

@ -62,12 +62,8 @@
type: 'error' type: 'error'
}); });
} else { } else {
localStorage.setItem('user', JSON.stringify(user));
if (this.$route.query.redirect) {
this.$router.push({ path: this.$route.query.redirect });
} else {
this.$router.push({ path: '/table' });
}
sessionStorage.setItem('user', JSON.stringify(user));
this.$router.push({ path: '/table' });
} }
}); });
} else { } else {

Loading…
Cancel
Save