refactor: 第二批收敛——公共 Excel 写出器 + 任务收尾零件下沉 + 前端上传区/任务面板抽取

This commit is contained in:
2026-10-01 15:00:52 +08:00
parent 16e2c9a5e7
commit 517b02485b
32 changed files with 2467 additions and 2826 deletions
@@ -5,23 +5,16 @@
<div class="main-content">
<aside class="left-panel">
<div class="section-title">选择文件</div>
<div class="upload-zone">
<div class="hint">选择需要转换的 Excel 文件或文件夹,将按所选模板生成 txt 文件。</div>
<div class="btns">
<button type="button" class="opt-btn" @click="selectConvertFiles">选择 Excel 文件</button>
<button type="button" class="opt-btn" @click="selectConvertFolder">选择文件夹</button>
</div>
<div class="selected-files clean-placeholder">
<template v-if="convertSelectedPaths.length">
<span v-for="path in convertDisplayPaths" :key="path">{{ path }}</span>
<span v-if="convertSelectedPaths.length > convertDisplayPaths.length" class="more-line">
还有 {{ convertSelectedPaths.length - convertDisplayPaths.length }} 个文件未展开显示
</span>
</template>
<span v-else>暂未选择待转换文件</span>
</div>
</div>
<FileUploadZone
hint="选择需要转换的 Excel 文件或文件夹,将按所选模板生成 txt 文件。"
:names="convertSelectedPaths"
:max-display="8"
files-label="选择 Excel 文件"
empty-text="暂未选择待转换文件"
files-class="clean-placeholder"
@select-files="selectConvertFiles"
@select-folder="selectConvertFolder"
/>
<div class="section-title">模板选择</div>
<div class="option-group">
@@ -152,9 +145,9 @@
import { computed, onMounted, ref } from 'vue'
import { ElMessage } from 'element-plus'
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
import TaskCenterPanel from '@/shared/components/tasks/TaskCenterPanel.vue'
import type { TaskItemView, TaskStatCard } from '@/shared/components/tasks/types'
import { expandBrandFolderRecursive } from '@/shared/api/brand'
import {
deleteConvertHistory,
getConvertHistory,
@@ -164,23 +157,38 @@ import {
type ConvertResultItem,
type ConvertTemplateVo,
} from '@/shared/api/java-modules'
import { getPywebviewApi, type UploadedJavaFile } from '@/shared/bridges/pywebview'
import { saveUrlWithProgress } from '@/shared/utils/download-progress'
import { EXCEL_EXTENSIONS, checkSelectedFiles, collectDistinctErrors, guardBlocked } from '@/shared/dispatch-guard'
import { collectDistinctErrors, guardBlocked } from '@/shared/dispatch-guard'
import { passGuard } from '@/shared/dispatch-guard-ui'
import { useExcelFileUpload } from '@/shared/composables/useExcelFileUpload'
import { formatDateTime } from '@/shared/utils/datetime'
import { uploadPathsToJava } from '@/shared/utils/upload-to-java'
import { runBatchDelete } from '@/shared/utils/batch-delete'
const convertSelectedPaths = ref<string[]>([])
const {
files: convertUploadedFiles,
selectedPaths: convertSelectedPaths,
selectFiles: selectConvertFiles,
selectFolder: selectConvertFolder,
} = useExcelFileUpload({
// 展示原始本机路径;文件夹展开后只展示相对路径(与原实现一致)
filePathsMode: 'raw',
folderPathsMode: 'relative',
filesSuccessMessage: (_files, paths) => `已选择 ${paths.length} 个待转换文件`,
folderSuccessMessage: (_files, items) => `已选择文件夹内 ${items.length} 个 xlsx 文件`,
folderEmptyWarning: (error) => error || '该文件夹下没有 xlsx 文件',
onFolderPicked: (folder) => {
convertArchiveName.value = folder.split(/[/\\]/).filter(Boolean).pop() || ''
},
onUploaded: (info) => {
if (info.action === 'files') convertArchiveName.value = ''
},
})
const convertArchiveName = ref('')
const convertUploadedFiles = ref<UploadedJavaFile[]>([])
const convertRunning = ref(false)
const convertResultItems = ref<ConvertResultItem[]>([])
const convertTemplates = ref<ConvertTemplateVo[]>([])
const convertTemplateId = ref('')
const convertDisplayPaths = computed(() => convertSelectedPaths.value.slice(0, 8))
const currentConvertTemplate = computed(
() => convertTemplates.value.find((item) => item.id === convertTemplateId.value) || null,
)
@@ -267,61 +275,6 @@ async function loadConvertTemplates(preferredTemplateId?: string) {
convertTemplateId.value = convertTemplates.value[0]?.id || ''
}
async function handleSelectedPaths(paths: string[], successMessage: string) {
convertSelectedPaths.value = paths
convertArchiveName.value = ''
convertUploadedFiles.value = await uploadPathsToJava(getPywebviewApi(), paths)
ElMessage.success(successMessage)
}
async function selectConvertFiles() {
const api = getPywebviewApi()
if (!api?.select_brand_xlsx_files) {
ElMessage.warning('当前环境不支持文件选择,请在本机客户端中打开')
return
}
try {
const paths = await api.select_brand_xlsx_files()
if (!paths?.length) return
if (!(await passGuard(checkSelectedFiles(paths, { allowedExtensions: EXCEL_EXTENSIONS })))) return
await handleSelectedPaths(paths, `已选择 ${paths.length} 个待转换文件`)
} catch (error) {
convertSelectedPaths.value = []
convertUploadedFiles.value = []
ElMessage.error(error instanceof Error ? error.message : '选择失败')
}
}
async function selectConvertFolder() {
const api = getPywebviewApi()
if (!api?.select_brand_folder) {
ElMessage.warning('当前环境不支持文件夹选择,请在本机客户端中打开')
return
}
try {
const folder = await api.select_brand_folder()
if (!folder) return
convertArchiveName.value = folder.split(/[/\\]/).filter(Boolean).pop() || ''
const result = await expandBrandFolderRecursive(folder)
if (result.success && result.items?.length) {
if (!(await passGuard(checkSelectedFiles(result.items, { allowedExtensions: EXCEL_EXTENSIONS })))) return
convertSelectedPaths.value = result.items.map((item) => item.relativePath)
convertUploadedFiles.value = await uploadPathsToJava(getPywebviewApi(), result.items)
ElMessage.success(`已选择文件夹内 ${result.items.length} 个 xlsx 文件`)
return
}
ElMessage.warning(result.error || '该文件夹下没有 xlsx 文件')
} catch (error) {
convertSelectedPaths.value = []
convertUploadedFiles.value = []
ElMessage.error(error instanceof Error ? error.message : '选择失败')
}
}
async function submitConvertRun() {
if (!convertUploadedFiles.value.length) {
ElMessage.warning('请先选择待转换 Excel 文件或文件夹')
@@ -460,17 +413,15 @@ async function batchDeleteHistory(views: TaskItemView[]) {
margin-bottom: 10px;
}
.upload-zone {
border: 1px dashed #3e4a62;
border-radius: 10px;
/* upload-zone 已抽到 FileUploadZone 组件;这里保留本 Tab 的差异样式 */
:deep(.upload-zone) {
padding: 24px;
text-align: center;
background: #242424;
margin-bottom: 20px;
transition: all 0.2s ease;
}
.upload-zone:hover {
:deep(.upload-zone:hover) {
border-color: #3498db;
background: #242424;
}
@@ -482,11 +433,42 @@ async function batchDeleteHistory(views: TaskItemView[]) {
line-height: 1.5;
}
.btns {
display: flex;
gap: 10px;
:deep(.upload-zone .hint) {
font-size: 13px;
margin-bottom: 12px;
}
:deep(.upload-zone .btns) {
justify-content: center;
flex-wrap: wrap;
}
:deep(.upload-zone .opt-btn) {
padding: 8px 16px;
font-size: 13px;
border-radius: 6px;
}
:deep(.upload-zone .opt-btn:hover) {
color: #3498db;
background: #333;
border-color: #3498db;
}
:deep(.upload-zone .opt-btn:disabled) {
cursor: not-allowed;
opacity: 0.55;
}
:deep(.selected-files) {
font-size: 12px;
color: #5e6878;
max-height: 112px;
overflow-y: auto;
text-align: left;
}
:deep(.more-line) {
color: #a0acbe;
}
.opt-btn,
@@ -529,25 +511,6 @@ async function batchDeleteHistory(views: TaskItemView[]) {
opacity: 0.55;
}
.selected-files {
margin-top: 14px;
font-size: 12px;
color: #5e6878;
max-height: 112px;
overflow-y: auto;
text-align: left;
}
.selected-files span {
display: block;
margin: 4px 0;
word-break: break-all;
}
.more-line {
color: #a0acbe;
}
.option-group {
margin-bottom: 20px;
}