popover.md 4.89 KB
Newer Older
1 2 3 4 5
---
order: 2
title: 带浮层卡片
---

6
点击展开通知卡片,展现多种类型的通知,通常放在导航工具栏。
7 8

````jsx
nikogu's avatar
nikogu committed
9
import NoticeIcon from 'ant-design-pro/lib/NoticeIcon';
10
import moment from 'moment';
11
import groupBy from 'lodash/groupBy';
afc163's avatar
afc163 committed
12
import { Tag } from 'antd';
13 14

const data = [{
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  id: '000000001',
  avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
  title: '你收到了 14 份新周报',
  datetime: '2017-08-09',
  type: '通知',
}, {
  id: '000000002',
  avatar: 'https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png',
  title: '你推荐的 曲妮妮 已通过第三轮面试',
  datetime: '2017-08-08',
  type: '通知',
}, {
  id: '000000003',
  avatar: 'https://gw.alipayobjects.com/zos/rmsportal/kISTdvpyTAhtGxpovNWd.png',
  title: '这种模板可以区分多种通知类型',
  datetime: '2017-08-07',
  read: true,
  type: '通知',
}, {
  id: '000000004',
  avatar: 'https://gw.alipayobjects.com/zos/rmsportal/GvqBnKhFgObvnSGkDsje.png',
  title: '左侧图标用于区分不同的类型',
  datetime: '2017-08-07',
  type: '通知',
}, {
  id: '000000005',
  avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
  title: '内容不要超过两行字,超出时自动截断',
  datetime: '2017-08-07',
  type: '通知',
}, {
  id: '000000006',
47 48 49
  avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  title: '曲丽丽 评论了你',
  description: '描述信息描述信息描述信息',
50 51
  datetime: '2017-08-07',
  type: '消息',
wingsico's avatar
wingsico committed
52
  clickClose: true,
53
}, {
54
  id: '000000007',
55 56 57
  avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  title: '朱偏右 回复了你',
  description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
58 59
  datetime: '2017-08-07',
  type: '消息',
wingsico's avatar
wingsico committed
60
  clickClose: true,
61
}, {
62
  id: '000000008',
63 64 65
  avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  title: '标题',
  description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
66 67
  datetime: '2017-08-07',
  type: '消息',
wingsico's avatar
wingsico committed
68
  clickClose: true,
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
}, {
  id: '000000009',
  title: '任务名称',
  description: '任务需要在 2017-01-12 20:00 前启动',
  extra: '未开始',
  status: 'todo',
  type: '待办',
}, {
  id: '000000010',
  title: '第三方紧急代码变更',
  description: '冠霖提交于 2017-01-06,需在 2017-01-07 前完成代码变更任务',
  extra: '马上到期',
  status: 'urgent',
  type: '待办',
}, {
  id: '000000011',
  title: '信息安全考试',
  description: '指派竹尔于 2017-01-09 前完成更新并发布',
  extra: '已耗时 8 天',
  status: 'doing',
  type: '待办',
}, {
  id: '000000012',
  title: 'ABCD 版本发布',
  description: '冠霖提交于 2017-01-06,需在 2017-01-07 前完成代码变更任务',
  extra: '进行中',
  status: 'processing',
  type: '待办',
97 98
}];

afc163's avatar
afc163 committed
99 100 101 102 103 104 105 106
function onItemClick(item, tabProps) {
  console.log(item, tabProps);
}

function onClear(tabTitle) {
  console.log(tabTitle);
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
function getNoticeData(notices) {
  if (notices.length === 0) {
    return {};
  }
  const newNotices = notices.map((notice) => {
    const newNotice = { ...notice };
    if (newNotice.datetime) {
      newNotice.datetime = moment(notice.datetime).fromNow();
    }
    // transform id to item key
    if (newNotice.id) {
      newNotice.key = newNotice.id;
    }
    if (newNotice.extra && newNotice.status) {
      const color = ({
        todo: '',
        processing: 'blue',
        urgent: 'red',
        doing: 'gold',
      })[newNotice.status];
      newNotice.extra = <Tag color={color} style={{ marginRight: 0 }}>{newNotice.extra}</Tag>;
    }
    return newNotice;
  });
  return groupBy(newNotices, 'type');
}

const noticeData = getNoticeData(data);

136
ReactDOM.render(
afc163's avatar
afc163 committed
137 138 139 140 141 142 143 144 145 146
  <div
    style={{
      textAlign: 'right',
      height: '64px',
      lineHeight: '64px',
      boxShadow: '0 1px 4px rgba(0,21,41,.12)',
      padding: '0 32px',
      width: '400px',
    }}
  >
147 148 149 150 151 152
    <NoticeIcon
      className="notice-icon"
      count={5}
      onItemClick={onItemClick}
      onClear={onClear}
    >
afc163's avatar
afc163 committed
153
      <NoticeIcon.Tab
154
        list={noticeData['通知']}
何乐's avatar
何乐 committed
155
        name="通知"
afc163's avatar
afc163 committed
156 157
        title="通知"
        emptyText="你已查看所有通知"
afc163's avatar
afc163 committed
158
        emptyImage="https://gw.alipayobjects.com/zos/rmsportal/wAhyIChODzsoKIOBHcBk.svg"
afc163's avatar
afc163 committed
159 160
      />
      <NoticeIcon.Tab
161
        list={noticeData['消息']}
何乐's avatar
何乐 committed
162
        name="消息"
afc163's avatar
afc163 committed
163 164
        title="消息"
        emptyText="您已读完所有消息"
afc163's avatar
afc163 committed
165
        emptyImage="https://gw.alipayobjects.com/zos/rmsportal/sAuJeJzSKbUmHfBQRzmZ.svg"
afc163's avatar
afc163 committed
166 167
      />
      <NoticeIcon.Tab
168
        list={noticeData['待办']}
何乐's avatar
何乐 committed
169
        name="待办"
afc163's avatar
afc163 committed
170 171 172 173
        title="待办"
        emptyText="你已完成所有待办"
        emptyImage="https://gw.alipayobjects.com/zos/rmsportal/HsIsxMZiWKrNUavQUXqx.svg"
      />
174 175 176 177
    </NoticeIcon>
  </div>
, mountNode);
````
178 179 180 181

```css

```