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 {
this.levelList2 = []; this.levelList2 = [];
} }
this.levelList2.unshift(ancestorsDir) this.levelList2.unshift(ancestorsDir)
console.log(this.levelList2); //console.log(this.levelList2);
this.breadcrumbq = false; this.breadcrumbq = false;
// console.log(currentid); // console.log(currentid);
// console.log(this.extractChild); // console.log(this.extractChild);

71
src/permission.js

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

8
src/store/modules/user.js

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

24
src/views/login/index.vue

@ -170,11 +170,27 @@ export default {
if (valid) { if (valid) {
this.loading = true this.loading = true
let thiss = this; let thiss = this;
this.$store.dispatch('user/login', this.loginForm).then(() => { this.$store.dispatch('user/login', this.loginForm).then(response => {
//this.$router.push({ path: this.redirect || '/' }) console.log(response);
this.$router.push({path: '/filemange/index'}) 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 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 this.loading = false
}) })
// login(this.loginForm).then(response => { // login(this.loginForm).then(response => {

Loading…
Cancel
Save