fix(system): app update notify
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
<template>
|
||||
<t-notice-bar
|
||||
v-if="noticeContent.length"
|
||||
v-if="noticeList.length"
|
||||
:key="noticeContent.join(',')"
|
||||
class="pending-notice"
|
||||
theme="warning"
|
||||
:visible="true"
|
||||
direction="vertical"
|
||||
:interval="4000"
|
||||
:content="1 < noticeContent.length ? noticeContent : noticeContent[0]"
|
||||
@change="currentIndex = $event"
|
||||
@change="handleChange"
|
||||
@click="openNotice"
|
||||
>
|
||||
<template #suffix-icon>
|
||||
@@ -17,17 +18,32 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAppUpdate } from "@/composables/useAppUpdate";
|
||||
import { usePendingNoticeStore } from "@/store/pendingNoticeStore";
|
||||
|
||||
const pendingNoticeStore = usePendingNoticeStore();
|
||||
const router = useRouter();
|
||||
const currentIndex = ref(0);
|
||||
const noticeContent = computed(() => pendingNoticeStore.pendingNoticeList.map(notice => notice.content));
|
||||
const { supported, latest, autoUpdate, hasUpdate } = useAppUpdate();
|
||||
const noticeList = computed(() => {
|
||||
const notices = [...pendingNoticeStore.pendingNoticeList];
|
||||
if (supported && !autoUpdate.value && hasUpdate() && latest.value) {
|
||||
notices.push({ content: `有可用新版本 v${latest.value.version} 更新`, name: "AppUpdate", query: {} });
|
||||
}
|
||||
return notices;
|
||||
});
|
||||
const noticeContent = computed(() => noticeList.value.map(notice => notice.content));
|
||||
let currentIndex = 0;
|
||||
|
||||
watch(noticeContent, () => { currentIndex.value = 0; });
|
||||
watch(noticeContent, () => {
|
||||
currentIndex = 0;
|
||||
});
|
||||
|
||||
function handleChange(index: number): void {
|
||||
currentIndex = index;
|
||||
}
|
||||
|
||||
async function openNotice(): Promise<void> {
|
||||
const notice = pendingNoticeStore.pendingNoticeList[currentIndex.value];
|
||||
const notice = noticeList.value[currentIndex];
|
||||
if (notice) {
|
||||
await router.push({ name: notice.name, query: notice.query });
|
||||
}
|
||||
@@ -38,6 +54,10 @@ async function openNotice(): Promise<void> {
|
||||
.pending-notice {
|
||||
margin-top: -1rem;
|
||||
|
||||
:deep(.t-swiper__container) {
|
||||
transition-duration: .5s !important;
|
||||
}
|
||||
|
||||
:deep(.t-swiper-nav__dots) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user