Skip to content

Commit

Permalink
Merge branch 'hotfix/login_redirect'
Browse files Browse the repository at this point in the history
Former-commit-id: 41f988f3f1db7f5c39685408bdd9a20be690d5b4 [formerly d4035d810e22d68b6aa683bb93051a3661994afb] [formerly 41f988f3f1db7f5c39685408bdd9a20be690d5b4 [formerly d4035d810e22d68b6aa683bb93051a3661994afb] [formerly 41f988f3f1db7f5c39685408bdd9a20be690d5b4 [formerly d4035d810e22d68b6aa683bb93051a3661994afb] [formerly d4035d810e22d68b6aa683bb93051a3661994afb [formerly e9b72fb [formerly 403027bdf474abf23f94d3d96aefecf7018b549a]]]]]
Former-commit-id: 526d029
Former-commit-id: e5b48cd
Former-commit-id: 3dc115454b7a0c7c37d6d2d9dbcbf6bda4a08d83 [formerly 88677a873886264d3f553008dc687123c60e4ef3]
Former-commit-id: 1a520ad46643c8ed224bc7d918221169b42f5a4c
Former-commit-id: 7d388c47329030bdf247451fa6eac2fdc76b5322
Former-commit-id: cf650a251f52cc7e196639e00d2776497392306c
Former-commit-id: 391933ce9b06216192d39d45fddcfab6415227c6
Former-commit-id: 05cc58d7089f9c6e3ce48c92e69e3ae8ec1b9f45
  • Loading branch information
FairyEver committed Nov 17, 2018
2 parents 9e3aed1 + 3477663 commit 9d7f20b
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d2-admin",
"version": "1.6.5",
"version": "1.6.6",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --open",
Expand Down
6 changes: 4 additions & 2 deletions src/pages/demo/playground/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<script>
export default {
data () {
filename: __filename
}
return {
filename: __filename
}
}
}
</script>
4 changes: 3 additions & 1 deletion src/pages/demo/playground/log/console/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
<script>
export default {
data () {
filename: __filename
return {
filename: __filename
}
},
methods: {
handleColorful () {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/demo/playground/log/error/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<script>
export default {
data () {
filename: __filename
return {
filename: __filename
}
},
methods: {
handleNewError () {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/demo/playground/page-argu/get.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<script>
export default {
data () {
filename: __filename
return {
filename: __filename
}
},
mounted () {
console.log('this.$route', this.$route)
Expand Down
4 changes: 3 additions & 1 deletion src/pages/demo/playground/page-cache/params.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default {
}
},
data () {
filename: __filename
return {
filename: __filename
}
},
computed: {
/**
Expand Down
4 changes: 3 additions & 1 deletion src/pages/demo/playground/store/fullscreen/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import { mapActions } from 'vuex'
export default {
data () {
filename: __filename
return {
filename: __filename
}
},
methods: {
...mapActions('d2admin/fullscreen', [
Expand Down
4 changes: 3 additions & 1 deletion src/pages/demo/playground/store/transition/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default {
])
},
data () {
filename: __filename
return {
filename: __filename
}
},
methods: {
...mapActions('d2admin/transition', [
Expand Down
4 changes: 3 additions & 1 deletion src/pages/demo/playground/store/ua/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import { mapState } from 'vuex'
export default {
data () {
filename: __filename
return {
filename: __filename
}
},
computed: {
...mapState('d2admin/ua', {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/demo/plugins/i18n/demo1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default {
DemoI18n: () => import('./components/DemoI18n')
},
data () {
filename: __filename
return {
filename: __filename
}
}
}
</script>
4 changes: 3 additions & 1 deletion src/pages/demo/plugins/i18n/demo2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default {
DemoI18n: () => import('./components/DemoI18n')
},
data () {
filename: __filename
return {
filename: __filename
}
}
}
</script>
4 changes: 3 additions & 1 deletion src/pages/demo/plugins/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<script>
export default {
data () {
filename: __filename
return {
filename: __filename
}
}
}
</script>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/demo/plugins/js-cookie/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import util from '@/libs/util.js'
export default {
data () {
filename: __filename
return {
filename: __filename
}
},
methods: {
set (name = 'default-name', value = 'default-value') {
Expand Down
10 changes: 10 additions & 0 deletions src/pages/login/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ export default {
username: this.formLogin.username,
password: this.formLogin.password
})
.then(() => {
const redirect = this.$route.query.redirect
if (redirect) {
// 重定向到指定的页面
this.$router.replace(redirect)
} else {
// 重定向到开始路径
this.$router.replace('/')
}
})
} else {
// 登录表单校验失败
this.$message.error('表单校验失败')
Expand Down
9 changes: 5 additions & 4 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ router.beforeEach((to, from, next) => {
if (token && token !== 'undefined') {
next()
} else {
// 将当前预计打开的页面完整地址临时存储 登录后继续跳转
// 这个 cookie(redirect) 会在登录后自动删除
util.cookies.set('redirect', to.fullPath)
// 没有登录的时候跳转到登录界面
// 携带上登陆成功之后需要跳转的页面完整路径
next({
name: 'login'
name: 'login',
query: {
redirect: to.fullPath
}
})
}
} else {
Expand Down
60 changes: 28 additions & 32 deletions src/store/modules/d2admin/modules/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,36 @@ export default {
login ({ dispatch }, {
vm,
username,
password,
route = {
path: '/'
}
password
}) {
// 开始请求登录接口
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')
// 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址
const path = util.cookies.get('redirect')
// 根据是否存有重定向页面判断如何重定向
vm.$router.replace(path ? { path } : route)
// 删除 cookie 中保存的重定向页面
util.cookies.remove('redirect')
})
.catch(err => {
console.log('err: ', err)
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)
})
})
},
/**
* @description 注销用户并返回登录页面
Expand Down

0 comments on commit 9d7f20b

Please sign in to comment.