feat: 通知下拉菜单新增未读总数显示并优化数据权限类型
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-dropdown class="notice__dropdown" trigger="click">
|
||||
<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" />
|
||||
</el-badge>
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
<script setup lang="ts">
|
||||
import { useNotice } from "./useNotice";
|
||||
|
||||
const { list, detail, dialogVisible, read, readAll, goMore } = useNotice();
|
||||
const { list, unreadTotal, detail, dialogVisible, read, readAll, goMore } = useNotice();
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -14,6 +14,7 @@ export function useNotice() {
|
||||
|
||||
// 状态
|
||||
const list = ref<NoticeItem[]>([]);
|
||||
const unreadTotal = ref(0);
|
||||
const detail = ref<NoticeDetail | null>(null);
|
||||
const dialogVisible = ref(false);
|
||||
|
||||
@@ -32,6 +33,7 @@ export function useNotice() {
|
||||
};
|
||||
const page = await NoticeAPI.getMyNoticePage(query);
|
||||
list.value = page.list || [];
|
||||
unreadTotal.value = page.total ?? 0;
|
||||
}
|
||||
|
||||
async function read(id: string) {
|
||||
@@ -41,11 +43,15 @@ export function useNotice() {
|
||||
// 从列表中移除已读项
|
||||
const idx = list.value.findIndex((item: NoticeItem) => item.id === id);
|
||||
if (idx >= 0) list.value.splice(idx, 1);
|
||||
if (unreadTotal.value > 0) unreadTotal.value -= 1;
|
||||
|
||||
await fetchList();
|
||||
}
|
||||
|
||||
async function readAll() {
|
||||
await NoticeAPI.readAll();
|
||||
list.value = [];
|
||||
unreadTotal.value = 0;
|
||||
ElMessage.success("已全部标记为已读");
|
||||
}
|
||||
|
||||
@@ -68,6 +74,8 @@ export function useNotice() {
|
||||
// 避免重复
|
||||
if (list.value.some((item: NoticeItem) => item.id === data.id)) return;
|
||||
|
||||
unreadTotal.value += 1;
|
||||
|
||||
list.value.unshift({
|
||||
id: data.id,
|
||||
title: data.title,
|
||||
@@ -75,6 +83,10 @@ export function useNotice() {
|
||||
publishTime: data.publishTime,
|
||||
} as NoticeItem);
|
||||
|
||||
if (list.value.length > PAGE_SIZE) {
|
||||
list.value.length = PAGE_SIZE;
|
||||
}
|
||||
|
||||
ElNotification({
|
||||
title: "您收到一条新的通知消息!",
|
||||
message: data.title,
|
||||
@@ -105,6 +117,7 @@ export function useNotice() {
|
||||
|
||||
return {
|
||||
list,
|
||||
unreadTotal,
|
||||
detail,
|
||||
dialogVisible,
|
||||
fetchList,
|
||||
|
||||
@@ -22,8 +22,10 @@ export interface RoleItem {
|
||||
sort?: number;
|
||||
/** 角色状态 */
|
||||
status?: number;
|
||||
/** 创建时间 */
|
||||
createTime?: Date;
|
||||
/** 数据权限(1-所有数据 2-部门及子部门数据 3-本部门数据 4-本人数据 5-自定义部门数据) */
|
||||
dataScope?: number;
|
||||
/** 数据权限标签 */
|
||||
dataScopeLabel?: string;
|
||||
/** 修改时间 */
|
||||
updateTime?: Date;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user