This commit is contained in:
+52
-19
@@ -1,8 +1,25 @@
|
|||||||
// API 服务层
|
// API 服务层
|
||||||
import api from '@/utils/api'
|
import api from '@/utils/api'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import type { ApiResponse, FileInfo, ConfigState, AdminUser, FileUploadResponse, TextSendResponse, DashboardData, FileListResponse, FileEditForm } from '@/types'
|
import type {
|
||||||
import type { UploadProgress, PresignInitRequest, PresignInitResponse, PresignConfirmRequest, PresignUploadResult, PresignStatusResponse } from '@/types'
|
ApiResponse,
|
||||||
|
FileInfo,
|
||||||
|
ConfigState,
|
||||||
|
AdminUser,
|
||||||
|
FileUploadResponse,
|
||||||
|
TextSendResponse,
|
||||||
|
DashboardData,
|
||||||
|
FileListResponse,
|
||||||
|
FileEditForm
|
||||||
|
} from '@/types'
|
||||||
|
import type {
|
||||||
|
UploadProgress,
|
||||||
|
PresignInitRequest,
|
||||||
|
PresignInitResponse,
|
||||||
|
PresignConfirmRequest,
|
||||||
|
PresignUploadResult,
|
||||||
|
PresignStatusResponse
|
||||||
|
} from '@/types'
|
||||||
|
|
||||||
// 系统配置服务
|
// 系统配置服务
|
||||||
export class ConfigService {
|
export class ConfigService {
|
||||||
@@ -30,6 +47,7 @@ export class FileService {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'multipart/form-data'
|
||||||
},
|
},
|
||||||
|
timeout: 0, // 禁用超时限制
|
||||||
onUploadProgress: (progressEvent) => {
|
onUploadProgress: (progressEvent) => {
|
||||||
if (onProgress && progressEvent.total) {
|
if (onProgress && progressEvent.total) {
|
||||||
const progress: UploadProgress = {
|
const progress: UploadProgress = {
|
||||||
@@ -62,19 +80,28 @@ export class FileService {
|
|||||||
return api.post('/admin/file/delete', { id: fileId })
|
return api.post('/admin/file/delete', { id: fileId })
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFileList(page = 1, limit = 10): Promise<ApiResponse<{
|
static async getFileList(
|
||||||
files: FileInfo[]
|
page = 1,
|
||||||
total: number
|
limit = 10
|
||||||
page: number
|
): Promise<
|
||||||
limit: number
|
ApiResponse<{
|
||||||
}>> {
|
files: FileInfo[]
|
||||||
|
total: number
|
||||||
|
page: number
|
||||||
|
limit: number
|
||||||
|
}>
|
||||||
|
> {
|
||||||
return api.get('/admin/file/list', {
|
return api.get('/admin/file/list', {
|
||||||
params: { page, size: limit }
|
params: { page, size: limit }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件管理相关方法
|
// 文件管理相关方法
|
||||||
static async getAdminFileList(params: { page: number; size: number; keyword?: string }): Promise<ApiResponse<FileListResponse>> {
|
static async getAdminFileList(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
keyword?: string
|
||||||
|
}): Promise<ApiResponse<FileListResponse>> {
|
||||||
return api.get('/admin/file/list', { params })
|
return api.get('/admin/file/list', { params })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +115,9 @@ export class FileService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async downloadAdminFile(id: number): Promise<{ data: Blob; headers: Record<string, string> }> {
|
static async downloadAdminFile(
|
||||||
|
id: number
|
||||||
|
): Promise<{ data: Blob; headers: Record<string, string> }> {
|
||||||
return api.get('/admin/file/download', {
|
return api.get('/admin/file/download', {
|
||||||
params: { id },
|
params: { id },
|
||||||
responseType: 'blob'
|
responseType: 'blob'
|
||||||
@@ -113,14 +142,16 @@ export class AuthService {
|
|||||||
|
|
||||||
// 统计服务
|
// 统计服务
|
||||||
export class StatsService {
|
export class StatsService {
|
||||||
static async getDashboardStats(): Promise<ApiResponse<{
|
static async getDashboardStats(): Promise<
|
||||||
totalFiles: number
|
ApiResponse<{
|
||||||
totalDownloads: number
|
totalFiles: number
|
||||||
todayUploads: number
|
totalDownloads: number
|
||||||
todayDownloads: number
|
todayUploads: number
|
||||||
storageUsed: number
|
todayDownloads: number
|
||||||
recentFiles: FileInfo[]
|
storageUsed: number
|
||||||
}>> {
|
recentFiles: FileInfo[]
|
||||||
|
}>
|
||||||
|
> {
|
||||||
return api.get('/admin/dashboard')
|
return api.get('/admin/dashboard')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +184,7 @@ export class PresignUploadService {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'multipart/form-data'
|
||||||
},
|
},
|
||||||
|
timeout: 0,
|
||||||
onUploadProgress: (progressEvent) => {
|
onUploadProgress: (progressEvent) => {
|
||||||
if (onProgress && progressEvent.total) {
|
if (onProgress && progressEvent.total) {
|
||||||
const progress: UploadProgress = {
|
const progress: UploadProgress = {
|
||||||
@@ -203,6 +235,7 @@ export class PresignUploadService {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/octet-stream'
|
'Content-Type': 'application/octet-stream'
|
||||||
},
|
},
|
||||||
|
timeout: 0,
|
||||||
onUploadProgress: (progressEvent) => {
|
onUploadProgress: (progressEvent) => {
|
||||||
if (onProgress && progressEvent.total) {
|
if (onProgress && progressEvent.total) {
|
||||||
const progress: UploadProgress = {
|
const progress: UploadProgress = {
|
||||||
@@ -230,4 +263,4 @@ export const services = {
|
|||||||
presignUpload: PresignUploadService
|
presignUpload: PresignUploadService
|
||||||
}
|
}
|
||||||
|
|
||||||
export default services
|
export default services
|
||||||
|
|||||||
@@ -858,6 +858,7 @@ const handleChunkUpload = async (file: File) => {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'multipart/form-data'
|
||||||
},
|
},
|
||||||
|
timeout: 0, // 禁用超时限制
|
||||||
onUploadProgress: (progressEvent: { loaded: number; total?: number }) => {
|
onUploadProgress: (progressEvent: { loaded: number; total?: number }) => {
|
||||||
// 计算已上传块的大小
|
// 计算已上传块的大小
|
||||||
const uploadedSize = Array.from(uploadedChunks).reduce((acc, idx) => {
|
const uploadedSize = Array.from(uploadedChunks).reduce((acc, idx) => {
|
||||||
@@ -912,6 +913,7 @@ const handleDefaultFileUpload = async (file: File) => {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'multipart/form-data'
|
||||||
},
|
},
|
||||||
|
timeout: 0, // 禁用超时限制
|
||||||
onUploadProgress: (progressEvent: { loaded: number; total?: number }) => {
|
onUploadProgress: (progressEvent: { loaded: number; total?: number }) => {
|
||||||
const percentCompleted = Math.round((progressEvent.loaded * 100) / (progressEvent.total || 1))
|
const percentCompleted = Math.round((progressEvent.loaded * 100) / (progressEvent.total || 1))
|
||||||
uploadProgress.value = percentCompleted
|
uploadProgress.value = percentCompleted
|
||||||
@@ -937,7 +939,7 @@ const handlePresignedUpload = async (file: File) => {
|
|||||||
uploadProgress.value = progress.percentage
|
uploadProgress.value = progress.percentage
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
|
|||||||
Reference in New Issue
Block a user