不再使用的代码清理

This commit is contained in:
2025-10-26 15:34:05 +08:00
parent 20c8d781c4
commit fdac026720
101 changed files with 278 additions and 38135 deletions
+58 -95
View File
@@ -14,49 +14,31 @@
label-width="80px"
@submit.prevent="handleLogin"
>
<el-form-item label="号" prop="account">
<el-form-item label="手机号" prop="phone">
<el-input
v-model="loginForm.account"
placeholder="请输入账号/邮箱/手机号"
v-model="loginForm.phone"
placeholder="请输入11位手机号"
:prefix-icon="User"
clearable
@keyup.enter="handleLogin"
/>
</el-form-item>
<el-form-item label="码" prop="password">
<el-input
v-model="loginForm.password"
type="password"
placeholder="请输入密码"
:prefix-icon="Lock"
show-password
clearable
@keyup.enter="handleLogin"
/>
</el-form-item>
<el-form-item label="验证码" prop="captcha">
<div class="flex gap-2">
<el-form-item label="短信验证码" prop="smsCode">
<div class="flex gap-2 w-full">
<el-input
v-model="loginForm.captcha"
placeholder="请输入验证码"
v-model="loginForm.smsCode"
placeholder="请输入6位验证码"
:prefix-icon="Key"
clearable
class="flex-1"
@keyup.enter="handleLogin"
maxlength="6"
show-word-limit
/>
<div class="captcha-container" @click="refreshCaptcha">
<img
v-if="captchaImage"
:src="captchaImage"
alt="验证码"
class="captcha-image"
/>
<div v-else class="captcha-loading">
<el-icon class="is-loading"><Loading /></el-icon>
</div>
</div>
<el-button type="primary" plain @click="handleSendSmsCode" :disabled="smsSending || countdown > 0">
{{ countdown > 0 ? `${countdown}s` : (smsSending ? '发送中...' : '获取验证码') }}
</el-button>
</div>
</el-form-item>
@@ -135,56 +117,61 @@ const loginFormRef = ref<FormInstance>()
// 加载状态
const loading = ref(false)
// 验证码相关
const captchaImage = ref('')
const captchaKey = ref('')
// 短信验证码发送状态
const smsSending = ref(false)
const countdown = ref(0)
let timer: number | null = null
// 登录表单数据
// 登录表单数据(手机号+短信验证码)
const loginForm = reactive<LoginRequest>({
account: '',
password: '',
captcha: '',
captchaKey: '',
phone: '',
smsCode: '',
rememberMe: false
})
// 表单验证规则
// 表单验证规则(手机号 + 短信验证码)
const loginRules: FormRules = {
account: [
{ required: true, message: '请输入号', trigger: 'blur' }
phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' },
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ min: 6, max: 20, message: '密码长度必须在6-20位之间', trigger: 'blur' }
],
captcha: [
smsCode: [
{ required: true, message: '请输入验证码', trigger: 'blur' },
{ min: 4, max: 6, message: '验证码长度不正确', trigger: 'blur' }
{ min: 6, max: 6, message: '验证码必须为6位', trigger: 'blur' }
]
}
/**
* 获取验证码
* 发送短信验证码
*/
const getCaptcha = async () => {
try {
const response = await AuthService.getCaptcha()
// 后端返回的数据已经包含了 data:image/png;base64, 前缀,直接使用
captchaImage.value = response.captchaImage
captchaKey.value = response.captchaKey
loginForm.captchaKey = response.captchaKey
} catch (error) {
console.error('获取验证码失败:', error)
ElMessage.error('获取验证码失败')
const handleSendSmsCode = async () => {
if (!loginForm.phone) {
ElMessage.warning('请先填写手机号')
return
}
if (!/^1[3-9]\d{9}$/.test(loginForm.phone)) {
ElMessage.warning('手机号格式不正确')
return
}
try {
smsSending.value = true
await AuthService.sendSmsCode(loginForm.phone)
ElMessage.success('验证码已发送,请注意查收')
// 启动倒计时
countdown.value = 60
timer && clearInterval(timer)
timer = window.setInterval(() => {
countdown.value -= 1
if (countdown.value <= 0 && timer) {
clearInterval(timer)
timer = null
}
}, 1000)
} catch (error) {
console.error('发送短信验证码失败:', error)
} finally {
smsSending.value = false
}
}
/**
* 刷新验证码
*/
const refreshCaptcha = () => {
loginForm.captcha = ''
getCaptcha()
}
/**
@@ -194,44 +181,23 @@ const handleLogin = async () => {
if (!loginFormRef.value) return
try {
console.log('开始登录流程...')
console.log('登录表单数据:', loginForm)
console.log('🔐 开始登录流程...')
// 表单验证
await loginFormRef.value.validate()
console.log('表单验证通过')
loading.value = true
// 调用登录接口
console.log('调用登录接口...')
// 调用登录接口(手机号 + 短信验证码)
const success = await authStore.login(loginForm)
console.log('登录结果:', success)
if (success) {
// 登录成功,确保认证状态已正确设置
console.log('登录成功,当前认证状态:', {
isLoggedIn: authStore.isLoggedIn,
hasToken: !!authStore.accessToken,
hasUserInfo: !!authStore.userInfo
})
// 跳转到目标页面或首页
const redirect = route.query.redirect as string || '/'
console.log('登录成功,跳转到:', redirect)
// 使用路由跳转而不是window.location.href,避免base路径问题
const redirect = (route.query.redirect as string) || '/'
await router.push(redirect)
} else {
// 登录失败,刷新验证码
console.log('登录失败,刷新验证码')
refreshCaptcha()
}
} catch (error) {
console.error('登录过程中发生错误:', error)
ElMessage.error('登录失败,请检查网络连接或稍后重试')
// 刷新验证码
refreshCaptcha()
} finally {
loading.value = false
}
@@ -245,13 +211,10 @@ const handleSocialLogin = (platform: 'wechat' | 'qq') => {
// TODO: 实现第三方登录逻辑
}
// 组件挂载时获取验证码
// 组件挂载时:如果已登录直接跳转
onMounted(() => {
getCaptcha()
// 如果已经登录,直接跳转
if (authStore.isLoggedIn) {
const redirect = route.query.redirect as string || '/'
const redirect = (route.query.redirect as string) || '/'
router.push(redirect)
}
})