From 78ef5dcc446078de1895ffce3ae7e30dcad0bd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Wed, 1 Jul 2026 00:01:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=20=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E5=8C=BA=E5=AE=8C=E5=96=84(=E6=96=87=E4=BB=B6=20Diff=20?= =?UTF-8?q?=E9=A2=84=E8=A7=88=20+=20=E5=88=86=E6=94=AF=E5=8F=AA=E8=AF=BB?= =?UTF-8?q?=E5=88=97=E8=A1=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 变更文件选中后展开 Diff 红绿预览(原 selectFile 拉了 diffContent 但未渲染) - 分支切换按钮实现只读列表弹窗(拉取分支列表 + 当前分支标记) - 分支切换提示走 AI 助手(git_branch 工具) --- src/components/project/GitChanges.vue | 140 +++++++++++++++++++++++++- src/i18n/en/gitChanges.ts | 3 + src/i18n/zh-CN/gitChanges.ts | 3 + 3 files changed, 144 insertions(+), 2 deletions(-) diff --git a/src/components/project/GitChanges.vue b/src/components/project/GitChanges.vue index b545a5f..3dd63f3 100644 --- a/src/components/project/GitChanges.vue +++ b/src/components/project/GitChanges.vue @@ -10,6 +10,29 @@ + +
+
+ {{ $t('gitChanges.branches') }} + +
+
+
+
+ {{ b.is_current ? '●' : '○' }} + {{ b.name }} + HEAD +
+
{{ $t('gitChanges.noBranches') }}
+
+
{{ $t('gitChanges.branchSwitchHint') }}
+
+
@@ -49,6 +72,25 @@ {{ filePathLeaf(f.path) }} + + +
+
+ {{ selectedFile }} + +
+
+
{{ $t('gitChanges.noDiff') }}
+
+
+ {{ ln.text }} + +
+
+
@@ -200,6 +242,7 @@ interface DiffLine { } const commitDiffLines = computed(() => parseDiff(commitDiff.value)) +const fileDiffLines = computed(() => parseDiff(diffContent.value)) function parseDiff(text: string): DiffLine[] { if (!text) return [] @@ -277,8 +320,31 @@ async function loadStatus() { } /** 占位:分支切换后续接入(需拉取分支列表 + checkout IPC)。 */ -function onSwitchBranch() { - // TODO: 弹出分支列表选择 + 调用 git checkout +const showBranchPicker = ref(false) +const branchList = ref<{ name: string; is_current: boolean }[]>([]) +const branchLoading = ref(false) +const currentBranch = ref('') + +async function onSwitchBranch() { + if (showBranchPicker.value) { + showBranchPicker.value = false + return + } + showBranchPicker.value = true + branchLoading.value = true + try { + const res = await moduleApi.listBranches(props.moduleId) + branchList.value = res.branches + currentBranch.value = res.current + } catch { + branchList.value = [] + } finally { + branchLoading.value = false + } +} + +function closeBranchPicker() { + showBranchPicker.value = false } async function loadMoreCommits() { @@ -417,6 +483,27 @@ watch(() => props.moduleId, loadStatus, { immediate: true }) position: sticky; top: 0; z-index: 1; } +/* 变更文件 diff 预览(列表下方展开) */ +.gc-file-diff { + margin-top: 8px; + border-top: 0.5px solid var(--df-border); +} +.gc-file-diff-header { + display: flex; + align-items: center; + padding: 6px 14px; + background: rgba(255,255,255,0.03); + font-family: var(--df-font-mono, Consolas, monospace); + font-size: 11px; + border-bottom: 0.5px solid var(--df-border); +} +.gc-file-diff-path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--df-text); } +.gc-file-diff-close { + background: none; border: none; color: var(--df-text-dim); + cursor: pointer; font-size: 14px; padding: 0 4px; +} +.gc-file-diff-close:hover { color: var(--df-text); } + /* Diff 预览 */ .gc-diff-content { font-family: var(--df-font-mono, Consolas, monospace); @@ -511,6 +598,55 @@ watch(() => props.moduleId, loadStatus, { immediate: true }) } .gc-load-more:hover { background: rgba(255,255,255,0.04); } +/* 分支列表弹窗 */ +.gc-branch-picker { + border-bottom: 0.5px solid var(--df-border); + background: var(--df-bg); +} +.gc-branch-picker-header { + display: flex; + align-items: center; + justify-content: space-between; + padding: 6px 14px; + font-size: 11px; + font-weight: 600; + color: var(--df-text-dim); + text-transform: uppercase; +} +.gc-branch-picker-close { + background: none; border: none; color: var(--df-text-dim); + cursor: pointer; font-size: 14px; padding: 0 4px; +} +.gc-branch-list { + max-height: 200px; + overflow-y: auto; + scrollbar-width: thin; +} +.gc-branch-item { + display: flex; + align-items: center; + gap: 8px; + padding: 5px 14px; + font-size: 12px; + cursor: default; +} +.gc-branch-item.current { color: var(--df-accent); } +.gc-branch-icon { font-size: 10px; flex-shrink: 0; } +.gc-branch-name { font-family: var(--df-font-mono, Consolas, monospace); } +.gc-branch-tag { + font-size: 9px; + padding: 1px 5px; + border-radius: 3px; + background: rgba(108,99,255,0.15); + color: var(--df-accent); +} +.gc-branch-picker-hint { + padding: 6px 14px; + font-size: 11px; + color: var(--df-text-dim); + border-top: 0.5px solid var(--df-border); +} + /* 骨架屏 */ .gc-skeleton { padding: 14px; diff --git a/src/i18n/en/gitChanges.ts b/src/i18n/en/gitChanges.ts index 83ad0ab..8ea3476 100644 --- a/src/i18n/en/gitChanges.ts +++ b/src/i18n/en/gitChanges.ts @@ -14,5 +14,8 @@ export default { detached: 'HEAD detached', loadMore: 'Load more', switchBranch: 'Switch branch', + branches: 'Branches', + noBranches: 'No branches', + branchSwitchHint: 'Use AI assistant to switch branches (git_branch tool)', }, } diff --git a/src/i18n/zh-CN/gitChanges.ts b/src/i18n/zh-CN/gitChanges.ts index 7222ac1..e9465cd 100644 --- a/src/i18n/zh-CN/gitChanges.ts +++ b/src/i18n/zh-CN/gitChanges.ts @@ -14,5 +14,8 @@ export default { detached: 'HEAD 分离', loadMore: '加载更多', switchBranch: '切换分支', + branches: '分支列表', + noBranches: '无分支', + branchSwitchHint: '分支切换请通过 AI 助手执行(git_branch 工具)', }, }