Skip to content

Commit

Permalink
1.修改项目浏览器显示图标
Browse files Browse the repository at this point in the history
2.新增response拦截器。优化response的内容显示问题。
  • Loading branch information
BoBoooooo committed Jan 10, 2018
1 parent de61167 commit 71d987a
Show file tree
Hide file tree
Showing 11 changed files with 503 additions and 410 deletions.
Binary file modified favicon.ico
Binary file not shown.
8 changes: 8 additions & 0 deletions src/api/system/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ export function UpdateUsers(data){
})
}


export function ChangePassword(data){
return fetch({
url: '/admin/ChangePassword',
method: 'post',
data
})
}
2 changes: 1 addition & 1 deletion src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const constantRouterMap = [
path: '/',
component: Layout,
redirect: '/dashboard',
name: 'Dashboard',
name: '首页',
hidden: true,
children: [{ path: 'dashboard', component: _import('dashboard/index') }]
}
Expand Down
101 changes: 71 additions & 30 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'

import {
login,
logout,
getInfo
} from '@/api/login'
import {
getToken,
setToken,
removeToken
} from '@/utils/auth'
import {
ChangePassword
} from '@/api/system/users'
const user = {
state: {
token: getToken(),
name: '',
// avatar: '',
name: '', //用户昵称名
realname:'',//用户登录名
roles: []
},

Expand All @@ -16,69 +26,100 @@ const user = {
SET_NAME: (state, name) => {
state.name = name
},
// SET_AVATAR: (state, avatar) => {
// state.avatar = avatar
// },

SET_ROLES: (state, roles) => {
state.roles = roles
},
SET_REALNAME: (state, realname) => {
state.realname = realname
}
},

actions: {
// 登录
Login({ commit }, userInfo) {
Login({
commit
}, userInfo) {
const username = userInfo.username.trim()
return new Promise((resolve, reject) => {
login(username, userInfo.password).then(response => {
const data = response.data
setToken(data.Token)
console.log(data.Token);

commit('SET_TOKEN', data.Token)
resolve()
if (data.Success != false) {
setToken(data.Token)


commit('SET_TOKEN', data.Token)
resolve(data)

} else {
commit('SET_TOKEN', '')
commit('SET_ROLES', [])
removeToken()
reject(data.Message)
}

}).catch(error => {
reject(error)
})
})
},

// 获取用户信息
GetInfo({ commit, state }) {
GetInfo({
commit,
state
}) {
return new Promise((resolve, reject) => {
getInfo(state.token).then(response => {

const data = response.data
console.log(data);
commit('SET_ROLES', data.Roles)
commit('SET_NAME', data.RealName)
// commit('SET_AVATAR', data.avatar)
commit('SET_REALNAME', data.UserName)

resolve(response)
}).catch(error => {
reject(error)
})
})
},

// 登出
LogOut({ commit, state }) {
return new Promise((resolve, reject) => {
commit('SET_TOKEN', '')
commit('SET_ROLES', [])
removeToken()
resolve()
}).catch(error => {
reject(error)

})
},

// 前端 登出
FedLogOut({ commit }) {
FedLogOut({
commit
}) {
return new Promise(resolve => {
commit('SET_TOKEN', '')
commit('SET_ROLES', [])

removeToken()
resolve()
})
},

ChangePassword({
commit,
state
}, NewPassword) {
return new Promise((resolve, reject) => {
ChangePassword({
UserName: state.realname,
Password: NewPassword
}).then(response => {
const data = response.data
if (data.Success != false) {
resolve(data)
} else {
reject(data.Message)

}
}).catch(error => {
reject(error)
})

})
}
}
}
Expand Down
107 changes: 63 additions & 44 deletions src/utils/fetch.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import axios from 'axios'
import { Message } from 'element-ui'
import {
Message
} from 'element-ui'
import store from '../store'
import { getToken } from '@/utils/auth'
import {
getToken
} from '@/utils/auth'

// 创建axios实例
const service = axios.create({
baseURL: process.env.BASE_API, // api的base_url
timeout: 15000 // 请求超时时间
timeout: 15000 // 请求超时时间
})

// request拦截器
Expand All @@ -18,50 +22,65 @@ service.interceptors.request.use(config => {
return config
}, error => {
// Do something with request error
console.log(error) // for debug
Message({
message: error.message,
type: 'error',
duration: 5 * 1000
})
Promise.reject(error)
})

// respone拦截器
// service.interceptors.response.use(
// response => {
// /**
// * code为非20000是抛错 可结合自己业务进行修改
// */
// const res = response.data
// if (res.code !== 20000) {
// Message({
// message: res.data,
// type: 'error',
// duration: 5 * 1000
// })
//respone拦截器
service.interceptors.response.use(
response => {
console.log(response)

// // 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了;
// if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
// MessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
// confirmButtonText: '重新登录',
// cancelButtonText: '取消',
// type: 'warning'
// }).then(() => {
// store.dispatch('FedLogOut').then(() => {
// location.reload()// 为了重新实例化vue-router对象 避免bug
// })
// })
// }
// return Promise.reject('error')
// } else {
// return response.data
// }
// },
// error => {
// console.log('err' + error)// for debug
// Message({
// message: error.message,
// type: 'error',
// duration: 5 * 1000
// })
// return Promise.reject(error)
// }
// )
const res = response.data

if (res.Success != null) {

if (res.Success == false) {
Message({
message: res.Message,
type: 'error',
duration: 1500
})


} else {
Message({
message: res.Message,
type: 'success',
duration: 1500
})
}
}

return response;

},
error => {
console.log('err' + error) // for debug
Message({
message: error.message,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
}
)

export default service
// // // 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了;
// // if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
// // MessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
// // confirmButtonText: '重新登录',
// // cancelButtonText: '取消',
// // type: 'warning'
// // }).then(() => {
// // store.dispatch('FedLogOut').then(() => {
// // location.reload()// 为了重新实例化vue-router对象 避免bug
// // })
// // })
// // }
// return Promise.reject('error')
4 changes: 2 additions & 2 deletions src/views/layout/Levelbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default {
getBreadcrumb() {
let matched = this.$route.matched.filter(item => item.name)
const first = matched[0]
if (first && (first.name !== 'Home' || first.path !== '')) {
matched = [{ name: 'Home', path: '/' }].concat(matched)
if (first && (first.name !== '首页' || first.path !== '')) {
matched = [{ name: '首页', path: '/' }].concat(matched)
}
this.levelList = matched
}
Expand Down
Loading

0 comments on commit 71d987a

Please sign in to comment.