增加记住授权码功能

This commit is contained in:
lion 2022-07-22 16:41:40 +08:00
parent 2a87cd760e
commit 749237a02d

View File

@ -50,10 +50,10 @@
<template #prefix> <template #prefix>
请输入授权码 请输入授权码
</template> </template>
<template #append>
<el-button @click="validate" type="primary">验证</el-button>
</template>
</el-input> </el-input>
<el-checkbox v-model="isRemember" style="margin-left: 180px">是否记住授权码</el-checkbox>
<el-button @click="validate" type="primary" @keydown.enter="validate" style="margin-left: 100px">验证</el-button>
</el-col> </el-col>
</div> </div>
@ -61,7 +61,7 @@
<script> <script>
import store from "../store"; import store from "../store";
import {computed, ref} from "vue"; import {computed, ref, onMounted} from "vue";
import {ElMessage} from "element-plus" import {ElMessage} from "element-plus"
export default { export default {
name: "DashBoard", name: "DashBoard",
@ -69,8 +69,13 @@ export default {
const link = ref("") const link = ref("")
const AuthCode = ref("") const AuthCode = ref("")
const keyword = ref("") const keyword = ref("")
const isRemember = ref(false)
let timer let timer
const loadComplete = computed(() => {
return store.getters.loadComplete
})
function post(){ function post(){
if(link.value.trim() === ''){ if(link.value.trim() === ''){
ElMessage("请输入链接后再提交") ElMessage("请输入链接后再提交")
@ -99,6 +104,7 @@ export default {
} }
else{ else{
store.dispatch("validate", AuthCode.value) store.dispatch("validate", AuthCode.value)
localStorage.setItem("auth", AuthCode.value)
} }
} }
@ -117,14 +123,16 @@ export default {
timer = setTimeout(() => { timer = setTimeout(() => {
store.dispatch("searchByKeyword", keyword.value) store.dispatch("searchByKeyword", keyword.value)
}, 500) }, 500)
} }
const loadComplete = computed(() => { onMounted(() => {
return store.getters.loadComplete const auth = localStorage.getItem("auth")
if(auth !== null){
store.dispatch("validate", auth)
}
}) })
return {link, post, query, validate, loadComplete, AuthCode, searchByLink, keyword, searchByKeyword, store} return {post, query, validate, searchByLink, searchByKeyword, link, loadComplete, AuthCode, keyword, isRemember, store}
} }
} }
</script> </script>
@ -140,7 +148,7 @@ export default {
width: auto; width: auto;
background-color: ghostwhite; background-color: ghostwhite;
display: block; display: block;
margin-left: 200px; margin-left: 180px;
margin-top: 200px; margin-top: 200px;
} }
</style> </style>