index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <script lang="ts" setup>
  2. import { ref, computed } from "vue"
  3. import { ElMessage } from "element-plus"
  4. import { Bell } from "@element-plus/icons-vue"
  5. import NotifyList from "./NotifyList.vue"
  6. import { type ListItem, notifyData, messageData, todoData } from "./data"
  7. type TabName = "通知" | "消息" | "待办"
  8. interface DataItem {
  9. name: TabName
  10. type: "primary" | "success" | "warning" | "danger" | "info"
  11. list: ListItem[]
  12. }
  13. /** 角标当前值 */
  14. const badgeValue = computed(() => {
  15. return data.value.reduce((sum, item) => sum + item.list.length, 0)
  16. })
  17. /** 角标最大值 */
  18. const badgeMax = 99
  19. /** 面板宽度 */
  20. const popoverWidth = 350
  21. /** 当前 Tab */
  22. const activeName = ref<TabName>("通知")
  23. /** 所有数据 */
  24. const data = ref<DataItem[]>([
  25. // 通知数据
  26. {
  27. name: "通知",
  28. type: "primary",
  29. list: notifyData
  30. },
  31. // 消息数据
  32. {
  33. name: "消息",
  34. type: "danger",
  35. list: messageData
  36. },
  37. // 待办数据
  38. {
  39. name: "待办",
  40. type: "warning",
  41. list: todoData
  42. }
  43. ])
  44. const handleHistory = () => {
  45. ElMessage.success(`跳转到${activeName.value}历史页面`)
  46. }
  47. </script>
  48. <template>
  49. <div class="notify">
  50. <el-popover placement="bottom" :width="popoverWidth" trigger="click">
  51. <template #reference>
  52. <el-badge :value="badgeValue" :max="badgeMax" :hidden="badgeValue === 0">
  53. <el-tooltip effect="dark" content="消息通知" placement="bottom">
  54. <el-icon :size="20">
  55. <Bell />
  56. </el-icon>
  57. </el-tooltip>
  58. </el-badge>
  59. </template>
  60. <template #default>
  61. <el-tabs v-model="activeName" class="demo-tabs" stretch>
  62. <el-tab-pane v-for="(item, index) in data" :name="item.name" :key="index">
  63. <template #label>
  64. {{ item.name }}
  65. <el-badge :value="item.list.length" :max="badgeMax" :type="item.type" />
  66. </template>
  67. <el-scrollbar height="400px">
  68. <NotifyList :list="item.list" />
  69. </el-scrollbar>
  70. </el-tab-pane>
  71. </el-tabs>
  72. <div class="notify-history">
  73. <el-button link @click="handleHistory">查看{{ activeName }}历史</el-button>
  74. </div>
  75. </template>
  76. </el-popover>
  77. </div>
  78. </template>
  79. <style lang="scss" scoped>
  80. .notify {
  81. margin-right: 10px;
  82. }
  83. .notify-history {
  84. text-align: center;
  85. padding-top: 12px;
  86. border-top: 1px solid var(--el-border-color);
  87. }
  88. </style>