66 lines
1.6 KiB
Vue
66 lines
1.6 KiB
Vue
<template>
|
||
<t-notice-bar
|
||
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="handleChange"
|
||
@click="openNotice"
|
||
>
|
||
<template #suffix-icon>
|
||
<t-icon name="chevron-right" />
|
||
</template>
|
||
</t-notice-bar>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { useAppUpdate } from "@/composables/useAppUpdate";
|
||
import { usePendingNoticeStore } from "@/store/pendingNoticeStore";
|
||
|
||
const pendingNoticeStore = usePendingNoticeStore();
|
||
const router = useRouter();
|
||
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 = 0;
|
||
});
|
||
|
||
function handleChange(index: number): void {
|
||
currentIndex = index;
|
||
}
|
||
|
||
async function openNotice(): Promise<void> {
|
||
const notice = noticeList.value[currentIndex];
|
||
if (notice) {
|
||
await router.push({ name: notice.name, query: notice.query });
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="less">
|
||
.pending-notice {
|
||
margin-top: -1rem;
|
||
|
||
:deep(.t-swiper__container) {
|
||
transition-duration: .5s !important;
|
||
}
|
||
|
||
:deep(.t-swiper-nav__dots) {
|
||
display: none;
|
||
}
|
||
}
|
||
</style>
|