From dfc403733f8e13a2514d243d2033591244d28c8d Mon Sep 17 00:00:00 2001 From: Alirea <2981883527@qq.com> Date: Sun, 28 Sep 2025 13:54:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E4=BC=98=E5=85=88=E5=B0=9D?= =?UTF-8?q?=E8=AF=95=E4=BD=BF=E7=94=A8=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=9A=84=E9=95=9C=E5=83=8F=E6=BA=90=E8=BF=9B=E8=A1=8C=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E6=9B=B4=E6=96=B0=EF=BC=8C=E6=9C=80=E5=90=8E=E4=BD=BF?= =?UTF-8?q?=E7=94=A8github?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/initialization/AutoMode.vue | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/initialization/AutoMode.vue b/frontend/src/components/initialization/AutoMode.vue index 472f35c..dfbbfb4 100644 --- a/frontend/src/components/initialization/AutoMode.vue +++ b/frontend/src/components/initialization/AutoMode.vue @@ -306,47 +306,66 @@ async function tryUpdateBackendWithRetry(config: any): Promise { const customMirrors = config.customGitMirrors || [] const combinedMirrors = [...allGitMirrors, ...customMirrors] - // 优先使用用户选择的镜像源 + // 分离镜像源和官方源(GitHub) + const mirrorSources = combinedMirrors.filter(m => m.type === 'mirror') + const officialSources = combinedMirrors.filter(m => m.type === 'official') + + // 构建尝试顺序:先尝试镜像源,最后尝试GitHub + let mirrorsToTry: any[] = [] + + // 首先添加用户选择的镜像源(如果是镜像源类型) const selectedMirror = combinedMirrors.find(m => m.key === config.selectedGitMirror) - let mirrorsToTry = selectedMirror ? [selectedMirror] : [] - - // 添加其他镜像源作为备选 - const otherMirrors = combinedMirrors.filter(m => m.key !== config.selectedGitMirror) - mirrorsToTry = [...mirrorsToTry, ...otherMirrors] - - console.log('准备尝试的Git镜像源:', mirrorsToTry.map(m => m.name)) - + if (selectedMirror && selectedMirror.type === 'mirror') { + mirrorsToTry.push(selectedMirror) + } + + // 然后添加其他镜像源(排除已选择的) + const otherMirrorSources = mirrorSources.filter(m => m.key !== config.selectedGitMirror) + mirrorsToTry = [...mirrorsToTry, ...otherMirrorSources] + + // 如果用户选择的是官方源,放在镜像源之后 + if (selectedMirror && selectedMirror.type === 'official') { + mirrorsToTry.push(selectedMirror) + } + + // 最后添加其他官方源(排除已选择的) + const otherOfficialSources = officialSources.filter(m => m.key !== config.selectedGitMirror) + mirrorsToTry = [...mirrorsToTry, ...otherOfficialSources] + + console.log('准备尝试的Git源(镜像源优先):', mirrorsToTry.map(m => `${m.name} (${m.type})`)) + for (let i = 0; i < mirrorsToTry.length; i++) { if (aborted.value) return false const mirror = mirrorsToTry[i] - progressText.value = `正在使用 ${mirror.name} 更新代码... (${i + 1}/${mirrorsToTry.length})` - + const sourceType = mirror.type === 'mirror' ? '镜像源' : '官方源' + progressText.value = `正在使用 ${mirror.name} ${sourceType}更新代码... (${i + 1}/${mirrorsToTry.length})` + try { - console.log(`尝试使用镜像源: ${mirror.name} (${mirror.url})`) + console.log(`尝试使用${sourceType}: ${mirror.name} (${mirror.url})`) const result = await window.electronAPI.updateBackend(mirror.url) if (result.success) { - console.log(`使用镜像源 ${mirror.name} 更新成功`) - message.success(`使用 ${mirror.name} 更新代码成功`) + console.log(`使用${sourceType} ${mirror.name} 更新成功`) + message.success(`使用 ${mirror.name} ${sourceType}更新代码成功`) return true } else { - console.warn(`镜像源 ${mirror.name} 更新失败:`, result.error) + console.warn(`${sourceType} ${mirror.name} 更新失败:`, result.error) if (i < mirrorsToTry.length - 1) { - progressText.value = `${mirror.name} 失败,尝试下一个镜像源...` + progressText.value = `${mirror.name} ${sourceType}失败,尝试下一个源...` await new Promise(resolve => setTimeout(resolve, 1000)) // 等待1秒 } } } catch (error) { - console.error(`镜像源 ${mirror.name} 更新异常:`, error) + console.error(`${sourceType} ${mirror.name} 更新异常:`, error) if (i < mirrorsToTry.length - 1) { - progressText.value = `${mirror.name} 异常,尝试下一个镜像源...` + progressText.value = `${mirror.name} ${sourceType}异常,尝试下一个源...` await new Promise(resolve => setTimeout(resolve, 1000)) // 等待1秒 } } } - console.error('所有Git镜像源都无法更新代码') + console.error('所有Git源(镜像源和官方源)都无法更新代码') return false }