refactor(initialization): 移除pip安装步骤

This commit is contained in:
2025-08-26 16:45:49 +08:00
parent 2f87d79713
commit 183e35ac97
5 changed files with 154 additions and 58 deletions

View File

@@ -97,7 +97,7 @@ async function startAutoProcess() {
if (aborted.value) return
if (hasUpdate) {
progressText.value = '正在更新...'
progressText.value = '发现更新,正在更新代码...'
progress.value = 40
// 使用配置中保存的Git镜像源

View File

@@ -0,0 +1,121 @@
<template>
<div class="step-panel">
<h3>Git 版本控制工具</h3>
<div v-if="!gitInstalled" class="install-section">
<p>需要安装 Git 工具来获取源代码</p>
<div class="git-info">
<a-alert
message="Git 工具信息"
description="将安装便携版 Git 工具,包含完整的版本控制功能,无需系统安装。"
type="info"
show-icon
/>
</div>
</div>
<div v-else class="already-installed">
<a-result status="success" title="Git已成功安装无需继续安装" />
<!-- <div class="reinstall-section">-->
<!-- <a-button type="primary" danger @click="handleForceReinstall" :loading="reinstalling">-->
<!-- {{ reinstalling ? '正在重新安装...' : '强制重新安装' }}-->
<!-- </a-button>-->
<!-- <p class="reinstall-note">点击此按钮将删除现有Git环境并重新安装</p>-->
<!-- </div>-->
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
defineProps<{
gitInstalled: boolean
}>()
const reinstalling = ref(false)
// 强制重新安装Git
async function handleForceReinstall() {
reinstalling.value = true
try {
console.log('开始强制重新安装Git')
// 先删除现有Git
const deleteResult = await window.electronAPI.deleteGit()
if (!deleteResult.success) {
throw new Error(`删除Git失败: ${deleteResult.error}`)
}
// 重新安装Git
const installResult = await window.electronAPI.downloadGit()
if (!installResult.success) {
throw new Error(`重新安装Git失败: ${installResult.error}`)
}
console.log('Git强制重新安装成功')
// 通知父组件更新状态
window.location.reload() // 简单的页面刷新来更新状态
} catch (error) {
console.error('Git强制重新安装失败:', error)
// 这里可以添加错误提示
} finally {
reinstalling.value = false
}
}
defineExpose({
handleForceReinstall,
})
</script>
<style scoped>
.step-panel {
padding: 20px;
background: var(--ant-color-bg-elevated);
border-radius: 8px;
border: 1px solid var(--ant-color-border);
}
.step-panel h3 {
font-size: 20px;
font-weight: 600;
color: var(--ant-color-text);
margin-bottom: 20px;
}
.install-section {
display: flex;
flex-direction: column;
gap: 20px;
}
.install-section p {
color: var(--ant-color-text-secondary);
margin: 0;
}
.git-info {
margin-top: 16px;
}
.already-installed {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 200px;
gap: 20px;
}
.reinstall-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
}
.reinstall-note {
font-size: 12px;
color: var(--ant-color-text-tertiary);
text-align: center;
margin: 0;
}
</style>

View File

@@ -4,19 +4,19 @@
<h1>AUTO_MAA 初始化向导</h1>
<p>欢迎使用 AUTO_MAA让我们来配置您的运行环境</p>
<!-- <div class="header-actions">-->
<!-- <a-button size="large" type="primary" @click="handleSkipToHome">-->
<!-- 跳转至首页仅开发用-->
<!-- </a-button>-->
<!-- <a-button-->
<!-- size="large"-->
<!-- type="default"-->
<!-- @click="handleJumpToStep(6)"-->
<!-- style="margin-left: 16px"-->
<!-- >-->
<!-- 跳到启动服务-->
<!-- </a-button>-->
<!-- </div>-->
<div class="header-actions">
<a-button size="large" type="primary" @click="handleSkipToHome">
跳转至首页仅开发用
</a-button>
<a-button
size="large"
type="default"
@click="handleJumpToStep(5)"
style="margin-left: 16px"
>
跳到启动服务
</a-button>
</div>
</div>
<a-steps :current="currentStep" :status="stepStatus" class="init-steps">
@@ -49,17 +49,17 @@
ref="pythonStepRef"
/>
<!-- 步骤 2: pip 安装 -->
<PipStep v-if="currentStep === 2" :pip-installed="pipInstalled" ref="pipStepRef" />
<!-- 步骤 2: Git 工具 -->
<GitStep v-if="currentStep === 2" :git-installed="gitInstalled" ref="gitStepRef" />
<!-- 步骤 3: 源码获取 -->
<BackendStep v-if="currentStep === 4" :backend-exists="backendExists" ref="backendStepRef" />
<BackendStep v-if="currentStep === 3" :backend-exists="backendExists" ref="backendStepRef" />
<!-- 步骤 4: 依赖安装 -->
<DependenciesStep v-if="currentStep === 5" ref="dependenciesStepRef" />
<DependenciesStep v-if="currentStep === 4" ref="dependenciesStepRef" />
<!-- 步骤 5: 启动服务 -->
<ServiceStep v-if="currentStep === 6" ref="serviceStepRef" />
<ServiceStep v-if="currentStep === 5" ref="serviceStepRef" />
</div>
<div class="step-actions">
@@ -82,7 +82,7 @@
{{ getNextButtonText() }}
</a-button>
<!-- 7步重新启动服务按钮 -->
<!-- 6步重新启动服务按钮 -->
<a-button
v-if="currentStep === 5"
type="default"
@@ -107,13 +107,14 @@
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { ref, computed, watch } from 'vue'
import { message } from 'ant-design-vue'
import { createComponentLogger } from '@/utils/logger'
import { saveConfig } from '@/utils/config'
import ThemeStep from './ThemeStep.vue'
import PythonStep from './PythonStep.vue'
import PipStep from './PipStep.vue'
import GitStep from './GitStep.vue'
import BackendStep from './BackendStep.vue'
import DependenciesStep from './DependenciesStep.vue'
import ServiceStep from './ServiceStep.vue'
@@ -124,7 +125,6 @@ const logger = createComponentLogger('ManualMode')
interface Props {
// 状态
pythonInstalled: boolean
pipInstalled: boolean
gitInstalled: boolean
backendExists: boolean
dependenciesInstalled: boolean
@@ -152,7 +152,6 @@ const progressText = ref('')
// 组件引用
const themeStepRef = ref()
const pythonStepRef = ref()
const pipStepRef = ref()
const gitStepRef = ref()
const backendStepRef = ref()
const dependenciesStepRef = ref()
@@ -195,10 +194,10 @@ async function handleNextStep() {
await installPython()
}
break
case 2: // pip 安装
console.log('执行pip安装')
if (!props.pipInstalled) {
await installPip()
case 2: // Git 工具
console.log('执行Git工具安装')
if (!props.gitInstalled) {
await installGit()
}
break
case 3: // 源码获取
@@ -242,7 +241,7 @@ function getNextButtonText() {
case 1:
return props.pythonInstalled ? '下一步' : '安装 Python'
case 2:
return props.pipInstalled ? '下一步' : '安装 pip'
return props.gitInstalled ? '下一步' : '安装 Git'
case 3:
return props.backendExists ? '更新代码' : '获取代码'
case 4:
@@ -265,20 +264,20 @@ async function autoStartSpeedTest() {
await pythonStepRef.value.testPythonMirrorSpeed()
}
break
case 4: // 源码获取
case 3: // 源码获取
if (backendStepRef.value?.testGitMirrorSpeed) {
console.log('自动开始Git镜像测速')
await backendStepRef.value.testGitMirrorSpeed()
}
break
case 5: // 依赖安装
case 4: // 依赖安装
if (!props.dependenciesInstalled && dependenciesStepRef.value?.testPipMirrorSpeed) {
console.log('自动开始pip镜像测速')
await dependenciesStepRef.value.testPipMirrorSpeed()
}
break
case 6: // 启动服务 - 自动启动后端
console.log('进入第步,自动启动后端服务')
case 5: // 启动服务 - 自动启动后端
console.log('进入第步,自动启动后端服务')
await autoStartBackendService()
break
}
@@ -299,17 +298,7 @@ async function installPython() {
}
}
async function installPip() {
logger.info('开始安装pip')
const result = await window.electronAPI.installPip()
if (result.success) {
logger.info('pip安装成功')
await saveConfig({ pipInstalled: true })
} else {
logger.error('pip安装失败', result.error)
throw new Error(result.error)
}
}
async function installGit() {
logger.info('开始安装Git工具')

View File

@@ -23,7 +23,6 @@ export interface FrontendConfig {
gitInstalled?: boolean
backendExists?: boolean
dependenciesInstalled?: boolean
pipInstalled?: boolean
}
const DEFAULT_CONFIG: FrontendConfig = {
@@ -38,7 +37,6 @@ const DEFAULT_CONFIG: FrontendConfig = {
gitInstalled: false,
backendExists: false,
dependenciesInstalled: false,
pipInstalled: false,
}
// 读取配置(内部使用,不触发保存)

View File

@@ -15,7 +15,6 @@
v-else
ref="manualModeRef"
:python-installed="pythonInstalled"
:pip-installed="pipInstalled"
:git-installed="gitInstalled"
:backend-exists="backendExists"
:dependencies-installed="dependenciesInstalled"
@@ -46,7 +45,6 @@ const autoMode = ref(false)
// 安装状态
const pythonInstalled = ref(false)
const pipInstalled = ref(false)
const gitInstalled = ref(false)
const backendExists = ref(false)
const dependenciesInstalled = ref(false)
@@ -89,7 +87,6 @@ async function checkCriticalFiles() {
const config = await getConfig()
return {
pythonExists: config.pythonInstalled || false,
pipExists: config.pipInstalled || false,
gitExists: config.gitInstalled || false,
mainPyExists: config.backendExists || false,
}
@@ -101,13 +98,11 @@ async function checkCriticalFiles() {
console.log('🔍 electronAPI.checkCriticalFiles() 原始返回结果:', criticalFiles)
console.log('🔍 详细检查结果:')
console.log(' - pythonExists:', criticalFiles.pythonExists, typeof criticalFiles.pythonExists)
console.log(' - pipExists:', criticalFiles.pipExists, typeof criticalFiles.pipExists)
console.log(' - gitExists:', criticalFiles.gitExists, typeof criticalFiles.gitExists)
console.log(' - mainPyExists:', criticalFiles.mainPyExists, typeof criticalFiles.mainPyExists)
const result = {
pythonExists: criticalFiles.pythonExists,
pipExists: criticalFiles.pipExists,
gitExists: criticalFiles.gitExists,
mainPyExists: criticalFiles.mainPyExists,
}
@@ -123,13 +118,11 @@ async function checkCriticalFiles() {
const config = await getConfig()
console.log('📄 使用配置文件中的状态:', {
pythonInstalled: config.pythonInstalled,
pipInstalled: config.pipInstalled,
gitInstalled: config.gitInstalled,
backendExists: config.backendExists,
})
return {
pythonExists: config.pythonInstalled || false,
pipExists: config.pipInstalled || false,
gitExists: config.gitInstalled || false,
mainPyExists: config.backendExists || false,
}
@@ -137,7 +130,6 @@ async function checkCriticalFiles() {
console.error('❌ 读取配置文件也失败了:', configError)
return {
pythonExists: false,
pipExists: false,
gitExists: false,
mainPyExists: false,
}
@@ -157,7 +149,6 @@ async function checkEnvironment() {
// 直接根据exe文件存在性设置状态
pythonInstalled.value = criticalFiles.pythonExists
pipInstalled.value = criticalFiles.pipExists
gitInstalled.value = criticalFiles.gitExists
backendExists.value = criticalFiles.mainPyExists
@@ -167,7 +158,6 @@ async function checkEnvironment() {
console.log('📊 最终状态设置:')
console.log(' - pythonInstalled:', pythonInstalled.value)
console.log(' - pipInstalled:', pipInstalled.value)
console.log(' - gitInstalled:', gitInstalled.value)
console.log(' - backendExists:', backendExists.value)
console.log(' - dependenciesInstalled:', dependenciesInstalled.value)
@@ -179,13 +169,11 @@ async function checkEnvironment() {
// 检查所有关键exe文件是否都存在
const allExeFilesExist =
criticalFiles.pythonExists &&
criticalFiles.pipExists &&
criticalFiles.gitExists &&
criticalFiles.mainPyExists
console.log('关键exe文件状态检查:')
console.log('- python.exe存在:', criticalFiles.pythonExists)
console.log('- pip.exe存在:', criticalFiles.pipExists)
console.log('- git.exe存在:', criticalFiles.gitExists)
console.log('- main.py存在:', criticalFiles.mainPyExists)
console.log('- 所有关键文件存在:', allExeFilesExist)