环境搭建配置
This commit is contained in:
@@ -39,48 +39,50 @@ export interface BrandTaskMutationResponse {
|
||||
error?: string
|
||||
}
|
||||
|
||||
const API_PREFIX = '/new'
|
||||
|
||||
export function getBrandTaskEventsUrl(taskId: string | number) {
|
||||
return `/api/brand/tasks/${taskId}/events`
|
||||
return `${API_PREFIX}/api/brand/tasks/${taskId}/events`
|
||||
}
|
||||
|
||||
export function getBrandTaskDownloadUrl(taskId: string | number) {
|
||||
return `/api/brand/download/${taskId}`
|
||||
return `${API_PREFIX}/api/brand/download/${taskId}`
|
||||
}
|
||||
|
||||
export function getBrandTemplateXlsxUrl() {
|
||||
return '/static/品牌文档格式_模板.xlsx'
|
||||
return `${API_PREFIX}/static/品牌文档格式_模板.xlsx`
|
||||
}
|
||||
|
||||
export function getBrandTemplateZipUrl() {
|
||||
return '/static/模板2-以文件夹方式上传.zip'
|
||||
return `${API_PREFIX}/static/模板2-以文件夹方式上传.zip`
|
||||
}
|
||||
|
||||
export function expandBrandFolder(folder: string) {
|
||||
return requestPostJson<BrandExpandFolderResponse>('/api/brand/expand-folder', { folder })
|
||||
return requestPostJson<BrandExpandFolderResponse>(`${API_PREFIX}/api/brand/expand-folder`, { folder })
|
||||
}
|
||||
|
||||
export function runBrandNow(paths: string[], strategy: string) {
|
||||
return requestPostJson<BrandTaskMutationResponse>('/api/brand/run', { paths, strategy })
|
||||
return requestPostJson<BrandTaskMutationResponse>(`${API_PREFIX}/api/brand/run`, { paths, strategy })
|
||||
}
|
||||
|
||||
export function createBrandTask(paths: string[], strategy: string) {
|
||||
return requestPostJson<BrandTaskMutationResponse>('/api/brand/tasks', { paths, strategy })
|
||||
return requestPostJson<BrandTaskMutationResponse>(`${API_PREFIX}/api/brand/tasks`, { paths, strategy })
|
||||
}
|
||||
|
||||
export function getBrandTasks() {
|
||||
return requestGetJson<BrandTaskListResponse>('/api/brand/tasks')
|
||||
return requestGetJson<BrandTaskListResponse>(`${API_PREFIX}/api/brand/tasks`)
|
||||
}
|
||||
|
||||
export function getBrandTask(taskId: string | number) {
|
||||
return requestGetJson<BrandTaskDetailResponse>(`/api/brand/tasks/${taskId}`)
|
||||
return requestGetJson<BrandTaskDetailResponse>(`${API_PREFIX}/api/brand/tasks/${taskId}`)
|
||||
}
|
||||
|
||||
export function cancelBrandTask(taskId: string | number) {
|
||||
return requestPostJson<BrandTaskMutationResponse>(`/api/brand/tasks/${taskId}/cancel`)
|
||||
return requestPostJson<BrandTaskMutationResponse>(`${API_PREFIX}/api/brand/tasks/${taskId}/cancel`)
|
||||
}
|
||||
|
||||
export function deleteBrandTask(taskId: string | number) {
|
||||
return requestDeleteJson<BrandTaskMutationResponse>(`/api/brand/tasks/${taskId}`)
|
||||
return requestDeleteJson<BrandTaskMutationResponse>(`${API_PREFIX}/api/brand/tasks/${taskId}`)
|
||||
}
|
||||
|
||||
export function createBrandTaskEvents(taskId: string | number) {
|
||||
|
||||
@@ -6,26 +6,36 @@ import axios, {
|
||||
type InternalAxiosRequestConfig,
|
||||
} from 'axios'
|
||||
|
||||
export interface ApiSuccess<T> {
|
||||
export interface LegacyApiSuccess<T> {
|
||||
success: true
|
||||
msg?: string
|
||||
data?: T
|
||||
}
|
||||
|
||||
export interface ApiFailure {
|
||||
export interface LegacyApiFailure {
|
||||
success: false
|
||||
error?: string
|
||||
}
|
||||
|
||||
export type ApiResponse<T> = ApiSuccess<T> | ApiFailure
|
||||
export type ApiResponse<T> = LegacyApiSuccess<T> | LegacyApiFailure
|
||||
export interface JavaApiResponse<T> {
|
||||
success: boolean
|
||||
message: string
|
||||
data: T | null
|
||||
}
|
||||
export type RequestOptions<D = unknown> = AxiosRequestConfig<D>
|
||||
|
||||
function extractErrorMessage(error: unknown) {
|
||||
if (error instanceof AxiosError) {
|
||||
const data = error.response?.data
|
||||
|
||||
if (data && typeof data === 'object' && 'error' in data) {
|
||||
return String(data.error)
|
||||
if (data && typeof data === 'object') {
|
||||
if ('error' in data && data.error) {
|
||||
return String(data.error)
|
||||
}
|
||||
if ('message' in data && data.message) {
|
||||
return String(data.message)
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof data === 'string' && data.trim()) {
|
||||
@@ -105,3 +115,11 @@ export const requestGetJson = get
|
||||
export const requestPostJson = post
|
||||
export const requestPutJson = put
|
||||
export const requestDeleteJson = del
|
||||
|
||||
export async function unwrapJavaResponse<T>(promise: Promise<JavaApiResponse<T>>) {
|
||||
const response = await promise
|
||||
if (!response.success) {
|
||||
throw new Error(response.message || '请求失败')
|
||||
}
|
||||
return response.data as T
|
||||
}
|
||||
|
||||
162
frontend-vue/src/shared/api/java-modules.ts
Normal file
162
frontend-vue/src/shared/api/java-modules.ts
Normal file
@@ -0,0 +1,162 @@
|
||||
import { del, get, http, post, type JavaApiResponse, unwrapJavaResponse } from '@/shared/api/http'
|
||||
|
||||
const JAVA_API_PREFIX = '/newApi/api'
|
||||
|
||||
export interface UploadedFileRef {
|
||||
fileKey: string
|
||||
originalFilename?: string
|
||||
}
|
||||
|
||||
export interface UploadFileVo {
|
||||
fileKey: string
|
||||
originalFilename: string
|
||||
localPath: string
|
||||
size: number
|
||||
}
|
||||
|
||||
export interface DedupeResultItem {
|
||||
resultId?: number
|
||||
sourceFilename: string
|
||||
outputFilename?: string
|
||||
success: boolean
|
||||
error?: string
|
||||
downloadUrl?: string
|
||||
}
|
||||
|
||||
export interface DedupeRunVo {
|
||||
total: number
|
||||
successCount: number
|
||||
failedCount: number
|
||||
items: DedupeResultItem[]
|
||||
}
|
||||
|
||||
export interface DedupeHistoryVo {
|
||||
items: DedupeResultItem[]
|
||||
}
|
||||
|
||||
export interface DedupeRunRequest {
|
||||
files: UploadedFileRef[]
|
||||
selectedColumns: string[]
|
||||
keepIntegerIds: boolean
|
||||
keepUnderscoreIds: boolean
|
||||
}
|
||||
|
||||
export interface SplitResultItem {
|
||||
resultId?: number
|
||||
sourceFilename: string
|
||||
outputFilename?: string
|
||||
success: boolean
|
||||
error?: string
|
||||
rowCount?: number
|
||||
downloadUrl?: string
|
||||
}
|
||||
|
||||
export interface SplitRunVo {
|
||||
total: number
|
||||
successCount: number
|
||||
failedCount: number
|
||||
items: SplitResultItem[]
|
||||
}
|
||||
|
||||
export interface SplitHistoryVo {
|
||||
items: SplitResultItem[]
|
||||
}
|
||||
|
||||
export interface SplitRunRequest {
|
||||
files: UploadedFileRef[]
|
||||
selectedColumns: string[]
|
||||
splitMode: 'rows_per_file' | 'parts'
|
||||
rowsPerFile?: number
|
||||
parts?: number
|
||||
}
|
||||
|
||||
export interface ConvertResultItem {
|
||||
resultId?: number
|
||||
sourceFilename: string
|
||||
outputFilename?: string
|
||||
success: boolean
|
||||
error?: string
|
||||
downloadUrl?: string
|
||||
}
|
||||
|
||||
export interface ConvertRunVo {
|
||||
total: number
|
||||
successCount: number
|
||||
failedCount: number
|
||||
items: ConvertResultItem[]
|
||||
}
|
||||
|
||||
export interface ConvertHistoryVo {
|
||||
items: ConvertResultItem[]
|
||||
}
|
||||
|
||||
export interface ConvertRunRequest {
|
||||
files: UploadedFileRef[]
|
||||
templateId: string
|
||||
}
|
||||
|
||||
export interface ConvertTemplateVo {
|
||||
id: string
|
||||
templateCode: string
|
||||
templateName: string
|
||||
outputFilename: string
|
||||
isDefault?: boolean
|
||||
builtIn?: boolean
|
||||
}
|
||||
|
||||
export interface ExcelInfoVo {
|
||||
headers: string[]
|
||||
totalRows: number
|
||||
}
|
||||
|
||||
export function getExcelInfo(fileKey: string) {
|
||||
return unwrapJavaResponse(get<JavaApiResponse<ExcelInfoVo>>(`${JAVA_API_PREFIX}/files/excel-info`, {
|
||||
params: { fileKey },
|
||||
}))
|
||||
}
|
||||
|
||||
export function runDedupe(request: DedupeRunRequest) {
|
||||
return unwrapJavaResponse(post<JavaApiResponse<DedupeRunVo>, DedupeRunRequest>(`${JAVA_API_PREFIX}/dedupe/run`, request))
|
||||
}
|
||||
|
||||
export function getDedupeHistory() {
|
||||
return unwrapJavaResponse(get<JavaApiResponse<DedupeHistoryVo>>(`${JAVA_API_PREFIX}/dedupe/history`))
|
||||
}
|
||||
|
||||
export function deleteDedupeHistory(resultId: number) {
|
||||
return unwrapJavaResponse(del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/dedupe/history/${resultId}`))
|
||||
}
|
||||
|
||||
export function runSplit(request: SplitRunRequest) {
|
||||
return unwrapJavaResponse(post<JavaApiResponse<SplitRunVo>, SplitRunRequest>(`${JAVA_API_PREFIX}/split/run`, request))
|
||||
}
|
||||
|
||||
export function getSplitHistory() {
|
||||
return unwrapJavaResponse(get<JavaApiResponse<SplitHistoryVo>>(`${JAVA_API_PREFIX}/split/history`))
|
||||
}
|
||||
|
||||
export function deleteSplitHistory(resultId: number) {
|
||||
return unwrapJavaResponse(del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/split/history/${resultId}`))
|
||||
}
|
||||
|
||||
export function getConvertTemplates() {
|
||||
return unwrapJavaResponse(get<JavaApiResponse<ConvertTemplateVo[]>>(`${JAVA_API_PREFIX}/convert/templates`))
|
||||
}
|
||||
|
||||
export function runConvert(request: ConvertRunRequest) {
|
||||
return unwrapJavaResponse(post<JavaApiResponse<ConvertRunVo>, ConvertRunRequest>(`${JAVA_API_PREFIX}/convert/run`, request))
|
||||
}
|
||||
|
||||
export function getConvertHistory() {
|
||||
return unwrapJavaResponse(get<JavaApiResponse<ConvertHistoryVo>>(`${JAVA_API_PREFIX}/convert/history`))
|
||||
}
|
||||
|
||||
export function deleteConvertHistory(resultId: number) {
|
||||
return unwrapJavaResponse(del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/convert/history/${resultId}`))
|
||||
}
|
||||
|
||||
export function getJavaDownloadUrl(path: string) {
|
||||
return path.startsWith('http://') || path.startsWith('https://') ? path : `${JAVA_API_PREFIX}${path}`
|
||||
}
|
||||
|
||||
export { JAVA_API_PREFIX, http }
|
||||
Reference in New Issue
Block a user