feat: 接入资产文件上传服务
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
import { AxiosProgressEvent } from 'axios'
|
||||
import { request } from '@/api/request'
|
||||
|
||||
/** 上传文件 */
|
||||
const FtsUpload = (data: FormData, onUploadProgress?: (progress: number) => void) => {
|
||||
data.append('provider', 'local')
|
||||
data.append('bucket', 'visual')
|
||||
|
||||
return request.post(`/Assets/v1/fts/uploader`, data, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
onUploadProgress: onUploadProgress
|
||||
? (progressEvent: AxiosProgressEvent) => {
|
||||
if (progressEvent.total) {
|
||||
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
||||
onUploadProgress(percentCompleted)
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
})
|
||||
}
|
||||
|
||||
export default FtsUpload
|
||||
@@ -1,5 +1,28 @@
|
||||
import { request } from '@/api/request'
|
||||
|
||||
export interface Floor {
|
||||
id?: number
|
||||
name?: string
|
||||
datacenter_id?: number
|
||||
floor_number?: number
|
||||
status?: string
|
||||
area?: number
|
||||
height?: number
|
||||
load_bearing?: number
|
||||
enabled?: boolean
|
||||
layout_plan?: string
|
||||
layout_plan_file_id?: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export type SaveFloorPayload = Omit<Floor, 'layout_plan'>
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
message: string
|
||||
details: T
|
||||
}
|
||||
|
||||
/** 获取楼层列表(分页) */
|
||||
export const fetchFloorList = (data?: { page?: number; page_size?: number; keyword?: string; datacenter_id?: number; status?: string }) => {
|
||||
return request.post('/Assets/v1/floor/list', data || {})
|
||||
@@ -16,13 +39,13 @@ export const fetchFloorListByDatacenter = (datacenterId: number, params?: { name
|
||||
}
|
||||
|
||||
/** 创建楼层 */
|
||||
export const createFloor = (data: any) => {
|
||||
return request.post('/Assets/v1/floor/create', data)
|
||||
export const createFloor = (data: SaveFloorPayload) => {
|
||||
return request.post<ApiResponse<Floor>>('/Assets/v1/floor/create', data)
|
||||
}
|
||||
|
||||
/** 更新楼层 */
|
||||
export const updateFloor = (data: any) => {
|
||||
return request.put('/Assets/v1/floor/update', data)
|
||||
export const updateFloor = (data: SaveFloorPayload) => {
|
||||
return request.put<ApiResponse<Floor>>('/Assets/v1/floor/update', data)
|
||||
}
|
||||
|
||||
/** 删除楼层 */
|
||||
|
||||
48
src/api/ops/floorFile.ts
Normal file
48
src/api/ops/floorFile.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { request } from '@/api/request'
|
||||
|
||||
export interface PendingUpload {
|
||||
file_id: string
|
||||
object_key: string
|
||||
upload: {
|
||||
method: string
|
||||
url: string
|
||||
headers: Record<string, string>
|
||||
expires_at: string
|
||||
}
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
message: string
|
||||
details: T
|
||||
}
|
||||
|
||||
/** 初始化楼层布局文件并直传 OSS。 */
|
||||
export async function uploadFloorLayout(file: File): Promise<PendingUpload> {
|
||||
const response = await request.post<ApiResponse<PendingUpload>>('/Assets/v1/floor/layout/init', {
|
||||
filename: file.name,
|
||||
size: file.size,
|
||||
content_type: file.type || 'application/octet-stream',
|
||||
})
|
||||
|
||||
if (response.code !== 0) {
|
||||
throw new Error(response.message || '初始化楼层布局文件上传失败')
|
||||
}
|
||||
|
||||
const pendingUpload = response.details
|
||||
if (!pendingUpload?.file_id || !pendingUpload.upload?.method || !pendingUpload.upload?.url) {
|
||||
throw new Error('楼层布局文件上传参数不完整')
|
||||
}
|
||||
|
||||
const uploadResponse = await fetch(pendingUpload.upload.url, {
|
||||
method: pendingUpload.upload.method,
|
||||
headers: pendingUpload.upload.headers,
|
||||
body: file,
|
||||
credentials: 'omit',
|
||||
})
|
||||
if (!uploadResponse.ok) {
|
||||
throw new Error(`上传楼层布局文件失败: HTTP ${uploadResponse.status}`)
|
||||
}
|
||||
|
||||
return pendingUpload
|
||||
}
|
||||
@@ -23,17 +23,6 @@ export interface GoViewProjectData {
|
||||
createUserId: string
|
||||
}
|
||||
|
||||
export interface GoViewFile {
|
||||
id: string
|
||||
fileName: string
|
||||
fileSize: number
|
||||
fileSuffix: string
|
||||
virtualKey: string
|
||||
relativePath: string
|
||||
absolutePath: string
|
||||
createTime: string
|
||||
}
|
||||
|
||||
export interface OssInfo {
|
||||
BucketName: string
|
||||
bucketURL: string
|
||||
@@ -106,15 +95,6 @@ export const publishProject = (data: { identity: string; state: -1 | 1 }) => {
|
||||
return request.put<GoViewResponse<{ identity: string; state: number }>>('/Visual/v1/project/publish', data)
|
||||
}
|
||||
|
||||
/** 上传文件 */
|
||||
export const uploadFile = (file: File) => {
|
||||
const formData = new FormData()
|
||||
formData.append('object', file)
|
||||
return request.post<GoViewResponse<GoViewFile>>('/Visual/v1/project/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
}
|
||||
|
||||
/** 保存项目数据 */
|
||||
export const saveProjectData = (projectId: string, content: string) => {
|
||||
const formData = new URLSearchParams()
|
||||
|
||||
Reference in New Issue
Block a user