refactor: 第二批收敛——公共 Excel 写出器 + 任务收尾零件下沉 + 前端上传区/任务面板抽取
This commit is contained in:
@@ -5,25 +5,16 @@
|
||||
<div class="main-content">
|
||||
<aside class="left-panel">
|
||||
<div class="section-title">待检品牌文件</div>
|
||||
<div class="upload-zone">
|
||||
<div class="hint">
|
||||
Excel 每行含「品牌」列即会加入检测。可多选文件或选择整个文件夹(.xlsx)。检测由本机客户端执行,请在桌面客户端中打开本页面。
|
||||
</div>
|
||||
<div class="btns">
|
||||
<button type="button" class="opt-btn" :disabled="!hasBridge" @click="selectFiles">选择 Excel</button>
|
||||
<button type="button" class="opt-btn" :disabled="!hasBridge" @click="selectFolder">选择文件夹</button>
|
||||
</div>
|
||||
<div class="selected-files">
|
||||
<template v-if="selectedPaths.length">
|
||||
<span v-for="name in displayPaths" :key="name" :title="name">{{ baseName(name) }}</span>
|
||||
<span v-if="selectedPaths.length > displayPaths.length" class="more-line">
|
||||
还有 {{ selectedPaths.length - displayPaths.length }} 个文件未展开显示
|
||||
</span>
|
||||
</template>
|
||||
<span v-else>暂未选择文件</span>
|
||||
</div>
|
||||
<div v-if="!hasBridge" class="bridge-tip">当前浏览器环境无桌面客户端桥接,仅可预览页面;请用本机客户端打开。</div>
|
||||
</div>
|
||||
<FileUploadZone
|
||||
hint="Excel 每行含「品牌」列即会加入检测。可多选文件或选择整个文件夹(.xlsx)。检测由本机客户端执行,请在桌面客户端中打开本页面。"
|
||||
:names="selectedPaths"
|
||||
:max-display="8"
|
||||
:disabled="!hasBridge"
|
||||
name-title
|
||||
:footer-tip="hasBridge ? '' : '当前浏览器环境无桌面客户端桥接,仅可预览页面;请用本机客户端打开。'"
|
||||
@select-files="selectFiles"
|
||||
@select-folder="selectFolder"
|
||||
/>
|
||||
|
||||
<div class="section-title">匹配策略</div>
|
||||
<div class="radio-cards">
|
||||
@@ -107,6 +98,7 @@
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } 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 { getPywebviewApi } from '@/shared/bridges/pywebview'
|
||||
@@ -119,18 +111,42 @@ import {
|
||||
runBrandNow,
|
||||
type BrandTaskItem,
|
||||
} from '@/shared/api/brand'
|
||||
import { checkSelectedFiles, EXCEL_EXTENSIONS } from '@/shared/dispatch-guard.ts'
|
||||
import { passGuard } from '@/shared/dispatch-guard-ui'
|
||||
import { useExcelFileUpload } from '@/shared/composables/useExcelFileUpload'
|
||||
import { getTaskPollIntervalMs } from '@/shared/task-progress-config'
|
||||
import { createCategorizedTimers } from '@/shared/utils/categorized-timers'
|
||||
import type { UploadFileVo } from '@/shared/api/upload.ts'
|
||||
import type { UploadedFileRef } from '@/shared/api/types/upload.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'
|
||||
|
||||
const uploadedFiles = ref<UploadFileVo[]>([])
|
||||
const {
|
||||
files: uploadedFiles,
|
||||
selectedPaths,
|
||||
selectFiles,
|
||||
selectFolder,
|
||||
} = useExcelFileUpload({
|
||||
pickFilesUnavailableWarning: '当前环境不支持文件选择,请在本机客户端中打开',
|
||||
folderUnavailableWarning: '当前环境不支持文件夹选择,请在本机客户端中打开',
|
||||
folderEmptyWarning: (error) => error || '该文件夹下没有 xlsx 文件',
|
||||
filesSuccessMessage: (files) => `已选择并上传 ${files.length} 个 Excel 文件`,
|
||||
folderSuccessMessage: (files) => `已选择并上传文件夹内 ${files.length} 个 Excel 文件`,
|
||||
errorFallbackMessage: (action) => (action === 'files' ? '文件上传失败' : '文件夹选择失败'),
|
||||
uploadOptions: { uploadOss: true },
|
||||
// 展示名与原实现一致:始终取上传结果的相对路径/文件名(文件、文件夹两个动作都一样)
|
||||
filePathsMode: 'uploaded',
|
||||
folderPathsMode: 'uploaded',
|
||||
// 原实现上传失败时保留上一批已上传文件,仅提示错误
|
||||
clearOnError: false,
|
||||
// 新版桌面客户端桥在本机展开文件夹(服务器无法访问用户本机目录)
|
||||
expandFolder: async (folder) => {
|
||||
const bridge = getPywebviewApi()
|
||||
if (!bridge?.expand_brand_folder) {
|
||||
ElMessage.warning('当前桌面客户端版本不支持文件夹展开,请使用"选择文件"(可多选)')
|
||||
return { success: false }
|
||||
}
|
||||
return await bridge.expand_brand_folder(folder)
|
||||
},
|
||||
})
|
||||
const strategy = ref<'Terms' | 'Simple'>('Simple')
|
||||
const submitting = ref(false)
|
||||
const tasks = ref<BrandTaskItem[]>([])
|
||||
@@ -143,15 +159,6 @@ const hasUid = computed(() => {
|
||||
const numeric = Number(raw.trim())
|
||||
return Number.isFinite(numeric) && numeric > 0
|
||||
})
|
||||
// 展示用:已上传文件列表的展示名(优先相对路径,其次原文件名)
|
||||
const selectedPaths = computed(() =>
|
||||
uploadedFiles.value.map((f) => f.relativePath || f.originalFilename || f.fileKey),
|
||||
)
|
||||
const displayPaths = computed(() => selectedPaths.value.slice(0, 8))
|
||||
|
||||
function baseName(path: string) {
|
||||
return path.split(/[\\/]/).pop() || path
|
||||
}
|
||||
|
||||
const timers = createCategorizedTimers('brand-brand-task')
|
||||
let pollTimer: number | null = null
|
||||
@@ -361,53 +368,6 @@ function toBrandTaskView(item: BrandTaskItem): TaskItemView {
|
||||
}
|
||||
}
|
||||
|
||||
/** 上传本地 xlsx 到 Java 临时目录,成功后回填 fileUrl(服务器本地路径,Java 直接读取) */
|
||||
async function selectFiles() {
|
||||
const bridge = getPywebviewApi()
|
||||
if (!bridge?.select_brand_xlsx_files) {
|
||||
ElMessage.warning('当前环境不支持文件选择,请在本机客户端中打开')
|
||||
return
|
||||
}
|
||||
const paths = await bridge.select_brand_xlsx_files()
|
||||
if (!paths?.length) return
|
||||
if (!(await passGuard(checkSelectedFiles(paths, { allowedExtensions: EXCEL_EXTENSIONS })))) return
|
||||
try {
|
||||
const files = await uploadPathsToJava(getPywebviewApi(), paths, { uploadOss: true })
|
||||
uploadedFiles.value = files
|
||||
ElMessage.success(`已选择并上传 ${files.length} 个 Excel 文件`)
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '文件上传失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function selectFolder() {
|
||||
const bridge = getPywebviewApi()
|
||||
if (!bridge?.select_brand_folder) {
|
||||
ElMessage.warning('当前环境不支持文件夹选择,请在本机客户端中打开')
|
||||
return
|
||||
}
|
||||
const folder = await bridge.select_brand_folder()
|
||||
if (!folder) return
|
||||
// 新版桌面客户端桥在本机展开文件夹(服务器无法访问用户本机目录)
|
||||
if (!bridge.expand_brand_folder) {
|
||||
ElMessage.warning('当前桌面客户端版本不支持文件夹展开,请使用"选择文件"(可多选)')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await bridge.expand_brand_folder(folder)
|
||||
if (!res.success || !res.items?.length) {
|
||||
ElMessage.warning(res.error || '该文件夹下没有 xlsx 文件')
|
||||
return
|
||||
}
|
||||
if (!(await passGuard(checkSelectedFiles(res.items.map((i) => i.absolutePath), { allowedExtensions: EXCEL_EXTENSIONS })))) return
|
||||
const files = await uploadPathsToJava(getPywebviewApi(), res.items, { uploadOss: true })
|
||||
uploadedFiles.value = files
|
||||
ElMessage.success(`已选择并上传文件夹内 ${files.length} 个 Excel 文件`)
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '文件夹选择失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function submitRun() {
|
||||
if (!hasBridge.value) {
|
||||
ElMessage.warning('请在桌面客户端中打开本页面执行品牌检测')
|
||||
@@ -568,16 +528,20 @@ async function batchDeleteHistory(views: TaskItemView[]) {
|
||||
.section-title { font-size: 13px; color: #a0acbe; margin: 12px 0 10px; }
|
||||
.hint, .loading-msg, .files, .muted { color: #5e6878; font-size: 12px; line-height: 1.5; }
|
||||
.hint { margin-bottom: 12px; }
|
||||
.upload-zone { border: 1px dashed #3e4a62; border-radius: 10px; padding: 16px; background: #242424; margin-bottom: 6px; }
|
||||
/* upload-zone 已抽到 FileUploadZone 组件;这里只保留本 Tab 的差异样式 */
|
||||
:deep(.upload-zone) { padding: 16px; margin-bottom: 6px; }
|
||||
:deep(.upload-zone .hint) { margin-bottom: 12px; }
|
||||
:deep(.upload-zone .opt-btn) { font-size: 12px; }
|
||||
:deep(.upload-zone .opt-btn:hover:not(:disabled)) { color: #3498db; border-color: #3498db; }
|
||||
:deep(.upload-zone .opt-btn:disabled) { opacity: 0.5; cursor: not-allowed; }
|
||||
:deep(.selected-files) { margin-top: 12px; }
|
||||
:deep(.selected-files span) { margin: 3px 0; }
|
||||
:deep(.bridge-tip) { margin-top: 10px; color: #e6a23c; font-size: 11px; }
|
||||
.btns, .run-row { display: flex; gap: 10px; flex-wrap: wrap; }
|
||||
.run-row { margin-top: 14px; }
|
||||
.opt-btn { padding: 8px 14px; color: #c8d2e2; background: #242424; border: 1px solid #3e4a62; border-radius: 7px; cursor: pointer; font-size: 12px; }
|
||||
.opt-btn:hover:not(:disabled) { color: #3498db; border-color: #3498db; }
|
||||
.opt-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.selected-files { margin-top: 12px; color: #a0acbe; font-size: 12px; word-break: break-all; }
|
||||
.selected-files span { display: block; margin: 3px 0; }
|
||||
.selected-files .more-line { color: #5e6878; }
|
||||
.bridge-tip { margin-top: 10px; color: #e6a23c; font-size: 11px; }
|
||||
.env-tip { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: rgba(230, 162, 60, 0.1); color: #e6a23c; font-size: 12px; line-height: 1.6; }
|
||||
.radio-cards { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
|
||||
.radio-card { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border: 1px solid #333; border-radius: 8px; background: #242424; cursor: pointer; }
|
||||
|
||||
Reference in New Issue
Block a user