index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. import { useMessage } from '/@/hooks/web/useMessage';
  36. // Tabs, TabPane: Tabs.TabPane, Badge, NoticeList
  37. export default defineComponent({
  38. components: { Popover, BellOutlined, Badge },
  39. setup() {
  40. const { prefixCls } = useDesign('header-notify');
  41. // const { createMessage } = useMessage();
  42. const listData = ref(tabListData);
  43. const go = useGo();
  44. const { createWarningModal } = useMessage();
  45. const count = ref(0);
  46. async function fetchNotice() {
  47. const unread = await unreadNoticeApi();
  48. console.log('unread', unread.totalCount);
  49. count.value = unread.totalCount;
  50. interface Unread {
  51. title: string;
  52. type: number;
  53. content: string;
  54. }
  55. if (unread.list?.length) {
  56. const list = unread.list[0] as unknown as Unread;
  57. if (list.type === 0) {
  58. createWarningModal({ title: list.title, content: list.content });
  59. }
  60. if (list.type === 1) {
  61. createWarningModal({
  62. title: list.title,
  63. content: `<img style="margin:0 auto" src="${list.content}"/>`,
  64. });
  65. }
  66. }
  67. }
  68. onMounted(async () => {
  69. fetchNotice();
  70. });
  71. function onNoticeClick() {
  72. go('/notification');
  73. count.value = 0;
  74. }
  75. return {
  76. prefixCls,
  77. listData,
  78. count,
  79. onNoticeClick,
  80. numberStyle: {},
  81. };
  82. },
  83. });
  84. </script>
  85. <style lang="less">
  86. @prefix-cls: ~'@{namespace}-header-notify';
  87. .@{prefix-cls} {
  88. padding-top: 2px;
  89. &__overlay {
  90. max-width: 360px;
  91. }
  92. .ant-tabs-content {
  93. width: 300px;
  94. }
  95. .ant-badge {
  96. font-size: 18px;
  97. .ant-badge-multiple-words {
  98. padding: 0 4px;
  99. transform: translate(50%, 50%);
  100. }
  101. svg {
  102. width: 0.9em;
  103. }
  104. }
  105. }
  106. </style>