完成新需求
This commit is contained in:
@@ -41,13 +41,23 @@
|
||||
:class="{ active: convertTemplateId === template.id }"
|
||||
>
|
||||
<input v-model="convertTemplateId" type="radio" :value="template.id" name="convert-template" />
|
||||
<div>
|
||||
<span class="label">
|
||||
{{ template.label }}
|
||||
<span v-if="template.is_default" class="template-tag">默认</span>
|
||||
<span v-else-if="template.built_in" class="template-tag muted">内置</span>
|
||||
</span>
|
||||
<div class="desc">输出文件:{{ template.output_filename }}</div>
|
||||
<div class="template-item-content">
|
||||
<div>
|
||||
<span class="label">
|
||||
{{ template.label }}
|
||||
<span v-if="template.is_default" class="template-tag">默认</span>
|
||||
<span v-else-if="template.built_in" class="template-tag muted">内置</span>
|
||||
</span>
|
||||
<div class="desc">输出文件:{{ template.output_filename }}</div>
|
||||
</div>
|
||||
<button
|
||||
v-if="!template.built_in"
|
||||
type="button"
|
||||
class="template-delete-btn"
|
||||
@click.stop.prevent="deleteConvertTemplate(template.id)"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
@@ -81,7 +91,7 @@
|
||||
{{ convertRunning ? '转换中...' : '开始转换' }}
|
||||
</button>
|
||||
<span class="loading-msg">
|
||||
{{ convertRunning ? '正在生成英国.txt,请稍候…' : '选择文件后即可执行格式转换' }}
|
||||
{{ convertRunning ? '正在生成并上传结果,请稍候…' : '选择文件后即可执行格式转换,结果会显示在右侧供下载' }}
|
||||
</span>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -108,9 +118,6 @@
|
||||
<div class="result-list-wrap">
|
||||
<div class="result-list-header">
|
||||
<span>生成的 txt 列表</span>
|
||||
<button type="button" class="download-all" :disabled="!convertOutputDir" @click="openConvertOutputDir">
|
||||
打开输出目录
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="convertResultItems.length === 0" class="empty-tasks">
|
||||
@@ -120,12 +127,12 @@
|
||||
<ul v-else class="task-list clean-result-list">
|
||||
<li
|
||||
v-for="item in convertResultItems"
|
||||
:key="`${item.source_path}-${item.output_path || item.error || 'convert'}`"
|
||||
:key="`${item.output_path || item.source_path || item.error || 'convert'}`"
|
||||
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-else-if="item.error" class="files">错误信息:{{ item.error }}</div>
|
||||
</div>
|
||||
|
||||
@@ -137,9 +144,17 @@
|
||||
v-if="item.success && item.output_path"
|
||||
type="button"
|
||||
class="download"
|
||||
@click="openConvertResult(item)"
|
||||
@click="downloadConvertResult(item)"
|
||||
>
|
||||
打开文件
|
||||
下载文件
|
||||
</button>
|
||||
<button
|
||||
v-if="item.result_id"
|
||||
type="button"
|
||||
class="btn-delete"
|
||||
@click="deleteConvertHistory(item.result_id)"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
@@ -175,7 +190,6 @@ function shorten(value: string, maxLength: number) {
|
||||
}
|
||||
|
||||
function resetConvertResults() {
|
||||
convertResultItems.value = []
|
||||
convertSummary.value = { total: 0, success_count: 0, failed_count: 0 }
|
||||
convertOutputDir.value = ''
|
||||
}
|
||||
@@ -217,6 +231,26 @@ async function importConvertTemplate() {
|
||||
ElMessage.success('模板导入成功')
|
||||
}
|
||||
|
||||
async function deleteConvertTemplate(templateId: string) {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.delete_txt_template) {
|
||||
ElMessage.warning('当前环境不支持删除模板')
|
||||
return
|
||||
}
|
||||
|
||||
const result = await api.delete_txt_template(templateId)
|
||||
if (!result.success) {
|
||||
ElMessage.error(result.error || '删除模板失败')
|
||||
return
|
||||
}
|
||||
|
||||
if (convertTemplateId.value === templateId) {
|
||||
convertTemplateId.value = ''
|
||||
}
|
||||
await loadConvertTemplates()
|
||||
ElMessage.success('模板已删除')
|
||||
}
|
||||
|
||||
async function setConvertDefaultTemplate() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.set_default_txt_template || !convertTemplateId.value) {
|
||||
@@ -279,7 +313,7 @@ async function selectConvertFolder() {
|
||||
|
||||
async function submitConvertRun() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.convert_excel_to_uk_txt || !api?.select_folder) {
|
||||
if (!api?.convert_excel_to_uk_txt) {
|
||||
ElMessage.warning('当前环境不支持格式转换,请在桌面端打开')
|
||||
return
|
||||
}
|
||||
@@ -289,13 +323,9 @@ async function submitConvertRun() {
|
||||
}
|
||||
|
||||
try {
|
||||
const outputDir = await api.select_folder()
|
||||
if (!outputDir) return
|
||||
|
||||
convertRunning.value = true
|
||||
const result = await api.convert_excel_to_uk_txt({
|
||||
paths: convertSelectedPaths.value,
|
||||
output_dir: outputDir,
|
||||
template_id: convertTemplateId.value,
|
||||
})
|
||||
|
||||
@@ -304,13 +334,13 @@ async function submitConvertRun() {
|
||||
return
|
||||
}
|
||||
|
||||
convertOutputDir.value = result.summary?.output_dir || outputDir
|
||||
convertOutputDir.value = ''
|
||||
convertSummary.value = {
|
||||
total: result.summary?.total || 0,
|
||||
success_count: result.summary?.success_count || 0,
|
||||
failed_count: result.summary?.failed_count || 0,
|
||||
}
|
||||
convertResultItems.value = result.items || []
|
||||
await loadConvertHistory()
|
||||
ElMessage.success('格式转换完成')
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '格式转换失败')
|
||||
@@ -319,34 +349,68 @@ async function submitConvertRun() {
|
||||
}
|
||||
}
|
||||
|
||||
async function openConvertOutputDir() {
|
||||
async function deleteConvertHistory(resultId: number) {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.open_path || !convertOutputDir.value) {
|
||||
ElMessage.warning('当前环境不支持打开输出目录')
|
||||
if (!api?.delete_history_item) {
|
||||
ElMessage.warning('当前环境不支持删除历史')
|
||||
return
|
||||
}
|
||||
|
||||
const result = await api.open_path(convertOutputDir.value)
|
||||
const result = await api.delete_history_item('convert', resultId)
|
||||
if (!result.success) {
|
||||
ElMessage.error(result.error || '打开目录失败')
|
||||
ElMessage.error(result.error || '删除失败')
|
||||
return
|
||||
}
|
||||
await loadConvertHistory()
|
||||
ElMessage.success('已删除')
|
||||
}
|
||||
|
||||
async function openConvertResult(item: ConvertTxtResultItem) {
|
||||
async function downloadConvertResult(item: ConvertTxtResultItem) {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.open_path || !item.output_path) {
|
||||
ElMessage.warning('当前环境不支持打开结果文件')
|
||||
if (!item.output_path) {
|
||||
ElMessage.warning('当前结果没有下载地址')
|
||||
return
|
||||
}
|
||||
|
||||
const result = await api.open_path(item.output_path)
|
||||
if (!result.success) {
|
||||
ElMessage.error(result.error || '打开文件失败')
|
||||
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}.txt`
|
||||
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')
|
||||
}
|
||||
|
||||
async function loadConvertHistory() {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.get_convert_history) return
|
||||
|
||||
try {
|
||||
const response = await api.get_convert_history()
|
||||
if (!response.success || !response.items) return
|
||||
convertResultItems.value = response.items
|
||||
convertSummary.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
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadConvertTemplates().catch(() => undefined)
|
||||
loadConvertHistory().catch(() => undefined)
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -374,7 +438,10 @@ onMounted(() => {
|
||||
.template-tag { margin-left: 8px; padding: 2px 8px; border-radius: 999px; font-size: 11px; color: #8fd0ff; background: rgba(52, 152, 219, 0.14); }
|
||||
.template-tag.muted { color: #b8b8b8; background: rgba(255, 255, 255, 0.08); }
|
||||
.compact-row { margin-top: 4px; }
|
||||
.radio-item { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 10px 12px; border-radius: 8px; background: #252525; border: 1px solid #2a2a2a; margin-bottom: 8px; transition: all 0.2s ease; }
|
||||
.radio-item { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 10px 12px; border-radius: 8px; background: #252525; border: 1px solid #2a2a2a; margin-bottom: 8px; transition: all 0.2s ease; }
|
||||
.template-item-content { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; }
|
||||
.template-delete-btn { padding: 6px 10px; border: 1px solid #5c2f2f; border-radius: 6px; background: rgba(231, 76, 60, 0.12); color: #ff8f8f; font-size: 12px; cursor: pointer; }
|
||||
.template-delete-btn:hover { background: rgba(231, 76, 60, 0.2); }
|
||||
.radio-item:hover, .radio-item.active { background: #2a2a2a; border-color: #3a3a3a; }
|
||||
.radio-item input { margin-top: 3px; }
|
||||
.label { font-weight: 500; color: #e0e0e0; font-size: 13px; }
|
||||
|
||||
Reference in New Issue
Block a user