feat: show update entry only in native app
This commit is contained in:
@@ -47,7 +47,7 @@
|
||||
</template>
|
||||
</t-cell>
|
||||
</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="currentVersion || '—'" />
|
||||
<t-cell title="自动检查更新">
|
||||
@@ -55,16 +55,43 @@
|
||||
<t-switch :model-value="autoUpdate" @change="handleAutoUpdateChange" />
|
||||
</template>
|
||||
</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>
|
||||
<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>
|
||||
</main>
|
||||
</div>
|
||||
@@ -155,48 +182,33 @@ const {
|
||||
|
||||
const autoUpdate = ref(isAutoUpdateEnabled());
|
||||
|
||||
/** 当前可执行的动作,按检查、下载、应用三阶段推进 */
|
||||
const actionTitle = computed<string>(() => {
|
||||
if (!updateSupported) {
|
||||
return "检查更新";
|
||||
}
|
||||
if (checking.value) {
|
||||
return "正在检查";
|
||||
}
|
||||
/** 当前所处的更新阶段 */
|
||||
const updateStage = computed<"check" | "download" | "downloading" | "apply">(() => {
|
||||
if (downloading.value) {
|
||||
return "正在下载";
|
||||
return "downloading";
|
||||
}
|
||||
if (ready.value) {
|
||||
return "现在更新";
|
||||
return "apply";
|
||||
}
|
||||
if (latest.value && hasUpdate()) {
|
||||
return "开始下载";
|
||||
return "download";
|
||||
}
|
||||
return "检查更新";
|
||||
return "check";
|
||||
});
|
||||
|
||||
const actionEnabled = computed<boolean>(() => {
|
||||
if (!updateSupported || checking.value || downloading.value) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const updateNote = computed<string>(() => {
|
||||
/** 阶段说明文案 */
|
||||
const updateHint = computed<string>(() => {
|
||||
if (!updateSupported) {
|
||||
return "仅在 App 内可用";
|
||||
}
|
||||
if (downloading.value) {
|
||||
return `${percent.value}%`;
|
||||
}
|
||||
if (ready.value) {
|
||||
return `v${ready.value.version} 已下载`;
|
||||
return `v${ready.value.version} 已下载,点击下方按钮重启生效`;
|
||||
}
|
||||
if (checking.value) {
|
||||
return "请稍候";
|
||||
if (latest.value && hasUpdate()) {
|
||||
return `发现新版本 v${latest.value.version}`;
|
||||
}
|
||||
if (latest.value) {
|
||||
return hasUpdate() ? `发现 v${latest.value.version}` : "已是最新";
|
||||
if (latest.value && !checking.value) {
|
||||
return "当前已是最新版本";
|
||||
}
|
||||
return "";
|
||||
});
|
||||
@@ -212,26 +224,7 @@ function handleAutoUpdateChange(value: boolean | string | number): void {
|
||||
localStorage.setItem(AUTO_UPDATE_KEY, enabled ? "1" : "0");
|
||||
}
|
||||
|
||||
async function handleAction(): 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;
|
||||
}
|
||||
// 检查更新
|
||||
async function handleCheck(): Promise<void> {
|
||||
const result = await check();
|
||||
if (!result) {
|
||||
Message.error(updateError.value || "检查更新失败");
|
||||
@@ -241,6 +234,23 @@ async function handleAction(): Promise<void> {
|
||||
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>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -280,8 +290,14 @@ async function handleAction(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
.update-progress {
|
||||
padding: 0 1rem .75rem;
|
||||
.update-panel {
|
||||
gap: .75rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.progress {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,6 +306,10 @@ async function handleAction(): Promise<void> {
|
||||
.volume-field span {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.update-hint {
|
||||
color: #94a3b8;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user