环境搭建配置
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 }
|
||||
@@ -1,149 +1,24 @@
|
||||
export interface SplitExcelPayload {
|
||||
paths: string[]
|
||||
selected_columns: string[]
|
||||
split_mode: 'rows_per_file' | 'parts'
|
||||
rows_per_file?: number
|
||||
parts?: number
|
||||
output_dir?: string
|
||||
}
|
||||
|
||||
export interface SplitExcelResultItem {
|
||||
result_id?: number
|
||||
source_path: string
|
||||
output_path?: string
|
||||
success: boolean
|
||||
error?: string
|
||||
row_count?: number
|
||||
}
|
||||
|
||||
export interface SplitExcelSummary {
|
||||
total: number
|
||||
success_count: number
|
||||
failed_count: number
|
||||
output_dir?: string
|
||||
}
|
||||
|
||||
export interface SplitExcelResponse {
|
||||
success: boolean
|
||||
summary?: SplitExcelSummary
|
||||
items?: SplitExcelResultItem[]
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface ExcelInfoResponse {
|
||||
success: boolean
|
||||
headers?: string[]
|
||||
total_rows?: number
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface CleanExcelPayload {
|
||||
paths: string[]
|
||||
selected_columns: string[]
|
||||
keep_integer_ids?: boolean
|
||||
keep_underscore_ids?: boolean
|
||||
output_dir?: string
|
||||
}
|
||||
|
||||
export interface CleanExcelResultItem {
|
||||
result_id?: number
|
||||
source_path: string
|
||||
output_path?: string
|
||||
success: boolean
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface ConvertTxtPayload {
|
||||
paths: string[]
|
||||
output_dir?: string
|
||||
template_id: string
|
||||
}
|
||||
|
||||
export interface ConvertTxtTemplateItem {
|
||||
id: string
|
||||
label: string
|
||||
output_filename: string
|
||||
is_default?: boolean
|
||||
built_in?: boolean
|
||||
}
|
||||
|
||||
export interface ConvertTxtResultItem {
|
||||
result_id?: number
|
||||
source_path: string
|
||||
output_path?: string
|
||||
success: boolean
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface ConvertTxtSummary {
|
||||
total: number
|
||||
success_count: number
|
||||
failed_count: number
|
||||
output_dir?: string
|
||||
}
|
||||
|
||||
export interface ConvertTxtResponse {
|
||||
success: boolean
|
||||
summary?: ConvertTxtSummary
|
||||
items?: ConvertTxtResultItem[]
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface CleanExcelSummary {
|
||||
total: number
|
||||
success_count: number
|
||||
failed_count: number
|
||||
output_dir?: string
|
||||
}
|
||||
|
||||
export interface CleanExcelResponse {
|
||||
success: boolean
|
||||
summary?: CleanExcelSummary
|
||||
items?: CleanExcelResultItem[]
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface ConvertTxtHistoryResponse {
|
||||
success: boolean
|
||||
items?: ConvertTxtResultItem[]
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface SplitExcelHistoryResponse {
|
||||
success: boolean
|
||||
items?: SplitExcelResultItem[]
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface CleanExcelHistoryResponse {
|
||||
success: boolean
|
||||
items?: CleanExcelResultItem[]
|
||||
error?: string
|
||||
export interface UploadedJavaFile {
|
||||
fileKey: string
|
||||
originalFilename: string
|
||||
localPath: string
|
||||
size: number
|
||||
}
|
||||
|
||||
export interface PywebviewApi {
|
||||
select_brand_xlsx_files?: () => Promise<string[]>
|
||||
select_clean_xlsx_files?: () => Promise<string[]>
|
||||
select_brand_folder?: () => Promise<string | null>
|
||||
select_clean_folder?: () => Promise<string | null>
|
||||
close?: () => Promise<void>
|
||||
minimize?: () => Promise<void>
|
||||
maximize?: () => Promise<void>
|
||||
toggle_maximize?: () => Promise<void>
|
||||
save_image?: (urlOrData: string, filename?: string) => Promise<{ success: boolean; path?: string; error?: string }>
|
||||
save_image_to_folder?: (urlOrData: string, dirPath: string, filename?: string) => Promise<{ success: boolean; path?: string; error?: string }>
|
||||
select_folder?: () => Promise<string | null>
|
||||
get_excel_headers?: (filePath: string) => Promise<{ success: boolean; headers?: string[]; error?: string }>
|
||||
get_dedupe_history?: () => Promise<CleanExcelHistoryResponse>
|
||||
get_convert_history?: () => Promise<ConvertTxtHistoryResponse>
|
||||
get_split_history?: () => Promise<SplitExcelHistoryResponse>
|
||||
delete_history_item?: (moduleType: string, resultId: number) => Promise<{ success: boolean; error?: string }>
|
||||
get_excel_info?: (filePath: string) => Promise<ExcelInfoResponse>
|
||||
clean_excel_files?: (payload: CleanExcelPayload) => Promise<CleanExcelResponse>
|
||||
split_excel_files?: (payload: SplitExcelPayload) => Promise<SplitExcelResponse>
|
||||
list_txt_templates?: () => Promise<ConvertTxtTemplateItem[]>
|
||||
import_txt_template?: (name?: string) => Promise<{ success: boolean; template?: ConvertTxtTemplateItem; error?: string }>
|
||||
set_default_txt_template?: (templateId: string) => Promise<{ success: boolean; error?: string }>
|
||||
delete_txt_template?: (templateId: string) => Promise<{ success: boolean; error?: string }>
|
||||
convert_excel_to_uk_txt?: (payload: ConvertTxtPayload) => Promise<ConvertTxtResponse>
|
||||
open_path?: (path: string) => Promise<{ success: boolean; error?: string }>
|
||||
select_brand_xlsx_files?: () => Promise<string[]>
|
||||
select_brand_folder?: () => Promise<string | null>
|
||||
upload_file_to_java?: (filePath: string) => Promise<{ success: boolean; message?: string; data?: UploadedJavaFile; error?: string }>
|
||||
save_file_from_url?: (url: string, filename: string) => Promise<{ success: boolean; path?: string; error?: string }>
|
||||
save_template_xlsx?: () => Promise<{ success: boolean; path?: string; error?: string }>
|
||||
save_template_zip?: () => Promise<{ success: boolean; path?: string; error?: string }>
|
||||
save_file_from_url?: (url: string, filename: string) => Promise<{ success: boolean; path?: string; error?: string }>
|
||||
}
|
||||
|
||||
declare global {
|
||||
@@ -154,8 +29,26 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
let cachedPywebviewApi: PywebviewApi | undefined
|
||||
let pywebviewReadyBound = false
|
||||
|
||||
function syncPywebviewApi() {
|
||||
cachedPywebviewApi = window.pywebview?.api
|
||||
return cachedPywebviewApi
|
||||
}
|
||||
|
||||
function bindPywebviewReady() {
|
||||
if (pywebviewReadyBound || typeof window === 'undefined' || !window.addEventListener) return
|
||||
pywebviewReadyBound = true
|
||||
window.addEventListener('pywebviewready', () => {
|
||||
syncPywebviewApi()
|
||||
})
|
||||
}
|
||||
|
||||
bindPywebviewReady()
|
||||
|
||||
export function getPywebviewApi() {
|
||||
return window.pywebview?.api
|
||||
return syncPywebviewApi() || cachedPywebviewApi
|
||||
}
|
||||
|
||||
export function hasPywebview() {
|
||||
|
||||
Reference in New Issue
Block a user