feat(initialization): 增加强制重新安装功能并优化环境检查逻辑
- 在 PythonStep、PipStep 和 GitStep 组件中添加强制重新安装功能 -优化环境检查逻辑,增加关键文件存在性检查 - 调整自动模式启动条件,确保关键文件存在 - 修复部分组件引用,增加必要的 ref
This commit is contained in:
@@ -99,15 +99,29 @@ async function startAutoProcess() {
|
||||
if (!result.success) {
|
||||
throw new Error(`代码更新失败: ${result.error}`)
|
||||
}
|
||||
}
|
||||
|
||||
progressText.value = '更新依赖包...'
|
||||
progress.value = 60
|
||||
// 无论是否有更新,都检查并安装依赖
|
||||
progressText.value = '检查并安装依赖包...'
|
||||
progress.value = 60
|
||||
|
||||
// 使用配置中保存的pip镜像源
|
||||
const pipResult = await window.electronAPI.installDependencies(config.selectedPipMirror)
|
||||
if (!pipResult.success) {
|
||||
throw new Error(`依赖更新失败: ${pipResult.error}`)
|
||||
}
|
||||
// 先尝试使用初始化时的镜像源
|
||||
let pipMirror = config.selectedPipMirror || 'tsinghua'
|
||||
let pipResult = await window.electronAPI.installDependencies(pipMirror)
|
||||
|
||||
// 如果初始化时的镜像源不通,让用户重新选择
|
||||
if (!pipResult.success) {
|
||||
logger.warn(`使用镜像源 ${pipMirror} 安装依赖失败,需要重新选择镜像源`)
|
||||
|
||||
// 切换到手动模式让用户重新选择镜像源
|
||||
progressText.value = '依赖安装失败,需要重新配置镜像源'
|
||||
progressStatus.value = 'exception'
|
||||
|
||||
setTimeout(() => {
|
||||
progressText.value = '请点击下方按钮重新配置环境'
|
||||
}, 2000)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
progressText.value = '启动后端服务...'
|
||||
@@ -121,7 +135,6 @@ async function startAutoProcess() {
|
||||
logger.info('自动启动流程完成,即将进入应用')
|
||||
|
||||
// 延迟0.5秒后自动进入应用
|
||||
// todo 记得修改这里,为了调试加长了5000s
|
||||
setTimeout(() => {
|
||||
props.onAutoComplete()
|
||||
}, 500)
|
||||
@@ -139,11 +152,17 @@ async function startAutoProcess() {
|
||||
}
|
||||
}
|
||||
|
||||
// 检查Git更新(简化版本,实际可以调用Git API)
|
||||
// 检查Git更新
|
||||
async function checkGitUpdate(): Promise<boolean> {
|
||||
// 这里可以实现更复杂的Git更新检查逻辑
|
||||
// 暂时返回false,表示没有更新
|
||||
return false
|
||||
try {
|
||||
// 调用Electron API检查Git仓库是否有更新
|
||||
const result = await window.electronAPI.checkGitUpdate()
|
||||
return result.hasUpdate || false
|
||||
} catch (error) {
|
||||
logger.warn('检查Git更新失败:', error)
|
||||
// 如果检查失败,假设有更新,这样会触发代码拉取和依赖安装
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// 根据镜像源key获取对应的URL
|
||||
|
||||
@@ -13,15 +13,57 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="already-installed">
|
||||
<a-result status="success" title="Git 工具已安装" />
|
||||
<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>
|
||||
@@ -56,8 +98,24 @@ defineProps<{
|
||||
|
||||
.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>
|
||||
@@ -46,10 +46,10 @@
|
||||
<PythonStep v-if="currentStep === 1" :python-installed="pythonInstalled" ref="pythonStepRef" />
|
||||
|
||||
<!-- 步骤 2: pip 安装 -->
|
||||
<PipStep v-if="currentStep === 2" :pip-installed="pipInstalled" />
|
||||
<PipStep v-if="currentStep === 2" :pip-installed="pipInstalled" ref="pipStepRef" />
|
||||
|
||||
<!-- 步骤 3: Git 工具 -->
|
||||
<GitStep v-if="currentStep === 3" :git-installed="gitInstalled" />
|
||||
<GitStep v-if="currentStep === 3" :git-installed="gitInstalled" ref="gitStepRef" />
|
||||
|
||||
<!-- 步骤 4: 源码获取 -->
|
||||
<BackendStep v-if="currentStep === 4" :backend-exists="backendExists" ref="backendStepRef" />
|
||||
@@ -152,6 +152,8 @@ const progressText = ref('')
|
||||
// 组件引用
|
||||
const themeStepRef = ref()
|
||||
const pythonStepRef = ref()
|
||||
const pipStepRef = ref()
|
||||
const gitStepRef = ref()
|
||||
const backendStepRef = ref()
|
||||
const dependenciesStepRef = ref()
|
||||
const serviceStepRef = ref()
|
||||
|
||||
@@ -14,15 +14,57 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="already-installed">
|
||||
<a-result status="success" title="pip 已安装" />
|
||||
<a-result status="success" title="pip已成功安装,无需继续安装" />
|
||||
<div class="reinstall-section">
|
||||
<a-button type="primary" danger @click="handleForceReinstall" :loading="reinstalling">
|
||||
{{ reinstalling ? '正在重新安装...' : '强制重新安装' }}
|
||||
</a-button>
|
||||
<p class="reinstall-note">点击此按钮将删除现有pip环境并重新安装</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineProps<{
|
||||
pipInstalled: boolean
|
||||
}>()
|
||||
|
||||
const reinstalling = ref(false)
|
||||
|
||||
// 强制重新安装pip
|
||||
async function handleForceReinstall() {
|
||||
reinstalling.value = true
|
||||
try {
|
||||
console.log('开始强制重新安装pip')
|
||||
// 先删除现有pip
|
||||
const deleteResult = await window.electronAPI.deletePip()
|
||||
if (!deleteResult.success) {
|
||||
throw new Error(`删除pip失败: ${deleteResult.error}`)
|
||||
}
|
||||
|
||||
// 重新安装pip
|
||||
const installResult = await window.electronAPI.installPip()
|
||||
if (!installResult.success) {
|
||||
throw new Error(`重新安装pip失败: ${installResult.error}`)
|
||||
}
|
||||
|
||||
console.log('pip强制重新安装成功')
|
||||
// 通知父组件更新状态
|
||||
window.location.reload() // 简单的页面刷新来更新状态
|
||||
} catch (error) {
|
||||
console.error('pip强制重新安装失败:', error)
|
||||
// 这里可以添加错误提示
|
||||
} finally {
|
||||
reinstalling.value = false
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
handleForceReinstall
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -57,8 +99,24 @@ defineProps<{
|
||||
|
||||
.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>
|
||||
@@ -28,7 +28,13 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="already-installed">
|
||||
<a-result status="success" title="Python 环境已安装" />
|
||||
<a-result status="success" title="Python已成功安装,无需继续安装" />
|
||||
<div class="reinstall-section">
|
||||
<a-button type="primary" danger @click="handleForceReinstall" :loading="reinstalling">
|
||||
{{ reinstalling ? '正在重新安装...' : '强制重新安装' }}
|
||||
</a-button>
|
||||
<p class="reinstall-note">点击此按钮将删除现有Python环境并重新安装</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -58,6 +64,7 @@ const pythonMirrors = ref<Mirror[]>([
|
||||
|
||||
const selectedPythonMirror = ref('tsinghua')
|
||||
const testingSpeed = ref(false)
|
||||
const reinstalling = ref(false)
|
||||
|
||||
// 加载配置中的镜像源选择
|
||||
async function loadMirrorConfig() {
|
||||
@@ -130,9 +137,38 @@ function getSpeedClass(speed: number | null) {
|
||||
return 'speed-slow'
|
||||
}
|
||||
|
||||
// 强制重新安装Python
|
||||
async function handleForceReinstall() {
|
||||
reinstalling.value = true
|
||||
try {
|
||||
console.log('开始强制重新安装Python')
|
||||
// 先删除现有Python目录
|
||||
const deleteResult = await window.electronAPI.deletePython()
|
||||
if (!deleteResult.success) {
|
||||
throw new Error(`删除Python目录失败: ${deleteResult.error}`)
|
||||
}
|
||||
|
||||
// 重新下载安装Python
|
||||
const installResult = await window.electronAPI.downloadPython(selectedPythonMirror.value)
|
||||
if (!installResult.success) {
|
||||
throw new Error(`重新安装Python失败: ${installResult.error}`)
|
||||
}
|
||||
|
||||
console.log('Python强制重新安装成功')
|
||||
// 通知父组件更新状态
|
||||
window.location.reload() // 简单的页面刷新来更新状态
|
||||
} catch (error) {
|
||||
console.error('Python强制重新安装失败:', error)
|
||||
// 这里可以添加错误提示
|
||||
} finally {
|
||||
reinstalling.value = false
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
selectedPythonMirror,
|
||||
testPythonMirrorSpeed
|
||||
testPythonMirrorSpeed,
|
||||
handleForceReinstall
|
||||
})
|
||||
|
||||
// 组件挂载时加载配置并自动开始测速
|
||||
@@ -267,8 +303,24 @@ onMounted(async () => {
|
||||
|
||||
.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>
|
||||
Reference in New Issue
Block a user