2026-01-16 22:04:12 +08:00
|
|
|
import { ref } from 'vue'
|
|
|
|
|
import { getCaptchaImage } from '@/api/system'
|
|
|
|
|
|
2026-04-07 11:01:11 +08:00
|
|
|
interface CaptchaFormData {
|
|
|
|
|
captcha_code: string
|
2026-01-16 22:04:12 +08:00
|
|
|
captcha_key: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 11:01:11 +08:00
|
|
|
interface CaptchaResponse {
|
|
|
|
|
code: number
|
|
|
|
|
msg: string
|
|
|
|
|
data: {
|
|
|
|
|
uuid: string
|
|
|
|
|
base64: string
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function useCaptcha(formData: CaptchaFormData) {
|
2026-01-16 22:04:12 +08:00
|
|
|
const image = ref('')
|
|
|
|
|
|
|
|
|
|
const refresh = async () => {
|
|
|
|
|
try {
|
2026-04-07 11:01:11 +08:00
|
|
|
const res = await getCaptchaImage() as CaptchaResponse
|
|
|
|
|
if (res.code === 0 && res.data) {
|
|
|
|
|
formData.captcha_key = res.data.uuid
|
|
|
|
|
formData.captcha_code = ''
|
|
|
|
|
image.value = res.data.base64.replace(/\r\n/g, '')
|
|
|
|
|
}
|
2026-01-16 22:04:12 +08:00
|
|
|
} catch (e) {
|
2026-04-07 11:01:11 +08:00
|
|
|
console.error('获取验证码失败:', e)
|
2026-01-16 22:04:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
image,
|
|
|
|
|
refresh
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-07 11:01:11 +08:00
|
|
|
|
|
|
|
|
|