refactor(品牌工具页): 抽取 formatDateTime 与 uploadPathsToJava 公共工具
- 新增 shared/utils/datetime.ts:13 个品牌页逐字重复的 formatDateTime 收敛为一处; 语义不同的 3 个变体(toLocaleString / 字符串切片 / 支持时间戳)保留不动 - 新增 shared/utils/upload-to-java.ts:10 个品牌页的上传循环收敛,api 依赖注入便于单测; 保留 uploadOss(品牌Tab)与 returnEmptyWhenUnavailable(跟价)两处行为差异 - 补 datetime / upload-to-java 单测 10 例 净减约 327 行;vue-tsc 构建与 690 个前端单测全通过
This commit is contained in:
@@ -191,7 +191,7 @@ import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.v
|
||||
import TaskCenterPanel from '@/shared/components/tasks/TaskCenterPanel.vue'
|
||||
import type { TaskItemView, TaskStatCard } from '@/shared/components/tasks/types'
|
||||
import ZiniaoVersionSetting from '@/shared/components/ZiniaoVersionSetting.vue'
|
||||
import { expandBrandFolderRecursive, type BrandExpandFolderItem } from '@/shared/api/brand'
|
||||
import { expandBrandFolderRecursive } from '@/shared/api/brand'
|
||||
import {
|
||||
activatePublishFile,
|
||||
activatePublishTask,
|
||||
@@ -219,6 +219,7 @@ import {
|
||||
} from '@/shared/dispatch-guard'
|
||||
import { passGuard } from '@/shared/dispatch-guard-ui'
|
||||
import { useZiniaoVersion, type ZiniaoVersion } from '@/shared/utils/ziniao-version'
|
||||
import { uploadPathsToJava } from '@/shared/utils/upload-to-java'
|
||||
|
||||
const COUNTRY_OPTIONS = [
|
||||
{ code: 'DE', label: '德国' },
|
||||
@@ -476,22 +477,6 @@ function onSyncCountryChange(code: string, event: Event) {
|
||||
syncCountries.value = COUNTRY_OPTIONS.map((item) => item.code).filter((item) => selected.has(item))
|
||||
}
|
||||
|
||||
async function uploadPathsToJava(paths: Array<string | BrandExpandFolderItem>) {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.upload_file_to_java) throw new Error('当前桌面端未提供文件上传能力')
|
||||
const uploaded: UploadedJavaFile[] = []
|
||||
for (const item of paths) {
|
||||
const filePath = typeof item === 'string' ? item : item.absolutePath
|
||||
const relativePath = typeof item === 'string' ? undefined : item.relativePath
|
||||
const result = await api.upload_file_to_java(filePath, relativePath)
|
||||
if (!result?.success || !result.data) {
|
||||
throw new Error(result?.error || result?.message || `上传失败:${filePath}`)
|
||||
}
|
||||
uploaded.push(result.data)
|
||||
}
|
||||
return uploaded
|
||||
}
|
||||
|
||||
async function selectFiles() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.select_brand_xlsx_files || !api.upload_file_to_java) {
|
||||
@@ -503,7 +488,7 @@ async function selectFiles() {
|
||||
if (!paths?.length) return
|
||||
if (!(await passGuard(checkSelectedFiles(paths, { allowedExtensions: EXCEL_EXTENSIONS })))) return
|
||||
uploading.value = true
|
||||
const uploaded = await uploadPathsToJava(paths)
|
||||
const uploaded = await uploadPathsToJava(getPywebviewApi(), paths)
|
||||
selectedPaths.value = paths
|
||||
uploadedFiles.value = uploaded
|
||||
ElMessage.success(`已上传 ${uploaded.length} 个待上架文件`)
|
||||
@@ -533,7 +518,7 @@ async function selectFolder() {
|
||||
}
|
||||
if (!(await passGuard(checkSelectedFiles(result.items, { allowedExtensions: EXCEL_EXTENSIONS })))) return
|
||||
uploading.value = true
|
||||
const uploaded = await uploadPathsToJava(result.items)
|
||||
const uploaded = await uploadPathsToJava(getPywebviewApi(), result.items)
|
||||
selectedPaths.value = result.items.map((item) => item.relativePath || item.absolutePath)
|
||||
uploadedFiles.value = uploaded
|
||||
ElMessage.success(`已上传文件夹内 ${uploaded.length} 个 xlsx 文件`)
|
||||
|
||||
Reference in New Issue
Block a user