Merge branch 'hotfix/login_redirect'

Former-commit-id: 41f988f3f1db7f5c39685408bdd9a20be690d5b4 [formerly d4035d810e22d68b6aa683bb93051a3661994afb] [formerly 41f988f3f1db7f5c39685408bdd9a20be690d5b4 [formerly d4035d810e22d68b6aa683bb93051a3661994afb] [formerly 41f988f3f1db7f5c39685408bdd9a20be690d5b4 [formerly d4035d810e22d68b6aa683bb93051a3661994afb] [formerly d4035d810e22d68b6aa683bb93051a3661994afb [formerly e9b72fb003ea8df9798c038c786947eb7440dc2a [formerly 403027bdf474abf23f94d3d96aefecf7018b549a]]]]]
Former-commit-id: 526d029774eb6cac018564d97a515c427a1c114b
Former-commit-id: e5b48cd208ef745d9f9d64bba4c5952d031e064c
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
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 注销用户并返回登录页面