环境搭建配置
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
<template>
|
||||
<div class="main-content">
|
||||
<aside class="left-panel">
|
||||
<div class="page-shell module-page">
|
||||
<BrandTopBar active="split" />
|
||||
|
||||
<div class="main-content">
|
||||
<aside class="left-panel">
|
||||
<div class="section-title">选择文件</div>
|
||||
<div class="upload-zone">
|
||||
<div class="hint">选择需要拆分的 Excel 文件或文件夹,按规则拆成多个 Excel 文件。</div>
|
||||
@@ -105,11 +108,11 @@
|
||||
</div>
|
||||
<div class="summary-card">
|
||||
<span class="summary-label">成功结果</span>
|
||||
<strong>{{ splitSummary.success_count }}</strong>
|
||||
<strong>{{ splitSummary.successCount }}</strong>
|
||||
</div>
|
||||
<div class="summary-card">
|
||||
<span class="summary-label">失败文件</span>
|
||||
<strong>{{ splitSummary.failed_count }}</strong>
|
||||
<strong>{{ splitSummary.failedCount }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -123,11 +126,11 @@
|
||||
</div>
|
||||
|
||||
<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">
|
||||
<li v-for="item in splitResultItems" :key="`${item.resultId || item.outputFilename || item.sourceFilename}-${item.rowCount || 0}`" class="task-item">
|
||||
<div class="left">
|
||||
<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>
|
||||
<span class="id" :title="item.sourceFilename">{{ item.sourceFilename || '-' }}</span>
|
||||
<div v-if="item.outputFilename" class="files">输出文件:{{ item.outputFilename }}</div>
|
||||
<div v-if="item.rowCount !== undefined" class="time">包含 {{ item.rowCount }} 条数据</div>
|
||||
<div v-else-if="item.error" class="files">错误信息:{{ item.error }}</div>
|
||||
</div>
|
||||
|
||||
@@ -136,7 +139,7 @@
|
||||
{{ item.success ? '已完成' : '失败' }}
|
||||
</span>
|
||||
<button
|
||||
v-if="item.success && item.output_path"
|
||||
v-if="item.success && item.downloadUrl"
|
||||
type="button"
|
||||
class="download"
|
||||
@click="downloadSplitResult(item)"
|
||||
@@ -144,10 +147,10 @@
|
||||
下载文件
|
||||
</button>
|
||||
<button
|
||||
v-if="item.result_id"
|
||||
v-if="item.resultId"
|
||||
type="button"
|
||||
class="btn-delete"
|
||||
@click="deleteSplitHistory(item.result_id)"
|
||||
@click="deleteSplitHistoryRecord(item.resultId)"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
@@ -157,16 +160,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import BrandTopBar from './BrandTopBar.vue'
|
||||
import { expandBrandFolder } from '@/shared/api/brand'
|
||||
import { type SplitExcelResultItem, getPywebviewApi, hasPywebview } from '@/shared/bridges/pywebview'
|
||||
import { deleteSplitHistory, getExcelInfo, getSplitHistory, runSplit, type SplitResultItem, type SplitRunVo } from '@/shared/api/java-modules'
|
||||
import { getPywebviewApi, type UploadedJavaFile } from '@/shared/bridges/pywebview'
|
||||
|
||||
const splitSelectedPaths = ref<string[]>([])
|
||||
const splitUploadedFiles = ref<UploadedJavaFile[]>([])
|
||||
const splitAvailableColumns = ref<string[]>([])
|
||||
const splitSelectedColumns = ref<string[]>([])
|
||||
const splitTotalRows = ref(0)
|
||||
@@ -174,55 +181,53 @@ const splitMode = ref<'rows_per_file' | 'parts'>('rows_per_file')
|
||||
const splitRowsPerFile = ref<number | null>(2000)
|
||||
const splitParts = ref<number | null>(5)
|
||||
const splitRunning = ref(false)
|
||||
const splitOutputDir = ref('')
|
||||
const splitResultItems = ref<SplitExcelResultItem[]>([])
|
||||
const splitSummary = ref({ total: 0, success_count: 0, failed_count: 0 })
|
||||
const splitResultItems = ref<SplitResultItem[]>([])
|
||||
const splitSummary = ref<SplitRunVo>({ total: 0, successCount: 0, failedCount: 0, items: [] })
|
||||
const splitDisplayPaths = computed(() => splitSelectedPaths.value.slice(0, 8))
|
||||
|
||||
function shorten(value: string, maxLength: number) {
|
||||
return value.length > maxLength ? `${value.slice(0, maxLength)}...` : value
|
||||
}
|
||||
|
||||
function resetSplitResults() {
|
||||
splitSummary.value = { total: 0, success_count: 0, failed_count: 0 }
|
||||
splitOutputDir.value = ''
|
||||
}
|
||||
|
||||
async function loadSplitInfo(filePath: string) {
|
||||
async function uploadPathsToJava(paths: string[]) {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.get_excel_info) {
|
||||
ElMessage.warning('当前环境不支持读取 Excel 信息,请在桌面端打开')
|
||||
return
|
||||
if (!api?.upload_file_to_java) {
|
||||
throw new Error('当前桌面端未提供文件上传桥接能力')
|
||||
}
|
||||
|
||||
resetSplitResults()
|
||||
const result = await api.get_excel_info(filePath)
|
||||
if (!result.success) {
|
||||
ElMessage.error(result.error || '读取 Excel 信息失败')
|
||||
splitAvailableColumns.value = []
|
||||
splitSelectedColumns.value = []
|
||||
splitTotalRows.value = 0
|
||||
return
|
||||
const uploaded: UploadedJavaFile[] = []
|
||||
for (const path of paths) {
|
||||
const result = await api.upload_file_to_java(path)
|
||||
if (!result?.success || !result.data) {
|
||||
throw new Error(result?.error || result?.message || `上传失败:${path}`)
|
||||
}
|
||||
uploaded.push(result.data)
|
||||
}
|
||||
return uploaded
|
||||
}
|
||||
|
||||
async function loadSplitInfo(fileKey: string) {
|
||||
const result = await getExcelInfo(fileKey)
|
||||
splitAvailableColumns.value = result.headers || []
|
||||
splitSelectedColumns.value = [...(result.headers || [])]
|
||||
splitTotalRows.value = result.total_rows || 0
|
||||
splitTotalRows.value = result.totalRows || 0
|
||||
}
|
||||
|
||||
async function handleSelectedPaths(paths: string[], successMessage: string) {
|
||||
splitSelectedPaths.value = paths
|
||||
splitUploadedFiles.value = await uploadPathsToJava(paths)
|
||||
if (splitUploadedFiles.value.length > 0) {
|
||||
await loadSplitInfo(splitUploadedFiles.value[0].fileKey)
|
||||
}
|
||||
ElMessage.success(successMessage)
|
||||
}
|
||||
|
||||
async function selectSplitFiles() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.select_clean_xlsx_files) {
|
||||
ElMessage.warning('当前环境不支持文件选择,请在桌面端打开')
|
||||
if (!api?.select_brand_xlsx_files) {
|
||||
ElMessage.warning('当前环境不支持文件选择,请在本机客户端中打开')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const paths = await api.select_clean_xlsx_files()
|
||||
const paths = await api.select_brand_xlsx_files()
|
||||
if (!paths?.length) return
|
||||
splitSelectedPaths.value = paths
|
||||
await loadSplitInfo(paths[0])
|
||||
ElMessage.success(`已选择 ${paths.length} 个待拆分文件`)
|
||||
await handleSelectedPaths(paths, `已选择 ${paths.length} 个待拆分文件`)
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '选择失败')
|
||||
}
|
||||
@@ -230,20 +235,18 @@ async function selectSplitFiles() {
|
||||
|
||||
async function selectSplitFolder() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.select_clean_folder) {
|
||||
ElMessage.warning('当前环境不支持文件夹选择,请在桌面端打开')
|
||||
if (!api?.select_brand_folder) {
|
||||
ElMessage.warning('当前环境不支持文件夹选择,请在本机客户端中打开')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const folder = await api.select_clean_folder()
|
||||
const folder = await api.select_brand_folder()
|
||||
if (!folder) return
|
||||
|
||||
const result = await expandBrandFolder(folder)
|
||||
if (result.success && result.paths?.length) {
|
||||
splitSelectedPaths.value = result.paths
|
||||
await loadSplitInfo(result.paths[0])
|
||||
ElMessage.success(`已选择文件夹内 ${result.paths.length} 个 xlsx 文件`)
|
||||
await handleSelectedPaths(result.paths, `已选择文件夹内 ${result.paths.length} 个 xlsx 文件`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -254,12 +257,7 @@ async function selectSplitFolder() {
|
||||
}
|
||||
|
||||
async function submitSplitRun() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.split_excel_files) {
|
||||
ElMessage.warning('当前环境不支持数据拆分,请在桌面端打开')
|
||||
return
|
||||
}
|
||||
if (!splitSelectedPaths.value.length) {
|
||||
if (!splitUploadedFiles.value.length) {
|
||||
ElMessage.warning('请先选择待拆分 Excel 文件或文件夹')
|
||||
return
|
||||
}
|
||||
@@ -278,25 +276,15 @@ async function submitSplitRun() {
|
||||
|
||||
try {
|
||||
splitRunning.value = true
|
||||
const result = await api.split_excel_files({
|
||||
paths: splitSelectedPaths.value,
|
||||
selected_columns: splitSelectedColumns.value,
|
||||
split_mode: splitMode.value,
|
||||
rows_per_file: splitRowsPerFile.value || undefined,
|
||||
parts: splitParts.value || undefined,
|
||||
const result = await runSplit({
|
||||
files: splitUploadedFiles.value.map((item) => ({ fileKey: item.fileKey, originalFilename: item.originalFilename })),
|
||||
selectedColumns: splitSelectedColumns.value,
|
||||
splitMode: splitMode.value,
|
||||
rowsPerFile: splitMode.value === 'rows_per_file' ? splitRowsPerFile.value || undefined : undefined,
|
||||
parts: splitMode.value === 'parts' ? splitParts.value || undefined : undefined,
|
||||
})
|
||||
|
||||
if (!result.success) {
|
||||
ElMessage.error(result.error || '数据拆分失败')
|
||||
return
|
||||
}
|
||||
|
||||
splitOutputDir.value = ''
|
||||
splitSummary.value = {
|
||||
total: result.summary?.total || 0,
|
||||
success_count: result.summary?.success_count || 0,
|
||||
failed_count: result.summary?.failed_count || 0,
|
||||
}
|
||||
splitSummary.value = result
|
||||
splitResultItems.value = result.items || []
|
||||
await loadSplitHistory()
|
||||
ElMessage.success('数据拆分完成')
|
||||
} catch (error) {
|
||||
@@ -307,57 +295,40 @@ async function submitSplitRun() {
|
||||
}
|
||||
|
||||
async function loadSplitHistory() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.get_split_history) return
|
||||
|
||||
try {
|
||||
const response = await api.get_split_history()
|
||||
if (!response.success || !response.items) return
|
||||
splitResultItems.value = response.items
|
||||
const response = await getSplitHistory()
|
||||
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,
|
||||
total: response.items?.length || 0,
|
||||
successCount: response.items?.filter((item) => item.success).length || 0,
|
||||
failedCount: response.items?.filter((item) => !item.success).length || 0,
|
||||
items: response.items || [],
|
||||
}
|
||||
} catch {
|
||||
// ignore history load errors
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadSplitHistory().catch(() => undefined)
|
||||
})
|
||||
|
||||
async function deleteSplitHistory(resultId: number) {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.delete_history_item) {
|
||||
ElMessage.warning('当前环境不支持删除历史')
|
||||
return
|
||||
async function deleteSplitHistoryRecord(resultId: number) {
|
||||
try {
|
||||
await deleteSplitHistory(resultId)
|
||||
await loadSplitHistory()
|
||||
ElMessage.success('已删除')
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '删除失败')
|
||||
}
|
||||
|
||||
const result = await api.delete_history_item('split', resultId)
|
||||
if (!result.success) {
|
||||
ElMessage.error(result.error || '删除失败')
|
||||
return
|
||||
}
|
||||
await loadSplitHistory()
|
||||
ElMessage.success('已删除')
|
||||
}
|
||||
|
||||
async function downloadSplitResult(item: SplitExcelResultItem) {
|
||||
async function downloadSplitResult(item: SplitResultItem) {
|
||||
const api = getPywebviewApi()
|
||||
if (!item.output_path) {
|
||||
if (!item.downloadUrl) {
|
||||
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`
|
||||
const filename = item.outputFilename || `${new Date().toISOString().slice(0, 10).replace(/-/g, '')}.xlsx`
|
||||
if (api?.save_file_from_url) {
|
||||
const result = await api.save_file_from_url(item.output_path, filename)
|
||||
const result = await api.save_file_from_url(item.downloadUrl, filename)
|
||||
if (result.success) {
|
||||
ElMessage.success(`已保存:${result.path || filename}`)
|
||||
} else if (result.error && result.error !== '用户取消') {
|
||||
@@ -366,12 +337,17 @@ async function downloadSplitResult(item: SplitExcelResultItem) {
|
||||
return
|
||||
}
|
||||
|
||||
window.open(item.output_path, '_blank')
|
||||
window.open(item.downloadUrl, '_blank')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadSplitHistory().catch(() => undefined)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.main-content { display: flex; height: calc(100vh - 56px); }
|
||||
.module-page { min-height: 100vh; background: #1a1a1a; }
|
||||
.main-content { display: flex; min-height: calc(100vh - 56px); height: calc(100vh - 56px); }
|
||||
.left-panel { width: 380px; background: #1e1e1e; padding: 20px; overflow-y: auto; border-right: 1px solid #2a2a2a; }
|
||||
.right-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #1a1a1a; }
|
||||
.section-title { font-size: 13px; color: #bbb; margin-bottom: 10px; }
|
||||
@@ -379,7 +355,7 @@ async function downloadSplitResult(item: SplitExcelResultItem) {
|
||||
.upload-zone:hover { border-color: #3498db; background: #2a2a2a; }
|
||||
.hint { color: #888; font-size: 13px; margin-bottom: 12px; line-height: 1.5; }
|
||||
.btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
|
||||
.opt-btn, .btn-run, .download { border: none; cursor: pointer; transition: all 0.2s ease; }
|
||||
.opt-btn, .btn-run, .download, .btn-delete { border: none; cursor: pointer; transition: all 0.2s ease; }
|
||||
.opt-btn { padding: 8px 16px; font-size: 13px; color: #ccc; background: #2a2a2a; border: 1px solid #3a3a3a; border-radius: 6px; }
|
||||
.opt-btn.small { padding: 6px 10px; font-size: 12px; }
|
||||
.opt-btn:hover { color: #3498db; background: #333; border-color: #3498db; }
|
||||
@@ -425,6 +401,8 @@ async function downloadSplitResult(item: SplitExcelResultItem) {
|
||||
.status.failed { background: rgba(231, 76, 60, 0.18); color: #ff6b6b; }
|
||||
.download { padding: 6px 10px; border-radius: 6px; font-size: 12px; background: rgba(52, 152, 219, 0.18); color: #69b6ff; }
|
||||
.download:hover { background: rgba(52, 152, 219, 0.28); }
|
||||
.btn-delete { padding: 6px 10px; border-radius: 6px; font-size: 12px; background: rgba(231, 76, 60, 0.12); color: #ff8f8f; }
|
||||
.btn-delete:hover { background: rgba(231, 76, 60, 0.22); }
|
||||
.empty-tasks { color: #666; font-size: 13px; padding: 24px 8px; }
|
||||
.clean-placeholder { max-height: none; }
|
||||
.clean-result-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 220px)); gap: 16px; margin-bottom: 18px; }
|
||||
@@ -433,7 +411,5 @@ async function downloadSplitResult(item: SplitExcelResultItem) {
|
||||
.summary-label { font-size: 12px; color: #8d8d8d; }
|
||||
.result-list-wrap { border: 1px solid #2a2a2a; border-radius: 10px; background: #1e1e1e; min-height: 260px; }
|
||||
.result-list-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid #2a2a2a; font-size: 14px; color: #ddd; }
|
||||
.download-all { padding: 7px 12px; border: 1px solid #2f5f85; border-radius: 6px; background: rgba(52, 152, 219, 0.14); color: #69b6ff; font-size: 12px; cursor: pointer; }
|
||||
.download-all:disabled { cursor: not-allowed; opacity: 0.55; }
|
||||
@media (max-width: 1100px) { .main-content { flex-direction: column; height: auto; } .left-panel { width: 100%; border-right: none; border-bottom: 1px solid #2a2a2a; } .right-panel { min-height: 420px; } .task-item { flex-direction: column; align-items: flex-start; } .task-right { width: 100%; justify-content: flex-start; } .clean-result-summary { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user