feat: 通知下拉菜单新增未读总数显示并优化数据权限类型

This commit is contained in:
Ray.Hao
2026-02-14 19:15:36 +08:00
parent b050824da7
commit bf418230ad
3 changed files with 19 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
<template> <template>
<el-dropdown class="notice__dropdown" trigger="click"> <el-dropdown class="notice__dropdown" trigger="click">
<div class="notice__trigger"> <div class="notice__trigger">
<el-badge v-if="list.length > 0" :value="list.length" :max="99"> <el-badge v-if="unreadTotal > 0" :value="unreadTotal" :max="99">
<div class="i-svg:bell" /> <div class="i-svg:bell" />
</el-badge> </el-badge>
@@ -78,7 +78,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useNotice } from "./useNotice"; import { useNotice } from "./useNotice";
const { list, detail, dialogVisible, read, readAll, goMore } = useNotice(); const { list, unreadTotal, detail, dialogVisible, read, readAll, goMore } = useNotice();
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -14,6 +14,7 @@ export function useNotice() {
// 状态 // 状态
const list = ref<NoticeItem[]>([]); const list = ref<NoticeItem[]>([]);
const unreadTotal = ref(0);
const detail = ref<NoticeDetail | null>(null); const detail = ref<NoticeDetail | null>(null);
const dialogVisible = ref(false); const dialogVisible = ref(false);
@@ -32,6 +33,7 @@ export function useNotice() {
}; };
const page = await NoticeAPI.getMyNoticePage(query); const page = await NoticeAPI.getMyNoticePage(query);
list.value = page.list || []; list.value = page.list || [];
unreadTotal.value = page.total ?? 0;
} }
async function read(id: string) { async function read(id: string) {
@@ -41,11 +43,15 @@ export function useNotice() {
// 从列表中移除已读项 // 从列表中移除已读项
const idx = list.value.findIndex((item: NoticeItem) => item.id === id); const idx = list.value.findIndex((item: NoticeItem) => item.id === id);
if (idx >= 0) list.value.splice(idx, 1); if (idx >= 0) list.value.splice(idx, 1);
if (unreadTotal.value > 0) unreadTotal.value -= 1;
await fetchList();
} }
async function readAll() { async function readAll() {
await NoticeAPI.readAll(); await NoticeAPI.readAll();
list.value = []; list.value = [];
unreadTotal.value = 0;
ElMessage.success("已全部标记为已读"); ElMessage.success("已全部标记为已读");
} }
@@ -68,6 +74,8 @@ export function useNotice() {
// 避免重复 // 避免重复
if (list.value.some((item: NoticeItem) => item.id === data.id)) return; if (list.value.some((item: NoticeItem) => item.id === data.id)) return;
unreadTotal.value += 1;
list.value.unshift({ list.value.unshift({
id: data.id, id: data.id,
title: data.title, title: data.title,
@@ -75,6 +83,10 @@ export function useNotice() {
publishTime: data.publishTime, publishTime: data.publishTime,
} as NoticeItem); } as NoticeItem);
if (list.value.length > PAGE_SIZE) {
list.value.length = PAGE_SIZE;
}
ElNotification({ ElNotification({
title: "您收到一条新的通知消息!", title: "您收到一条新的通知消息!",
message: data.title, message: data.title,
@@ -105,6 +117,7 @@ export function useNotice() {
return { return {
list, list,
unreadTotal,
detail, detail,
dialogVisible, dialogVisible,
fetchList, fetchList,

View File

@@ -22,8 +22,10 @@ export interface RoleItem {
sort?: number; sort?: number;
/** 角色状态 */ /** 角色状态 */
status?: number; status?: number;
/** 创建时间 */ /** 数据权限(1-所有数据 2-部门及子部门数据 3-本部门数据 4-本人数据 5-自定义部门数据) */
createTime?: Date; dataScope?: number;
/** 数据权限标签 */
dataScopeLabel?: string;
/** 修改时间 */ /** 修改时间 */
updateTime?: Date; updateTime?: Date;
} }