修改用户上传
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 导出认证服务实例
|
||||
|
||||
Reference in New Issue
Block a user