|
1 | 1 | <template> |
2 | 2 | <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> |
3 | 11 | <div class="flex items-center justify-between px-1"> |
4 | 12 | <div class="flex items-center flex-wrap gap-4"> |
5 | 13 | <BranchDropdown @changeBranch="changeBranch" |
|
169 | 177 | const { t, locale } = useI18n(); |
170 | 178 | const loading = ref(true) |
171 | 179 |
|
172 | | - const { repoTab, setRepoTab } = useRepoTabStore() |
| 180 | + const { repoTab, setRepoTab, resetFileNotFound } = useRepoTabStore() |
173 | 181 | const currentBranch = ref(repoTab.currentBranch || '') |
174 | 182 | const currentPath = ref(repoTab.lastPath || '') |
175 | 183 |
|
|
189 | 197 |
|
190 | 198 | const emit = defineEmits(['changeBranch']) |
191 | 199 |
|
192 | | - // 添加防重复请求的标记 |
193 | 200 | const isInitializing = ref(false) |
194 | 201 |
|
195 | | - // 修改路由监听逻辑 |
196 | 202 | watch(() => route.query, (newQuery) => { |
197 | | - // 只有当 tab 是 files 且 actionName 是 files 或为空时才处理 |
198 | 203 | if (newQuery.tab === 'files' && (newQuery.actionName === 'files' || !newQuery.actionName)) { |
199 | | - // 更新 actionName |
200 | 204 | if (newQuery.actionName && newQuery.actionName !== repoTab.actionName) { |
201 | 205 | setRepoTab({ |
202 | 206 | actionName: newQuery.actionName, |
|
205 | 209 | }) |
206 | 210 | } |
207 | 211 | |
208 | | - // 更新路径和分支 |
209 | 212 | if (newQuery.path !== currentPath.value) { |
210 | 213 | currentPath.value = newQuery.path || '' |
211 | 214 | } |
212 | 215 | if (newQuery.branch && newQuery.branch !== currentBranch.value) { |
213 | 216 | currentBranch.value = newQuery.branch |
214 | 217 | } |
215 | 218 | |
216 | | - // 只有在文件列表页面且未初始化时才重新初始化 |
217 | 219 | if (!isInitializing.value) { |
218 | 220 | init() |
219 | 221 | } |
|
244 | 246 | } |
245 | 247 |
|
246 | 248 | 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 | + } |
260 | 265 | |
261 | | - router.push({ |
262 | | - path: router.currentRoute.value.path, |
263 | | - query |
264 | | - }) |
| 266 | + router.push({ |
| 267 | + path: router.currentRoute.value.path, |
| 268 | + query |
| 269 | + }) |
265 | 270 |
|
266 | | - init() |
| 271 | + init() |
| 272 | + } |
267 | 273 | } |
268 | 274 |
|
269 | 275 | 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 | + } |
284 | 293 | |
285 | | - router.push({ |
286 | | - path: router.currentRoute.value.path, |
287 | | - query |
288 | | - }) |
| 294 | + router.push({ |
| 295 | + path: router.currentRoute.value.path, |
| 296 | + query |
| 297 | + }) |
289 | 298 |
|
290 | | - init() |
| 299 | + init() |
| 300 | + } |
291 | 301 | } |
292 | 302 |
|
293 | 303 | const goToNewFile = () => { |
|
378 | 388 | } |
379 | 389 |
|
380 | 390 | 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 | + } |
396 | 409 | |
397 | | - router.push({ |
398 | | - path: router.currentRoute.value.path, |
399 | | - query |
400 | | - }) |
| 410 | + router.push({ |
| 411 | + path: router.currentRoute.value.path, |
| 412 | + query |
| 413 | + }) |
401 | 414 |
|
402 | | - init() |
403 | | - } |
| 415 | + init() |
| 416 | + } |
| 417 | + } |
404 | 418 |
|
405 | 419 | const goToBlob = (path) => { |
| 420 | + resetFileNotFound() |
406 | 421 | currentPath.value = path |
407 | 422 | const query = { |
408 | 423 | tab: 'files', |
|
604 | 619 | if (isInitializing.value) return // 防止重复初始化 |
605 | 620 | |
606 | 621 | isInitializing.value = true |
| 622 | + resetFileNotFound() |
| 623 | + |
607 | 624 | files.value = [] |
608 | 625 | commitList.value = [] |
609 | | - tempCommit.value = [] |
610 | 626 | loading.value = true |
611 | 627 | updateBreadcrumb() |
612 | 628 | fetchFileListData() |
613 | 629 | fetchLastCommit() |
614 | 630 | |
615 | | - // 延迟重置标记 |
616 | 631 | setTimeout(() => { |
617 | 632 | isInitializing.value = false |
618 | 633 | }, 100) |
619 | 634 | } |
620 | 635 |
|
621 | | - // 在 onMounted 中初始化时也要处理 URL 参数 |
622 | 636 | onMounted(() => { |
623 | | - // 从 URL 参数中恢复状态 |
624 | 637 | const params = new URLSearchParams(window.location.search) |
625 | 638 | const urlActionName = params.get('actionName') |
626 | 639 | const urlPath = params.get('path') |
627 | 640 | const urlBranch = params.get('branch') |
628 | 641 | const currentTab = params.get('tab') |
629 | 642 | |
630 | | - // 只有在当前 tab 是 files 且 actionName 是 files 或为空时才初始化 |
631 | 643 | if (currentTab === 'files' && (urlActionName === 'files' || !urlActionName)) { |
632 | 644 | if (urlActionName && urlActionName !== 'files') { |
633 | 645 | setRepoTab({ |
|
637 | 649 | }) |
638 | 650 | } |
639 | 651 | |
640 | | - // 确保 currentPath 不为 null 或 undefined |
641 | 652 | if (urlPath !== undefined && urlPath !== null) { |
642 | 653 | currentPath.value = urlPath |
643 | 654 | } else { |
|
0 commit comments