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
+31
View File
@@ -0,0 +1,31 @@
import { axios } from "timi-web-api";
import type { AppUpdateNotesQuery, AppUpdateNotesResult } from "@/types/AppUpdate";
const URI = "/app/update";
/**
* 查询更新日志
*
* 区间为「当前版本 → 通道当前版本」,与灰度无关,免登录态
*
* @param query 查询参数,versionName 传当前运行的 Web 包版本
* @returns 变更说明列表,按版本号从新到旧
*/
async function notes(query: AppUpdateNotesQuery): Promise<AppUpdateNotesResult> {
const { appId, versionName, versionCode, platform, channel } = query;
// 后端按 Capgo 插件的上报协议接收下划线字段,只在这一层转换
/* eslint-disable camelcase */
const payload = {
app_id: appId,
version_name: versionName,
version_code: versionCode,
platform,
channel
};
/* eslint-enable camelcase */
return await axios.post(`${URI}/notes`, payload);
}
export default {
notes
};
+14 -2
View File
@@ -6,11 +6,23 @@ import { ref } from "vue";
/** 自动更新的存储键 */
export const AUTO_UPDATE_KEY = "app.autoUpdate";
/** Capacitor appId,与 capacitor.config.ts 保持一致 */
export const APP_ID = "com.imyeyu.gao.customer";
/**
* 服务端下发的更新信息
*
* 在插件协议基础上多一个 note:更新说明由后端附加,插件不识别但会原样透传
*/
export type UpdateInfo = LatestVersion & {
note?: string;
};
// 模块级状态,页面与启动逻辑共享同一份
const supported = Capacitor.isNativePlatform();
const currentVersion = ref("");
const nativeVersion = ref("");
const latest = ref<LatestVersion | null>(null);
const latest = ref<UpdateInfo | null>(null);
const checking = ref(false);
const downloading = ref(false);
const percent = ref(0);
@@ -34,7 +46,7 @@ async function loadCurrent(): Promise<void> {
}
/** 查询服务端最新版本 */
async function check(): Promise<LatestVersion | null> {
async function check(): Promise<UpdateInfo | null> {
if (!supported) {
error.value = "仅在 App 内可用";
return null;
+78 -57
View File
@@ -1,5 +1,5 @@
<template>
<div class="tui-page-layout tui-navbar">
<div class="tui-page-layout tui-navbar about">
<t-navbar
fixed
:z-index="20"
@@ -7,47 +7,65 @@
left-arrow
@left-click="$router.back()"
/>
<main class="tui-page-content scroll column">
<div class="about-page">
<section class="brand" v-entrance-transition>
<logo @click="handleLogoClick" />
<h1 v-text="appName" />
<p v-text="`版本 ${displayVersion}`" />
<p v-text="appDescription" />
</section>
<t-cell-group v-if="agreementItemList.length" theme="card" v-entrance-transition>
<t-cell
v-for="item in agreementItemList"
:key="item.id"
:title="item.title"
arrow
hover
@click="openAgreement(item)"
<master-detail-page
class="list"
:split="isWide"
:selected="!!selectedId"
:direction="paneDirection"
>
<template #master>
<div class="about-page tui-page-content column">
<section class="brand" v-entrance-transition>
<logo @click="handleLogoClick" />
<h1 v-text="appName" />
<p class="version" v-text="`版本 ${displayVersion}`" />
<p class="description" v-text="appDescription" />
</section>
<t-cell-group
v-if="agreementItemList.length"
theme="card"
v-entrance-transition
>
<template #leftIcon>
<t-icon :name="item.icon" size="1.75rem" />
</template>
</t-cell>
</t-cell-group>
<t-empty
v-else
:description="isLoading ? '正在加载协议配置' : '暂无可用协议'"
<t-cell
v-for="item in agreementItemList"
:key="item.id"
:title="item.title"
arrow
hover
@click="openAgreement(item)"
>
<template #leftIcon>
<t-icon :name="item.icon" size="1.75rem" />
</template>
</t-cell>
</t-cell-group>
<t-empty
v-else
:description="isLoading ? '正在加载协议配置' : '暂无可用协议'"
/>
<t-cell-group theme="card" v-entrance-transition>
<t-cell title="版本更新" arrow hover @click="openDetail('update')">
<template #leftIcon>
<t-icon name="download" size="1.75rem" />
</template>
</t-cell>
</t-cell-group>
<footer class="footer" v-entrance-transition>
<p>技术支持:夜雨</p>
<p>联系技术:imyeyu@qq.com</p>
<p>短信服务支持:广州易保网络科技有限公司</p>
<p>Copyright © 2026 imyeyu.com</p>
</footer>
</div>
</template>
<template #detail>
<app-update v-if="selectedId === 'update'" />
<agreement
v-else-if="selectedId?.startsWith('agreement:')"
:article-id="selectedId.slice(10)"
/>
<t-cell-group v-if="updateSupported" theme="card" v-entrance-transition>
<t-cell title="版本更新" arrow hover @click="router.push({ name: 'AppUpdate' })">
<template #leftIcon>
<t-icon name="download" size="1.75rem" />
</template>
</t-cell>
</t-cell-group>
<footer class="footer" v-entrance-transition>
<p>技术支持:夜雨</p>
<p>联系技术:imyeyu@qq.com</p>
<p>短信服务支持:广州易保网络科技有限公司</p>
<p>Copyright © 2026 imyeyu.com</p>
</footer>
</div>
</main>
</template>
</master-detail-page>
</div>
</template>
@@ -55,6 +73,9 @@
import { version } from "../../../package.json";
import { useAppUpdate } from "@/composables/useAppUpdate";
import { SettingAPI } from "timi-web-api";
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
import Agreement from "@/pages/setting/Agreement.vue";
import AppUpdate from "@/pages/setting/AppUpdate.vue";
import Logo from "@/pages/user/component/Logo.vue";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
@@ -71,9 +92,12 @@ defineOptions({
});
const appName = "糕店客户管理";
const appDescription = "面向门店的客户、登记、积分与经营管理工具";
const router = useRouter();
const { supported: updateSupported, currentVersion, loadCurrent } = useAppUpdate();
const appDescription = "融合客户服务、门店经营与 AI 智能助手的一体化管理平台";
const { selectedId, paneDirection, isWide, openDetail } = useMasterDetailPane({
path: "/management/about",
detail: id => id === "update" ? "/management/about/update" : `/management/about/agreement/${encodeURIComponent(id.slice(10))}`
});
const { currentVersion, loadCurrent } = useAppUpdate();
const displayVersion = computed(() => currentVersion.value && currentVersion.value !== "builtin" ? currentVersion.value : version);
const agreementItemList = ref<AgreementItem[]>([]);
@@ -81,13 +105,8 @@ const isLoading = ref(false);
const handleLogoClick = createVConsoleClickHandler(toggleVConsole);
async function openAgreement(item: AgreementItem): Promise<void> {
await router.push({
name: "Agreement",
params: {
id: item.id
}
});
function openAgreement(item: AgreementItem): void {
openDetail(`agreement:${item.id}`);
}
function normalizeAgreementItem(value: unknown): AgreementItem | undefined {
@@ -145,10 +164,6 @@ onMounted(async () => {
<style scoped lang="less">
.about-page {
gap: 1rem;
display: flex;
padding: 0 0 5rem;
flex-direction: column;
.brand {
padding: 1rem;
@@ -159,17 +174,23 @@ onMounted(async () => {
}
h1 {
margin: .875rem 0 .5rem;
color: #0f172a;
margin: .875rem 0 .5rem;
font-size: 1.5rem;
font-weight: 700;
}
p {
margin: 0;
color: #52607a;
margin: 0;
}
.version {
font-size: .875rem;
line-height: 1.7;
}
.description {
font-size: .75rem;
}
}
+16 -5
View File
@@ -5,7 +5,7 @@
:z-index="20"
:title="routeNavBarTitle"
left-arrow
@left-click="$router.back()"
@left-click="goBack"
/>
<main class="tui-page-content scroll column">
<div class="agreement-page">
@@ -35,7 +35,7 @@
<script setup lang="ts">
import { type Article, ArticleAPI, AttachmentAPI } from "timi-web-api";
import { ArticleView } from "timi-tdesign-mobile";
import { ArticleView, usePane } from "timi-tdesign-mobile";
import { MarkdownView } from "timi-web";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
@@ -45,6 +45,17 @@ defineOptions({
});
const route = useRoute();
const router = useRouter();
const pane = usePane();
const props = defineProps<{ articleId?: string }>();
function goBack(): void {
if (pane) {
pane.close();
return;
}
router.back();
}
const routeNavBarTitle = computed(() => {
switch (route.name) {
@@ -57,7 +68,7 @@ const routeNavBarTitle = computed(() => {
case "OpenSourceAgreement":
return "开源软件协议";
default:
return "";
return "协议";
}
});
const article = ref<Article>();
@@ -72,7 +83,7 @@ async function loadArticle(): Promise<void> {
const requestToken = loadToken + 1;
loadToken = requestToken;
article.value = undefined;
const articleId = String(route.params.id || "").trim();
const articleId = String(props.articleId || route.params.id || "").trim();
if (!articleId) {
return;
}
@@ -93,7 +104,7 @@ async function loadArticle(): Promise<void> {
}
}
watch(() => route.params.id, async () => {
watch(() => props.articleId || route.params.id, async () => {
await loadArticle();
}, { immediate: true });
</script>
+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>
+35
View File
@@ -0,0 +1,35 @@
/**
* 更新日志查询参数
*
* 内部用驼峰,下划线协议字段在 API 层转换,避免业务代码出现 snake_case
*/
export type AppUpdateNotesQuery = {
/** 产品标识,与 capacitor.config.ts 的 appId 一致 */
appId: string;
/** 当前运行的 Web 包版本,内置包为 builtin */
versionName?: string;
/** 当前原生 versionCode */
versionCode?: string;
/** 平台 */
platform?: string;
/** 通道代码 */
channel?: string;
};
/** 单条版本变更说明 */
export type AppUpdateNote = {
/** 版本号 */
version: string;
/** 变更说明,markdown 原文 */
note: string;
/** 首次发布时间,回滚上线的版本可能为空 */
publishedAt?: number;
};
/** 更新日志响应 */
export type AppUpdateNotesResult = {
/** 通道当前版本号,为空表示没有可展示的版本 */
version?: string;
/** 变更说明,按版本号从新到旧 */
notes: AppUpdateNote[];
};