Browse Source

优化登入错误信息提示,以及用vuex设置访问其他页面如果未登入则跳到登入页,删除调试代码

master
wen 2 years ago
parent
commit
d1e575a0bd
  1. 2
      dist/index.html
  2. 2
      src/components/Breadcrumb/index.vue
  3. 71
      src/permission.js
  4. 8
      src/store/modules/user.js
  5. 24
      src/views/login/index.vue

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

2
src/components/Breadcrumb/index.vue

@ -89,7 +89,7 @@ export default { @@ -89,7 +89,7 @@ export default {
this.levelList2 = [];
}
this.levelList2.unshift(ancestorsDir)
console.log(this.levelList2);
//console.log(this.levelList2);
this.breadcrumbq = false;
// console.log(currentid);
// console.log(this.extractChild);

71
src/permission.js

@ -19,44 +19,45 @@ router.beforeEach(async(to, from, next) => { @@ -19,44 +19,45 @@ router.beforeEach(async(to, from, next) => {
document.title = getPageTitle(to.meta.title)
next()
// determine whether the user has logged in
// const hasToken = getToken()
const hasToken = getToken()
// if (hasToken) {
// if (to.path === '/login') {
// // if is logged in, redirect to the home page
// next({ path: '/' })
// NProgress.done()
// } else {
// const hasGetUserInfo = store.getters.name
// if (hasGetUserInfo) {
// next()
// } else {
// try {
// // get user info
// await store.dispatch('user/getInfo')
if (hasToken) {
if (to.path === '/login') {
// if is logged in, redirect to the home page
next({ path: '/' })
NProgress.done()
}
// else {
// const hasGetUserInfo = store.getters.name
// if (hasGetUserInfo) {
// next()
// } else {
// try {
// // get user info
// await store.dispatch('user/getInfo')
// next()
// } catch (error) {
// // remove token and go to login page to re-login
// await store.dispatch('user/resetToken')
// Message.error(error || 'Has Error')
// next(`/login?redirect=${to.path}`)
// NProgress.done()
// }
// }
// }
// } else {
// /* has no token*/
// next()
// } catch (error) {
// // remove token and go to login page to re-login
// await store.dispatch('user/resetToken')
// Message.error(error || 'Has Error')
// next(`/login?redirect=${to.path}`)
// NProgress.done()
// }
// }
// }
} else {
/* has no token*/
// if (whiteList.indexOf(to.path) !== -1) {
// // in the free login whitelist, go directly
// next()
// } else {
// // other pages that do not have permission to access are redirected to the login page.
// next(`/login?redirect=${to.path}`)
// NProgress.done()
// }
// }
if (whiteList.indexOf(to.path) !== -1) {
// in the free login whitelist, go directly
next()
} else {
// other pages that do not have permission to access are redirected to the login page.
next(`/login?redirect=${to.path}`)
NProgress.done()
}
}
})
router.afterEach(() => {

8
src/store/modules/user.js

@ -33,10 +33,10 @@ const actions = { @@ -33,10 +33,10 @@ const actions = {
const { username, password, captcha} = userInfo
return new Promise((resolve, reject) => {
login({ username: username.trim(), password: password, captcha: captcha}).then(response => {
const { data } = response
commit('SET_TOKEN', data.token)
setToken(data.token)
resolve()
const { data } = 1
commit('SET_TOKEN', data)
setToken(data)
resolve(response)
}).catch(error => {
reject(error)
})

24
src/views/login/index.vue

@ -170,11 +170,27 @@ export default { @@ -170,11 +170,27 @@ export default {
if (valid) {
this.loading = true
let thiss = this;
this.$store.dispatch('user/login', this.loginForm).then(() => {
//this.$router.push({ path: this.redirect || '/' })
this.$router.push({path: '/filemange/index'})
this.$store.dispatch('user/login', this.loginForm).then(response => {
console.log(response);
let datamain = response.data;
if (datamain.code == 1) {
//console.log(datamain);
this.$router.push({ path: this.redirect || '/filemange/index' })
this.$message({showClose: true,message: datamain.msg, type:'success'});
} else if (datamain.code == 0) {
this.$message({showClose: true,message: datamain.err, type:'error'});
}
this.loading = false
}).catch(() => {
}).catch((error) => {
if (error.response) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else if (error.request) {
thiss.$message({showClose: true,message: error.request,type: 'error'});
} else {
thiss.$message({showClose: true,message: error.message,type: 'error'});
}
this.loading = false
})
// login(this.loginForm).then(response => {

Loading…
Cancel
Save