99 lines
2.4 KiB
Vue
Raw Normal View History

2022-10-27 18:21:25 +08:00
<script lang="ts" setup>
2024-11-22 21:13:49 +08:00
import type { NotifyItem } from "./type"
2022-10-27 18:21:25 +08:00
import { Bell } from "@element-plus/icons-vue"
2024-11-18 19:40:44 +08:00
import { messageData, notifyData, todoData } from "./data"
2024-11-22 21:13:49 +08:00
import List from "./List.vue"
2022-10-27 18:21:25 +08:00
type TabName = "通知" | "消息" | "待办"
2022-10-27 18:21:25 +08:00
interface DataItem {
name: TabName
2022-10-27 18:21:25 +08:00
type: "primary" | "success" | "warning" | "danger" | "info"
2024-11-22 21:13:49 +08:00
list: NotifyItem[]
2022-10-27 18:21:25 +08:00
}
/** 角标当前值 */
2024-11-19 20:14:23 +08:00
const badgeValue = computed(() => data.value.reduce((sum, item) => sum + item.list.length, 0))
2022-10-27 18:21:25 +08:00
/** 角标最大值 */
const badgeMax = 99
2022-10-27 18:21:25 +08:00
/** 面板宽度 */
const popoverWidth = 350
2022-10-27 18:21:25 +08:00
/** 当前 Tab */
const activeName = ref<TabName>("通知")
2022-10-27 18:21:25 +08:00
/** 所有数据 */
const data = ref<DataItem[]>([
2022-10-27 18:21:25 +08:00
// 通知数据
{
name: "通知",
type: "primary",
2022-10-31 11:19:22 +08:00
list: notifyData
2022-10-27 18:21:25 +08:00
},
// 消息数据
{
name: "消息",
type: "danger",
2022-10-31 11:19:22 +08:00
list: messageData
2022-10-27 18:21:25 +08:00
},
// 待办数据
{
name: "待办",
type: "warning",
2022-10-31 11:19:22 +08:00
list: todoData
2022-10-27 18:21:25 +08:00
}
])
2024-11-18 19:40:44 +08:00
function handleHistory() {
2022-10-27 18:21:25 +08:00
ElMessage.success(`跳转到${activeName.value}历史页面`)
}
</script>
<template>
<div class="notify">
<el-popover placement="bottom" :width="popoverWidth" trigger="click">
<template #reference>
<el-badge :value="badgeValue" :max="badgeMax" :hidden="badgeValue === 0">
<el-tooltip effect="dark" content="消息通知" placement="bottom">
<el-icon :size="20">
<Bell />
</el-icon>
</el-tooltip>
</el-badge>
</template>
<template #default>
<el-tabs v-model="activeName" class="demo-tabs" stretch>
2024-11-18 19:40:44 +08:00
<el-tab-pane v-for="(item, index) in data" :key="index" :name="item.name">
2022-10-27 18:21:25 +08:00
<template #label>
{{ item.name }}
<el-badge :value="item.list.length" :max="badgeMax" :type="item.type" />
</template>
2022-10-28 18:05:16 +08:00
<el-scrollbar height="400px">
2024-11-22 21:13:49 +08:00
<List :data="item.list" />
2022-10-28 18:05:16 +08:00
</el-scrollbar>
2022-10-27 18:21:25 +08:00
</el-tab-pane>
</el-tabs>
<div class="notify-history">
2024-11-18 19:40:44 +08:00
<el-button link @click="handleHistory">
查看{{ activeName }}历史
</el-button>
2022-10-27 18:21:25 +08:00
</div>
</template>
</el-popover>
</div>
</template>
<style lang="scss" scoped>
.notify {
margin-right: 10px;
}
2024-03-28 21:34:24 +08:00
2022-10-27 18:21:25 +08:00
.notify-history {
text-align: center;
padding-top: 12px;
border-top: 1px solid var(--el-border-color);
}
</style>