验证码获取测试

This commit is contained in:
Ken 2025-03-11 10:27:13 +08:00
parent a040fd8ef1
commit 3d378aebe9

View file

@ -89,9 +89,10 @@ export default {
try { try {
this.captchaUuid = Date.now().toString() this.captchaUuid = Date.now().toString()
const response = await api.get(`/captcha?uuid=${this.captchaUuid}`, { const response = await api.get(`/captcha?uuid=${this.captchaUuid}`, {
responseType: 'blob', // Keep this as first config option responseType: 'blob',
headers: { headers: {
'Accept': 'image/gif' // Match with actual backend type 'Content-Type': 'application/json;charset=utf8',
'Accept': 'image/gif'
} }
}) })
@ -102,13 +103,14 @@ export default {
// 验证图片类型并创建新URL // 验证图片类型并创建新URL
if (response.data.type === 'image/png') { if (response.data.type === 'image/png') {
// Directly use the received Blob
this.captchaUrl = URL.createObjectURL(response.data) this.captchaUrl = URL.createObjectURL(response.data)
console.log('PNG验证码加载成功,UUID:', this.captchaUuid) console.log('PNG验证码加载成功,UUID:', this.captchaUuid)
} else { } else {
throw new Error(`无效的图片类型: ${response.data.type}`) throw new Error(`无效的图片类型: ${response.data.type}`)
} }
} catch (error) { }
catch (error) {
// 清空验证码图片并显示错误 // 清空验证码图片并显示错误
this.captchaUrl = '' this.captchaUrl = ''
showDanger('验证码加载失败,请重试') showDanger('验证码加载失败,请重试')