fix: 修复文件管理部分并更新UI
This commit is contained in:
parent
e57b4b7d9a
commit
950c1fa714
|
|
@ -121,11 +121,6 @@ export const modelApi = {
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
// Clear cache (e.g., when models changed on server)
|
|
||||||
clearCache() {
|
|
||||||
modelsCache = null
|
|
||||||
localStorage.removeItem('models_cache')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const statsApi = {
|
export const statsApi = {
|
||||||
|
|
@ -205,30 +200,6 @@ export const projectApi = {
|
||||||
return request(`/projects/${projectId}`, { method: 'DELETE' })
|
return request(`/projects/${projectId}`, { method: 'DELETE' })
|
||||||
},
|
},
|
||||||
|
|
||||||
uploadFolder(data) {
|
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('name', data.name || '')
|
|
||||||
formData.append('description', data.description || '')
|
|
||||||
for (const file of data.files) {
|
|
||||||
formData.append('files', file, file.webkitRelativePath)
|
|
||||||
}
|
|
||||||
return fetch(`${BASE}/projects/upload`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: formData,
|
|
||||||
}).then(async res => {
|
|
||||||
let json
|
|
||||||
try {
|
|
||||||
json = await res.json()
|
|
||||||
} catch (_) {
|
|
||||||
throw new Error(`服务器错误 (${res.status}),请确认后端已重启`)
|
|
||||||
}
|
|
||||||
if (json.code !== 0) {
|
|
||||||
throw new Error(json.message || 'Request failed')
|
|
||||||
}
|
|
||||||
return json
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
listFiles(projectId, path = '') {
|
listFiles(projectId, path = '') {
|
||||||
return request(`/projects/${projectId}/files${buildQueryParams({ path })}`)
|
return request(`/projects/${projectId}/files${buildQueryParams({ path })}`)
|
||||||
},
|
},
|
||||||
|
|
@ -261,11 +232,4 @@ export const projectApi = {
|
||||||
body: { path: dirPath },
|
body: { path: dirPath },
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
search(projectId, query, options = {}) {
|
|
||||||
return request(`/projects/${projectId}/search`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: { query, ...options },
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ const props = defineProps({
|
||||||
toolsEnabled: { type: Boolean, default: true },
|
toolsEnabled: { type: Boolean, default: true },
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['sendMessage', 'deleteMessage', 'regenerateMessage', 'toggleSettings', 'toggleStats', 'loadMoreMessages', 'toggleTools'])
|
const emit = defineEmits(['sendMessage', 'deleteMessage', 'regenerateMessage', 'loadMoreMessages', 'toggleTools'])
|
||||||
|
|
||||||
const scrollContainer = ref(null)
|
const scrollContainer = ref(null)
|
||||||
const inputRef = ref(null)
|
const inputRef = ref(null)
|
||||||
|
|
|
||||||
|
|
@ -60,25 +60,13 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="viewer-actions">
|
<div class="viewer-actions">
|
||||||
<button v-if="!editing" class="btn-icon-sm" @click="startEdit" title="编辑">
|
<button class="btn-icon-sm save" @click="saveFile" title="保存 (Ctrl+S)" :disabled="saving">
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
||||||
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
|
|
||||||
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button v-if="editing" class="btn-icon-sm save" @click="saveFile" title="保存 (Ctrl+S)" :disabled="saving">
|
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/>
|
<path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/>
|
||||||
<polyline points="17 21 17 13 7 13 7 21"/>
|
<polyline points="17 21 17 13 7 13 7 21"/>
|
||||||
<polyline points="7 3 7 8 15 8"/>
|
<polyline points="7 3 7 8 15 8"/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<button v-if="editing" class="btn-icon-sm" @click="cancelEdit" title="取消">
|
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
||||||
<line x1="18" y1="6" x2="6" y2="18"/>
|
|
||||||
<line x1="6" y1="6" x2="18" y2="18"/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button class="btn-icon-sm danger" @click="deleteFile" title="删除文件">
|
<button class="btn-icon-sm danger" @click="deleteFile" title="删除文件">
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<polyline points="3 6 5 6 21 6"/>
|
<polyline points="3 6 5 6 21 6"/>
|
||||||
|
|
@ -105,21 +93,9 @@
|
||||||
<span>{{ fileError }}</span>
|
<span>{{ fileError }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Read-only viewer (code highlighted, markdown rendered) -->
|
<!-- Text / code editor (default mode) -->
|
||||||
<div
|
<div v-else-if="fileType !== 'image'" class="editor-container">
|
||||||
v-else-if="!editing && fileType !== 'image'"
|
<div class="editor-highlight" aria-hidden="true" v-html="editorHighlighted"></div>
|
||||||
class="file-content-viewer md-content"
|
|
||||||
v-html="renderedContent"
|
|
||||||
></div>
|
|
||||||
|
|
||||||
<!-- Image viewer -->
|
|
||||||
<div v-else-if="!editing && fileType === 'image'" class="image-viewer">
|
|
||||||
<img :src="imageUrl" :alt="activeFile" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Highlighted editor -->
|
|
||||||
<div v-else class="editor-container">
|
|
||||||
<pre class="editor-highlight" aria-hidden="true"><code v-html="editorHighlighted"></code></pre>
|
|
||||||
<textarea
|
<textarea
|
||||||
ref="editorRef"
|
ref="editorRef"
|
||||||
v-model="editContent"
|
v-model="editContent"
|
||||||
|
|
@ -129,6 +105,11 @@
|
||||||
@scroll="syncScroll"
|
@scroll="syncScroll"
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Image viewer -->
|
||||||
|
<div v-else class="image-viewer">
|
||||||
|
<img :src="imageUrl" :alt="activeFile" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Empty state -->
|
<!-- Empty state -->
|
||||||
|
|
@ -150,7 +131,6 @@ import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
||||||
import { projectApi } from '../api'
|
import { projectApi } from '../api'
|
||||||
import FileTreeItem from './FileTreeItem.vue'
|
import FileTreeItem from './FileTreeItem.vue'
|
||||||
import { renderMarkdown } from '../utils/markdown'
|
import { renderMarkdown } from '../utils/markdown'
|
||||||
import { highlightCode } from '../utils/highlight'
|
|
||||||
import { normalizeFileTree } from '../utils/fileTree'
|
import { normalizeFileTree } from '../utils/fileTree'
|
||||||
|
|
||||||
const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'svg', 'ico'])
|
const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'svg', 'ico'])
|
||||||
|
|
@ -169,10 +149,8 @@ const loadingTree = ref(false)
|
||||||
|
|
||||||
// -- Viewer state --
|
// -- Viewer state --
|
||||||
const activeFile = ref(null)
|
const activeFile = ref(null)
|
||||||
const fileContent = ref('')
|
|
||||||
const fileError = ref('')
|
const fileError = ref('')
|
||||||
const loadingFile = ref(false)
|
const loadingFile = ref(false)
|
||||||
const editing = ref(false)
|
|
||||||
const editContent = ref('')
|
const editContent = ref('')
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
const editorRef = ref(null)
|
const editorRef = ref(null)
|
||||||
|
|
@ -195,18 +173,11 @@ const fileType = computed(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// -- Content rendering --
|
// -- Content rendering --
|
||||||
const renderedContent = computed(() => {
|
|
||||||
if (!fileContent.value) return ''
|
|
||||||
if (isMarkdownFile.value) return renderMarkdown(fileContent.value)
|
|
||||||
// Wrap code in fenced code block — rendered by same markdown pipeline, same CSS
|
|
||||||
const lang = fileExt.value || ''
|
|
||||||
return renderMarkdown('```' + lang + '\n' + fileContent.value + '\n```')
|
|
||||||
})
|
|
||||||
|
|
||||||
const editorHighlighted = computed(() => {
|
const editorHighlighted = computed(() => {
|
||||||
if (!editContent.value) return ''
|
if (!editContent.value) return ''
|
||||||
|
if (isMarkdownFile.value) return renderMarkdown(editContent.value)
|
||||||
const lang = fileExt.value || ''
|
const lang = fileExt.value || ''
|
||||||
return highlightCode(editContent.value, lang)
|
return renderMarkdown('```' + lang + '\n' + editContent.value + '\n```')
|
||||||
})
|
})
|
||||||
|
|
||||||
function syncScroll() {
|
function syncScroll() {
|
||||||
|
|
@ -232,9 +203,8 @@ async function loadTree(path = '') {
|
||||||
|
|
||||||
async function openFile(filepath) {
|
async function openFile(filepath) {
|
||||||
activeFile.value = filepath
|
activeFile.value = filepath
|
||||||
fileContent.value = ''
|
|
||||||
fileError.value = ''
|
fileError.value = ''
|
||||||
editing.value = false
|
editContent.value = ''
|
||||||
imageUrl.value = ''
|
imageUrl.value = ''
|
||||||
loadingFile.value = true
|
loadingFile.value = true
|
||||||
|
|
||||||
|
|
@ -254,7 +224,7 @@ async function openFile(filepath) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await projectApi.readFile(props.projectId, filepath)
|
const res = await projectApi.readFile(props.projectId, filepath)
|
||||||
fileContent.value = res.data.content
|
editContent.value = res.data.content
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
fileError.value = e.message || '加载文件失败'
|
fileError.value = e.message || '加载文件失败'
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -262,23 +232,11 @@ async function openFile(filepath) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startEdit() {
|
|
||||||
editContent.value = fileContent.value
|
|
||||||
editing.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function cancelEdit() {
|
|
||||||
editing.value = false
|
|
||||||
editContent.value = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
async function saveFile() {
|
async function saveFile() {
|
||||||
if (!activeFile.value || saving.value) return
|
if (!activeFile.value || saving.value) return
|
||||||
saving.value = true
|
saving.value = true
|
||||||
try {
|
try {
|
||||||
await projectApi.writeFile(props.projectId, activeFile.value, editContent.value)
|
await projectApi.writeFile(props.projectId, activeFile.value, editContent.value)
|
||||||
fileContent.value = editContent.value
|
|
||||||
editing.value = false
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('保存失败: ' + e.message)
|
alert('保存失败: ' + e.message)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -293,7 +251,6 @@ function deleteFile() {
|
||||||
|
|
||||||
projectApi.deleteFile(props.projectId, activeFile.value).then(() => {
|
projectApi.deleteFile(props.projectId, activeFile.value).then(() => {
|
||||||
activeFile.value = null
|
activeFile.value = null
|
||||||
fileContent.value = ''
|
|
||||||
loadTree()
|
loadTree()
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
alert('删除失败: ' + e.message)
|
alert('删除失败: ' + e.message)
|
||||||
|
|
@ -308,7 +265,6 @@ async function createNewFile() {
|
||||||
await projectApi.writeFile(props.projectId, path, '')
|
await projectApi.writeFile(props.projectId, path, '')
|
||||||
await loadTree()
|
await loadTree()
|
||||||
openFile(path)
|
openFile(path)
|
||||||
startEdit()
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('创建失败: ' + e.message)
|
alert('创建失败: ' + e.message)
|
||||||
}
|
}
|
||||||
|
|
@ -330,14 +286,11 @@ function onEditorKeydown(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
saveFile()
|
saveFile()
|
||||||
}
|
}
|
||||||
if (e.key === 'Escape') {
|
|
||||||
cancelEdit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ctrl+S global shortcut
|
// Ctrl+S global shortcut
|
||||||
function onGlobalKeydown(e) {
|
function onGlobalKeydown(e) {
|
||||||
if (e.key === 's' && (e.ctrlKey || e.metaKey) && editing.value) {
|
if (e.key === 's' && (e.ctrlKey || e.metaKey) && activeFile.value) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
saveFile()
|
saveFile()
|
||||||
}
|
}
|
||||||
|
|
@ -345,9 +298,8 @@ function onGlobalKeydown(e) {
|
||||||
|
|
||||||
watch(() => props.projectId, () => {
|
watch(() => props.projectId, () => {
|
||||||
activeFile.value = null
|
activeFile.value = null
|
||||||
fileContent.value = ''
|
editContent.value = ''
|
||||||
imageUrl.value = ''
|
imageUrl.value = ''
|
||||||
editing.value = false
|
|
||||||
loadTree()
|
loadTree()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -536,10 +488,6 @@ onUnmounted(() => {
|
||||||
resize: none;
|
resize: none;
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
padding: 12px;
|
|
||||||
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
|
||||||
font-size: 13px;
|
|
||||||
line-height: 1.5;
|
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
background: var(--bg-code);
|
background: var(--bg-code);
|
||||||
tab-size: 4;
|
tab-size: 4;
|
||||||
|
|
@ -547,14 +495,12 @@ onUnmounted(() => {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-editor::-webkit-scrollbar,
|
.file-editor::-webkit-scrollbar {
|
||||||
.file-content-viewer::-webkit-scrollbar {
|
|
||||||
width: 6px;
|
width: 6px;
|
||||||
height: 6px;
|
height: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-editor::-webkit-scrollbar-thumb,
|
.file-editor::-webkit-scrollbar-thumb {
|
||||||
.file-content-viewer::-webkit-scrollbar-thumb {
|
|
||||||
background: var(--scrollbar-thumb);
|
background: var(--scrollbar-thumb);
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
@ -575,48 +521,55 @@ onUnmounted(() => {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: 8px;
|
|
||||||
border: 1px solid var(--border-light);
|
|
||||||
border-radius: 8px;
|
|
||||||
background: var(--bg-code);
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-container pre.editor-highlight {
|
.editor-highlight {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 12px;
|
padding: 20px 24px;
|
||||||
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
|
||||||
font-size: 13px;
|
|
||||||
line-height: 1.5;
|
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
background: var(--bg-code);
|
background: transparent;
|
||||||
|
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.7;
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
tab-size: 4;
|
tab-size: 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Strip wrapper styles from markdown-rendered <pre><code> so text aligns with textarea */
|
||||||
|
.editor-highlight :deep(pre),
|
||||||
|
.editor-highlight :deep(code) {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background: transparent !important;
|
||||||
|
border: none;
|
||||||
|
border-radius: 0;
|
||||||
|
font-size: inherit;
|
||||||
|
font-family: inherit;
|
||||||
|
line-height: inherit;
|
||||||
|
white-space: inherit;
|
||||||
|
tab-size: inherit;
|
||||||
|
word-wrap: normal;
|
||||||
|
}
|
||||||
|
|
||||||
.editor-container .file-editor {
|
.editor-container .file-editor {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
border: none;
|
border: none;
|
||||||
|
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.7;
|
||||||
|
padding: 20px 24px;
|
||||||
color: transparent;
|
color: transparent;
|
||||||
caret-color: var(--text-primary);
|
caret-color: var(--text-primary);
|
||||||
background: transparent;
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-content-viewer {
|
|
||||||
flex: 1;
|
|
||||||
overflow: auto;
|
|
||||||
padding: 20px 24px;
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.7;
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -- Image viewer -- */
|
/* -- Image viewer -- */
|
||||||
.image-viewer {
|
.image-viewer {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,9 @@
|
||||||
<svg class="chevron" :class="{ collapsed: !expandedGroups['__standalone__'] }" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg class="chevron" :class="{ collapsed: !expandedGroups['__standalone__'] }" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<polyline points="6 9 12 15 18 9"/>
|
<polyline points="6 9 12 15 18 9"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
<svg class="standalone-icon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
|
||||||
|
</svg>
|
||||||
<span class="conv-count">{{ groupedData.standalone.length }}</span>
|
<span class="conv-count">{{ groupedData.standalone.length }}</span>
|
||||||
<button
|
<button
|
||||||
class="btn-group-action"
|
class="btn-group-action"
|
||||||
|
|
@ -88,6 +91,7 @@
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<span class="btn-placeholder"></span>
|
<span class="btn-placeholder"></span>
|
||||||
|
<span class="btn-placeholder"></span>
|
||||||
</div>
|
</div>
|
||||||
<div v-show="expandedGroups['__standalone__']">
|
<div v-show="expandedGroups['__standalone__']">
|
||||||
<div
|
<div
|
||||||
|
|
@ -303,6 +307,11 @@ function onScroll(e) {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.standalone-icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
.btn-placeholder { width: 24px; flex-shrink: 0; }
|
.btn-placeholder { width: 24px; flex-shrink: 0; }
|
||||||
|
|
||||||
.conv-count {
|
.conv-count {
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ import { useTheme } from '../composables/useTheme'
|
||||||
import { formatNumber } from '../utils/format'
|
import { formatNumber } from '../utils/format'
|
||||||
import CloseButton from './CloseButton.vue'
|
import CloseButton from './CloseButton.vue'
|
||||||
|
|
||||||
const emit = defineEmits(['close'])
|
defineEmits(['close'])
|
||||||
|
|
||||||
const { isDark } = useTheme()
|
const { isDark } = useTheme()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue