Merge pull request 'v1.0.3' (#4) from dev into master
Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
+162
-122
@@ -1,124 +1,128 @@
|
|||||||
import { Capacitor } from "@capacitor/core";
|
import { Capacitor } from "@capacitor/core";
|
||||||
import { CapacitorUpdater, type BundleInfo, type LatestVersion } from "@capgo/capacitor-updater";
|
import { CapacitorUpdater, type BundleInfo, type LatestVersion } from "@capgo/capacitor-updater";
|
||||||
|
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
|
|
||||||
/** 自动检查更新的存储键 */
|
/** 自动更新的存储键 */
|
||||||
export const AUTO_UPDATE_KEY = "app.autoUpdate";
|
export const AUTO_UPDATE_KEY = "app.autoUpdate";
|
||||||
|
|
||||||
|
// 模块级状态,页面与启动逻辑共享同一份
|
||||||
|
const supported = Capacitor.isNativePlatform();
|
||||||
|
const currentVersion = ref("");
|
||||||
|
const nativeVersion = ref("");
|
||||||
|
const latest = ref<LatestVersion | null>(null);
|
||||||
|
const checking = ref(false);
|
||||||
|
const downloading = ref(false);
|
||||||
|
const percent = ref(0);
|
||||||
|
const ready = ref<BundleInfo | null>(null);
|
||||||
|
const error = ref("");
|
||||||
|
const autoUpdate = ref(localStorage.getItem(AUTO_UPDATE_KEY) === "1");
|
||||||
|
|
||||||
|
/** 读取当前运行的 Web 包版本与原生壳版本 */
|
||||||
|
async function loadCurrent(): Promise<void> {
|
||||||
|
if (!supported) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const result = await CapacitorUpdater.current();
|
||||||
|
currentVersion.value = result.bundle?.version ?? "builtin";
|
||||||
|
nativeVersion.value = result.native ?? "";
|
||||||
|
} catch {
|
||||||
|
currentVersion.value = "";
|
||||||
|
nativeVersion.value = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查询服务端最新版本 */
|
||||||
|
async function check(): Promise<LatestVersion | null> {
|
||||||
|
if (!supported) {
|
||||||
|
error.value = "仅在 App 内可用";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
checking.value = true;
|
||||||
|
error.value = "";
|
||||||
|
try {
|
||||||
|
const result = await CapacitorUpdater.getLatest();
|
||||||
|
latest.value = result;
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof Error ? e.message : "检查更新失败";
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
checking.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 是否发现新版本 */
|
||||||
|
function hasUpdate(): boolean {
|
||||||
|
const target = latest.value;
|
||||||
|
return Boolean(target?.url) && target?.version !== currentVersion.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 下载最新版本,只落盘不激活 */
|
||||||
|
async function download(): Promise<BundleInfo | null> {
|
||||||
|
const target = latest.value;
|
||||||
|
if (!target?.url) {
|
||||||
|
error.value = "没有可下载的版本";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
downloading.value = true;
|
||||||
|
percent.value = 0;
|
||||||
|
error.value = "";
|
||||||
|
const listener = await CapacitorUpdater.addListener("download", info => {
|
||||||
|
percent.value = info.percent;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const bundle = await CapacitorUpdater.download({
|
||||||
|
url: target.url,
|
||||||
|
version: target.version,
|
||||||
|
checksum: target.checksum,
|
||||||
|
sessionKey: target.sessionKey
|
||||||
|
});
|
||||||
|
ready.value = bundle;
|
||||||
|
return bundle;
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof Error ? e.message : "下载失败";
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
downloading.value = false;
|
||||||
|
await listener.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 立即应用并重启 */
|
||||||
|
async function apply(bundle: BundleInfo): Promise<void> {
|
||||||
|
await CapacitorUpdater.set({ id: bundle.id });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 排队到下次启动应用 */
|
||||||
|
async function defer(bundle: BundleInfo): Promise<void> {
|
||||||
|
await CapacitorUpdater.next({ id: bundle.id });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查找已下载但尚未应用的版本 */
|
||||||
|
async function restorePending(): Promise<void> {
|
||||||
|
if (!supported) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const [current, list] = await Promise.all([CapacitorUpdater.current(), CapacitorUpdater.list()]);
|
||||||
|
const currentId = current.bundle?.id;
|
||||||
|
const pending = list.bundles
|
||||||
|
.filter(bundle => bundle.id !== currentId)
|
||||||
|
.sort((a, b) => Date.parse(b.downloaded) - Date.parse(a.downloaded))[0];
|
||||||
|
ready.value = pending ?? null;
|
||||||
|
} catch {
|
||||||
|
ready.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用热更新
|
* 应用热更新
|
||||||
*
|
*
|
||||||
* 只在原生环境可用,Web 端调用会得到 supported = false
|
* 只在原生环境可用,Web 端 supported 恒为 false
|
||||||
*
|
|
||||||
* 下载完成后调用 next 排队,下次切后台或重启自动生效,不打断当前操作
|
|
||||||
*/
|
*/
|
||||||
export function useAppUpdate() {
|
export function useAppUpdate() {
|
||||||
const supported = Capacitor.isNativePlatform();
|
|
||||||
const currentVersion = ref("");
|
|
||||||
const nativeVersion = ref("");
|
|
||||||
const latest = ref<LatestVersion | null>(null);
|
|
||||||
const checking = ref(false);
|
|
||||||
const downloading = ref(false);
|
|
||||||
const percent = ref(0);
|
|
||||||
const ready = ref<BundleInfo | null>(null);
|
|
||||||
const error = ref("");
|
|
||||||
|
|
||||||
/** 读取当前运行的 Web 包版本与原生壳版本 */
|
|
||||||
async function loadCurrent(): Promise<void> {
|
|
||||||
if (!supported) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const result = await CapacitorUpdater.current();
|
|
||||||
currentVersion.value = result.bundle?.version ?? "builtin";
|
|
||||||
nativeVersion.value = result.native ?? "";
|
|
||||||
} catch {
|
|
||||||
currentVersion.value = "";
|
|
||||||
nativeVersion.value = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 查询服务端最新版本 */
|
|
||||||
async function check(): Promise<LatestVersion | null> {
|
|
||||||
if (!supported) {
|
|
||||||
error.value = "仅在 App 内可用";
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
checking.value = true;
|
|
||||||
error.value = "";
|
|
||||||
try {
|
|
||||||
const result = await CapacitorUpdater.getLatest();
|
|
||||||
latest.value = result;
|
|
||||||
return result;
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : "检查更新失败";
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
checking.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 是否发现新版本 */
|
|
||||||
function hasUpdate(): boolean {
|
|
||||||
const target = latest.value;
|
|
||||||
return Boolean(target?.url) && target?.version !== currentVersion.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 下载最新版本,只落盘不激活,等用户确认后再应用 */
|
|
||||||
async function download(): Promise<BundleInfo | null> {
|
|
||||||
const target = latest.value;
|
|
||||||
if (!target?.url) {
|
|
||||||
error.value = "没有可下载的版本";
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
downloading.value = true;
|
|
||||||
percent.value = 0;
|
|
||||||
error.value = "";
|
|
||||||
const listener = await CapacitorUpdater.addListener("download", info => {
|
|
||||||
percent.value = info.percent;
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
const bundle = await CapacitorUpdater.download({
|
|
||||||
url: target.url,
|
|
||||||
version: target.version,
|
|
||||||
checksum: target.checksum,
|
|
||||||
sessionKey: target.sessionKey
|
|
||||||
});
|
|
||||||
ready.value = bundle;
|
|
||||||
return bundle;
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : "下载失败";
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
downloading.value = false;
|
|
||||||
await listener.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 应用已下载的版本并重启,只有用户明确点了才执行 */
|
|
||||||
async function apply(bundle: BundleInfo): Promise<void> {
|
|
||||||
await CapacitorUpdater.set({ id: bundle.id });
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 查找已下载但尚未应用的版本,用户不点就一直停在这里 */
|
|
||||||
async function restorePending(): Promise<void> {
|
|
||||||
if (!supported) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const [current, list] = await Promise.all([CapacitorUpdater.current(), CapacitorUpdater.list()]);
|
|
||||||
const currentId = current.bundle?.id;
|
|
||||||
const pending = list.bundles
|
|
||||||
.filter(bundle => bundle.id !== currentId)
|
|
||||||
.sort((a, b) => Date.parse(b.downloaded) - Date.parse(a.downloaded))[0];
|
|
||||||
if (pending) {
|
|
||||||
ready.value = pending;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
ready.value = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
supported,
|
supported,
|
||||||
currentVersion,
|
currentVersion,
|
||||||
@@ -129,38 +133,74 @@ export function useAppUpdate() {
|
|||||||
percent,
|
percent,
|
||||||
ready,
|
ready,
|
||||||
error,
|
error,
|
||||||
|
autoUpdate,
|
||||||
loadCurrent,
|
loadCurrent,
|
||||||
check,
|
check,
|
||||||
hasUpdate,
|
hasUpdate,
|
||||||
download,
|
download,
|
||||||
apply,
|
apply,
|
||||||
|
defer,
|
||||||
restorePending
|
restorePending
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 是否开启自动检查更新 */
|
/** 是否开启自动更新 */
|
||||||
export function isAutoUpdateEnabled(): boolean {
|
export function isAutoUpdateEnabled(): boolean {
|
||||||
return localStorage.getItem(AUTO_UPDATE_KEY) === "1";
|
return autoUpdate.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 切换自动更新,同时写入本地存储 */
|
||||||
|
export function setAutoUpdate(enabled: boolean): void {
|
||||||
|
autoUpdate.value = enabled;
|
||||||
|
localStorage.setItem(AUTO_UPDATE_KEY, enabled ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 弹窗让用户决定立即更新还是下次启动 */
|
||||||
|
function promptUpdate(bundle: BundleInfo): void {
|
||||||
|
const dialog = DialogPlugin.confirm({
|
||||||
|
title: "发现新版本",
|
||||||
|
content: `v${bundle.version} 已下载完成,重启后生效`,
|
||||||
|
cancelBtn: "稍后更新",
|
||||||
|
confirmBtn: "现在更新",
|
||||||
|
onCancel() {
|
||||||
|
dialog.destroy();
|
||||||
|
// 稍后更新即排队,下次启动自动应用
|
||||||
|
void defer(bundle);
|
||||||
|
},
|
||||||
|
async onConfirm() {
|
||||||
|
dialog.destroy();
|
||||||
|
await apply(bundle);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动时静默检查更新
|
* 启动时检查更新
|
||||||
*
|
*
|
||||||
* 只下载不应用,是否切换版本始终由用户决定
|
* 检查每次启动都做;是否静默下载取决于自动更新开关
|
||||||
|
* 下载完成后弹窗让用户选择立即重启还是稍后
|
||||||
*/
|
*/
|
||||||
export async function runAutoUpdate(): Promise<void> {
|
export async function runAutoUpdate(): Promise<void> {
|
||||||
if (!Capacitor.isNativePlatform() || !isAutoUpdateEnabled()) {
|
if (!supported) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const update = useAppUpdate();
|
await loadCurrent();
|
||||||
await update.loadCurrent();
|
await restorePending();
|
||||||
await update.restorePending();
|
if (ready.value) {
|
||||||
if (update.ready.value) {
|
if (isAutoUpdateEnabled()) {
|
||||||
|
promptUpdate(ready.value);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = await update.check();
|
const result = await check();
|
||||||
if (!result?.url || result.version === update.currentVersion.value) {
|
if (!result?.url || result.version === currentVersion.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await update.download();
|
if (!isAutoUpdateEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await download();
|
||||||
|
if (ready.value) {
|
||||||
|
promptUpdate(ready.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="tui-page-layout tui-navbar">
|
<div class="tui-page-layout settings-page tui-navbar">
|
||||||
<t-navbar
|
<t-navbar
|
||||||
fixed
|
fixed
|
||||||
:z-index="20"
|
:z-index="20"
|
||||||
@@ -8,90 +8,89 @@
|
|||||||
@left-click="$router.back()"
|
@left-click="$router.back()"
|
||||||
/>
|
/>
|
||||||
<main class="tui-page-content scroll column">
|
<main class="tui-page-content scroll column">
|
||||||
<div class="settings-page">
|
<t-cell-group title="显示" theme="card" v-entrance-transition>
|
||||||
<t-cell-group title="显示" theme="card" v-entrance-transition>
|
<t-cell class="theme" title="显示模式">
|
||||||
<t-cell class="theme" title="显示模式">
|
<template #right-icon>
|
||||||
<template #right-icon>
|
<segmented-slider
|
||||||
<segmented-slider
|
class="theme-slider"
|
||||||
class="theme-slider"
|
:model-value="globalUIStore.themeMode"
|
||||||
:model-value="globalUIStore.themeMode"
|
:options="themeOptions"
|
||||||
:options="themeOptions"
|
@change="handleThemeChange"
|
||||||
@change="handleThemeChange"
|
/>
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</t-cell>
|
|
||||||
</t-cell-group>
|
|
||||||
<t-cell-group title="声音" theme="card" v-entrance-transition>
|
|
||||||
<t-cell title="扫码成功">
|
|
||||||
<template #right-icon>
|
|
||||||
<t-switch :model-value="settingStore.sound.scanSuccess" @change="value => handleScanSuccessChange(value === true)" />
|
|
||||||
</template>
|
|
||||||
</t-cell>
|
|
||||||
<t-cell title="登记成功">
|
|
||||||
<template #right-icon>
|
|
||||||
<t-switch :model-value="settingStore.sound.registerSuccess" @change="value => handleRegisterSuccessChange(value === true)" />
|
|
||||||
</template>
|
|
||||||
</t-cell>
|
|
||||||
<t-cell title="音量">
|
|
||||||
<template #right-icon>
|
|
||||||
<div class="volume-field">
|
|
||||||
<t-slider
|
|
||||||
:model-value="settingStore.sound.volume"
|
|
||||||
:min="0"
|
|
||||||
:max="100"
|
|
||||||
:step="1"
|
|
||||||
@change="handleVolumeChange"
|
|
||||||
/>
|
|
||||||
<span v-text="`${settingStore.sound.volume}%`" />
|
|
||||||
</div>
|
|
||||||
</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 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>
|
</template>
|
||||||
<t-button
|
</t-cell>
|
||||||
v-else-if="updateStage === 'apply'"
|
</t-cell-group>
|
||||||
class="cell-button"
|
<t-cell-group title="声音" theme="card" v-entrance-transition>
|
||||||
theme="primary"
|
<t-cell title="扫码成功">
|
||||||
size="large"
|
<template #right-icon>
|
||||||
@click="handleApply"
|
<t-switch :model-value="settingStore.sound.scanSuccess" @change="value => handleScanSuccessChange(value === true)" />
|
||||||
>
|
</template>
|
||||||
现在更新
|
</t-cell>
|
||||||
|
<t-cell title="登记成功">
|
||||||
|
<template #right-icon>
|
||||||
|
<t-switch :model-value="settingStore.sound.registerSuccess" @change="value => handleRegisterSuccessChange(value === true)" />
|
||||||
|
</template>
|
||||||
|
</t-cell>
|
||||||
|
<t-cell title="音量">
|
||||||
|
<template #right-icon>
|
||||||
|
<div class="volume-field">
|
||||||
|
<t-slider
|
||||||
|
:model-value="settingStore.sound.volume"
|
||||||
|
:min="0"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
@change="handleVolumeChange"
|
||||||
|
/>
|
||||||
|
<span v-text="`${settingStore.sound.volume}%`" />
|
||||||
|
</div>
|
||||||
|
</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>
|
</t-button>
|
||||||
</div>
|
</template>
|
||||||
|
<t-button
|
||||||
|
v-else-if="updateStage === 'apply'"
|
||||||
|
class="cell-button"
|
||||||
|
theme="primary"
|
||||||
|
size="large"
|
||||||
|
@click="handleApply"
|
||||||
|
>
|
||||||
|
现在更新
|
||||||
|
</t-button>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
@@ -102,7 +101,7 @@ import type { ThemeMode } from "@/store/globalUI";
|
|||||||
import { useGlobalUIStore } from "@/store/globalUI";
|
import { useGlobalUIStore } from "@/store/globalUI";
|
||||||
import SegmentedSlider from "@/components/SegmentedSlider.vue";
|
import SegmentedSlider from "@/components/SegmentedSlider.vue";
|
||||||
import { useSettingStore } from "@/store/settingStore";
|
import { useSettingStore } from "@/store/settingStore";
|
||||||
import { AUTO_UPDATE_KEY, isAutoUpdateEnabled, useAppUpdate } from "@/composables/useAppUpdate";
|
import { setAutoUpdate, useAppUpdate } from "@/composables/useAppUpdate";
|
||||||
import { Message } from "@/utils/message";
|
import { Message } from "@/utils/message";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@@ -172,6 +171,7 @@ const {
|
|||||||
percent,
|
percent,
|
||||||
ready,
|
ready,
|
||||||
error: updateError,
|
error: updateError,
|
||||||
|
autoUpdate,
|
||||||
loadCurrent,
|
loadCurrent,
|
||||||
check,
|
check,
|
||||||
hasUpdate,
|
hasUpdate,
|
||||||
@@ -180,7 +180,8 @@ const {
|
|||||||
restorePending
|
restorePending
|
||||||
} = useAppUpdate();
|
} = useAppUpdate();
|
||||||
|
|
||||||
const autoUpdate = ref(isAutoUpdateEnabled());
|
/** 有更新时展示目标版本号 */
|
||||||
|
const latestVersionText = computed<string>(() => (hasUpdate() ? `v${latest.value?.version ?? ""}` : ""));
|
||||||
|
|
||||||
/** 当前所处的更新阶段 */
|
/** 当前所处的更新阶段 */
|
||||||
const updateStage = computed<"check" | "download" | "downloading" | "apply">(() => {
|
const updateStage = computed<"check" | "download" | "downloading" | "apply">(() => {
|
||||||
@@ -219,9 +220,7 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function handleAutoUpdateChange(value: boolean | string | number): void {
|
function handleAutoUpdateChange(value: boolean | string | number): void {
|
||||||
const enabled = value === true;
|
setAutoUpdate(value === true);
|
||||||
autoUpdate.value = enabled;
|
|
||||||
localStorage.setItem(AUTO_UPDATE_KEY, enabled ? "1" : "0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleCheck(): Promise<void> {
|
async function handleCheck(): Promise<void> {
|
||||||
@@ -255,9 +254,6 @@ async function handleApply(): Promise<void> {
|
|||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
.settings-page {
|
.settings-page {
|
||||||
padding: 0 0 1rem 0;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
.theme {
|
.theme {
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
title="客户"
|
title="客户"
|
||||||
>
|
>
|
||||||
<template #right>
|
<template #right>
|
||||||
|
<app-update-button />
|
||||||
<navbar-notify-button />
|
<navbar-notify-button />
|
||||||
</template>
|
</template>
|
||||||
</t-navbar>
|
</t-navbar>
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
<store-overview ref="storeOverviewRef" compact />
|
<store-overview ref="storeOverviewRef" compact />
|
||||||
</template>
|
</template>
|
||||||
<template #right-actions>
|
<template #right-actions>
|
||||||
|
<app-update-button />
|
||||||
<navbar-notify-button />
|
<navbar-notify-button />
|
||||||
</template>
|
</template>
|
||||||
<template #right>
|
<template #right>
|
||||||
@@ -53,6 +55,7 @@ import { useLayout } from "timi-tdesign-mobile";
|
|||||||
import PendingNoticeBar from "./component/PendingNoticeBar.vue";
|
import PendingNoticeBar from "./component/PendingNoticeBar.vue";
|
||||||
import CustomerEntryPanel from "./component/CustomerEntryPanel.vue";
|
import CustomerEntryPanel from "./component/CustomerEntryPanel.vue";
|
||||||
import NavbarNotifyButton from "./component/NavbarNotifyButton.vue";
|
import NavbarNotifyButton from "./component/NavbarNotifyButton.vue";
|
||||||
|
import AppUpdateButton from "./component/AppUpdateButton.vue";
|
||||||
import StoreOverview from "./component/StoreOverview.vue";
|
import StoreOverview from "./component/StoreOverview.vue";
|
||||||
import TabSplitView from "./component/TabSplitView.vue";
|
import TabSplitView from "./component/TabSplitView.vue";
|
||||||
import { permissionCodes } from "@/utils/permission";
|
import { permissionCodes } from "@/utils/permission";
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<template>
|
||||||
|
<t-button
|
||||||
|
v-if="visible"
|
||||||
|
aria-label="有新版本"
|
||||||
|
@click="router.push('/management/settings')"
|
||||||
|
theme="default"
|
||||||
|
shape="square"
|
||||||
|
variant="text"
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<t-badge dot :offset="[-4, 4]">
|
||||||
|
<t-icon name="download" size="1.25rem" />
|
||||||
|
</t-badge>
|
||||||
|
</t-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAppUpdate } from "@/composables/useAppUpdate";
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: "AppUpdateButton"
|
||||||
|
});
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const { supported, latest, autoUpdate, hasUpdate } = useAppUpdate();
|
||||||
|
|
||||||
|
// 只在有更新且未开启自动更新时出现,开启自动更新后由启动弹窗负责提醒
|
||||||
|
const visible = computed(() => {
|
||||||
|
void latest.value;
|
||||||
|
return supported && hasUpdate() && !autoUpdate.value;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user