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

陈帅's avatar
陈帅 committed
4
import { formatMessage } from 'umi-plugin-react/locale';
陈帅's avatar
陈帅 committed
5

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

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

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

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