From abbf6d9556b407fbfe8d4288ddc8c9e615d06ee9 Mon Sep 17 00:00:00 2001 From: zhx Date: Tue, 19 May 2026 13:21:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/resource-batch-drawer.vue | 82 +++++-------------- 1 file changed, 20 insertions(+), 62 deletions(-) diff --git a/apps/src/views/props/components/resource-batch-drawer.vue b/apps/src/views/props/components/resource-batch-drawer.vue index c0fe07e..8ce8173 100644 --- a/apps/src/views/props/components/resource-batch-drawer.vue +++ b/apps/src/views/props/components/resource-batch-drawer.vue @@ -193,10 +193,6 @@ const RESOURCE_NAME_TRANSLATION_ENTRIES = ([ (current, next) => next[0].length - current[0].length, ); -function isImageSourceTypeByType(type: string) { - return ['CHAT_BUBBLE', 'LAYOUT', 'THEME'].includes(type); -} - function isAmountRequiredByType(type: string) { return !['CUSTOMIZE', 'FRAGMENTS'].includes(type); } @@ -209,7 +205,6 @@ function showExpandUploadByType(type: string) { return type === 'CHAT_BUBBLE'; } -const isImageSourceType = computed(() => isImageSourceTypeByType(batchForm.type)); const isAmountRequired = computed(() => isAmountRequiredByType(batchForm.type)); const showExpandUpload = computed(() => showExpandUploadByType(batchForm.type)); const hasExpandColumn = computed( @@ -416,43 +411,6 @@ function isResourceFile(file: File) { return /\.(mp4|pag|svga|zip)$/i.test(file.name); } -function classifyFile(file: File): AssetKind | null { - const path = getFilePath(file); - const lowerPath = path.toLowerCase(); - const image = isImageFile(file); - if (!image && !isResourceFile(file)) { - return null; - } - if ( - image - && showExpandUpload.value - && /(^|\/)(android|expand)(\/|$)|[_-](android|expand)\./i.test(lowerPath) - ) { - return 'expand'; - } - if ( - image - && /(^|\/)(cover|covers|封面)(\/|$)|[_-](cover|封面)\./i.test(lowerPath) - ) { - return 'cover'; - } - if (isResourceFile(file)) { - return 'source'; - } - if ( - image - && isImageSourceType.value - && /(^|\/)(source|resource|resources|ios|资源)(\/|$)|[_-](source|resource|ios|资源)\./i.test(lowerPath) - ) { - return 'source'; - } - return image ? 'cover' : 'source'; -} - -function getFileBaseName(file: File) { - return normalizeBaseName(getPathFileName(getFilePath(file))); -} - function parseStructuredResourceFile(file: File): null | StructuredResourceFile { if (!isImageFile(file) && !isResourceFile(file)) { return null; @@ -489,8 +447,9 @@ function parseStructuredResourceFile(file: File): null | StructuredResourceFile return null; } const amount = Number(parts[parts.length - 3]); + const duration = String(parts[parts.length - 2] || ''); const name = parts.slice(1, -3).join('_').trim(); - if (!name || !Number.isFinite(amount) || amount < 0) { + if (!name || !/^\d+天$/.test(duration) || !Number.isFinite(amount) || amount < 0) { return null; } return { @@ -638,35 +597,34 @@ async function uploadAsset( function processFiles(files: File[]) { let accepted = 0; + let ignored = 0; files.forEach((file) => { const structuredFile = parseStructuredResourceFile(file); - if (structuredFile) { - const row = findOrCreateRow(structuredFile.name, { - adminFree: false, - amount: structuredFile.amount, - amountTouched: true, - code: structuredFile.code, - type: structuredFile.type, - typeTouched: true, - }); - setRowAsset(row, structuredFile.assetKind, file); - accepted += 1; + if (!structuredFile) { + ignored += 1; return; } - const kind = classifyFile(file); - if (!kind) { - return; - } - const row = findOrCreateRow(getFileBaseName(file)); - setRowAsset(row, kind, file); + const row = findOrCreateRow(structuredFile.name, { + adminFree: false, + amount: structuredFile.amount, + amountTouched: true, + code: structuredFile.code, + type: structuredFile.type, + typeTouched: true, + }); + setRowAsset(row, structuredFile.assetKind, file); accepted += 1; }); if (accepted === 0 && files.length > 0) { - message.warning('未识别到可导入的封面或资源文件'); + message.warning('未识别到符合命名规则的资源文件'); return; } if (accepted > 0) { - message.success(`已导入 ${accepted} 个文件`); + message.success( + ignored > 0 + ? `已导入 ${accepted} 个文件,忽略 ${ignored} 个非规则文件` + : `已导入 ${accepted} 个文件`, + ); } }