feat: 公告弹窗优化
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<!-- 纵向布局作为基础布局 -->
|
||||
<script setup lang="ts">
|
||||
import { getSystemAnnouncements } from '@/api';
|
||||
import SystemAnnouncementDialog from '@/components/SystemAnnouncementDialog/index.vue';
|
||||
import { useSafeArea } from '@/hooks/useSafeArea';
|
||||
import { useWindowWidthObserver } from '@/hooks/useWindowWidthObserver';
|
||||
@@ -29,27 +28,11 @@ useSafeArea({
|
||||
useWindowWidthObserver();
|
||||
|
||||
// 应用加载时检查是否需要显示公告弹窗
|
||||
onMounted(async () => {
|
||||
onMounted(() => {
|
||||
console.log('announcementStore.shouldShowDialog--', announcementStore.shouldShowDialog);
|
||||
// 检查是否应该显示弹窗(只有"关闭一周"且未超过7天才不显示)
|
||||
// 数据获取已移至 SystemAnnouncementDialog 组件内部,每次打开弹窗时都会获取最新数据
|
||||
if (announcementStore.shouldShowDialog) {
|
||||
try {
|
||||
// 从接口获取公告数据(不使用缓存)
|
||||
const res = await getSystemAnnouncements();
|
||||
if (res && res.data && Array.isArray(res.data) && res.data.length > 0) {
|
||||
announcementStore.setAnnouncementData(res.data);
|
||||
}
|
||||
else {
|
||||
// 接口返回成功但数据为空,设置空数组
|
||||
announcementStore.setAnnouncementData([]);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取系统公告失败:', error);
|
||||
// API失败时设置空数组,仍然显示弹窗(显示错误或空状态)
|
||||
announcementStore.setAnnouncementData([]);
|
||||
}
|
||||
// 无论成功失败都显示弹窗
|
||||
announcementStore.openDialog();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user