100 lines
2.5 KiB
Vue
Raw Normal View History

2022-10-27 18:21:25 +08:00
<script lang="ts" setup>
import { ref, computed } from "vue"
import { ElMessage } from "element-plus"
import { Bell } from "@element-plus/icons-vue"
2022-10-28 18:05:16 +08:00
import NotifyList from "./NotifyList.vue"
import { type ListItem, notifyData, messageData, todoData } from "./data"
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"
list: ListItem[]
2022-10-27 18:21:25 +08:00
}
/** 角标当前值 */
const badgeValue = computed(() => {
let value = 0
for (let i = 0; i < data.value.length; i++) {
value += data.value[i].list.length
}
return value
})
/** 角标最大值 */
const badgeMax = 99
/** 面板宽度 */
const popoverWidth = 350
/** 当前 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
}
])
const handleHistory = () => {
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>
<el-tab-pane v-for="(item, index) in data" :name="item.name" :key="index">
<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">
<NotifyList :list="item.list" />
</el-scrollbar>
2022-10-27 18:21:25 +08:00
</el-tab-pane>
</el-tabs>
<div class="notify-history">
<el-button link @click="handleHistory">查看{{ activeName }}历史</el-button>
</div>
</template>
</el-popover>
</div>
</template>
<style lang="scss" scoped>
.notify {
margin-right: 10px;
color: var(--el-text-color-regular);
}
.notify-history {
text-align: center;
padding-top: 12px;
border-top: 1px solid var(--el-border-color);
}
</style>