fix: open url file render error

This commit is contained in:
engigu
2026-01-14 19:46:25 +08:00
parent 137a3f4711
commit ae7983da25
2 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ const router = createRouter({
children: [
{ path: '', name: 'dashboard', component: () => import('@/views/dashboard/Dashboard.vue') },
{ path: 'tasks', name: 'tasks', component: () => import('@/views/tasks/Tasks.vue') },
{ path: 'editor/:path(.*)?', name: 'editor', component: () => import('@/views/editor/Editor.vue') },
{ path: 'editor', name: 'editor', component: () => import('@/views/editor/Editor.vue') },
{ path: 'environments', name: 'environments', component: () => import('@/views/environments/Environments.vue') },
{ path: 'dependencies', name: 'dependencies', component: () => import('@/views/dependencies/Dependencies.vue') },
{ path: 'agents', name: 'agents', component: () => import('@/views/agents/Agents.vue') },
+6 -5
View File
@@ -76,8 +76,8 @@ async function loadTree() {
async function handleSelect(node: FileNode) {
selectedPath.value = node.path
// 更新 URL
router.replace({ name: 'editor', params: { path: node.path } })
// 更新 URL 使用 query 参数
router.replace({ name: 'editor', query: { file: node.path } })
if (node.isDir) {
if (expandedDirs.value.has(node.path)) {
@@ -217,10 +217,10 @@ async function handleMove(oldPath: string, newPath: string) {
if (selectedFile.value === oldPath) {
selectedFile.value = newPath
selectedPath.value = newPath
router.replace({ name: 'editor', params: { path: newPath } })
router.replace({ name: 'editor', query: { file: newPath } })
} else if (selectedPath.value === oldPath) {
selectedPath.value = newPath
router.replace({ name: 'editor', params: { path: newPath } })
router.replace({ name: 'editor', query: { file: newPath } })
}
await loadTree()
} catch {
@@ -314,7 +314,7 @@ function expandParentDirs(path: string) {
// 从 URL 初始化选中状态
async function initFromUrl() {
await loadTree()
const urlPath = route.params.path as string
const urlPath = route.query.file as string
if (urlPath) {
selectedPath.value = urlPath
expandParentDirs(urlPath)
@@ -324,6 +324,7 @@ async function initFromUrl() {
selectedFile.value = urlPath
fileContent.value = res.content
originalContent.value = res.content
isEditMode.value = false
} catch {
// 可能是文件夹,忽略错误
}