Merge branch 'hotfix/login_redirect' into develop

Former-commit-id: db498ccc317f674bb6697cfe6234f8af2c299568 [formerly db8fcc9d5708b49d5264f1f5d23fe607e51d5263] [formerly db498ccc317f674bb6697cfe6234f8af2c299568 [formerly db8fcc9d5708b49d5264f1f5d23fe607e51d5263] [formerly db498ccc317f674bb6697cfe6234f8af2c299568 [formerly db8fcc9d5708b49d5264f1f5d23fe607e51d5263] [formerly db8fcc9d5708b49d5264f1f5d23fe607e51d5263 [formerly a5ada78114bb3fa9d04ad5317fa3651696b7b781 [formerly ecba5be967e88adb2e4edf1e59262b9f76d69cab]]]]]
Former-commit-id: 7f309dc02aca685483f0d19a8b50ded6f907b9b6
Former-commit-id: 89bac3f1ff0a7faadf45caecf2e09d37070bbb4e
Former-commit-id: 15b009dae988122cbc3b47b86fd022f540d0dd00 [formerly 0f6bb4ddf44394b20f7620d7b5fe48def73f18cc]
Former-commit-id: 68f3cfb44ef04efe68b570f7f395860ca1063202
Former-commit-id: 4d7712f325a9393b6d94fa5691aeb32fe3752c41
Former-commit-id: d50970628d69cf08b69fcac3035d8a003bac74e3
Former-commit-id: c2d0e373113fa588798a09851985bb177d9e5aee
Former-commit-id: 02aecb2ba9a8d67938cc5b38175a1a974b3e7685
This commit is contained in:
liyang
2018-11-17 22:33:37 +08:00
16 changed files with 81 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "d2-admin", "name": "d2-admin",
"version": "1.6.5", "version": "1.6.6",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve --open", "serve": "vue-cli-service serve --open",

View File

@@ -11,7 +11,9 @@
<script> <script>
export default { export default {
data () { data () {
filename: __filename return {
filename: __filename
}
} }
} }
</script> </script>

View File

@@ -43,7 +43,9 @@
<script> <script>
export default { export default {
data () { data () {
filename: __filename return {
filename: __filename
}
}, },
methods: { methods: {
handleColorful () { handleColorful () {

View File

@@ -9,7 +9,9 @@
<script> <script>
export default { export default {
data () { data () {
filename: __filename return {
filename: __filename
}
}, },
methods: { methods: {
handleNewError () { handleNewError () {

View File

@@ -10,7 +10,9 @@
<script> <script>
export default { export default {
data () { data () {
filename: __filename return {
filename: __filename
}
}, },
mounted () { mounted () {
console.log('this.$route', this.$route) console.log('this.$route', this.$route)

View File

@@ -20,7 +20,9 @@ export default {
} }
}, },
data () { data () {
filename: __filename return {
filename: __filename
}
}, },
computed: { computed: {
/** /**

View File

@@ -11,7 +11,9 @@
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
export default { export default {
data () { data () {
filename: __filename return {
filename: __filename
}
}, },
methods: { methods: {
...mapActions('d2admin/fullscreen', [ ...mapActions('d2admin/fullscreen', [

View File

@@ -18,7 +18,9 @@ export default {
]) ])
}, },
data () { data () {
filename: __filename return {
filename: __filename
}
}, },
methods: { methods: {
...mapActions('d2admin/transition', [ ...mapActions('d2admin/transition', [

View File

@@ -11,7 +11,9 @@
import { mapState } from 'vuex' import { mapState } from 'vuex'
export default { export default {
data () { data () {
filename: __filename return {
filename: __filename
}
}, },
computed: { computed: {
...mapState('d2admin/ua', { ...mapState('d2admin/ua', {

View File

@@ -13,7 +13,9 @@ export default {
DemoI18n: () => import('./components/DemoI18n') DemoI18n: () => import('./components/DemoI18n')
}, },
data () { data () {
filename: __filename return {
filename: __filename
}
} }
} }
</script> </script>

View File

@@ -13,7 +13,9 @@ export default {
DemoI18n: () => import('./components/DemoI18n') DemoI18n: () => import('./components/DemoI18n')
}, },
data () { data () {
filename: __filename return {
filename: __filename
}
} }
} }
</script> </script>

View File

@@ -11,7 +11,9 @@
<script> <script>
export default { export default {
data () { data () {
filename: __filename return {
filename: __filename
}
} }
} }
</script> </script>

View File

@@ -26,7 +26,9 @@
import util from '@/libs/util.js' import util from '@/libs/util.js'
export default { export default {
data () { data () {
filename: __filename return {
filename: __filename
}
}, },
methods: { methods: {
set (name = 'default-name', value = 'default-value') { set (name = 'default-name', value = 'default-value') {

View File

@@ -141,6 +141,16 @@ export default {
username: this.formLogin.username, username: this.formLogin.username,
password: this.formLogin.password password: this.formLogin.password
}) })
.then(() => {
const redirect = this.$route.query.redirect
if (redirect) {
// 重定向到指定的页面
this.$router.replace(redirect)
} else {
// 重定向到开始路径
this.$router.replace('/')
}
})
} else { } else {
// 登录表单校验失败 // 登录表单校验失败
this.$message.error('表单校验失败') this.$message.error('表单校验失败')

View File

@@ -36,12 +36,13 @@ router.beforeEach((to, from, next) => {
if (token && token !== 'undefined') { if (token && token !== 'undefined') {
next() next()
} else { } else {
// 将当前预计打开的页面完整地址临时存储 登录后继续跳转
// 这个 cookie(redirect) 会在登录后自动删除
util.cookies.set('redirect', to.fullPath)
// 没有登录的时候跳转到登录界面 // 没有登录的时候跳转到登录界面
// 携带上登陆成功之后需要跳转的页面完整路径
next({ next({
name: 'login' name: 'login',
query: {
redirect: to.fullPath
}
}) })
} }
} else { } else {

View File

@@ -15,40 +15,36 @@ export default {
login ({ dispatch }, { login ({ dispatch }, {
vm, vm,
username, username,
password, password
route = {
path: '/'
}
}) { }) {
// 开始请求登录接口 return new Promise((resolve, reject) => {
AccountLogin({ // 开始请求登录接口
username, AccountLogin({
password 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 注销用户并返回登录页面 * @description 注销用户并返回登录页面