index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div :class="prefixCls">
  3. <Popover title="" trigger="click" :overlayClassName="`${prefixCls}__overlay`">
  4. <Badge size="small" dot :count="count" :numberStyle="numberStyle" @click="onNoticeClick">
  5. <BellOutlined />
  6. </Badge>
  7. <!-- <template #content>
  8. <Tabs>
  9. <template v-for="item in listData" :key="item.key">
  10. <TabPane>
  11. <template #tab>
  12. {{ item.name }}
  13. <span v-if="item.list.length !== 0">({{ item.list.length }})</span>
  14. </template>
  15. <NoticeList :list="item.list" v-if="item.key === '1'" @title-click="onNoticeClick" />
  16. <NoticeList :list="item.list" v-else />
  17. </TabPane>
  18. </template>
  19. </Tabs>
  20. </template> -->
  21. </Popover>
  22. </div>
  23. </template>
  24. <script lang="ts">
  25. import { onMounted, defineComponent, ref } from 'vue';
  26. // Tabs, Badge
  27. import { Popover, Badge } from 'ant-design-vue';
  28. import { BellOutlined } from '@ant-design/icons-vue';
  29. import { tabListData } from './data';
  30. // import NoticeList from './NoticeList.vue';
  31. import { useDesign } from '/@/hooks/web/useDesign';
  32. // import { useMessage } from '/@/hooks/web/useMessage';
  33. import { unreadNoticeApi } from '/@/api/notification/list';
  34. import { useGo } from '/@/hooks/web/usePage';
  35. // Tabs, TabPane: Tabs.TabPane, Badge, NoticeList
  36. export default defineComponent({
  37. components: { Popover, BellOutlined, Badge },
  38. setup() {
  39. const { prefixCls } = useDesign('header-notify');
  40. // const { createMessage } = useMessage();
  41. const listData = ref(tabListData);
  42. const go = useGo();
  43. const count = ref(0);
  44. onMounted(async () => {
  45. const unread = await unreadNoticeApi();
  46. console.log('unread', unread.totalCount);
  47. count.value = unread.totalCount;
  48. });
  49. function onNoticeClick() {
  50. if (count.value > 0) {
  51. go('/notification/list');
  52. }
  53. // createMessage.success('你点击了通知,ID=' + record.id);
  54. }
  55. return {
  56. prefixCls,
  57. listData,
  58. count,
  59. onNoticeClick,
  60. numberStyle: {},
  61. };
  62. },
  63. });
  64. </script>
  65. <style lang="less">
  66. @prefix-cls: ~'@{namespace}-header-notify';
  67. .@{prefix-cls} {
  68. padding-top: 2px;
  69. &__overlay {
  70. max-width: 360px;
  71. }
  72. .ant-tabs-content {
  73. width: 300px;
  74. }
  75. .ant-badge {
  76. font-size: 18px;
  77. .ant-badge-multiple-words {
  78. padding: 0 4px;
  79. transform: translate(50%, 50%);
  80. }
  81. svg {
  82. width: 0.9em;
  83. }
  84. }
  85. }
  86. </style>