add: app update page
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
<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>
|
||||
@@ -32,6 +33,13 @@
|
||||
v-else
|
||||
:description="isLoading ? '正在加载协议配置' : '暂无可用协议'"
|
||||
/>
|
||||
<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>
|
||||
@@ -44,6 +52,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { version } from "../../../package.json";
|
||||
import { useAppUpdate } from "@/composables/useAppUpdate";
|
||||
import { SettingAPI } from "timi-web-api";
|
||||
import Logo from "@/pages/user/component/Logo.vue";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
@@ -63,6 +73,8 @@ defineOptions({
|
||||
const appName = "糕店客户管理";
|
||||
const appDescription = "面向门店的客户、登记、积分与经营管理工具";
|
||||
const router = useRouter();
|
||||
const { supported: updateSupported, currentVersion, loadCurrent } = useAppUpdate();
|
||||
const displayVersion = computed(() => currentVersion.value && currentVersion.value !== "builtin" ? currentVersion.value : version);
|
||||
|
||||
const agreementItemList = ref<AgreementItem[]>([]);
|
||||
const isLoading = ref(false);
|
||||
@@ -127,7 +139,7 @@ async function loadSettings(): Promise<void> {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadSettings();
|
||||
await Promise.all([loadSettings(), loadCurrent()]);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -192,3 +204,4 @@ onMounted(async () => {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -51,52 +51,6 @@
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group v-if="updateSupported" title="版本更新" theme="card" v-entrance-transition>
|
||||
<t-cell title="外壳版本" :note="nativeVersion || '—'" />
|
||||
<t-cell title="系统版本" :note="currentVersion || '—'" />
|
||||
<t-cell v-if="latestVersionText" title="最新版本" :note="latestVersionText" />
|
||||
<t-cell title="自动更新">
|
||||
<template #right-icon>
|
||||
<t-switch :model-value="autoUpdate" @change="handleAutoUpdateChange" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</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>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
@@ -106,8 +60,6 @@ import type { ThemeMode } from "@/store/globalUI";
|
||||
import { useGlobalUIStore } from "@/store/globalUI";
|
||||
import SegmentedSlider from "@/components/SegmentedSlider.vue";
|
||||
import { useSettingStore } from "@/store/settingStore";
|
||||
import { setAutoUpdate, useAppUpdate } from "@/composables/useAppUpdate";
|
||||
import { Message } from "@/utils/message";
|
||||
|
||||
defineOptions({
|
||||
name: "AppSettings"
|
||||
@@ -164,97 +116,7 @@ async function playSettingSoundPreview(type: "scanSuccess" | "registerSuccess"):
|
||||
await settingStore.playRegisterSuccessSound();
|
||||
}
|
||||
|
||||
// ---------- 版本更新 ----------
|
||||
|
||||
const {
|
||||
supported: updateSupported,
|
||||
currentVersion,
|
||||
nativeVersion,
|
||||
latest,
|
||||
checking,
|
||||
downloading,
|
||||
percent,
|
||||
ready,
|
||||
error: updateError,
|
||||
autoUpdate,
|
||||
loadCurrent,
|
||||
check,
|
||||
hasUpdate,
|
||||
download,
|
||||
apply,
|
||||
restorePending
|
||||
} = useAppUpdate();
|
||||
|
||||
/** 有更新时展示目标版本号 */
|
||||
const latestVersionText = computed<string>(() => (hasUpdate() ? `v${latest.value?.version ?? ""}` : ""));
|
||||
|
||||
/** 当前所处的更新阶段 */
|
||||
const updateStage = computed<"check" | "download" | "downloading" | "apply">(() => {
|
||||
if (downloading.value) {
|
||||
return "downloading";
|
||||
}
|
||||
if (ready.value) {
|
||||
return "apply";
|
||||
}
|
||||
if (latest.value && hasUpdate()) {
|
||||
return "download";
|
||||
}
|
||||
return "check";
|
||||
});
|
||||
|
||||
/** 阶段说明文案 */
|
||||
const updateHint = computed<string>(() => {
|
||||
if (!updateSupported) {
|
||||
return "仅在 App 内可用";
|
||||
}
|
||||
if (ready.value) {
|
||||
return `v${ready.value.version} 已下载,点击下方按钮重启生效`;
|
||||
}
|
||||
if (latest.value && hasUpdate()) {
|
||||
return `发现新版本 v${latest.value.version}`;
|
||||
}
|
||||
if (latest.value && !checking.value) {
|
||||
return "当前已是最新版本";
|
||||
}
|
||||
return "";
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await loadCurrent();
|
||||
await restorePending();
|
||||
});
|
||||
|
||||
function handleAutoUpdateChange(value: boolean | string | number): void {
|
||||
setAutoUpdate(value === true);
|
||||
}
|
||||
|
||||
async function handleCheck(): Promise<void> {
|
||||
const result = await check();
|
||||
if (!result) {
|
||||
Message.error(updateError.value || "检查更新失败");
|
||||
return;
|
||||
}
|
||||
if (!hasUpdate()) {
|
||||
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">
|
||||
@@ -291,15 +153,6 @@ async function handleApply(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
.update-panel {
|
||||
gap: .75rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.progress {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) {
|
||||
@@ -307,10 +160,6 @@ async function handleApply(): Promise<void> {
|
||||
.volume-field span {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.update-hint {
|
||||
color: #94a3b8;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<div class="tui-page-layout tui-navbar">
|
||||
<t-navbar fixed :z-index="20" title="版本更新" left-arrow @left-click="$router.back()" />
|
||||
<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 title="外壳版本" :note="nativeVersion || '—'" />
|
||||
<t-cell title="系统版本" :note="currentVersion || '—'" />
|
||||
<t-cell v-if="latestVersionText" title="最新版本" :note="latestVersionText" />
|
||||
<t-cell title="自动更新">
|
||||
<template #right-icon>
|
||||
<t-switch :model-value="autoUpdate" @change="handleAutoUpdateChange" />
|
||||
</template>
|
||||
</t-cell>
|
||||
</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
|
||||
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>
|
||||
<span v-text="`下载中 ${percent}%`" />
|
||||
</t-button>
|
||||
</template>
|
||||
<t-button
|
||||
v-else-if="updateStage === 'apply'"
|
||||
class="cell-button"
|
||||
theme="primary"
|
||||
size="large"
|
||||
@click="handleApply"
|
||||
>
|
||||
现在更新
|
||||
</t-button>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { setAutoUpdate, useAppUpdate } from "@/composables/useAppUpdate";
|
||||
import { Message } from "@/utils/message";
|
||||
|
||||
defineOptions({
|
||||
name: "AppUpdate"
|
||||
});
|
||||
|
||||
// ---------- 版本更新 ----------
|
||||
|
||||
const {
|
||||
supported: updateSupported,
|
||||
currentVersion,
|
||||
nativeVersion,
|
||||
latest,
|
||||
checking,
|
||||
downloading,
|
||||
percent,
|
||||
ready,
|
||||
error: updateError,
|
||||
autoUpdate,
|
||||
loadCurrent,
|
||||
check,
|
||||
hasUpdate,
|
||||
download,
|
||||
apply,
|
||||
restorePending
|
||||
} = useAppUpdate();
|
||||
|
||||
/** 有更新时展示目标版本号 */
|
||||
const latestVersionText = computed<string>(() => (hasUpdate() ? `v${latest.value?.version ?? ""}` : ""));
|
||||
|
||||
/** 当前所处的更新阶段 */
|
||||
const updateStage = computed<"check" | "download" | "downloading" | "apply">(() => {
|
||||
if (downloading.value) {
|
||||
return "downloading";
|
||||
}
|
||||
if (ready.value) {
|
||||
return "apply";
|
||||
}
|
||||
if (latest.value && hasUpdate()) {
|
||||
return "download";
|
||||
}
|
||||
return "check";
|
||||
});
|
||||
|
||||
/** 阶段说明文案 */
|
||||
const updateHint = computed<string>(() => {
|
||||
if (!updateSupported) {
|
||||
return "仅在 App 内可用";
|
||||
}
|
||||
if (ready.value) {
|
||||
return `v${ready.value.version} 已下载,点击下方按钮重启生效`;
|
||||
}
|
||||
if (latest.value && hasUpdate()) {
|
||||
return `发现新版本 v${latest.value.version}`;
|
||||
}
|
||||
if (latest.value && !checking.value) {
|
||||
return "当前已是最新版本";
|
||||
}
|
||||
return "";
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await loadCurrent();
|
||||
await restorePending();
|
||||
});
|
||||
|
||||
function handleAutoUpdateChange(value: boolean | string | number): void {
|
||||
setAutoUpdate(value === true);
|
||||
}
|
||||
|
||||
async function handleCheck(): Promise<void> {
|
||||
const result = await check();
|
||||
if (!result) {
|
||||
Message.error(updateError.value || "检查更新失败");
|
||||
return;
|
||||
}
|
||||
if (!hasUpdate()) {
|
||||
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">
|
||||
.update-panel {
|
||||
gap: .75rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.progress {
|
||||
margin: 0 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -137,6 +137,17 @@ export const managementSettingRoutes: RouteRecordRaw[] = [
|
||||
darkBodyBackground: "#10161f"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/management/about/update",
|
||||
name: "AppUpdate",
|
||||
component: () => import("@/pages/setting/AppUpdate.vue"),
|
||||
meta: {
|
||||
depth: 4,
|
||||
tabBarVisible: false,
|
||||
bodyBackground: "#F5F5F8",
|
||||
darkBodyBackground: "#10161f"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/management/about/agreement/:id",
|
||||
name: "Agreement",
|
||||
|
||||
Reference in New Issue
Block a user