notification.tsx 1.58 KB
Newer Older
陈帅's avatar
陈帅 committed
1
import React, { Component, Fragment } from 'react';
陈帅's avatar
陈帅 committed
2
import { formatMessage } from 'umi-plugin-react/locale';
陈帅's avatar
陈帅 committed
3 4
import { Switch, List } from 'antd';

陈帅's avatar
陈帅 committed
5 6
type Unpacked<T> = T extends (infer U)[] ? U : T;

张秀玲's avatar
张秀玲 committed
7
class NotificationView extends Component {
陈帅's avatar
陈帅 committed
8
  getData = () => {
张秀玲's avatar
张秀玲 committed
9 10
    const Action = (
      <Switch
11 12
        checkedChildren={formatMessage({ id: 'BLOCK_NAME.settings.open' })}
        unCheckedChildren={formatMessage({ id: 'BLOCK_NAME.settings.close' })}
张秀玲's avatar
张秀玲 committed
13 14 15
        defaultChecked
      />
    );
陈帅's avatar
陈帅 committed
16 17
    return [
      {
18 19
        title: formatMessage({ id: 'BLOCK_NAME.notification.password' }, {}),
        description: formatMessage({ id: 'BLOCK_NAME.notification.password-description' }, {}),
陈帅's avatar
陈帅 committed
20 21 22
        actions: [Action],
      },
      {
23 24
        title: formatMessage({ id: 'BLOCK_NAME.notification.messages' }, {}),
        description: formatMessage({ id: 'BLOCK_NAME.notification.messages-description' }, {}),
陈帅's avatar
陈帅 committed
25 26 27
        actions: [Action],
      },
      {
28 29
        title: formatMessage({ id: 'BLOCK_NAME.notification.todo' }, {}),
        description: formatMessage({ id: 'BLOCK_NAME.notification.todo-description' }, {}),
陈帅's avatar
陈帅 committed
30 31 32 33
        actions: [Action],
      },
    ];
  };
陈帅's avatar
陈帅 committed
34

陈帅's avatar
陈帅 committed
35
  render() {
陈帅's avatar
陈帅 committed
36
    const data = this.getData();
陈帅's avatar
陈帅 committed
37 38
    return (
      <Fragment>
陈帅's avatar
陈帅 committed
39
        <List<Unpacked<typeof data>>
陈帅's avatar
陈帅 committed
40
          itemLayout="horizontal"
陈帅's avatar
陈帅 committed
41
          dataSource={data}
陈帅's avatar
陈帅 committed
42 43
          renderItem={item => (
            <List.Item actions={item.actions}>
jim's avatar
jim committed
44
              <List.Item.Meta title={item.title} description={item.description} />
陈帅's avatar
陈帅 committed
45 46 47 48 49 50 51
            </List.Item>
          )}
        />
      </Fragment>
    );
  }
}
lijiehua's avatar
lijiehua committed
52

陈帅's avatar
陈帅 committed
53
export default NotificationView;