Blame view

src/layouts/default/header/components/notify/index.vue 2.57 KB
chen-xt authored
1
<template>
vben authored
2
3
  <div :class="prefixCls">
    <Popover title="" trigger="click" :overlayClassName="`${prefixCls}__overlay`">
4
      <Badge :count="count" dot :numberStyle="numberStyle">
vben authored
5
        <BellOutlined />
chen-xt authored
6
7
8
      </Badge>
      <template #content>
        <Tabs>
9
          <template v-for="item in listData" :key="item.key">
chen-xt authored
10
11
12
13
14
            <TabPane>
              <template #tab>
                {{ item.name }}
                <span v-if="item.list.length !== 0">({{ item.list.length }})</span>
              </template>
15
16
17
              <!-- 绑定title-click事件的通知列表中标题是“可点击”的-->
              <NoticeList :list="item.list" v-if="item.key === '1'" @title-click="onNoticeClick" />
              <NoticeList :list="item.list" v-else />
chen-xt authored
18
19
20
21
22
23
24
25
            </TabPane>
          </template>
        </Tabs>
      </template>
    </Popover>
  </div>
</template>
<script lang="ts">
26
  import { computed, defineComponent, ref } from 'vue';
chen-xt authored
27
28
  import { Popover, Tabs, Badge } from 'ant-design-vue';
  import { BellOutlined } from '@ant-design/icons-vue';
29
  import { tabListData, ListItem } from './data';
chen-xt authored
30
  import NoticeList from './NoticeList.vue';
vben authored
31
  import { useDesign } from '/@/hooks/web/useDesign';
32
  import { useMessage } from '/@/hooks/web/useMessage';
chen-xt authored
33
34
35
36

  export default defineComponent({
    components: { Popover, BellOutlined, Tabs, TabPane: Tabs.TabPane, Badge, NoticeList },
    setup() {
vben authored
37
      const { prefixCls } = useDesign('header-notify');
38
39
      const { createMessage } = useMessage();
      const listData = ref(tabListData);
vben authored
40
41
42
43
44
45
46
47
      const count = computed(() => {
        let count = 0;
        for (let i = 0; i < tabListData.length; i++) {
          count += tabListData[i].list.length;
        }
        return count;
      });
vben authored
48
49
50
51
52
      function onNoticeClick(record: ListItem) {
        createMessage.success('你点击了通知,ID=' + record.id);
        // 可以直接将其标记为已读(为标题添加删除线),此处演示的代码会切换删除线状态
        record.titleDelete = !record.titleDelete;
chen-xt authored
53
54
55
      }

      return {
vben authored
56
        prefixCls,
57
        listData,
chen-xt authored
58
        count,
59
        onNoticeClick,
chen-xt authored
60
61
62
63
64
        numberStyle: {},
      };
    },
  });
</script>
65
<style lang="less">
vben authored
66
  @prefix-cls: ~'@{namespace}-header-notify';
vben authored
67
vben authored
68
  .@{prefix-cls} {
69
    padding-bottom: 1px;
chen-xt authored
70
vben authored
71
72
73
74
    &__overlay {
      max-width: 360px;
    }
75
76
77
    .ant-tabs-content {
      width: 300px;
    }
chen-xt authored
78
79
    .ant-badge {
80
81
      display: flex;
      align-items: center;
82
      font-size: 18px;
chen-xt authored
83
84
85
86
87
88
89
90
      .ant-badge-multiple-words {
        padding: 0 4px;
      }

      svg {
        width: 0.9em;
      }
chen-xt authored
91
92
93
    }
  }
</style>