完成新需求
This commit is contained in:
@@ -90,7 +90,7 @@
|
||||
{{ splitRunning ? '拆分中...' : '开始拆分' }}
|
||||
</button>
|
||||
<span class="loading-msg">
|
||||
{{ splitRunning ? '正在拆分文件,请稍候…' : '选择文件、保留列和拆分规则后即可执行本地拆分' }}
|
||||
{{ splitRunning ? '正在拆分并上传结果,请稍候…' : '选择文件、保留列和拆分规则后即可执行拆分,结果会显示在右侧供下载' }}
|
||||
</span>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -116,9 +116,6 @@
|
||||
<div class="result-list-wrap">
|
||||
<div class="result-list-header">
|
||||
<span>拆分后的 Excel 列表</span>
|
||||
<button type="button" class="download-all" :disabled="!splitOutputDir" @click="openSplitOutputDir">
|
||||
打开输出目录
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="splitResultItems.length === 0" class="empty-tasks">
|
||||
@@ -128,8 +125,8 @@
|
||||
<ul v-else class="task-list clean-result-list">
|
||||
<li v-for="item in splitResultItems" :key="`${item.output_path || item.source_path}-${item.row_count || 0}`" class="task-item">
|
||||
<div class="left">
|
||||
<span class="id" :title="item.source_path">{{ shorten(item.source_path, 42) }}</span>
|
||||
<div v-if="item.output_path" class="files">输出文件:{{ item.output_path }}</div>
|
||||
<span class="id" :title="item.source_path">{{ item.source_path || '-' }}</span>
|
||||
<div v-if="item.output_path" class="files">结果下载地址已生成</div>
|
||||
<div v-if="item.row_count !== undefined" class="time">包含 {{ item.row_count }} 条数据</div>
|
||||
<div v-else-if="item.error" class="files">错误信息:{{ item.error }}</div>
|
||||
</div>
|
||||
@@ -142,9 +139,17 @@
|
||||
v-if="item.success && item.output_path"
|
||||
type="button"
|
||||
class="download"
|
||||
@click="openSplitResult(item)"
|
||||
@click="downloadSplitResult(item)"
|
||||
>
|
||||
打开文件
|
||||
下载文件
|
||||
</button>
|
||||
<button
|
||||
v-if="item.result_id"
|
||||
type="button"
|
||||
class="btn-delete"
|
||||
@click="deleteSplitHistory(item.result_id)"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
@@ -156,7 +161,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { expandBrandFolder } from '@/shared/api/brand'
|
||||
import { type SplitExcelResultItem, getPywebviewApi, hasPywebview } from '@/shared/bridges/pywebview'
|
||||
@@ -179,7 +184,6 @@ function shorten(value: string, maxLength: number) {
|
||||
}
|
||||
|
||||
function resetSplitResults() {
|
||||
splitResultItems.value = []
|
||||
splitSummary.value = { total: 0, success_count: 0, failed_count: 0 }
|
||||
splitOutputDir.value = ''
|
||||
}
|
||||
@@ -251,7 +255,7 @@ async function selectSplitFolder() {
|
||||
|
||||
async function submitSplitRun() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.split_excel_files || !api?.select_folder) {
|
||||
if (!api?.split_excel_files) {
|
||||
ElMessage.warning('当前环境不支持数据拆分,请在桌面端打开')
|
||||
return
|
||||
}
|
||||
@@ -273,9 +277,6 @@ async function submitSplitRun() {
|
||||
}
|
||||
|
||||
try {
|
||||
const outputDir = await api.select_folder()
|
||||
if (!outputDir) return
|
||||
|
||||
splitRunning.value = true
|
||||
const result = await api.split_excel_files({
|
||||
paths: splitSelectedPaths.value,
|
||||
@@ -283,7 +284,6 @@ async function submitSplitRun() {
|
||||
split_mode: splitMode.value,
|
||||
rows_per_file: splitRowsPerFile.value || undefined,
|
||||
parts: splitParts.value || undefined,
|
||||
output_dir: outputDir,
|
||||
})
|
||||
|
||||
if (!result.success) {
|
||||
@@ -291,13 +291,13 @@ async function submitSplitRun() {
|
||||
return
|
||||
}
|
||||
|
||||
splitOutputDir.value = result.summary?.output_dir || outputDir
|
||||
splitOutputDir.value = ''
|
||||
splitSummary.value = {
|
||||
total: result.summary?.total || 0,
|
||||
success_count: result.summary?.success_count || 0,
|
||||
failed_count: result.summary?.failed_count || 0,
|
||||
}
|
||||
splitResultItems.value = result.items || []
|
||||
await loadSplitHistory()
|
||||
ElMessage.success('数据拆分完成')
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '数据拆分失败')
|
||||
@@ -306,30 +306,67 @@ async function submitSplitRun() {
|
||||
}
|
||||
}
|
||||
|
||||
async function openSplitOutputDir() {
|
||||
async function loadSplitHistory() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.open_path || !splitOutputDir.value) {
|
||||
ElMessage.warning('当前环境不支持打开输出目录')
|
||||
return
|
||||
}
|
||||
if (!api?.get_split_history) return
|
||||
|
||||
const result = await api.open_path(splitOutputDir.value)
|
||||
if (!result.success) {
|
||||
ElMessage.error(result.error || '打开目录失败')
|
||||
try {
|
||||
const response = await api.get_split_history()
|
||||
if (!response.success || !response.items) return
|
||||
splitResultItems.value = response.items
|
||||
splitSummary.value = {
|
||||
total: response.items.length,
|
||||
success_count: response.items.filter((item) => item.success).length,
|
||||
failed_count: response.items.filter((item) => !item.success).length,
|
||||
}
|
||||
} catch {
|
||||
// ignore history load errors
|
||||
}
|
||||
}
|
||||
|
||||
async function openSplitResult(item: SplitExcelResultItem) {
|
||||
onMounted(() => {
|
||||
loadSplitHistory().catch(() => undefined)
|
||||
})
|
||||
|
||||
async function deleteSplitHistory(resultId: number) {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.open_path || !item.output_path) {
|
||||
ElMessage.warning('当前环境不支持打开结果文件')
|
||||
if (!api?.delete_history_item) {
|
||||
ElMessage.warning('当前环境不支持删除历史')
|
||||
return
|
||||
}
|
||||
|
||||
const result = await api.open_path(item.output_path)
|
||||
const result = await api.delete_history_item('split', resultId)
|
||||
if (!result.success) {
|
||||
ElMessage.error(result.error || '打开文件失败')
|
||||
ElMessage.error(result.error || '删除失败')
|
||||
return
|
||||
}
|
||||
await loadSplitHistory()
|
||||
ElMessage.success('已删除')
|
||||
}
|
||||
|
||||
async function downloadSplitResult(item: SplitExcelResultItem) {
|
||||
const api = getPywebviewApi()
|
||||
if (!item.output_path) {
|
||||
ElMessage.warning('当前结果没有下载地址')
|
||||
return
|
||||
}
|
||||
|
||||
const today = new Date()
|
||||
const yyyy = String(today.getFullYear())
|
||||
const mm = String(today.getMonth() + 1).padStart(2, '0')
|
||||
const dd = String(today.getDate()).padStart(2, '0')
|
||||
const filename = `${yyyy}${mm}${dd}.xlsx`
|
||||
if (api?.save_file_from_url) {
|
||||
const result = await api.save_file_from_url(item.output_path, filename)
|
||||
if (result.success) {
|
||||
ElMessage.success(`已保存:${result.path || filename}`)
|
||||
} else if (result.error && result.error !== '用户取消') {
|
||||
ElMessage.error(result.error)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
window.open(item.output_path, '_blank')
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user