登陆跳转转交登陆页面处理

Former-commit-id: cfd1438def08f0c214df214e42e8fa54433b29ed [formerly cfd1438def08f0c214df214e42e8fa54433b29ed [formerly cfd1438def08f0c214df214e42e8fa54433b29ed [formerly cfd1438def08f0c214df214e42e8fa54433b29ed [formerly 850c00a248f8dace4cdb42cdda77dfbf528b8e15 [formerly e43dc23c06b5e7addc34b225e0d7512afa4cbf88]]]]]
Former-commit-id: b7a006b238aee7cfd6bbcd587fc1826aa53f9ecc
Former-commit-id: bba6b8fb7a93cb3363d4109490ea54a3a0066f4c
Former-commit-id: bbb7c9d3c44357c023c7194b1c85f529aa048fbc [formerly fa2a2a5a267fe5a96c5e82cc0c1650eb024da71b]
Former-commit-id: 383bf4b86f457cff9830e54bf43340e42a2045ab
Former-commit-id: 348c1d718cd6c5441c2b721fd6efd30a8f231838
Former-commit-id: 4c9476c29fb68d59150d2b0992dc20bbd2d588ad
Former-commit-id: 7bd01ddd895e182be3d7a24267c4721376225bd3
Former-commit-id: 70079fa65f5107867d7bb5b460f3d24563b61e9c
This commit is contained in:
liyang
2018-11-17 22:31:41 +08:00
parent 9e3aed173b
commit 36a09f9c3d
3 changed files with 43 additions and 36 deletions

View File

@@ -15,40 +15,36 @@ export default {
login ({ dispatch }, {
vm,
username,
password,
route = {
path: '/'
}
password
}) {
// 开始请求登录接口
AccountLogin({
username,
password
return new Promise((resolve, reject) => {
// 开始请求登录接口
AccountLogin({
username,
password
})
.then(async res => {
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
// 整个系统依赖这两个数据进行校验和存储
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
// token 代表用户当前登录状态 建议在网络请求中携带 token
// 如有必要 token 需要定时更新,默认保存一天
util.cookies.set('uuid', res.uuid)
util.cookies.set('token', res.token)
// 设置 vuex 用户信息
await dispatch('d2admin/user/set', {
name: res.name
}, { root: true })
// 用户登录后从持久化数据加载一系列的设置
await dispatch('load')
// 结束
resolve()
})
.catch(err => {
console.log('err: ', err)
reject(err)
})
})
.then(async res => {
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
// 整个系统依赖这两个数据进行校验和存储
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
// token 代表用户当前登录状态 建议在网络请求中携带 token
// 如有必要 token 需要定时更新,默认保存一天
util.cookies.set('uuid', res.uuid)
util.cookies.set('token', res.token)
// 设置 vuex 用户信息
await dispatch('d2admin/user/set', {
name: res.name
}, { root: true })
// 用户登录后从持久化数据加载一系列的设置
await dispatch('load')
// 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址
const path = util.cookies.get('redirect')
// 根据是否存有重定向页面判断如何重定向
vm.$router.replace(path ? { path } : route)
// 删除 cookie 中保存的重定向页面
util.cookies.remove('redirect')
})
.catch(err => {
console.log('err: ', err)
})
},
/**
* @description 注销用户并返回登录页面