refactor: 第二批收敛——公共 Excel 写出器 + 任务收尾零件下沉 + 前端上传区/任务面板抽取
This commit is contained in:
@@ -5,22 +5,13 @@
|
||||
<div class="main-content">
|
||||
<aside class="left-panel left-panel--with-template">
|
||||
<div class="section-title">上传文件</div>
|
||||
<div class="upload-zone">
|
||||
<div class="hint">选择需要采集的 Excel 文件或文件夹(默认根目录:采集前数据.xlsx),系统将按下方筛选条件自动采集数据。</div>
|
||||
<div class="btns">
|
||||
<button type="button" class="opt-btn" @click="selectFiles">选择 Excel</button>
|
||||
<button type="button" class="opt-btn" @click="selectFolder">选择文件夹</button>
|
||||
</div>
|
||||
<div class="selected-files">
|
||||
<template v-if="selectedFileNames.length">
|
||||
<span v-for="name in displayFileNames" :key="name">{{ name }}</span>
|
||||
<span v-if="selectedFileNames.length > displayFileNames.length" class="more-line">
|
||||
还有 {{ selectedFileNames.length - displayFileNames.length }} 个文件未展开显示
|
||||
</span>
|
||||
</template>
|
||||
<span v-else>暂未选择文件</span>
|
||||
</div>
|
||||
</div>
|
||||
<FileUploadZone
|
||||
hint="选择需要采集的 Excel 文件或文件夹(默认根目录:采集前数据.xlsx),系统将按下方筛选条件自动采集数据。"
|
||||
:names="selectedFileNames"
|
||||
:max-display="8"
|
||||
@select-files="selectFiles"
|
||||
@select-folder="selectFolder"
|
||||
/>
|
||||
|
||||
<div class="section-title">筛选条件</div>
|
||||
<div class="filter-zone">
|
||||
@@ -147,19 +138,18 @@
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
|
||||
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
|
||||
import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.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 { getPywebviewApi } from '@/shared/bridges/pywebview'
|
||||
import { useExcelFileUpload } from '@/shared/composables/useExcelFileUpload'
|
||||
import { useTaskProgressLoop } from '@/shared/composables/useTaskProgressLoop'
|
||||
import { createCategorizedTimers } from '@/shared/utils/categorized-timers'
|
||||
import { saveUrlWithProgress } from '@/shared/utils/download-progress'
|
||||
import {
|
||||
EXCEL_EXTENSIONS,
|
||||
checkParseResult,
|
||||
checkQueuePayload,
|
||||
checkSelectedFiles,
|
||||
} from '@/shared/dispatch-guard'
|
||||
import { passGuard } from '@/shared/dispatch-guard-ui'
|
||||
import {
|
||||
@@ -177,12 +167,10 @@ import {
|
||||
type CollectDataHistoryItem,
|
||||
type CollectDataParseVo,
|
||||
type CollectDataTaskDetailVo,
|
||||
type UploadFileVo,
|
||||
} from '@/shared/api/java-modules'
|
||||
import { getPollingProgressBatch } from '@/shared/api/task-progress-polling.ts'
|
||||
import { formatDateTime } from '@/shared/utils/datetime'
|
||||
import { taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
||||
import { uploadPathsToJava } from '@/shared/utils/upload-to-java'
|
||||
import { runBatchDelete } from '@/shared/utils/batch-delete'
|
||||
import { confirmTaskDeletion } from '@/shared/task-delete-confirm'
|
||||
|
||||
@@ -194,10 +182,27 @@ const COUNTRY_OPTIONS = [
|
||||
{ code: 'ES', label: '西班牙' },
|
||||
] as const
|
||||
|
||||
const selectedFileNames = ref<string[]>([])
|
||||
const uploadedFiles = ref<UploadFileVo[]>([])
|
||||
const submitting = ref(false)
|
||||
const pushing = ref(false)
|
||||
const {
|
||||
files: uploadedFiles,
|
||||
selectedPaths: selectedFileNames,
|
||||
selectFiles,
|
||||
selectFolder,
|
||||
} = useExcelFileUpload({
|
||||
requireUploadCapability: true,
|
||||
pickFilesUnavailableWarning: '当前环境不支持文件选择或上传',
|
||||
folderUnavailableWarning: '当前环境不支持文件夹选择,请在本地客户端中打开',
|
||||
errorFallbackMessage: (action) => (action === 'files' ? '文件选择失败' : '选择失败'),
|
||||
onUploaded: () => {
|
||||
lastTaskId.value = null
|
||||
lastParseVo.value = null
|
||||
},
|
||||
onFailed: () => {
|
||||
lastTaskId.value = null
|
||||
lastParseVo.value = null
|
||||
},
|
||||
})
|
||||
|
||||
const filters = reactive<{
|
||||
minAmount: number | null
|
||||
@@ -314,8 +319,6 @@ const progressLoop = useTaskProgressLoop<CollectDataTaskDetailVo>({
|
||||
},
|
||||
})
|
||||
|
||||
const displayFileNames = computed(() => selectedFileNames.value.slice(0, 8))
|
||||
|
||||
function selectCountry(code: string) {
|
||||
if (!COUNTRY_OPTIONS.some((row) => row.code === code)) return
|
||||
if (selectedCountryCode.value === code) return
|
||||
@@ -359,61 +362,6 @@ async function loadCountryPreference() {
|
||||
}
|
||||
}
|
||||
|
||||
async function selectFiles() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.select_brand_xlsx_files || !api.upload_file_to_java) {
|
||||
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
|
||||
const files = await uploadPathsToJava(getPywebviewApi(), paths)
|
||||
uploadedFiles.value = files
|
||||
selectedFileNames.value = files.map((f) => f.relativePath || f.originalFilename || f.fileKey)
|
||||
lastTaskId.value = null
|
||||
lastParseVo.value = null
|
||||
} catch (error) {
|
||||
// 上传失败时清空选择,避免残留上一批文件让用户误以为新文件已就绪
|
||||
uploadedFiles.value = []
|
||||
selectedFileNames.value = []
|
||||
lastTaskId.value = null
|
||||
lastParseVo.value = null
|
||||
ElMessage.error(error instanceof Error ? error.message : '文件选择失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function selectFolder() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.select_brand_folder) {
|
||||
ElMessage.warning('当前环境不支持文件夹选择,请在本地客户端中打开')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const folder = await api.select_brand_folder()
|
||||
if (!folder) return
|
||||
const result = await expandBrandFolderRecursive(folder)
|
||||
if (!result.success || !result.items?.length) {
|
||||
ElMessage.warning(result.error || '该文件夹下没有可用的 xlsx 文件')
|
||||
return
|
||||
}
|
||||
if (!(await passGuard(checkSelectedFiles(result.items, { allowedExtensions: EXCEL_EXTENSIONS })))) return
|
||||
const files = await uploadPathsToJava(getPywebviewApi(), result.items)
|
||||
uploadedFiles.value = files
|
||||
selectedFileNames.value = result.items.map((item) => item.relativePath || item.absolutePath)
|
||||
lastTaskId.value = null
|
||||
lastParseVo.value = null
|
||||
ElMessage.success(`已选择文件夹内 ${result.items.length} 个 Excel 文件`)
|
||||
} catch (error) {
|
||||
uploadedFiles.value = []
|
||||
selectedFileNames.value = []
|
||||
lastTaskId.value = null
|
||||
lastParseVo.value = null
|
||||
ElMessage.error(error instanceof Error ? error.message : '选择失败')
|
||||
}
|
||||
}
|
||||
|
||||
function buildFiltersPayload() {
|
||||
const minAmount = filters.minAmount === null || filters.minAmount === undefined || Number.isNaN(filters.minAmount)
|
||||
? null
|
||||
@@ -791,7 +739,6 @@ async function batchDeleteHistory(views: TaskItemView[]) {
|
||||
.left-panel { width: 400px; background: #242424; padding: 20px; overflow-y: auto; border-right: 1px solid #2e3a52; }
|
||||
.right-panel { flex: 1; min-width: 0; background: #242424; display: flex; flex-direction: column; }
|
||||
.section-title { font-size: 13px; color: #a0acbe; margin: 12px 0 10px; }
|
||||
.upload-zone { border: 1px dashed #3e4a62; border-radius: 10px; padding: 18px; background: #242424; margin-bottom: 18px; }
|
||||
.hint, .loading-msg, .files, .muted { color: #5e6878; font-size: 12px; line-height: 1.5; }
|
||||
.btns, .run-row { display: flex; gap: 10px; flex-wrap: wrap; }
|
||||
.opt-btn, .btn-run, .btn-delete, .download { border: none; cursor: pointer; border-radius: 7px; }
|
||||
@@ -799,9 +746,6 @@ async function batchDeleteHistory(views: TaskItemView[]) {
|
||||
.btn-run { padding: 10px 18px; color: #f5f8fc; background: #3498db; font-weight: 600; }
|
||||
.btn-run.btn-queue { background: #27ae60; }
|
||||
.btn-run:disabled { opacity: .55; cursor: not-allowed; }
|
||||
.selected-files { margin-top: 14px; color: #a0acbe; font-size: 12px; word-break: break-all; }
|
||||
.selected-files span { display: block; margin: 4px 0; }
|
||||
.selected-files .more-line { color: #5e6878; }
|
||||
|
||||
.filter-zone {
|
||||
border: 1px solid #2e3a52;
|
||||
|
||||
Reference in New Issue
Block a user