refactor: 第二批收敛——公共 Excel 写出器 + 任务收尾零件下沉 + 前端上传区/任务面板抽取
This commit is contained in:
@@ -5,29 +5,19 @@
|
||||
<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 文件或文件夹;每个 Excel 文件名会作为店铺名进行匹配。
|
||||
</div>
|
||||
<div class="btns">
|
||||
<button type="button" class="opt-btn" :disabled="selectionDisabled" @click="selectFiles">
|
||||
{{ uploading ? '上传中...' : '选择 Excel 文件' }}
|
||||
</button>
|
||||
<button type="button" class="opt-btn" :disabled="selectionDisabled" @click="selectFolder">
|
||||
选择文件夹
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="selected-files clean-placeholder publish-selected-files">
|
||||
<template v-if="selectedPaths.length">
|
||||
<span v-for="path in displayPaths" :key="path">{{ path }}</span>
|
||||
<span v-if="selectedPaths.length > displayPaths.length" class="more-line">
|
||||
还有 {{ selectedPaths.length - displayPaths.length }} 个文件未展开显示
|
||||
</span>
|
||||
</template>
|
||||
<span v-else>暂未选择上架文件</span>
|
||||
</div>
|
||||
</div>
|
||||
<FileUploadZone
|
||||
hint="选择需要上架的 Excel 文件或文件夹;每个 Excel 文件名会作为店铺名进行匹配。"
|
||||
:names="selectedPaths"
|
||||
:max-display="8"
|
||||
files-label="选择 Excel 文件"
|
||||
uploading-label="上传中..."
|
||||
:uploading="uploading"
|
||||
:disabled="selectionDisabled"
|
||||
empty-text="暂未选择上架文件"
|
||||
files-class="clean-placeholder publish-selected-files"
|
||||
@select-files="selectFiles"
|
||||
@select-folder="selectFolder"
|
||||
/>
|
||||
|
||||
<div class="section-title">国家选择</div>
|
||||
<div class="country-group">
|
||||
@@ -187,11 +177,11 @@ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } 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 ZiniaoVersionSetting from '@/shared/components/ZiniaoVersionSetting.vue'
|
||||
import { expandBrandFolderRecursive } from '@/shared/api/brand'
|
||||
import {
|
||||
activatePublishFile,
|
||||
activatePublishTask,
|
||||
@@ -206,23 +196,21 @@ import {
|
||||
type PublishFileItem,
|
||||
type PublishTaskDetailVo,
|
||||
} from '@/shared/api/java-modules'
|
||||
import { getPywebviewApi, type UploadedJavaFile } from '@/shared/bridges/pywebview'
|
||||
import { getPywebviewApi } from '@/shared/bridges/pywebview'
|
||||
import { useExcelFileUpload } from '@/shared/composables/useExcelFileUpload'
|
||||
import { useTaskProgressLoop } from '@/shared/composables/useTaskProgressLoop'
|
||||
import { getTaskPollIntervalMs } from '@/shared/task-progress-config'
|
||||
import { createCategorizedTimers } from '@/shared/utils/categorized-timers'
|
||||
import { saveUrlWithProgress } from '@/shared/utils/download-progress'
|
||||
import { taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
||||
import {
|
||||
EXCEL_EXTENSIONS,
|
||||
checkParseResult,
|
||||
checkQueuePayload,
|
||||
checkSelectedFiles,
|
||||
collectDistinctErrors,
|
||||
guardBlocked,
|
||||
} 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'
|
||||
import { runBatchDelete } from '@/shared/utils/batch-delete'
|
||||
|
||||
const COUNTRY_OPTIONS = [
|
||||
@@ -252,9 +240,23 @@ interface StoredPublishQueueState {
|
||||
pending: PublishQueueBatch[]
|
||||
}
|
||||
|
||||
const selectedPaths = ref<string[]>([])
|
||||
const uploadedFiles = ref<UploadedJavaFile[]>([])
|
||||
const uploading = ref(false)
|
||||
const {
|
||||
files: uploadedFiles,
|
||||
selectedPaths,
|
||||
uploading,
|
||||
selectFiles,
|
||||
selectFolder,
|
||||
} = useExcelFileUpload({
|
||||
requireUploadCapability: true,
|
||||
folderRequireUploadCapability: true,
|
||||
pickFilesUnavailableWarning: '当前环境不支持文件选择或上传,请在本机客户端中打开',
|
||||
folderUnavailableWarning: '当前环境不支持文件夹选择或上传,请在本机客户端中打开',
|
||||
folderEmptyWarning: (error) => error || '该文件夹下没有 xlsx 文件',
|
||||
// 展示原始本机路径;文件夹展开后展示 relativePath || absolutePath(与原实现一致)
|
||||
filePathsMode: 'raw',
|
||||
filesSuccessMessage: (files) => `已上传 ${files.length} 个待上架文件`,
|
||||
folderSuccessMessage: (files) => `已上传文件夹内 ${files.length} 个 xlsx 文件`,
|
||||
})
|
||||
const parsing = ref(false)
|
||||
const queueWorkerRunning = ref(false)
|
||||
const queueMessage = ref('')
|
||||
@@ -370,7 +372,6 @@ const progressLoop = useTaskProgressLoop<PublishTaskDetailVo>({
|
||||
},
|
||||
})
|
||||
|
||||
const displayPaths = computed(() => selectedPaths.value.slice(0, 8))
|
||||
const activeBatchHasWork = computed(() => pendingFileIds.value.length > 0 || activeFileId.value != null)
|
||||
const hasQueueWork = computed(() => activeBatchHasWork.value || queuedBatches.value.length > 0)
|
||||
const selectionDisabled = computed(() => uploading.value || parsing.value)
|
||||
@@ -481,60 +482,6 @@ function onSyncCountryChange(code: string, event: Event) {
|
||||
syncCountries.value = COUNTRY_OPTIONS.map((item) => item.code).filter((item) => selected.has(item))
|
||||
}
|
||||
|
||||
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
|
||||
uploading.value = true
|
||||
const uploaded = await uploadPathsToJava(getPywebviewApi(), paths)
|
||||
selectedPaths.value = paths
|
||||
uploadedFiles.value = uploaded
|
||||
ElMessage.success(`已上传 ${uploaded.length} 个待上架文件`)
|
||||
} catch (error) {
|
||||
// 上传失败时清空选择,避免残留上一批文件让用户误以为新文件已就绪
|
||||
selectedPaths.value = []
|
||||
uploadedFiles.value = []
|
||||
ElMessage.error(error instanceof Error ? error.message : '选择失败')
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function selectFolder() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.select_brand_folder || !api.upload_file_to_java) {
|
||||
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
|
||||
uploading.value = true
|
||||
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 文件`)
|
||||
} catch (error) {
|
||||
selectedPaths.value = []
|
||||
uploadedFiles.value = []
|
||||
ElMessage.error(error instanceof Error ? error.message : '选择失败')
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function isMatchedFile(file: PublishFileItem) {
|
||||
const matchStatus = normalizeStatus(file.matchStatus)
|
||||
return Boolean(
|
||||
@@ -1209,7 +1156,12 @@ 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; display: flex; flex-direction: column; min-width: 0; background: #242424; }
|
||||
.section-title { margin-bottom: 10px; color: #a0acbe; font-size: 13px; }
|
||||
.upload-zone { margin-bottom: 20px; padding: 20px; border: 1px dashed #3e4a62; border-radius: 8px; background: #242424; text-align: center; }
|
||||
/* upload-zone 已抽到 FileUploadZone 组件;这里保留本 Tab 的差异样式 */
|
||||
:deep(.upload-zone) { margin-bottom: 20px; padding: 20px; border-radius: 8px; text-align: center; }
|
||||
:deep(.upload-zone .btns) { justify-content: center; }
|
||||
:deep(.upload-zone .opt-btn) { padding: 8px 16px; font-size: 13px; border-radius: 6px; }
|
||||
:deep(.upload-zone .opt-btn:hover:not(:disabled)) { border-color: #3498db; color: #67b7ef; }
|
||||
:deep(.upload-zone .opt-btn:disabled) { opacity: .55; cursor: not-allowed; }
|
||||
.hint, .loading-msg { color: #5e6878; font-size: 12px; line-height: 1.5; }
|
||||
.btns, .run-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
|
||||
.btns { justify-content: center; }
|
||||
@@ -1217,9 +1169,8 @@ async function batchDeleteHistory(views: TaskItemView[]) {
|
||||
.opt-btn { padding: 8px 16px; border: 1px solid #3e4a62; background: #242424; color: #c8d2e2; font-size: 13px; }
|
||||
.opt-btn:hover:not(:disabled) { border-color: #3498db; color: #67b7ef; }
|
||||
.opt-btn:disabled, .btn-run:disabled { opacity: .55; cursor: not-allowed; }
|
||||
.selected-files { max-height: 120px; min-height: 72px; margin-top: 14px; overflow-y: auto; color: #5e6878; font-size: 12px; text-align: left; }
|
||||
.selected-files span { display: block; margin: 4px 0; word-break: break-all; }
|
||||
.more-line { color: #a0acbe; }
|
||||
:deep(.publish-selected-files) { max-height: 120px; min-height: 72px; overflow-y: auto; color: #5e6878; }
|
||||
:deep(.more-line) { color: #a0acbe; }
|
||||
.country-group { margin-bottom: 12px; padding: 14px; border: 1px solid #323e58; border-radius: 8px; background: #242424; }
|
||||
.country-group-title { margin-bottom: 10px; color: #a0acbe; font-size: 12px; }
|
||||
.country-checks { display: flex; flex-wrap: wrap; gap: 10px 16px; }
|
||||
|
||||
Reference in New Issue
Block a user