refactor: 第二批收敛——公共 Excel 写出器 + 任务收尾零件下沉 + 前端上传区/任务面板抽取
This commit is contained in:
@@ -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 文件或文件夹,按规则拆成多个 Excel 文件。</div>
|
||||
<div class="btns">
|
||||
<button type="button" class="opt-btn" @click="selectSplitFiles">选择 Excel 文件</button>
|
||||
<button type="button" class="opt-btn" @click="selectSplitFolder">选择文件夹</button>
|
||||
</div>
|
||||
|
||||
<div class="selected-files clean-placeholder split-selected-files">
|
||||
<template v-if="splitSelectedPaths.length">
|
||||
<span v-for="path in splitDisplayPaths" :key="path">{{ path }}</span>
|
||||
<span v-if="splitSelectedPaths.length > splitDisplayPaths.length" class="more-line">
|
||||
还有 {{ splitSelectedPaths.length - splitDisplayPaths.length }} 个文件未展开显示
|
||||
</span>
|
||||
</template>
|
||||
<span v-else>暂未选择待拆分文件</span>
|
||||
</div>
|
||||
</div>
|
||||
<FileUploadZone
|
||||
hint="选择需要拆分的 Excel 文件或文件夹,按规则拆成多个 Excel 文件。"
|
||||
:names="splitSelectedPaths"
|
||||
:max-display="8"
|
||||
files-label="选择 Excel 文件"
|
||||
empty-text="暂未选择待拆分文件"
|
||||
files-class="clean-placeholder split-selected-files"
|
||||
@select-files="selectSplitFiles"
|
||||
@select-folder="selectSplitFolder"
|
||||
/>
|
||||
|
||||
<div class="section-title">保留列设置</div>
|
||||
<div class="option-group column-option-group">
|
||||
@@ -139,21 +132,40 @@
|
||||
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 { deleteSplitHistory, getExcelInfo, getSplitHistory, getSplitResultDownloadUrl, runSplit, type SplitResultItem } 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 splitSelectedPaths = ref<string[]>([])
|
||||
const {
|
||||
files: splitUploadedFiles,
|
||||
selectedPaths: splitSelectedPaths,
|
||||
selectFiles: selectSplitFiles,
|
||||
selectFolder: selectSplitFolder,
|
||||
} = useExcelFileUpload({
|
||||
// 展示原始本机路径;文件夹展开后只展示相对路径(与原实现一致)
|
||||
filePathsMode: 'raw',
|
||||
folderPathsMode: 'relative',
|
||||
filesSuccessMessage: (_files, paths) => `已选择 ${paths.length} 个待拆分文件`,
|
||||
folderSuccessMessage: (_files, items) => `已选择文件夹内 ${items.length} 个 xlsx 文件`,
|
||||
folderEmptyWarning: (error) => error || '该文件夹下没有 xlsx 文件',
|
||||
onFolderPicked: (folder) => {
|
||||
splitArchiveName.value = folder.split(/[/\\]/).filter(Boolean).pop() || ''
|
||||
},
|
||||
onUploaded: async (info) => {
|
||||
if (info.action === 'files') splitArchiveName.value = ''
|
||||
if (info.files.length > 0) {
|
||||
await loadSplitInfo(info.files[0].fileKey)
|
||||
}
|
||||
},
|
||||
})
|
||||
const splitArchiveName = ref('')
|
||||
const splitUploadedFiles = ref<UploadedJavaFile[]>([])
|
||||
const splitAvailableColumns = ref<string[]>([])
|
||||
const splitSelectedColumns = ref<string[]>([])
|
||||
const splitTotalRows = ref(0)
|
||||
@@ -162,7 +174,6 @@ const splitRowsPerFile = ref<number | null>(2000)
|
||||
const splitParts = ref<number | null>(5)
|
||||
const splitRunning = ref(false)
|
||||
const splitResultItems = ref<SplitResultItem[]>([])
|
||||
const splitDisplayPaths = computed(() => splitSelectedPaths.value.slice(0, 8))
|
||||
|
||||
// ---- 右侧任务面板统一视图(TaskCenterPanel)----
|
||||
const splitCards = computed<TaskStatCard[]>(() => [
|
||||
@@ -232,67 +243,6 @@ async function loadSplitInfo(fileKey: string) {
|
||||
splitTotalRows.value = result.totalRows || 0
|
||||
}
|
||||
|
||||
async function handleSelectedPaths(paths: string[], successMessage: string) {
|
||||
splitSelectedPaths.value = paths
|
||||
splitArchiveName.value = ''
|
||||
splitUploadedFiles.value = await uploadPathsToJava(getPywebviewApi(), paths)
|
||||
if (splitUploadedFiles.value.length > 0) {
|
||||
await loadSplitInfo(splitUploadedFiles.value[0].fileKey)
|
||||
}
|
||||
ElMessage.success(successMessage)
|
||||
}
|
||||
|
||||
async function selectSplitFiles() {
|
||||
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) {
|
||||
splitSelectedPaths.value = []
|
||||
splitUploadedFiles.value = []
|
||||
ElMessage.error(error instanceof Error ? error.message : '选择失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function selectSplitFolder() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.select_brand_folder) {
|
||||
ElMessage.warning('当前环境不支持文件夹选择,请在本机客户端中打开')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const folder = await api.select_brand_folder()
|
||||
if (!folder) return
|
||||
splitArchiveName.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
|
||||
splitSelectedPaths.value = result.items.map((item) => item.relativePath)
|
||||
splitUploadedFiles.value = await uploadPathsToJava(getPywebviewApi(), result.items)
|
||||
if (splitUploadedFiles.value.length > 0) {
|
||||
await loadSplitInfo(splitUploadedFiles.value[0].fileKey)
|
||||
}
|
||||
ElMessage.success(`已选择文件夹内 ${result.items.length} 个 xlsx 文件`)
|
||||
return
|
||||
}
|
||||
|
||||
ElMessage.warning(result.error || '该文件夹下没有 xlsx 文件')
|
||||
} catch (error) {
|
||||
splitSelectedPaths.value = []
|
||||
splitUploadedFiles.value = []
|
||||
ElMessage.error(error instanceof Error ? error.message : '选择失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function submitSplitRun() {
|
||||
if (!splitUploadedFiles.value.length) {
|
||||
ElMessage.warning('请先选择待拆分 Excel 文件或文件夹')
|
||||
@@ -448,33 +398,61 @@ 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;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: #5e6878;
|
||||
:deep(.upload-zone .hint) {
|
||||
font-size: 13px;
|
||||
margin-bottom: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.btns {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
: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;
|
||||
}
|
||||
|
||||
:deep(.split-selected-files) {
|
||||
max-height: 120px;
|
||||
min-height: 72px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.opt-btn,
|
||||
@@ -506,31 +484,6 @@ async function batchDeleteHistory(views: TaskItemView[]) {
|
||||
border-color: #3498db;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.split-selected-files {
|
||||
max-height: 120px;
|
||||
min-height: 72px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.option-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user