feat(system): app update log

This commit is contained in:
Timi
2026-11-13 15:05:20 +08:00
parent 04ad331e8d
commit 7cb4836b40
11 changed files with 418 additions and 83 deletions
+141 -11
View File
@@ -1,11 +1,16 @@
<template>
<div class="tui-page-layout tui-navbar">
<t-navbar fixed :z-index="20" title="版本更新" left-arrow @left-click="$router.back()" />
<div class="tui-page-layout tui-navbar app-update">
<t-navbar
fixed
:z-index="20"
title="版本更新"
left-arrow
@left-click="goBack"
/>
<main class="tui-page-content scroll column">
<center-tips v-if="!updateSupported" content="仅在 App 内可用" />
<t-cell-group v-if="updateSupported" title="版本更新" theme="card" v-entrance-transition>
<t-cell-group v-if="updateSupported" theme="card" v-entrance-transition>
<t-cell title="外壳版本" :note="nativeVersion || '—'" />
<t-cell title="系统版本" :note="currentVersion || '—'" />
<t-cell title="系统版本" :note="displayVersion" />
<t-cell v-if="latestVersionText" title="最新版本" :note="latestVersionText" />
<t-cell title="自动更新">
<template #right-icon>
@@ -13,6 +18,9 @@
</template>
</t-cell>
</t-cell-group>
<t-cell-group v-else theme="card" v-entrance-transition>
<t-cell title="系统版本" :note="displayVersion" />
</t-cell-group>
<div v-if="updateSupported" class="update-panel" v-entrance-transition>
<center-tips v-if="updateHint"><span v-text="updateHint" /></center-tips>
<t-button
@@ -50,18 +58,71 @@
现在更新
</t-button>
</div>
<section v-if="noteList.length" class="versions">
<h2 class="title" v-text="noteTitle" />
<timeline>
<timeline-item
class="version"
v-for="item in noteList"
:key="item.version"
v-entrance-transition
>
<template #label>
<div class="label">
<t-tag
size="small"
theme="primary"
variant="light-outline"
:content="item.version"
/>
<time-label class="time" :timestamp="item.publishedAt" />
</div>
</template>
<markdown-view class="content bg-white" :content="item.note" />
</timeline-item>
<timeline-item v-entrance-transition>
<template #label>
<div class="label">
<t-tag
size="small"
theme="primary"
variant="light-outline"
content="..."
/>
</div>
</template>
</timeline-item>
</timeline>
</section>
</main>
</div>
</template>
<script setup lang="ts">
import { setAutoUpdate, useAppUpdate } from "@/composables/useAppUpdate";
import { version } from "../../../package.json";
import { Capacitor } from "@capacitor/core";
import { Timeline, TimelineItem, usePane } from "timi-tdesign-mobile";
import { MarkdownView, TimeLabel } from "timi-web";
import AppUpdateAPI from "@/api/AppUpdateAPI";
import { APP_ID, setAutoUpdate, useAppUpdate } from "@/composables/useAppUpdate";
import type { AppUpdateNote } from "@/types/AppUpdate";
import { Message } from "@/utils/message";
defineOptions({
name: "AppUpdate"
});
const router = useRouter();
const pane = usePane();
function goBack(): void {
if (pane) {
pane.close();
return;
}
router.back();
}
// ---------- 版本更新 ----------
const {
@@ -83,6 +144,11 @@ const {
restorePending
} = useAppUpdate();
/** 系统版本:原生端优先取热更包版本,未热更过或 web 端回落到构建版本 */
const displayVersion = computed<string>(
() => (currentVersion.value && currentVersion.value !== "builtin" ? currentVersion.value : version)
);
/** 有更新时展示目标版本号 */
const latestVersionText = computed<string>(() => (hasUpdate() ? `v${latest.value?.version ?? ""}` : ""));
@@ -117,11 +183,43 @@ const updateHint = computed<string>(() => {
return "";
});
// ---------- 更新日志 ----------
/** web 端只展示最近几个版本 */
const WEB_NOTE_LIMIT = 3;
const noteList = ref<AppUpdateNote[]>([]);
const noteTitle = computed<string>(() => (updateSupported ? "更新内容" : "最近更新"));
/** 查询当前版本到通道最新版本之间的变更说明 */
async function loadNotes(): Promise<void> {
try {
const result = await AppUpdateAPI.notes({
appId: APP_ID,
// web 端没有热更包版本,从内置包开始算,后端会返回通道的完整历史
versionName: updateSupported ? currentVersion.value || "builtin" : "builtin",
platform: Capacitor.getPlatform(),
channel: "stable"
});
const list = result?.notes ?? [];
noteList.value = updateSupported ? list : list.slice(0, WEB_NOTE_LIMIT);
} catch {
// 日志不是关键路径,失败时安静降级,不弹错误
noteList.value = [];
}
}
// ---------- 生命周期 ----------
onMounted(async () => {
await loadCurrent();
await restorePending();
await loadNotes();
});
// ---------- 交互 ----------
function handleAutoUpdateChange(value: boolean | string | number): void {
setAutoUpdate(value === true);
}
@@ -135,6 +233,8 @@ async function handleCheck(): Promise<void> {
if (!hasUpdate()) {
Message.info("已是最新版本");
}
// 检查后目标版本可能变化,重查一次日志
await loadNotes();
}
async function handleDownload(): Promise<void> {
@@ -156,14 +256,44 @@ async function handleApply(): Promise<void> {
</script>
<style scoped lang="less">
.update-panel {
gap: .75rem;
display: flex;
flex-direction: column;
.app-update {
.progress {
margin: 0 1rem;
}
.versions {
gap: .5rem;
display: flex;
padding: .25rem 1rem 1rem;
flex-direction: column;
.title {
color: var(--td-text-color-secondary);
margin: .5rem .25rem 0;
font-size: .8125rem;
font-weight: 500;
}
.version {
.label {
gap: .5rem;
display: flex;
align-items: center;
.time {
font-size: .875rem;
}
}
.content {
padding: .5rem;
font-size: .875rem;
margin-top: .5rem;
border-radius: 1rem;
}
}
}
}
</style>