将锁屏密码和token保存在一起
This commit is contained in:
parent
1b4d34bee9
commit
9a7c4ae65e
@ -44,7 +44,7 @@
|
|||||||
* @version:
|
* @version:
|
||||||
* @Date: 2021-04-23 14:15:50
|
* @Date: 2021-04-23 14:15:50
|
||||||
* @LastEditors: huzhushan@126.com
|
* @LastEditors: huzhushan@126.com
|
||||||
* @LastEditTime: 2021-04-23 15:24:54
|
* @LastEditTime: 2021-04-28 09:23:23
|
||||||
* @Author: huzhushan@126.com
|
* @Author: huzhushan@126.com
|
||||||
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
|
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
|
||||||
* @Github: https://github.com/huzhushan/vue3-element-admin
|
* @Github: https://github.com/huzhushan/vue3-element-admin
|
||||||
@ -87,9 +87,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import { defineComponent, reactive, ref } from 'vue'
|
import { defineComponent, reactive, ref } from 'vue'
|
||||||
import Avatar from '@/components/Avatar/index.vue'
|
import Avatar from '@/components/Avatar/index.vue'
|
||||||
import { setItem } from '@/utils/storage'
|
|
||||||
import { AesEncryption } from '@/utils/encrypt'
|
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
import { useStore } from 'vuex'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
@ -97,6 +96,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const store = useStore()
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const lockForm = ref(null)
|
const lockForm = ref(null)
|
||||||
const lockModel = reactive({
|
const lockModel = reactive({
|
||||||
@ -111,11 +111,9 @@ export default defineComponent({
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对密码加密
|
// 对密码加密并跟token保存在一起
|
||||||
const encryption = new AesEncryption()
|
store.dispatch('app/setScreenCode', lockModel.password)
|
||||||
const pwd = encryption.encryptByAES(lockModel.password)
|
|
||||||
// 存储到localStorage
|
|
||||||
setItem('__VEA_SCREEN_LOCKED__', pwd)
|
|
||||||
// 跳转到锁屏页面
|
// 跳转到锁屏页面
|
||||||
router.push('/lock?redirect=' + router.currentRoute.value.fullPath)
|
router.push('/lock?redirect=' + router.currentRoute.value.fullPath)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
* @version:
|
* @version:
|
||||||
* @Date: 2021-04-20 11:06:21
|
* @Date: 2021-04-20 11:06:21
|
||||||
* @LastEditors: huzhushan@126.com
|
* @LastEditors: huzhushan@126.com
|
||||||
* @LastEditTime: 2021-04-25 13:50:27
|
* @LastEditTime: 2021-04-28 09:31:23
|
||||||
* @Author: huzhushan@126.com
|
* @Author: huzhushan@126.com
|
||||||
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
|
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
|
||||||
* @Github: https://github.com/huzhushan/vue3-element-admin
|
* @Github: https://github.com/huzhushan/vue3-element-admin
|
||||||
@ -77,13 +77,16 @@ router.beforeEach(async to => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否处于锁屏状态
|
// 判断是否处于锁屏状态
|
||||||
if (to.name !== 'lock' && !!getItem('__VEA_SCREEN_LOCKED__')) {
|
if (to.name !== 'lock') {
|
||||||
return {
|
const { authorization } = store.state.app
|
||||||
name: 'lock',
|
if (!!authorization && !!authorization.screenCode) {
|
||||||
query: {
|
return {
|
||||||
redirect: to.path,
|
name: 'lock',
|
||||||
},
|
query: {
|
||||||
replace: true,
|
redirect: to.path,
|
||||||
|
},
|
||||||
|
replace: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,13 +3,15 @@
|
|||||||
* @version:
|
* @version:
|
||||||
* @Date: 2021-04-20 11:06:21
|
* @Date: 2021-04-20 11:06:21
|
||||||
* @LastEditors: huzhushan@126.com
|
* @LastEditors: huzhushan@126.com
|
||||||
* @LastEditTime: 2021-04-21 09:34:07
|
* @LastEditTime: 2021-04-28 09:38:35
|
||||||
* @Author: huzhushan@126.com
|
* @Author: huzhushan@126.com
|
||||||
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
|
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
|
||||||
* @Github: https://github.com/huzhushan/vue3-element-admin
|
* @Github: https://github.com/huzhushan/vue3-element-admin
|
||||||
* @Donate: https://huzhushan.gitee.io/vue3-element-admin/donate/
|
* @Donate: https://huzhushan.gitee.io/vue3-element-admin/donate/
|
||||||
*/
|
*/
|
||||||
import { getItem, setItem, removeItem } from '@/utils/storage' //getItem和setItem是封装的操作localStorage的方法
|
import { getItem, setItem, removeItem } from '@/utils/storage' //getItem和setItem是封装的操作localStorage的方法
|
||||||
|
import { AesEncryption } from '@/utils/encrypt'
|
||||||
|
import { toRaw } from 'vue'
|
||||||
export const TOKEN = 'VEA-TOKEN'
|
export const TOKEN = 'VEA-TOKEN'
|
||||||
const COLLAPSE = 'VEA-COLLAPSE'
|
const COLLAPSE = 'VEA-COLLAPSE'
|
||||||
|
|
||||||
@ -55,5 +57,27 @@ export default {
|
|||||||
// 清除用户信息
|
// 清除用户信息
|
||||||
commit('account/clearUserinfo', '', { root: true })
|
commit('account/clearUserinfo', '', { root: true })
|
||||||
},
|
},
|
||||||
|
setScreenCode({ commit, state }, password) {
|
||||||
|
const authorization = toRaw(state.authorization)
|
||||||
|
|
||||||
|
if (!password) {
|
||||||
|
try {
|
||||||
|
delete authorization.screenCode
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
commit('setToken', authorization)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对密码加密
|
||||||
|
const screenCode = new AesEncryption().encryptByAES(password)
|
||||||
|
|
||||||
|
commit('setToken', {
|
||||||
|
...authorization,
|
||||||
|
screenCode,
|
||||||
|
})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@
|
|||||||
* @version:
|
* @version:
|
||||||
* @Date: 2021-04-23 19:17:20
|
* @Date: 2021-04-23 19:17:20
|
||||||
* @LastEditors: huzhushan@126.com
|
* @LastEditors: huzhushan@126.com
|
||||||
* @LastEditTime: 2021-04-25 10:57:31
|
* @LastEditTime: 2021-04-28 09:35:20
|
||||||
* @Author: huzhushan@126.com
|
* @Author: huzhushan@126.com
|
||||||
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
|
* @HomePage: https://huzhushan.gitee.io/vue3-element-admin
|
||||||
* @Github: https://github.com/huzhushan/vue3-element-admin
|
* @Github: https://github.com/huzhushan/vue3-element-admin
|
||||||
@ -106,12 +106,12 @@ export default defineComponent({
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
const checkPwd = async (rule, value, callback) => {
|
const checkPwd = async (rule, value, callback) => {
|
||||||
const encryption = new AesEncryption()
|
const { authorization } = store.state.app
|
||||||
const cipher = getItem('__VEA_SCREEN_LOCKED__')
|
const cipher = authorization && authorization.screenCode
|
||||||
if (!cipher) {
|
if (!cipher) {
|
||||||
return callback()
|
return callback()
|
||||||
}
|
}
|
||||||
const pwd = encryption.decryptByAES(cipher)
|
const pwd = new AesEncryption().decryptByAES(cipher)
|
||||||
if (pwd === value) {
|
if (pwd === value) {
|
||||||
return callback()
|
return callback()
|
||||||
} else {
|
} else {
|
||||||
@ -161,7 +161,8 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 返回锁屏前的页面
|
// 返回锁屏前的页面
|
||||||
router.push({ path: route.query.redirect || '/', replace: true })
|
router.push({ path: route.query.redirect || '/', replace: true })
|
||||||
removeItem('__VEA_SCREEN_LOCKED__')
|
// 清除锁屏密码
|
||||||
|
store.dispatch('app/setScreenCode', '')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +175,6 @@ export default defineComponent({
|
|||||||
router.push('/login?redirect=' + (route.query.redirect || '/'))
|
router.push('/login?redirect=' + (route.query.redirect || '/'))
|
||||||
// 清除token
|
// 清除token
|
||||||
store.dispatch('app/clearToken')
|
store.dispatch('app/clearToken')
|
||||||
removeItem('__VEA_SCREEN_LOCKED__')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user