Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 1m10s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import axios from 'axios'
|
|
import { showToast } from 'vant'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
|
|
/**
|
|
* 账单导入相关 API
|
|
*/
|
|
|
|
/**
|
|
* 上传账单文件
|
|
* @param {File} file - 要上传的文件
|
|
* @param {string} type - 账单类型 ('Alipay' | 'WeChat')
|
|
* @returns {Promise<{success: boolean, message: string, data: any}>}
|
|
*/
|
|
export const uploadBillFile = (file, type) => {
|
|
const formData = new FormData()
|
|
formData.append('file', file)
|
|
formData.append('type', type)
|
|
|
|
return axios({
|
|
url: `${import.meta.env.VITE_API_BASE_URL}/BillImport/UploadFile`,
|
|
method: 'post',
|
|
data: formData,
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
Authorization: `Bearer ${useAuthStore().token || ''}`
|
|
},
|
|
timeout: 60000 // 文件上传增加超时时间
|
|
})
|
|
.then((response) => {
|
|
const { data } = response
|
|
|
|
if (data.success === false) {
|
|
showToast(data.message || '上传失败')
|
|
return Promise.reject(new Error(data.message || '上传失败'))
|
|
}
|
|
|
|
return data
|
|
})
|
|
.catch((error) => {
|
|
console.error('上传错误:', error)
|
|
|
|
if (error.response) {
|
|
const { status, data } = error.response
|
|
let message = '上传失败'
|
|
|
|
switch (status) {
|
|
case 400:
|
|
message = data?.message || '请求参数错误'
|
|
break
|
|
case 401:
|
|
message = '未授权,请先登录'
|
|
break
|
|
case 403:
|
|
message = '没有权限'
|
|
break
|
|
case 413:
|
|
message = '文件过大'
|
|
break
|
|
case 500:
|
|
message = '服务器错误'
|
|
break
|
|
}
|
|
|
|
showToast(message)
|
|
return Promise.reject(new Error(message))
|
|
}
|
|
|
|
showToast('网络错误,请检查网络连接')
|
|
return Promise.reject(error)
|
|
})
|
|
}
|