Files
gao-customer-h5/src/pages/tabs/component/PendingNoticeBar.vue
T
2026-11-13 16:50:16 +08:00

66 lines
1.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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>