fetch(modify):修改bug
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 5m20s

This commit is contained in:
sexygoat
2026-01-31 16:33:21 +08:00
parent 16d53709ef
commit ecb79dae43
20 changed files with 1369 additions and 649 deletions

View File

@@ -8,7 +8,7 @@ import type { BaseResponse } from '@/types/api'
/**
* 文件用途枚举
*/
export type FilePurpose = 'iot_import' | 'export' | 'attachment'
export type FilePurpose = 'iot_import' | 'device_import' | 'export' | 'attachment'
/**
* 获取上传 URL 请求参数
@@ -56,18 +56,18 @@ export class StorageService extends BaseService {
* - 预签名 URL 有效期 15 分钟,请及时使用
* - 上传时 Content-Type 需与请求时一致
* - file_key 在上传成功后永久有效
* - 开发环境通过代理上传,生产环境直接上传
*
* @param uploadUrl 预签名 URL
* @param uploadUrl 预签名 URL(由对象存储生成)
* @param file 文件
* @param contentType 文件类型(需与 getUploadUrl 请求时保持一致)
*/
static async uploadFile(uploadUrl: string, file: File, contentType?: string): Promise<void> {
try {
// 开发环境下,使用代理路径避免 CORS 问题
// 开发环境使用代理解决 CORS 问题
let finalUrl = uploadUrl
if (import.meta.env.DEV) {
// 将对象存储域名替换为代理路径
// 例如http://obs-helf.cucloud.cn/cmp/... -> /obs-proxy/cmp/...
// 将对象存储域名替换为代理路径
finalUrl = uploadUrl.replace(/^https?:\/\/obs-helf\.cucloud\.cn/, '/obs-proxy')
}
@@ -81,8 +81,7 @@ export class StorageService extends BaseService {
const response = await fetch(finalUrl, {
method: 'PUT',
body: file,
headers,
mode: 'cors' // 明确指定 CORS 模式
headers
})
if (!response.ok) {