Files
Situation-Awareness-Platfor…/src/components/Header/Notice.vue
2025-03-17 19:25:02 +08:00

62 lines
1.5 KiB
Vue

<template>
<router-link to="/personalCenter?status=all&message_type=mr">
<d-badge class="g-notice" :count="accountInfo.noticeUnreadNum" :offset="[-2, 4]" :hidden="!accountInfo.noticeUnreadNum" status="danger">
<d-icon style="font-size: 16px" name="notice" />
</d-badge>
</router-link>
</template>
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { getMessageCount } from '@/api/notice';
import { addEventListener, offEvent } from '@/utils/eventBus';
import debounce from 'lodash/debounce';
import { useAccount } from '@/utils/hooks/useAccount';
const { accountInfo, RemoveInfo } = useAccount();
const counts = ref(9);
const getCounts = () => {
getMessageCount().then((result) => {
counts.value = result.data?.reduce((prev: number, curr: Record<string, any>) => {
return prev + curr.un_read_count;
}, 0);
});
};
onMounted(() => {
getCounts();
addEventListener('updateNotice', debounce((count: number) => {
counts.value = count;
}, 500));
});
onBeforeUnmount(() => {
offEvent('updateNotice');
});
</script>
<style lang="scss" scoped>
@import 'devui-theme/styles-var/devui-var.scss';
.g-notice {
cursor: pointer;
margin: 0 8px;
padding-top: 6px;
&-list {
display: flex;
flex-direction: column;
padding: 8px;
&-item {
width: 280px;
padding: 8px 0;
&-title {
font-weight: 500;
}
&-content {
font-weight: 400;
}
}
}
}
</style>