修改用户上传

This commit is contained in:
张成
2025-09-08 11:39:59 +08:00
parent b5405c58a4
commit e2d717204f
10 changed files with 284 additions and 78 deletions

View File

@@ -1,7 +1,7 @@
import httpService from './httpService'
import type { ApiResponse } from './httpService'
import Taro from '@tarojs/taro'
import envConfig from '@/config/env'
import { API_CONFIG } from '@/config/api'
import httpService from './httpService'
// 用户接口
export interface UploadFilesData {
@@ -39,18 +39,28 @@ export interface uploadFileResponseData {
updated_at: string,
}
function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms))
}
// 发布球局类
class UploadApi {
async upload(req: UploadFilesData): Promise<{ id: string, data: uploadFileResponseData }> {
// return httpService.post('/files/upload', req, {
// showLoading: true,
// })
let fullUrl = `${envConfig.apiBaseURL}/api/gallery/upload`
// 后门id用于调试
let userid = httpService.getHashParam("userIdTest")
if (userid) {
if (fullUrl.indexOf("?") > -1) {
fullUrl += `&userIdTest45=${userid}`
}
else {
fullUrl += `?userIdTest45=${userid}`
}
}
const { id, ...rest } = req
return Taro.uploadFile({
url: `${envConfig.apiBaseURL}/api/gallery/upload`,
url: fullUrl,
filePath: rest.filePath,
name: 'file',
formData: {
@@ -69,6 +79,42 @@ class UploadApi {
async batchUpload(req: UploadFilesData[]): Promise<{ id: string, data: uploadFileResponseData }[]> {
return Promise.all(req.map(item => this.upload(item)))
}
// 上传单张图片到OSS
async upload_oss_img(file_path: string): Promise<any> {
try {
let fullUrl = `${envConfig.apiBaseURL}/api${API_CONFIG.UPLOAD.OSS_IMG}`
// 后门id用于调试
let userid = httpService.getHashParam("userIdTest")
if (userid) {
if (fullUrl.indexOf("?") > -1) {
fullUrl += `&userIdTest45=${userid}`
}
else {
fullUrl += `?userIdTest45=${userid}`
}
}
const response = await Taro.uploadFile({
url: fullUrl,
filePath: file_path,
name: 'file',
});
const result = JSON.parse(response.data);
if (result.code === 0) {
return result.data;
} else {
throw new Error(result.message || '上传失败');
}
} catch (error) {
console.error('上传图片失败:', error);
throw error;
}
}
}
// 导出认证服务实例