1
This commit is contained in:
@@ -2,15 +2,18 @@
|
||||
<div>
|
||||
<div class="version-info" @click="autoCheck">v{{ version || '-' }}</div>
|
||||
|
||||
<el-dialog v-model="show" width="522px" :close-on-click-modal="false" align-center class="update-dialog" :title="stage === 'downloading' ? `正在更新 ${appName}` : '软件更新'">
|
||||
<el-dialog v-model="show" width="522px" :close-on-click-modal="false" align-center class="update-dialog"
|
||||
:title="stage === 'downloading' ? `正在更新 ${appName}` : '软件更新'">
|
||||
<div v-if="stage === 'check'" class="update-content">
|
||||
<div class="update-layout">
|
||||
<div class="left-pane">
|
||||
<img src="/icon/icon.png" class="app-icon app-icon-large" alt="App Icon" />
|
||||
<img src="/icon/icon.png" class="app-icon app-icon-large" alt="App Icon"/>
|
||||
</div>
|
||||
<div class="right-pane">
|
||||
<p class="announce">新版本的"{{ appName }}"已经发布</p>
|
||||
<p class="desc">{{ appName }} {{ info.latestVersion }} 可供安装,您现在的版本是 {{ version }},要现在安装吗?</p>
|
||||
<p class="desc">{{ appName }} {{ info.latestVersion }} 可供安装,您现在的版本是 {{
|
||||
version
|
||||
}},要现在安装吗?</p>
|
||||
|
||||
<div class="update-details form">
|
||||
<h4>更新信息</h4>
|
||||
@@ -20,7 +23,7 @@
|
||||
class="notes-box"
|
||||
:rows="6"
|
||||
readonly
|
||||
resize="none" />
|
||||
resize="none"/>
|
||||
</div>
|
||||
|
||||
<div class="update-actions row">
|
||||
@@ -41,7 +44,7 @@
|
||||
<div v-else-if="stage === 'downloading'" class="update-content">
|
||||
<div class="download-main">
|
||||
<div class="download-icon">
|
||||
<img src="/icon/icon.png" class="app-icon" alt="App Icon" />
|
||||
<img src="/icon/icon.png" class="app-icon" alt="App Icon"/>
|
||||
</div>
|
||||
<div class="download-content">
|
||||
<div class="download-info">
|
||||
@@ -52,7 +55,7 @@
|
||||
:percentage="prog.percentage"
|
||||
:show-text="false"
|
||||
:stroke-width="6"
|
||||
color="#409EFF" />
|
||||
color="#409EFF"/>
|
||||
<div class="progress-details">
|
||||
<span style="font-weight: 500">{{ prog.current }} / {{ prog.total }}</span>
|
||||
<el-button size="small" @click="cancelDownload">取消</el-button>
|
||||
@@ -64,7 +67,7 @@
|
||||
|
||||
<div v-else-if="stage === 'completed'" class="update-content">
|
||||
<div class="update-header text-center">
|
||||
<img src="/icon/icon.png" class="app-icon" alt="App Icon" />
|
||||
<img src="/icon/icon.png" class="app-icon" alt="App Icon"/>
|
||||
<h3>更新完成</h3>
|
||||
<p>更新文件已下载,将在重启后自动应用</p>
|
||||
</div>
|
||||
@@ -77,7 +80,7 @@
|
||||
:percentage="100"
|
||||
:show-text="false"
|
||||
:stroke-width="6"
|
||||
color="#67C23A" />
|
||||
color="#67C23A"/>
|
||||
</div>
|
||||
|
||||
<div class="update-buttons">
|
||||
@@ -90,9 +93,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { updateApi } from '../../api/update'
|
||||
import {ref, computed, onMounted, onUnmounted} from 'vue'
|
||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||
import {updateApi} from '../../api/update'
|
||||
|
||||
const props = defineProps<{ modelValue: boolean }>()
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: boolean] }>()
|
||||
@@ -105,8 +108,8 @@ const show = computed({
|
||||
type Stage = 'check' | 'downloading' | 'completed'
|
||||
const stage = ref<Stage>('check')
|
||||
const appName = ref('我了个电商')
|
||||
const version = ref('2.0.0')
|
||||
const prog = ref({ percentage: 0, current: '0 MB', total: '0 MB', speed: '' })
|
||||
const version = ref('')
|
||||
const prog = ref({percentage: 0, current: '0 MB', total: '0 MB', speed: ''})
|
||||
const info = ref({
|
||||
latestVersion: '2.4.8',
|
||||
downloadUrl: '',
|
||||
@@ -117,49 +120,48 @@ const info = ref({
|
||||
|
||||
async function autoCheck() {
|
||||
try {
|
||||
ElMessage({ message: '正在检查更新...', type: 'info' })
|
||||
version.value = await (window as any).electronAPI.getJarVersion()
|
||||
const checkRes: any = await updateApi.checkUpdate(version.value)
|
||||
const result = checkRes?.data || checkRes
|
||||
|
||||
try {
|
||||
version.value = await updateApi.getVersion()
|
||||
} catch (error) {
|
||||
console.error('获取版本失败:', error)
|
||||
version.value = '2.0.0'
|
||||
if (!result.needUpdate) {
|
||||
ElMessage.info('当前已是最新版本')
|
||||
return
|
||||
}
|
||||
|
||||
info.value = {
|
||||
currentVersion: version.value,
|
||||
latestVersion: '2.4.9',
|
||||
downloadUrl: 'https://qiniu.pxdj.tashowz.com/2025/09/becac13811214c909d11162d2ff2c863.asar',
|
||||
currentVersion: result.currentVersion,
|
||||
latestVersion: result.latestVersion,
|
||||
downloadUrl: result.downloadUrl || '',
|
||||
updateNotes: '• 优化了用户界面体验\n• 修复了已知问题\n• 提升了系统稳定性\n• 轻量级更新(仅替换app.asar)',
|
||||
hasUpdate: true
|
||||
}
|
||||
|
||||
show.value = true
|
||||
stage.value = 'check'
|
||||
ElMessage({ message: '发现新版本', type: 'success' })
|
||||
ElMessage.success('发现新版本')
|
||||
} catch (error) {
|
||||
console.error('检查更新失败:', error)
|
||||
ElMessage({ message: '检查更新失败', type: 'error' })
|
||||
ElMessage.error('检查更新失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function start() {
|
||||
if (!info.value.downloadUrl) {
|
||||
ElMessage({ message: '下载链接不可用', type: 'error' });
|
||||
return;
|
||||
ElMessage.error('下载链接不可用')
|
||||
return
|
||||
}
|
||||
|
||||
stage.value = 'downloading';
|
||||
prog.value = { percentage: 0, current: '0 MB', total: '0 MB', speed: '' };
|
||||
stage.value = 'downloading'
|
||||
prog.value = {percentage: 0, current: '0 MB', total: '0 MB', speed: ''}
|
||||
|
||||
(window as any).electronAPI.onDownloadProgress((progress: any) => {
|
||||
;(window as any).electronAPI.onDownloadProgress((progress: any) => {
|
||||
prog.value = {
|
||||
percentage: progress.percentage || 0,
|
||||
current: progress.current || '0 MB',
|
||||
total: progress.total || '0 MB',
|
||||
speed: progress.speed || ''
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
const response = await (window as any).electronAPI.downloadUpdate(info.value.downloadUrl)
|
||||
@@ -167,14 +169,14 @@ async function start() {
|
||||
if (response.success) {
|
||||
stage.value = 'completed'
|
||||
prog.value.percentage = 100
|
||||
ElMessage({ message: '下载完成', type: 'success' })
|
||||
ElMessage.success('下载完成')
|
||||
} else {
|
||||
ElMessage({ message: '下载失败: ' + (response.error || '未知错误'), type: 'error' })
|
||||
ElMessage.error('下载失败: ' + (response.error || '未知错误'))
|
||||
stage.value = 'check'
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('下载失败:', error)
|
||||
ElMessage({ message: '下载失败', type: 'error' })
|
||||
ElMessage.error('下载失败')
|
||||
stage.value = 'check'
|
||||
}
|
||||
}
|
||||
@@ -195,37 +197,26 @@ async function cancelDownload() {
|
||||
async function installUpdate() {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'安装过程中程序将自动重启,请确保已保存所有工作。确定要立即安装更新吗?',
|
||||
'确认安装',
|
||||
{
|
||||
confirmButtonText: '立即安装',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
'安装过程中程序将自动重启,请确保已保存所有工作。确定要立即安装更新吗?',
|
||||
'确认安装',
|
||||
{
|
||||
confirmButtonText: '立即安装',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
)
|
||||
const response = await (window as any).electronAPI.installUpdate()
|
||||
|
||||
if (response.success) {
|
||||
ElMessage({ message: '应用即将重启', type: 'success' })
|
||||
ElMessage.success('应用即将重启')
|
||||
setTimeout(() => show.value = false, 1000)
|
||||
} else {
|
||||
ElMessage({ message: '重启失败: ' + (response.error || '未知错误'), type: 'error' })
|
||||
stage.value = 'check'
|
||||
}
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('安装失败:', error)
|
||||
ElMessage({ message: '安装失败', type: 'error' })
|
||||
}
|
||||
if (error !== 'cancel') ElMessage.error('安装失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
version.value = await updateApi.getVersion()
|
||||
} catch (error) {
|
||||
console.error('获取版本失败:', error)
|
||||
}
|
||||
version.value = await (window as any).electronAPI.getJarVersion()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -238,7 +229,7 @@ onUnmounted(() => {
|
||||
position: fixed;
|
||||
right: 10px;
|
||||
bottom: 10px;
|
||||
background: rgba(255,255,255,0.9);
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
padding: 5px 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
@@ -273,11 +264,38 @@ onUnmounted(() => {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.left-pane { display: flex; flex-direction: column; align-items: flex-start; }
|
||||
.app-icon-large { width: 70px; height: 70px; border-radius: 12px; margin: 4px 0 0 0; }
|
||||
.right-pane { min-width: 0; }
|
||||
.right-pane .announce { font-size: 16px; font-weight: 600; color: #1f2937; margin: 4px 0 6px; word-break: break-word; }
|
||||
.right-pane .desc { font-size: 13px; color: #6b7280; line-height: 1.6; margin: 0; word-break: break-word; }
|
||||
.left-pane {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.app-icon-large {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
border-radius: 12px;
|
||||
margin: 4px 0 0 0;
|
||||
}
|
||||
|
||||
.right-pane {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.right-pane .announce {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin: 4px 0 6px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.right-pane .desc {
|
||||
font-size: 13px;
|
||||
color: #6b7280;
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.update-header {
|
||||
display: flex;
|
||||
@@ -324,8 +342,13 @@ onUnmounted(() => {
|
||||
margin: 12px 0 8px 0;
|
||||
}
|
||||
|
||||
.update-details.form { max-height: none; }
|
||||
.notes-box :deep(textarea.el-textarea__inner) { white-space: pre-wrap; }
|
||||
.update-details.form {
|
||||
max-height: none;
|
||||
}
|
||||
|
||||
.notes-box :deep(textarea.el-textarea__inner) {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.update-details h4 {
|
||||
font-size: 14px;
|
||||
@@ -347,10 +370,24 @@ onUnmounted(() => {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.update-actions.row .update-buttons { justify-content: space-between; }
|
||||
:deep(.update-actions.row .update-buttons .el-button) { flex: none; min-width: 100px; }
|
||||
.left-actions { display: flex; gap: 12px; }
|
||||
.right-actions { display: flex; gap: 8px; }
|
||||
.update-actions.row .update-buttons {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
:deep(.update-actions.row .update-buttons .el-button) {
|
||||
flex: none;
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.left-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.right-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
:deep(.update-buttons .el-button) {
|
||||
flex: 1;
|
||||
|
||||
Reference in New Issue
Block a user