feat: 调整登录

This commit is contained in:
duanshuwen
2025-09-29 21:47:18 +08:00
parent 3aa8e85054
commit 02b85f3251
3 changed files with 37 additions and 17 deletions

View File

@@ -20,7 +20,7 @@
<div class="fz-22 mb-20">手机扫码登录</div>
<div class="w-48 h-48 bg-white rounded-lg mx-auto flex items-center justify-center">
<div class="qr text-center mt-20">
<vue-qrcode value="https://www.1stg.me" width="195" margin="3" />
<VueQrcode value="https://www.1stg.me" :width="195" :margin="3" />
<!-- 二维码失效 -->
<div class="qrcode-error">
@@ -140,12 +140,16 @@
</div>
</template>
<script setup ts>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { User, Lock, Key } from '@element-plus/icons-vue'
import VueQrcode from 'vue-qrcode'
// 路由实例
const router = useRouter()
// 登录表单
const loginFormRef = ref()
const loginForm = reactive({
@@ -173,11 +177,8 @@ const showCaptcha = ref(false)
const captchaCode = ref('8K9M')
const loginAttempts = ref(0)
// 生成二维码
const qrCodeUrl = ref('')
// 刷新验证码
const refreshCaptcha = () => {
const refreshCaptcha = (): void => {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
let code = ''
for (let i = 0; i < 4; i++) {
@@ -187,7 +188,7 @@ const refreshCaptcha = () => {
}
// 处理登录
const handleLogin = async () => {
const handleLogin = async (): Promise<void> => {
try {
await loginFormRef.value.validate()
@@ -198,13 +199,18 @@ const handleLogin = async () => {
loading.value = false
loginAttempts.value++
// 模拟登录失败,显示验证码
if (loginAttempts.value >= 1) {
showCaptcha.value = true
// 模拟登录成功
if (loginForm.username === 'admin' && loginForm.password === '123456') {
ElMessage.success('登录成功')
// 登录成功后,跳转到首页
router.push({ name: 'home' })
// 登录成功后,通知主进程
if (window.electron && window.electron.ipcRenderer) {
window.electron.ipcRenderer.send('login-success')
}
} else {
ElMessage.error('用户名或密码错误')
refreshCaptcha()
} else {
ElMessage.success('登录成功')
}
}, 1500)
} catch (error) {
@@ -213,7 +219,7 @@ const handleLogin = async () => {
}
// 处理忘记密码
const handleForgotPassword = () => {
const handleForgotPassword = (): void => {
ElMessage.info('忘记密码功能开发中...')
}
@@ -221,7 +227,7 @@ const handleForgotPassword = () => {
onMounted(() => {
const usernameInput = document.querySelector('input[placeholder="请输入用户名/邮箱/手机号"]')
if (usernameInput) {
usernameInput.focus()
;(usernameInput as HTMLInputElement).focus()
}
})
</script>