Skip to content

Commit 420ec7b

Browse files
ice201508jiuling
andauthored
fix repo detail change branch error (#1331)
* Draft MR * fix-repo-detail-change-branch-error --------- Co-authored-by: jiuling <[email protected]>
1 parent 90c3d03 commit 420ec7b

File tree

8 files changed

+133
-81
lines changed

8 files changed

+133
-81
lines changed

frontend/src/components/shared/Blob.vue

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@
359359
const isLastItem = index === breadcrumb.value.length - 1
360360
361361
if (isLastItem) {
362-
// 如果是最后一个面包屑项(当前文件),导航到blob页面
363362
const query = {
364363
tab: 'files',
365364
actionName: 'blob',
@@ -381,7 +380,6 @@
381380
382381
fetchFileContent()
383382
} else {
384-
// 否则导航到文件列表页面
385383
const query = {
386384
tab: 'files',
387385
actionName: 'files',
@@ -496,7 +494,28 @@
496494
).json()
497495
498496
if (response.value.status === 404) {
499-
ToNotFoundPage()
497+
setRepoTab({
498+
actionName: 'files',
499+
lastPath: '',
500+
fileNotFound: {
501+
show: true,
502+
fileName: currentPath.value,
503+
branchName: currentBranch.value
504+
}
505+
})
506+
507+
const query = {
508+
tab: 'files',
509+
actionName: 'files'
510+
}
511+
if (currentBranch.value) {
512+
query.branch = currentBranch.value
513+
}
514+
515+
router.push({
516+
path: router.currentRoute.value.path,
517+
query
518+
})
500519
return false
501520
}
502521

frontend/src/components/shared/BranchDropdown.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@
2727
import { ref, onMounted } from 'vue'
2828
import { ElMessage } from 'element-plus'
2929
import useFetchApi from '../../packs/useFetchApi'
30+
import { useRepoTabStore } from '../../stores/RepoTabStore'
3031
3132
const props = defineProps({
3233
currentBranch: String
3334
})
3435
36+
const { resetFileNotFound } = useRepoTabStore()
3537
const branches = ref([])
3638
3739
const emit = defineEmits(['changeBranch'])
3840
3941
const handleClick = (branch) => {
42+
resetFileNotFound()
4043
emit('changeBranch', branch)
4144
}
4245

frontend/src/components/shared/FileList.vue

Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<template>
22
<div class="min-h-[300px] py-8 md:px-5">
3+
<div v-if="repoTab.fileNotFound.show" style="max-width: 600px">
4+
<el-alert
5+
:title="`${$t('all.files')} '${repoTab.fileNotFound.fileName}' ${$t('all.inBranch')} '${repoTab.fileNotFound.branchName}' ${$t('all.notExist')}`"
6+
type="warning"
7+
show-icon
8+
class="!mb-5"
9+
/>
10+
</div>
311
<div class="flex items-center justify-between px-1">
412
<div class="flex items-center flex-wrap gap-4">
513
<BranchDropdown @changeBranch="changeBranch"
@@ -169,7 +177,7 @@
169177
const { t, locale } = useI18n();
170178
const loading = ref(true)
171179
172-
const { repoTab, setRepoTab } = useRepoTabStore()
180+
const { repoTab, setRepoTab, resetFileNotFound } = useRepoTabStore()
173181
const currentBranch = ref(repoTab.currentBranch || '')
174182
const currentPath = ref(repoTab.lastPath || '')
175183
@@ -189,14 +197,10 @@
189197
190198
const emit = defineEmits(['changeBranch'])
191199
192-
// 添加防重复请求的标记
193200
const isInitializing = ref(false)
194201
195-
// 修改路由监听逻辑
196202
watch(() => route.query, (newQuery) => {
197-
// 只有当 tab 是 files 且 actionName 是 files 或为空时才处理
198203
if (newQuery.tab === 'files' && (newQuery.actionName === 'files' || !newQuery.actionName)) {
199-
// 更新 actionName
200204
if (newQuery.actionName && newQuery.actionName !== repoTab.actionName) {
201205
setRepoTab({
202206
actionName: newQuery.actionName,
@@ -205,15 +209,13 @@
205209
})
206210
}
207211
208-
// 更新路径和分支
209212
if (newQuery.path !== currentPath.value) {
210213
currentPath.value = newQuery.path || ''
211214
}
212215
if (newQuery.branch && newQuery.branch !== currentBranch.value) {
213216
currentBranch.value = newQuery.branch
214217
}
215218
216-
// 只有在文件列表页面且未初始化时才重新初始化
217219
if (!isInitializing.value) {
218220
init()
219221
}
@@ -244,50 +246,58 @@
244246
}
245247
246248
const goToNamespace = () => {
247-
currentPath.value = ''
248-
setRepoTab({
249-
actionName: 'files',
250-
lastPath: ''
251-
})
252-
253-
const query = {
254-
tab: 'files',
255-
actionName: 'files'
256-
}
257-
if (currentBranch.value) {
258-
query.branch = currentBranch.value
259-
}
249+
if (!isInitializing.value) {
250+
resetFileNotFound()
251+
252+
currentPath.value = ''
253+
setRepoTab({
254+
actionName: 'files',
255+
lastPath: ''
256+
})
257+
258+
const query = {
259+
tab: 'files',
260+
actionName: 'files'
261+
}
262+
if (currentBranch.value) {
263+
query.branch = currentBranch.value
264+
}
260265
261-
router.push({
262-
path: router.currentRoute.value.path,
263-
query
264-
})
266+
router.push({
267+
path: router.currentRoute.value.path,
268+
query
269+
})
265270
266-
init()
271+
init()
272+
}
267273
}
268274
269275
const goToBreadcrumb = (path) => {
270-
currentPath.value = path.includes('/') ? path?.slice(1) : path
271-
setRepoTab({
272-
actionName: 'files',
273-
lastPath: currentPath.value
274-
})
275-
276-
const query = {
277-
tab: 'files',
278-
actionName: 'files',
279-
path: currentPath.value
280-
}
281-
if (currentBranch.value) {
282-
query.branch = currentBranch.value
283-
}
276+
if (!isInitializing.value) {
277+
resetFileNotFound()
278+
279+
currentPath.value = path.includes('/') ? path?.slice(1) : path
280+
setRepoTab({
281+
actionName: 'files',
282+
lastPath: currentPath.value
283+
})
284+
285+
const query = {
286+
tab: 'files',
287+
actionName: 'files',
288+
path: currentPath.value
289+
}
290+
if (currentBranch.value) {
291+
query.branch = currentBranch.value
292+
}
284293
285-
router.push({
286-
path: router.currentRoute.value.path,
287-
query
288-
})
294+
router.push({
295+
path: router.currentRoute.value.path,
296+
query
297+
})
289298
290-
init()
299+
init()
300+
}
291301
}
292302
293303
const goToNewFile = () => {
@@ -378,31 +388,36 @@
378388
}
379389
380390
const goToDir = (path) => {
381-
currentPath.value = path
382-
setRepoTab({
383-
actionName: 'files',
384-
lastPath: path
385-
})
386-
387-
// 更新 URL 参数
388-
const query = {
389-
tab: 'files',
390-
actionName: 'files',
391-
path: path
392-
}
393-
if (currentBranch.value) {
394-
query.branch = currentBranch.value
395-
}
391+
if (!isInitializing.value) {
392+
resetFileNotFound()
393+
394+
currentPath.value = path
395+
setRepoTab({
396+
actionName: 'files',
397+
lastPath: path
398+
})
399+
400+
// 更新 URL 参数
401+
const query = {
402+
tab: 'files',
403+
actionName: 'files',
404+
path: path
405+
}
406+
if (currentBranch.value) {
407+
query.branch = currentBranch.value
408+
}
396409
397-
router.push({
398-
path: router.currentRoute.value.path,
399-
query
400-
})
410+
router.push({
411+
path: router.currentRoute.value.path,
412+
query
413+
})
401414
402-
init()
403-
}
415+
init()
416+
}
417+
}
404418
405419
const goToBlob = (path) => {
420+
resetFileNotFound()
406421
currentPath.value = path
407422
const query = {
408423
tab: 'files',
@@ -604,30 +619,27 @@
604619
if (isInitializing.value) return // 防止重复初始化
605620
606621
isInitializing.value = true
622+
resetFileNotFound()
623+
607624
files.value = []
608625
commitList.value = []
609-
tempCommit.value = []
610626
loading.value = true
611627
updateBreadcrumb()
612628
fetchFileListData()
613629
fetchLastCommit()
614630
615-
// 延迟重置标记
616631
setTimeout(() => {
617632
isInitializing.value = false
618633
}, 100)
619634
}
620635
621-
// 在 onMounted 中初始化时也要处理 URL 参数
622636
onMounted(() => {
623-
// 从 URL 参数中恢复状态
624637
const params = new URLSearchParams(window.location.search)
625638
const urlActionName = params.get('actionName')
626639
const urlPath = params.get('path')
627640
const urlBranch = params.get('branch')
628641
const currentTab = params.get('tab')
629642
630-
// 只有在当前 tab 是 files 且 actionName 是 files 或为空时才初始化
631643
if (currentTab === 'files' && (urlActionName === 'files' || !urlActionName)) {
632644
if (urlActionName && urlActionName !== 'files') {
633645
setRepoTab({
@@ -637,7 +649,6 @@
637649
})
638650
}
639651
640-
// 确保 currentPath 不为 null 或 undefined
641652
if (urlPath !== undefined && urlPath !== null) {
642653
currentPath.value = urlPath
643654
} else {

frontend/src/components/shared/RepoDetail.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import { isWithinTwoWeeks } from '../../packs/datetimeUtils'
5454
import { useRepoTabStore } from '../../stores/RepoTabStore'
5555
56-
const { setRepoTab } = useRepoTabStore()
56+
const { setRepoTab, resetFileNotFound } = useRepoTabStore()
5757
5858
const props = defineProps({
5959
defaultTab: String,
@@ -194,12 +194,14 @@
194194
return
195195
}
196196
197-
// 重新获取数据
197+
resetFileNotFound()
198+
198199
fetchRepoDetail()
199200
fetchLastCommit()
200201
}
201202
202203
onMounted(async () => {
204+
resetFileNotFound()
203205
const urlParams = getUrlParams()
204206
205207
const initialData = {
@@ -214,7 +216,6 @@
214216
215217
setRepoTab(initialData)
216218
217-
// 只有主请求成功后才获取其他数据
218219
const success = await fetchRepoDetail()
219220
if (success) {
220221
fetchLastCommit()
@@ -225,6 +226,7 @@
225226
226227
onUnmounted(() => {
227228
window.removeEventListener('popstate', handlePopState)
229+
resetFileNotFound()
228230
})
229231
230232
provide('fetchRepoDetail', fetchRepoDetail)

frontend/src/locales/en_js/all.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,7 @@ export const all = {
138138
copy: "Copy",
139139
copySuccess: "Copied successfully",
140140
allTab:'All Products',
141-
unknown: "Unknown"
141+
unknown: "Unknown",
142+
inBranch: "in branch",
143+
notExist: "not exist"
142144
}

frontend/src/locales/zh_hant_js/all.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,7 @@ export const all = {
146146
copy:"複製",
147147
copySuccess: "複製成功",
148148
allTab:'全部產品',
149-
unknown: "未知"
149+
unknown: "未知",
150+
inBranch: "在分支",
151+
notExist: "中不存在"
150152
}

frontend/src/locales/zh_js/all.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,7 @@ export const all = {
138138
copy:"复制",
139139
copySuccess: "复制成功",
140140
allTab:'全部产品',
141-
unknown: "未知"
141+
unknown: "未知",
142+
inBranch: "在分支",
143+
notExist: "中不存在"
142144
}

0 commit comments

Comments
 (0)