feat: show update entry only in native app

This commit is contained in:
Timi
2026-11-07 16:49:35 +08:00
parent a3bae17581
commit 163ef12265
+80 -60
View File
@@ -47,7 +47,7 @@
</template> </template>
</t-cell> </t-cell>
</t-cell-group> </t-cell-group>
<t-cell-group title="版本更新" theme="card" v-entrance-transition> <t-cell-group v-if="updateSupported" title="版本更新" theme="card" v-entrance-transition>
<t-cell title="外壳版本" :note="nativeVersion || '—'" /> <t-cell title="外壳版本" :note="nativeVersion || '—'" />
<t-cell title="系统版本" :note="currentVersion || '—'" /> <t-cell title="系统版本" :note="currentVersion || '—'" />
<t-cell title="自动检查更新"> <t-cell title="自动检查更新">
@@ -55,16 +55,43 @@
<t-switch :model-value="autoUpdate" @change="handleAutoUpdateChange" /> <t-switch :model-value="autoUpdate" @change="handleAutoUpdateChange" />
</template> </template>
</t-cell> </t-cell>
<t-cell
:title="actionTitle"
:note="updateNote"
:arrow="actionEnabled"
@click="handleAction"
/>
<div v-if="downloading" class="update-progress">
<t-progress :percentage="percent" :label="false" />
</div>
</t-cell-group> </t-cell-group>
<div v-if="updateSupported" class="update-panel" v-entrance-transition>
<center-tips v-if="updateHint" v-text="updateHint" />
<t-button
v-if="updateStage === 'check'"
class="cell-button"
theme="primary"
size="large"
:loading="checking"
@click="handleCheck"
>
检查更新
</t-button>
<t-button
v-else-if="updateStage === 'download'"
class="cell-button"
theme="primary"
size="large"
@click="handleDownload"
>
下载更新
</t-button>
<template v-else-if="updateStage === 'downloading'">
<t-progress class="progress" stroke-width=".5rem" :percentage="percent" /> <t-button theme="primary" size="large" block disabled>
下载中 {{ percent }}%
</t-button>
</template>
<t-button
v-else-if="updateStage === 'apply'"
class="cell-button"
theme="primary"
size="large"
@click="handleApply"
>
现在更新
</t-button>
</div>
</div> </div>
</main> </main>
</div> </div>
@@ -155,48 +182,33 @@ const {
const autoUpdate = ref(isAutoUpdateEnabled()); const autoUpdate = ref(isAutoUpdateEnabled());
/** 当前可执行的动作,按检查、下载、应用三阶段推进 */ /** 当前所处的更新阶段 */
const actionTitle = computed<string>(() => { const updateStage = computed<"check" | "download" | "downloading" | "apply">(() => {
if (!updateSupported) {
return "检查更新";
}
if (checking.value) {
return "正在检查";
}
if (downloading.value) { if (downloading.value) {
return "正在下载"; return "downloading";
} }
if (ready.value) { if (ready.value) {
return "现在更新"; return "apply";
} }
if (latest.value && hasUpdate()) { if (latest.value && hasUpdate()) {
return "开始下载"; return "download";
} }
return "检查更新"; return "check";
}); });
const actionEnabled = computed<boolean>(() => { /** 阶段说明文案 */
if (!updateSupported || checking.value || downloading.value) { const updateHint = computed<string>(() => {
return false;
}
return true;
});
const updateNote = computed<string>(() => {
if (!updateSupported) { if (!updateSupported) {
return "仅在 App 内可用"; return "仅在 App 内可用";
} }
if (downloading.value) {
return `${percent.value}%`;
}
if (ready.value) { if (ready.value) {
return `v${ready.value.version} 已下载`; return `v${ready.value.version} 已下载,点击下方按钮重启生效`;
} }
if (checking.value) { if (latest.value && hasUpdate()) {
return "请稍候"; return `发现新版本 v${latest.value.version}`;
} }
if (latest.value) { if (latest.value && !checking.value) {
return hasUpdate() ? `发现 v${latest.value.version}` : "已是最新"; return "当前已是最新版本";
} }
return ""; return "";
}); });
@@ -212,26 +224,7 @@ function handleAutoUpdateChange(value: boolean | string | number): void {
localStorage.setItem(AUTO_UPDATE_KEY, enabled ? "1" : "0"); localStorage.setItem(AUTO_UPDATE_KEY, enabled ? "1" : "0");
} }
async function handleAction(): Promise<void> { async function handleCheck(): Promise<void> {
if (!actionEnabled.value) {
return;
}
// 已下载,应用并重启
if (ready.value) {
await apply(ready.value);
return;
}
// 已发现新版本,开始下载
if (latest.value && hasUpdate()) {
const bundle = await download();
if (bundle) {
Message.success(`v${bundle.version} 已下载,点「现在更新」生效`);
return;
}
Message.error(updateError.value || "下载失败");
return;
}
// 检查更新
const result = await check(); const result = await check();
if (!result) { if (!result) {
Message.error(updateError.value || "检查更新失败"); Message.error(updateError.value || "检查更新失败");
@@ -241,6 +234,23 @@ async function handleAction(): Promise<void> {
Message.info("已是最新版本"); Message.info("已是最新版本");
} }
} }
async function handleDownload(): Promise<void> {
const bundle = await download();
if (!bundle) {
Message.error(updateError.value || "下载失败");
return;
}
Message.success(`v${bundle.version} 已下载`);
}
async function handleApply(): Promise<void> {
const bundle = ready.value;
if (!bundle) {
return;
}
await apply(bundle);
}
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
@@ -280,8 +290,14 @@ async function handleAction(): Promise<void> {
} }
} }
.update-progress { .update-panel {
padding: 0 1rem .75rem; gap: .75rem;
display: flex;
flex-direction: column;
.progress {
margin: 0 1rem;
}
} }
} }
@@ -290,6 +306,10 @@ async function handleAction(): Promise<void> {
.volume-field span { .volume-field span {
color: #94a3b8; color: #94a3b8;
} }
.update-hint {
color: #94a3b8;
}
} }
} }
</style> </style>