feat(思维导图助手):优化重构
parent
846739cf77
commit
46f3467959
|
|
@ -1,8 +1,8 @@
|
|||
import request from '@/utils/request'
|
||||
import type { AxiosResponse } from 'axios'
|
||||
|
||||
import { hubCall } from './hub'
|
||||
import { uuid } from '@/utils/uuid'
|
||||
export interface ParseParams {
|
||||
files: File[]
|
||||
parser_resource_id: string
|
||||
output_dir: string
|
||||
lang_list: string
|
||||
backend: string
|
||||
|
|
@ -41,80 +41,41 @@ export interface MindmapOrganizeProgress extends ParseProgress {
|
|||
result_md?: string | null
|
||||
}
|
||||
|
||||
export const documentApi = {
|
||||
/**
|
||||
* 解析文档
|
||||
*/
|
||||
parseDocument(params: ParseParams, taskId?: string): Promise<ParseResult> {
|
||||
const formData = new FormData()
|
||||
|
||||
// 添加文件
|
||||
params.files.forEach(file => {
|
||||
formData.append('files', file)
|
||||
})
|
||||
|
||||
// 添加其他参数
|
||||
formData.append('output_dir', params.output_dir)
|
||||
formData.append('lang_list', params.lang_list)
|
||||
formData.append('backend', params.backend)
|
||||
formData.append('parse_method', params.parse_method)
|
||||
formData.append('formula_enable', params.formula_enable.toString())
|
||||
formData.append('table_enable', params.table_enable.toString())
|
||||
formData.append('start_page_id', params.start_page_id.toString())
|
||||
formData.append('end_page_id', params.end_page_id.toString())
|
||||
formData.append('return_md', params.return_md.toString())
|
||||
formData.append('return_middle_json', params.return_middle_json.toString())
|
||||
formData.append('response_format_zip', params.response_format_zip.toString())
|
||||
|
||||
if (params.server_url) {
|
||||
formData.append('server_url', params.server_url)
|
||||
}
|
||||
if (taskId) {
|
||||
formData.append('task_id', taskId)
|
||||
}
|
||||
|
||||
return request.post('/file_parse', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
...(taskId ? { 'X-Task-ID': taskId } : {})
|
||||
}
|
||||
}).then(result => {
|
||||
console.log("解析成功:", result);
|
||||
return result as unknown as ParseResult;
|
||||
}).catch(error => {
|
||||
console.error("解析失败:", error);
|
||||
throw error;
|
||||
})
|
||||
},
|
||||
|
||||
createParseTask(taskId: string): Promise<ParseProgress> {
|
||||
return request.post(`/parse_tasks/${encodeURIComponent(taskId)}`).then(result => {
|
||||
return result as unknown as ParseProgress
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 查询解析进度
|
||||
*/
|
||||
getParseProgress(taskId: string): Promise<ParseProgress> {
|
||||
return request.get(`/parse_progress/${taskId}`).then(result => {
|
||||
return result as unknown as ParseProgress
|
||||
})
|
||||
},
|
||||
|
||||
createMindmapTask(taskId: string, markdown: string, mode = 'smart', prompt?: string): Promise<MindmapOrganizeProgress> {
|
||||
return request.post(`/mindmap_tasks/${encodeURIComponent(taskId)}`, {
|
||||
markdown,
|
||||
mode,
|
||||
prompt
|
||||
}).then(result => {
|
||||
return result as unknown as MindmapOrganizeProgress
|
||||
})
|
||||
},
|
||||
|
||||
getMindmapProgress(taskId: string): Promise<MindmapOrganizeProgress> {
|
||||
return request.get(`/mindmap_progress/${encodeURIComponent(taskId)}`).then(result => {
|
||||
return result as unknown as MindmapOrganizeProgress
|
||||
})
|
||||
}
|
||||
const ids = new Map<string, string>()
|
||||
const states: Record<string, ParseProgress['status']> = { PENDING: 'pending', RUNNING: 'processing', SUCCESS: 'completed', FAILED: 'failed' }
|
||||
async function progress(taskId: string): Promise<MindmapOrganizeProgress> {
|
||||
const id = ids.get(taskId)
|
||||
if (!id) return { progress: 0, status: 'pending', stage: '准备中', error: null, file_names: '' }
|
||||
const task = await hubCall('tasks', 'get', undefined, id)
|
||||
return { progress: task.status === 'SUCCESS' ? 100 : Math.floor((task.steps || []).filter((s: any) => s.status === 'SUCCESS').length * 100 / Math.max(1, task.snapshot?.nodes?.length || 1)), status: states[task.status], stage: task.status === 'PENDING' ? '等待处理' : task.status === 'RUNNING' ? '处理中' : task.status === 'SUCCESS' ? '完成' : '失败', error: task.error, file_names: task.name, result_md: task.result?.markdown }
|
||||
}
|
||||
export const documentApi = {
|
||||
async parseDocument(params: ParseParams, taskId: string = uuid()): Promise<ParseResult> {
|
||||
if (!params.parser_resource_id) throw new Error('请选择解析服务')
|
||||
const results: ParseResult['results'] = {}
|
||||
for (const file of params.files) {
|
||||
const task = await hubCall('tasks', 'post', { name: file.name.slice(0, 128), nodes: [{ type: 'parse', resource_id: params.parser_resource_id }, { type: 'render' }] }, undefined, file)
|
||||
ids.set(taskId, task.id)
|
||||
const until = Date.now() + 30 * 60 * 1000
|
||||
let completed = false
|
||||
while (Date.now() < until) {
|
||||
const current = await hubCall('tasks', 'get', undefined, task.id)
|
||||
if (current.status === 'FAILED') throw new Error(current.error || '解析失败')
|
||||
if (current.status === 'SUCCESS') { results[file.name] = { md_content: current.result.markdown, middle_json: JSON.stringify(current.result.source) }; completed = true; break }
|
||||
await new Promise(resolve => setTimeout(resolve, 1500))
|
||||
}
|
||||
if (!completed) throw new Error('任务仍在处理中,请到管理页查看')
|
||||
}
|
||||
return { backend: 'shared', version: '1', results }
|
||||
},
|
||||
async createParseTask(_taskId: string): Promise<ParseProgress> { return { progress: 0, stage: '准备中', status: 'pending', error: null, file_names: '' } },
|
||||
getParseProgress: progress,
|
||||
async createMindmapTask(taskId: string, markdown: string, _mode = 'smart', prompt?: string, config?: { model_id: string; temperature: number }): Promise<MindmapOrganizeProgress> {
|
||||
if (!config?.model_id) throw new Error('请选择整理模型')
|
||||
const task = await hubCall('tasks', 'post', { name: '智能整理', markdown, nodes: [{ type: 'organize', model_id: config.model_id, prompt, temperature: config.temperature }, { type: 'render' }] })
|
||||
ids.set(taskId, task.id)
|
||||
return progress(taskId)
|
||||
},
|
||||
getMindmapProgress: progress
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,483 +1,35 @@
|
|||
<template>
|
||||
<div class="config-panel">
|
||||
<h3 class="panel-title">{{ $t('config.title') }}</h3>
|
||||
|
||||
<el-form :model="config" label-position="top" label-width="120px" class="config-form">
|
||||
<!-- 最大页数 -->
|
||||
<el-form-item :label="$t('config.maxPages')" class="form-item">
|
||||
<el-slider
|
||||
v-model="draftConfig.maxPages"
|
||||
:min="1"
|
||||
:max="1000"
|
||||
show-input
|
||||
class="slider"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 解析后端 -->
|
||||
<el-form-item :label="$t('config.backend')" class="form-item">
|
||||
<el-select
|
||||
v-model="draftConfig.backend"
|
||||
style="width: 100%"
|
||||
@change="onBackendChange"
|
||||
class="select"
|
||||
>
|
||||
<el-option
|
||||
v-for="option in backendOptions"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-item-description">
|
||||
{{ getBackendDescription(draftConfig.backend) }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 服务器URL (仅当使用http-client时显示) -->
|
||||
<el-form-item
|
||||
v-if="showServerUrl"
|
||||
:label="$t('config.serverUrl')"
|
||||
class="form-item"
|
||||
>
|
||||
<el-input
|
||||
v-model="draftConfig.serverUrl"
|
||||
:placeholder="'http://localhost:30000'"
|
||||
class="input"
|
||||
/>
|
||||
<div class="form-item-description">
|
||||
{{ $t('config.serverUrlInfo') }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 识别选项 -->
|
||||
<div class="section-title">{{ $t('config.recognitionOptions') }}</div>
|
||||
|
||||
<!-- 表格识别 -->
|
||||
<el-form-item class="form-item">
|
||||
<el-checkbox v-model="draftConfig.tableEnable" class="checkbox">
|
||||
{{ $t('config.tableEnable') }}
|
||||
</el-checkbox>
|
||||
<div class="form-item-description">
|
||||
{{ $t('config.tableInfo') }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 公式识别 -->
|
||||
<el-form-item class="form-item">
|
||||
<el-checkbox v-model="draftConfig.formulaEnable" class="checkbox">
|
||||
{{ getFormulaLabel(draftConfig.backend) }}
|
||||
</el-checkbox>
|
||||
<div class="form-item-description">
|
||||
{{ getFormulaInfo(draftConfig.backend) }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<!-- OCR选项 (非VLM后端时显示) -->
|
||||
<template v-if="!isVlmBackend">
|
||||
<div class="divider"></div>
|
||||
|
||||
<!-- OCR语言 -->
|
||||
<el-form-item :label="$t('config.ocrLanguage')" class="form-item">
|
||||
<el-select v-model="draftConfig.language" style="width: 100%" class="select">
|
||||
<el-option
|
||||
v-for="option in languageOptions"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-item-description">
|
||||
{{ $t('config.ocrLanguageInfo') }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 强制OCR -->
|
||||
<el-form-item class="form-item">
|
||||
<el-checkbox v-model="draftConfig.forceOcr" class="checkbox">
|
||||
{{ $t('config.forceOcr') }}
|
||||
</el-checkbox>
|
||||
<div class="form-item-description">
|
||||
{{ $t('config.forceOcrInfo') }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="section-title">导出与智能整理</div>
|
||||
|
||||
<el-form-item label="导出分辨率" class="form-item">
|
||||
<el-select v-model="exportResolutionPreset" style="width: 100%" class="select">
|
||||
<el-option
|
||||
v-for="option in exportResolutionOptions"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input-number
|
||||
v-if="exportResolutionPreset === 'custom'"
|
||||
v-model="draftConfig.exportResolution"
|
||||
:min="720"
|
||||
:max="16384"
|
||||
:step="100"
|
||||
controls-position="right"
|
||||
class="export-resolution-input"
|
||||
/>
|
||||
<div class="form-item-description">
|
||||
PNG/JPEG 导出长边上限;默认 8K,导出文件会按该最大长边生效。
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="大模型服务地址" class="form-item">
|
||||
<el-input
|
||||
v-model="draftConfig.mindmapLlmBaseUrl"
|
||||
placeholder="例如:http://10.100.53.199:9527/v1"
|
||||
class="input"
|
||||
clearable
|
||||
/>
|
||||
<div class="form-item-description">
|
||||
OpenAI 兼容接口地址,后端会请求该地址下的 /chat/completions;留空时使用服务端 MINDMAP_LLM_BASE_URL。
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="大模型 API Key" class="form-item">
|
||||
<el-input
|
||||
v-model="draftConfig.mindmapLlmApiKey"
|
||||
type="password"
|
||||
placeholder="留空则使用服务端 MINDMAP_LLM_API_KEY"
|
||||
class="input"
|
||||
show-password
|
||||
clearable
|
||||
/>
|
||||
<div class="form-item-description">
|
||||
仅随智能整理请求发送给后端,后端日志不会输出明文 Key。
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="大模型名称" class="form-item">
|
||||
<el-input
|
||||
v-model="draftConfig.mindmapLlmModel"
|
||||
placeholder="gemma-4-26B"
|
||||
class="input"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<div class="llm-grid">
|
||||
<el-form-item label="请求超时(秒)" class="form-item">
|
||||
<el-input-number
|
||||
v-model="draftConfig.mindmapLlmTimeout"
|
||||
:min="30"
|
||||
:max="3600"
|
||||
:step="30"
|
||||
controls-position="right"
|
||||
class="number-input"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="温度" class="form-item">
|
||||
<el-input-number
|
||||
v-model="draftConfig.mindmapLlmTemperature"
|
||||
:min="0"
|
||||
:max="2"
|
||||
:step="0.1"
|
||||
:precision="1"
|
||||
controls-position="right"
|
||||
class="number-input"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="最大上下文 Token" class="form-item">
|
||||
<el-input-number
|
||||
v-model="draftConfig.mindmapLlmMaxContextTokens"
|
||||
:min="4096"
|
||||
:max="262144"
|
||||
:step="1024"
|
||||
controls-position="right"
|
||||
class="number-input"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="最大输出 Token" class="form-item">
|
||||
<el-input-number
|
||||
v-model="draftConfig.mindmapLlmMaxOutputTokens"
|
||||
:min="512"
|
||||
:max="32768"
|
||||
:step="512"
|
||||
controls-position="right"
|
||||
class="number-input"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="安全预留 Token" class="form-item">
|
||||
<el-input-number
|
||||
v-model="draftConfig.mindmapLlmSafetyTokens"
|
||||
:min="0"
|
||||
:max="8192"
|
||||
:step="256"
|
||||
controls-position="right"
|
||||
class="number-input"
|
||||
/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<el-form-item label="智能整理提示词" class="form-item">
|
||||
<el-input
|
||||
v-model="draftConfig.mindmapPrompt"
|
||||
type="textarea"
|
||||
:rows="10"
|
||||
resize="vertical"
|
||||
class="input"
|
||||
/>
|
||||
<div class="form-item-description">
|
||||
切换到“智能整理”时发送给后端大模型;默认保留标题结构、总结段落要点,并保持原文语言。
|
||||
</div>
|
||||
</el-form-item>
|
||||
<div class="config-actions">
|
||||
<el-button @click="resetDraft">重置</el-button>
|
||||
<el-button type="primary" @click="confirmConfig">确认</el-button>
|
||||
</div>
|
||||
<el-form label-position="top">
|
||||
<el-form-item label="解析服务"><el-select v-model="draft.parserResourceId" placeholder="请选择"><el-option v-for="p in resources.parsers" :key="p.id" :label="p.name" :value="p.id"/></el-select></el-form-item>
|
||||
<el-form-item label="整理模型"><el-select v-model="draft.mindmapModelId" clearable placeholder="请选择"><el-option v-for="m in models" :key="m.id" :label="m.name" :value="m.id"/></el-select></el-form-item>
|
||||
<el-form-item label="温度"><el-input-number v-model="draft.mindmapLlmTemperature" :min="0" :max="2" :step="0.1"/></el-form-item>
|
||||
<el-form-item label="整理提示词"><el-input v-model="draft.mindmapPrompt" type="textarea" :rows="6" /></el-form-item>
|
||||
<el-form-item label="导出长边"><el-select v-model="draft.exportResolution"><el-option label="1080P" :value="1080"/><el-option label="2K" :value="2560"/><el-option label="4K" :value="3840"/></el-select></el-form-item>
|
||||
<div v-if="error" class="error">{{ error }}</div>
|
||||
<div class="actions"><el-button @click="load">刷新资源</el-button><el-button type="primary" @click="confirm">确认</el-button></div>
|
||||
</el-form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { DEFAULT_DOCUMENT_CONFIG, type DocumentConfig } from '@/composables/useDocumentProcessor'
|
||||
|
||||
interface Props {
|
||||
modelValue: DocumentConfig
|
||||
backendOptions: Array<{ value: string; label: string }>
|
||||
languageOptions: Array<{ value: string; label: string }>
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: DocumentConfig): void
|
||||
(e: 'backendChange', backend: string): void
|
||||
(e: 'close'): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const exportResolutionOptions = [
|
||||
{ label: '1080P', value: 1080 },
|
||||
{ label: '2K', value: 2560 },
|
||||
{ label: '4K', value: 3840 },
|
||||
{ label: '8K', value: 7680 },
|
||||
{ label: '自定义', value: 'custom' }
|
||||
] as const
|
||||
|
||||
const createDraft = (value: DocumentConfig): DocumentConfig => ({ ...value })
|
||||
const draftConfig = reactive<DocumentConfig>(createDraft(props.modelValue))
|
||||
|
||||
const getExportResolutionPreset = (resolution: number): number | 'custom' => {
|
||||
const isPreset = exportResolutionOptions.some((option) => {
|
||||
return typeof option.value === 'number' && option.value === resolution
|
||||
})
|
||||
return isPreset ? resolution : 'custom'
|
||||
}
|
||||
|
||||
const exportResolutionPreset = ref<number | 'custom'>(getExportResolutionPreset(props.modelValue.exportResolution))
|
||||
|
||||
watch(exportResolutionPreset, (value) => {
|
||||
if (value === 'custom') {
|
||||
if (getExportResolutionPreset(draftConfig.exportResolution) !== 'custom') {
|
||||
draftConfig.exportResolution = 3840
|
||||
}
|
||||
return
|
||||
}
|
||||
draftConfig.exportResolution = value
|
||||
})
|
||||
|
||||
const syncDraft = (value: DocumentConfig) => {
|
||||
Object.assign(draftConfig, createDraft(value))
|
||||
exportResolutionPreset.value = getExportResolutionPreset(value.exportResolution)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => syncDraft(value),
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const showServerUrl = computed(() => {
|
||||
return draftConfig.backend.includes('http-client')
|
||||
})
|
||||
|
||||
const isVlmBackend = computed(() => {
|
||||
return draftConfig.backend.startsWith('vlm')
|
||||
})
|
||||
|
||||
const onBackendChange = (backend: string) => {
|
||||
if (!backend.includes('http-client')) {
|
||||
draftConfig.serverUrl = props.modelValue.serverUrl
|
||||
}
|
||||
}
|
||||
|
||||
const resetDraft = () => {
|
||||
const defaults = createDraft(DEFAULT_DOCUMENT_CONFIG)
|
||||
syncDraft(defaults)
|
||||
emit('update:modelValue', defaults)
|
||||
emit('backendChange', defaults.backend)
|
||||
ElMessage.success('已恢复默认设置')
|
||||
emit('close')
|
||||
}
|
||||
|
||||
const confirmConfig = () => {
|
||||
const confirmed = createDraft(draftConfig)
|
||||
emit('update:modelValue', confirmed)
|
||||
emit('backendChange', confirmed.backend)
|
||||
ElMessage.success('设置已确认')
|
||||
emit('close')
|
||||
}
|
||||
|
||||
const getFormulaLabel = (backend: string) => {
|
||||
if (backend.startsWith('vlm')) {
|
||||
return '启用行间公式识别'
|
||||
} else if (backend === 'pipeline') {
|
||||
return '启用公式识别'
|
||||
} else if (backend.startsWith('hybrid')) {
|
||||
return '启用行内公式识别'
|
||||
}
|
||||
return '启用公式识别'
|
||||
}
|
||||
|
||||
const getFormulaInfo = (backend: string) => {
|
||||
if (backend.startsWith('vlm')) {
|
||||
return '禁用后,行间公式将显示为图片。'
|
||||
} else if (backend === 'pipeline') {
|
||||
return '禁用后,行间公式将显示为图片,行内公式将不会被检测或解析。'
|
||||
} else if (backend.startsWith('hybrid')) {
|
||||
return '禁用后,行内公式将不会被检测或解析。'
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
const getBackendDescription = (backend: string) => {
|
||||
const descriptions: Record<string, string> = {
|
||||
'pipeline': '传统多模型管道解析,支持多语言,无幻觉。',
|
||||
'vlm-auto-engine': '多模态大模型高精度解析,仅支持中英文文档。',
|
||||
'hybrid-auto-engine': '高精度混合解析,支持多语言。',
|
||||
'vlm-http-client': '多模态大模型高精度解析,通过远程服务器处理。',
|
||||
'hybrid-http-client': '高精度混合解析,通过远程服务器处理。'
|
||||
}
|
||||
return descriptions[backend] || '选择文档解析的后端引擎。'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import type { DocumentConfig } from '@/composables/useDocumentProcessor'
|
||||
import { hubCall } from '@/api/hub'
|
||||
const props = defineProps<{ modelValue: DocumentConfig; backendOptions: any[]; languageOptions: any[] }>()
|
||||
const emit = defineEmits(['update:modelValue', 'backendChange', 'close'])
|
||||
const draft = reactive({ ...props.modelValue })
|
||||
const resources = ref<any>({ parsers: [], models: [] }), error = ref('')
|
||||
const models = computed(() => resources.value.models.filter((m: any) => m.model_type === 'LLM'))
|
||||
watch(() => props.modelValue, value => Object.assign(draft, value), { deep: true })
|
||||
async function load() {
|
||||
try {
|
||||
resources.value = await hubCall('resources'); error.value = ''
|
||||
if (!draft.parserResourceId && resources.value.parsers?.length) draft.parserResourceId = resources.value.parsers[0].id
|
||||
if (!draft.mindmapModelId && models.value.length) draft.mindmapModelId = models.value[0].id
|
||||
if (draft.parserResourceId || draft.mindmapModelId) emit('update:modelValue', { ...draft })
|
||||
} catch (e: any) { error.value = e.message }
|
||||
}
|
||||
function confirm() { emit('update:modelValue', { ...draft }); emit('close') }
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.config-panel {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
color: #303133;
|
||||
margin: 0 0 20px 0;
|
||||
}
|
||||
|
||||
.config-form {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-item label {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #303133;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
height: 1px;
|
||||
background-color: #E4E7ED;
|
||||
margin: 24px 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-weight: 500;
|
||||
margin: 0 0 16px 0;
|
||||
color: #303133;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-item-description {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 8px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.llm-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0 12px;
|
||||
}
|
||||
|
||||
.number-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.config-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid #E4E7ED;
|
||||
}
|
||||
|
||||
.slider :deep(.el-slider__runway) {
|
||||
background-color: #E4E7ED;
|
||||
}
|
||||
|
||||
.slider :deep(.el-slider__bar) {
|
||||
background-color: #1677FF;
|
||||
}
|
||||
|
||||
.slider :deep(.el-slider__button) {
|
||||
border-color: #1677FF;
|
||||
}
|
||||
|
||||
.select :deep(.el-select__input) {
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.select :deep(.el-select__wrapper) {
|
||||
border: 1px solid #E4E7ED;
|
||||
border-radius: 4px;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.select :deep(.el-select__wrapper.is-focus) {
|
||||
border-color: #1677FF;
|
||||
box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.2);
|
||||
}
|
||||
|
||||
.input :deep(.el-input__wrapper) {
|
||||
border: 1px solid #E4E7ED;
|
||||
border-radius: 4px;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.input :deep(.el-input__wrapper.is-focus) {
|
||||
border-color: #1677FF;
|
||||
box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.2);
|
||||
}
|
||||
|
||||
.checkbox :deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
|
||||
background-color: #1677FF;
|
||||
border-color: #1677FF;
|
||||
}
|
||||
|
||||
.checkbox :deep(.el-checkbox__label) {
|
||||
color: #303133;
|
||||
}
|
||||
</style>
|
||||
<style scoped>.config-panel { padding: 12px; } .el-select { width: 100%; } .actions { display: flex; justify-content: flex-end; gap: 8px; } .error { color: var(--el-color-danger); margin: 8px 0; }</style>
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
|||
// 导入 markmap 相关包
|
||||
import { Transformer } from 'markmap-lib'
|
||||
import { Markmap, loadCSS, loadJS } from 'markmap-view'
|
||||
import * as markmapView from 'markmap-view'
|
||||
|
||||
const props = defineProps({
|
||||
content: {
|
||||
|
|
@ -159,11 +160,11 @@ const initMarkmap = async () => {
|
|||
isRendering.value = true
|
||||
|
||||
try {
|
||||
const { root } = transformer.transform(props.content)
|
||||
const { styles, scripts } = transformer.getAssets()
|
||||
const { root, features } = transformer.transform(props.content)
|
||||
const { styles, scripts } = transformer.getUsedAssets(features)
|
||||
|
||||
if (styles) loadCSS(styles)
|
||||
if (scripts) loadJS(scripts)
|
||||
if (scripts) await loadJS(scripts, { getMarkmap: () => markmapView })
|
||||
|
||||
await nextTick()
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@ export interface DocumentConfig {
|
|||
serverUrl: string
|
||||
exportResolution: number
|
||||
mindmapPrompt: string
|
||||
mindmapLlmBaseUrl: string
|
||||
mindmapLlmApiKey: string
|
||||
mindmapLlmModel: string
|
||||
parserResourceId: string
|
||||
mindmapModelId: string
|
||||
mindmapLlmTimeout: number
|
||||
mindmapLlmTemperature: number
|
||||
mindmapLlmMaxContextTokens: number
|
||||
|
|
@ -57,9 +56,8 @@ export const DEFAULT_DOCUMENT_CONFIG: DocumentConfig = {
|
|||
serverUrl: 'http://localhost:30000',
|
||||
exportResolution: 7680,
|
||||
mindmapPrompt: DEFAULT_MINDMAP_PROMPT,
|
||||
mindmapLlmBaseUrl: '',
|
||||
mindmapLlmApiKey: '',
|
||||
mindmapLlmModel: 'gemma-4-26B',
|
||||
parserResourceId: '',
|
||||
mindmapModelId: '',
|
||||
mindmapLlmTimeout: 180,
|
||||
mindmapLlmTemperature: 0.2,
|
||||
mindmapLlmMaxContextTokens: 32768,
|
||||
|
|
@ -74,8 +72,12 @@ export const DEFAULT_DOCUMENT_CONFIG: DocumentConfig = {
|
|||
function loadCachedConfig(): Partial<DocumentConfig> {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(DOCUMENT_CONFIG_STORAGE_KEY)
|
||||
return raw ? JSON.parse(raw) : {}
|
||||
const cached = raw ? JSON.parse(raw) : {}
|
||||
const safe = Object.fromEntries(Object.keys(DEFAULT_DOCUMENT_CONFIG).filter(key => key in cached).map(key => [key, cached[key]]))
|
||||
window.localStorage.setItem(DOCUMENT_CONFIG_STORAGE_KEY, JSON.stringify(safe))
|
||||
return safe
|
||||
} catch {
|
||||
try { window.localStorage.removeItem(DOCUMENT_CONFIG_STORAGE_KEY) } catch { /* Storage unavailable. */ }
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
|
@ -308,6 +310,7 @@ export function useDocumentProcessor() {
|
|||
processingStage.value = '提交文档到解析服务'
|
||||
const params: ParseParams = {
|
||||
files: uploadedFiles.value,
|
||||
parser_resource_id: config.parserResourceId,
|
||||
output_dir: './output',
|
||||
lang_list: config.language,
|
||||
backend: config.backend,
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@
|
|||
<div class="document-processor">
|
||||
<header class="top-header">
|
||||
<h2 class="ellipsis" title="思维导图">思维导图</h2>
|
||||
<div class="header-actions">
|
||||
<el-button :disabled="!results" @click="saveArtifact">保存图谱</el-button>
|
||||
<el-button type="text" @click="toggleSettings" class="settings-button">
|
||||
设置
|
||||
</el-button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
|
|
@ -251,6 +254,7 @@ import { ElMessage } from 'element-plus'
|
|||
import ConfigPanel from '@/components/ConfigPanel.vue'
|
||||
import MarkdownRenderer from '@/components/MarkdownRenderer.vue'
|
||||
import MindMapRenderer from '@/components/MindMapRenderer.vue'
|
||||
import { hubCall, onOpenArtifact } from '@/api/hub'
|
||||
import { documentApi } from '@/api/document'
|
||||
import { DOCUMENT_CONFIG_STORAGE_KEY, useDocumentProcessor } from '@/composables/useDocumentProcessor'
|
||||
import { markdownToAstString } from '@/utils/markdownAst'
|
||||
|
|
@ -457,14 +461,8 @@ const startSmartOrganize = async () => {
|
|||
|
||||
try {
|
||||
await documentApi.createMindmapTask(taskId, markdown, 'hybrid', config.mindmapPrompt, {
|
||||
base_url: config.mindmapLlmBaseUrl || undefined,
|
||||
api_key: config.mindmapLlmApiKey || undefined,
|
||||
model: config.mindmapLlmModel || undefined,
|
||||
timeout: config.mindmapLlmTimeout,
|
||||
temperature: config.mindmapLlmTemperature,
|
||||
max_context_tokens: config.mindmapLlmMaxContextTokens,
|
||||
max_output_tokens: config.mindmapLlmMaxOutputTokens,
|
||||
safety_tokens: config.mindmapLlmSafetyTokens
|
||||
model_id: config.mindmapModelId,
|
||||
temperature: config.mindmapLlmTemperature
|
||||
})
|
||||
startSmartOrganizePolling(taskId)
|
||||
} catch (err) {
|
||||
|
|
@ -545,6 +543,8 @@ const applyConfig = (nextConfig: typeof config) => {
|
|||
}
|
||||
|
||||
const handleProcessDocument = async () => {
|
||||
openedArtifact.value = null
|
||||
originalRecognized.value = ''
|
||||
resetSmartOrganizeState()
|
||||
await processDocument()
|
||||
if (error.value) {
|
||||
|
|
@ -623,6 +623,8 @@ const triggerUpload = () => {
|
|||
const handleFileInputChange = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement
|
||||
if (input.files) {
|
||||
openedArtifact.value = null
|
||||
originalRecognized.value = ''
|
||||
await handleFileUpload(input.files)
|
||||
input.value = ''
|
||||
if (uploadedFiles.value.length > 0) {
|
||||
|
|
@ -643,6 +645,8 @@ const handleDrop = async (event: DragEvent) => {
|
|||
isDragging.value = false
|
||||
|
||||
if (event.dataTransfer?.files) {
|
||||
openedArtifact.value = null
|
||||
originalRecognized.value = ''
|
||||
await handleFileUpload(event.dataTransfer.files)
|
||||
if (uploadedFiles.value.length > 0) {
|
||||
resetSmartOrganizeState()
|
||||
|
|
@ -671,12 +675,38 @@ const clearAllFiles = () => {
|
|||
isUploadAreaCollapsed.value = false
|
||||
}
|
||||
|
||||
const openedArtifact = ref<any>(null)
|
||||
const originalRecognized = ref('')
|
||||
const stopArtifactListener = onOpenArtifact((artifact) => {
|
||||
resetSmartOrganizeState()
|
||||
openedArtifact.value = artifact
|
||||
originalRecognized.value = artifact.original || ''
|
||||
results.value = { markdown: artifact.markdown, source: artifact.markdown, mindmap: buildMindmapMarkdown(artifact.markdown) }
|
||||
})
|
||||
watch(() => results.value?.markdown, (value) => {
|
||||
if (!openedArtifact.value && value) originalRecognized.value = value
|
||||
})
|
||||
async function saveArtifact() {
|
||||
try {
|
||||
const current = openedArtifact.value
|
||||
const saved = await hubCall('artifacts', 'post', {
|
||||
name: current?.name || uploadedDisplayFiles.value[0]?.name || '思维导图',
|
||||
revision: current?.revision, markdown: activeSourceMarkdownContent.value,
|
||||
original: originalRecognized.value || manualMarkdownContent.value,
|
||||
layout: current?.layout || 'tree'
|
||||
}, current?.id)
|
||||
openedArtifact.value = saved
|
||||
ElMessage.success('已保存')
|
||||
} catch (e: any) { ElMessage.error(e.message || '保存失败') }
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
updateViewportState()
|
||||
window.addEventListener('resize', updateViewportState)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
stopArtifactListener()
|
||||
stopSmartOrganizePolling()
|
||||
window.removeEventListener('resize', updateViewportState)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue