feat(客户端更新): 登录页/首页更新面板显示更新包下载进度条
- 新增 shared/utils/update-progress.ts:进度事件解析/百分比钳制/文案格式化(纯函数) - 新增 shared/components/UpdateProgressBar.vue:两页共用,失败态琥珀色并停在断点 百分比、总大小未知走不确定态 - useVersionUpdate:先挂监听再发桥调用(避免丢首帧),监听 pywebview-update-progress (Python 侧 evaluate_js 推送,同 pywebview-download-progress 约定);失败保留上次进度 - 测试:tests/update-progress.test.ts(8 用例) 兼容:老客户端没有该事件源,进度条不出现,其余行为不变(优雅降级)。 注:本仓库 modules-withdraw / modules-image-video 有 3 个既存失败用例(隔离复现), 与本次改动无关;全仓库仅新增测试引用本次新增模块。
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<template>
|
||||
<div
|
||||
v-if="progress"
|
||||
class="update-progress"
|
||||
:class="{ 'is-error': progress.status === 'failed', 'is-indeterminate': percent < 0 }"
|
||||
>
|
||||
<div class="update-progress-track">
|
||||
<div
|
||||
class="update-progress-fill"
|
||||
:style="percent >= 0 ? { width: percent + '%' } : undefined"
|
||||
></div>
|
||||
</div>
|
||||
<div class="update-progress-text">{{ text }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 客户端更新包下载进度条(登录页 / 首页更新面板共用)。
|
||||
*
|
||||
* 数据来自 Python 侧 do_update_app 推的 pywebview-update-progress 事件,
|
||||
* 经 useVersionUpdate 的 progress 传入;总大小未知时走不确定态(滑动条纹),
|
||||
* 失败时进度条停在断点处并用琥珀色区分"可重试续传"。
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
|
||||
import {
|
||||
formatUpdateProgressText,
|
||||
updateProgressPercent,
|
||||
type UpdateProgress,
|
||||
} from '@/shared/utils/update-progress'
|
||||
|
||||
const props = defineProps<{ progress: UpdateProgress | null }>()
|
||||
|
||||
const percent = computed(() => updateProgressPercent(props.progress))
|
||||
const text = computed(() => formatUpdateProgressText(props.progress))
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.update-progress {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.update-progress-track {
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background: #e6e6e6;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.update-progress-fill {
|
||||
height: 100%;
|
||||
width: 0;
|
||||
border-radius: 3px;
|
||||
background: #28a745;
|
||||
transition: width 0.2s ease;
|
||||
}
|
||||
|
||||
/* 总大小未知:用滑动条纹表示"在下载但算不出百分比" */
|
||||
.update-progress.is-indeterminate .update-progress-fill {
|
||||
width: 40%;
|
||||
animation: update-progress-slide 1.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
/* 失败:进度条停在断点处,用琥珀色区分"已暂停、可重试续传" */
|
||||
.update-progress.is-error .update-progress-fill {
|
||||
background: #d48806;
|
||||
}
|
||||
|
||||
.update-progress-text {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin-top: 4px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
@keyframes update-progress-slide {
|
||||
0% { transform: translateX(-100%); }
|
||||
100% { transform: translateX(250%); }
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user