From 7cb4836b40ae7b6acf1565416c82e98ac446a59f Mon Sep 17 00:00:00 2001 From: Timi Date: Fri, 13 Nov 2026 15:05:20 +0800 Subject: [PATCH] feat(system): app update log --- .gitea/workflows/release.yml | 96 +++++++++++++++++++- .gitignore | 2 + components.d.ts | 1 - package.json | 2 +- pnpm-lock.yaml | 10 +-- src/api/AppUpdateAPI.ts | 31 +++++++ src/composables/useAppUpdate.ts | 16 +++- src/pages/setting/About.vue | 135 ++++++++++++++++------------ src/pages/setting/Agreement.vue | 21 +++-- src/pages/setting/AppUpdate.vue | 152 +++++++++++++++++++++++++++++--- src/types/AppUpdate.ts | 35 ++++++++ 11 files changed, 418 insertions(+), 83 deletions(-) create mode 100644 src/api/AppUpdateAPI.ts create mode 100644 src/types/AppUpdate.ts diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 37df9ef..de057d9 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -51,6 +51,89 @@ jobs: echo "publish=false" >> $GITHUB_OUTPUT fi + # 从 CHANGELOG.md 提取当前版本的说明,落到 release-note.txt + # 用文件而不是 step output 传递:note 是多行文本,多行 output 在各版本 runner 上行为不一致 + - name: Resolve release note + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + if [ ! -f CHANGELOG.md ]; then + echo "WARN: 缺少 CHANGELOG.md,本次发布不带变更说明" + : > release-note.txt + exit 0 + fi + node --input-type=module <<'NODE' + import fs from "node:fs"; + + const version = process.env.VERSION; + const heading = "## v" + version; + const lines = fs.readFileSync("CHANGELOG.md", "utf8").split(/\r?\n/); + const start = lines.findIndex(line => line.trim() === heading); + + if (start < 0) { + console.error("WARN: CHANGELOG.md 中没有 " + heading + ",本次发布不带变更说明"); + fs.writeFileSync("release-note.txt", ""); + process.exit(0); + } + + const LIMIT = 480; + const picked = []; + let inComment = false; + for (let i = start + 1; i < lines.length; i += 1) { + const raw = lines[i]; + if (/^##\s/.test(raw)) { + break; + } + // 跳过 HTML 注释,避免注释内容占掉长度 + if (inComment) { + if (raw.includes("-->")) { + inComment = false; + } + continue; + } + if (raw.includes("")) { + inComment = true; + } + continue; + } + if (raw.trim() === "") { + // 连续空行压成一个,只用于分隔段落 + if (picked.length > 0 && picked[picked.length - 1] !== "") { + picked.push(""); + } + continue; + } + // 去掉行尾空白,保留行首缩进(嵌套列表) + picked.push(raw.replace(/\s+$/, "")); + } + while (picked.length > 0 && picked[picked.length - 1] === "") { + picked.pop(); + } + + if (picked.length === 0) { + console.error("WARN: " + heading + " 下没有内容,本次发布不带变更说明"); + } + + // 按行累积到上限,不切半行,避免出现断句 + const kept = []; + let total = 0; + for (const line of picked) { + const length = Array.from(line).length + (kept.length > 0 ? 1 : 0); + if (LIMIT < total + length) { + console.error("WARN: 内容超过 " + LIMIT + " 字,截断到第 " + kept.length + " 行"); + break; + } + kept.push(line); + total += length; + } + + // 尖括号转义:note 最终走 v-html 渲染,不能让 CHANGELOG 里的 HTML 被执行 + const note = kept.join("\n").replace(/ WorkBuddy 本地工作目录 # 内含 AI 工作记忆与每日日志:写明本机绝对路径与调试上下文,且每次会话都在追加, diff --git a/components.d.ts b/components.d.ts index 66ac3c9..95b65d8 100644 --- a/components.d.ts +++ b/components.d.ts @@ -45,7 +45,6 @@ declare module 'vue' { SegmentedSlider: typeof import('./src/components/SegmentedSlider.vue')['default'] StoreRemoveDialog: typeof import('./src/components/StoreRemoveDialog.vue')['default'] TagSelector: typeof import('./src/components/TagSelector.vue')['default'] - TAvatar: typeof import('tdesign-mobile-vue')['Avatar'] TBadge: typeof import('tdesign-mobile-vue')['Badge'] TButton: typeof import('tdesign-mobile-vue')['Button'] TCalendar: typeof import('tdesign-mobile-vue')['Calendar'] diff --git a/package.json b/package.json index cdc22a2..5184961 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "less": "^4.3.0", "pinia": "^3.0.2", "tdesign-mobile-vue": "^1.17.1", - "timi-tdesign-mobile": "^1.1.1", + "timi-tdesign-mobile": "^1.2.0", "timi-ts": "^1.0.0", "timi-web": "^1.0.2", "timi-web-api": "^1.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ff9c0a6..d7489b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,8 +47,8 @@ importers: specifier: ^1.17.1 version: 1.17.1(patch_hash=c98db305008fbfd00046666ca890e1c6cb88257c0619418694689cddf8cd78c3)(vue@3.5.40(typescript@5.8.3)) timi-tdesign-mobile: - specifier: ^1.1.1 - version: 1.1.1(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3)) + specifier: ^1.2.0 + version: 1.2.0(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3)) timi-ts: specifier: ^1.0.0 version: 1.0.0 @@ -2748,8 +2748,8 @@ packages: through2@4.0.2: resolution: {integrity: sha512-iOqSav00cVxEEICeD7TjLB1sueEL+81Wpzp2bY17uZjZN0pWZPuo4suZ/61VujxmqSGFfgOcNuTZ85QJwNZQpw==} - timi-tdesign-mobile@1.1.1: - resolution: {integrity: sha512-aR6SKu8zVbaqHRJHRtria3amvp9UKS6jTT99FNei38ZrP1sJDBsvCoQmWi0xzUD3F/wkGnSECWWrJQToqso6PQ==} + timi-tdesign-mobile@1.2.0: + resolution: {integrity: sha512-FW9LyZlh+aSjaG3tEXBf3+YYmm+OruYVH+atQMFmlCT33q3e6Gt0rr6n6d4vLH5n0tzyidlAJ0hmrvKspKKDdw==} engines: {node: '>=20.0.0'} peerDependencies: vue: ^3.5.0 @@ -5849,7 +5849,7 @@ snapshots: dependencies: readable-stream: 3.6.2 - timi-tdesign-mobile@1.1.1(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3)): + timi-tdesign-mobile@1.2.0(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3)): dependencies: tdesign-mobile-vue: 1.17.1(patch_hash=c98db305008fbfd00046666ca890e1c6cb88257c0619418694689cddf8cd78c3)(vue@3.5.40(typescript@5.8.3)) timi-web: 1.0.2(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue@3.5.40(typescript@5.8.3)) diff --git a/src/api/AppUpdateAPI.ts b/src/api/AppUpdateAPI.ts new file mode 100644 index 0000000..ca47a60 --- /dev/null +++ b/src/api/AppUpdateAPI.ts @@ -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 { + 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 +}; diff --git a/src/composables/useAppUpdate.ts b/src/composables/useAppUpdate.ts index 8af04fc..570565c 100644 --- a/src/composables/useAppUpdate.ts +++ b/src/composables/useAppUpdate.ts @@ -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(null); +const latest = ref(null); const checking = ref(false); const downloading = ref(false); const percent = ref(0); @@ -34,7 +46,7 @@ async function loadCurrent(): Promise { } /** 查询服务端最新版本 */ -async function check(): Promise { +async function check(): Promise { if (!supported) { error.value = "仅在 App 内可用"; return null; diff --git a/src/pages/setting/About.vue b/src/pages/setting/About.vue index 606df80..51f54a2 100644 --- a/src/pages/setting/About.vue +++ b/src/pages/setting/About.vue @@ -1,5 +1,5 @@ @@ -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([]); @@ -81,13 +105,8 @@ const isLoading = ref(false); const handleLogoClick = createVConsoleClickHandler(toggleVConsole); -async function openAgreement(item: AgreementItem): Promise { - 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 () => { - diff --git a/src/types/AppUpdate.ts b/src/types/AppUpdate.ts new file mode 100644 index 0000000..577d42c --- /dev/null +++ b/src/types/AppUpdate.ts @@ -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[]; +};