diff --git a/src/apis/modules/common.js b/src/apis/modules/common.js index 568b547..e7f2c10 100644 --- a/src/apis/modules/common.js +++ b/src/apis/modules/common.js @@ -1,5 +1,5 @@ import request from '@/utils/request' - +import axios from 'axios' // 获取地区 export const getRegion = (params) => request.basic.get('/region', params) @@ -10,4 +10,10 @@ export const getCaptcha = (params) => request.basic.get('/api/v1/captcha/id', pa export const getCaptchaImage = (params) => request.basic.get('/api/v1/captcha/image', params , { responseType: 'blob' }) //上传图片 -export const uploadImg=(params)=>request.basic.post('/api/v1/upload',params,{Headers:{'Content-Type': 'multipart/form-data'}}) \ No newline at end of file +// export const uploadImg=(params)=>request.basic.post('/api/v1/upload',params,{Headers:{'Authorization':'','Content-Type': 'multipart/form-data'}}) + export const uploadImg=(params)=>axios.post('https://zh.shibeitong.com/api/v1/upload',params,{ + headers: { + 'Authorization':'', + 'Content-Type': 'multipart/form-data' + }, + }) \ No newline at end of file diff --git a/src/views/login/index.vue b/src/views/login/index.vue index a18b546..9e78dca 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -95,11 +95,24 @@ onMounted(() => { * 获取 验证码ID */ async function getCaptcha() { - const { data } = await apis.common.getCaptcha().catch((err) => { - console.log(err) - }) - captcha_id.value = data.captcha_id - captcha_img.value = httpApi + `?id=${data.captcha_id}` + try { + // 1. 获取 captcha_id + const response = await apis.common.getCaptcha() + const data = response.data + if (!data?.captcha_id) { + console.warn('验证码ID缺失') + return + } + captcha_id.value = data.captcha_id + const imageResponse = await apis.common.getCaptchaImage({ id: data.captcha_id,reload:1 }) + console.log('Blob 对象:', imageResponse) + const blobUrl = URL.createObjectURL(imageResponse) + captcha_img.value = blobUrl + console.log('验证码图片URL:', blobUrl) + } catch (err) { + console.error('获取验证码失败:', err) + captcha_img.value = '' + } } /** * 登录