index.jsx 1.0 KB
Newer Older
Y
yiminghe 已提交
1
import React from 'react';
翰文 已提交
2 3
import Notification from 'rc-notification';

A
afc163 已提交
4
let defaultDuration = 1.5;
翰文 已提交
5

A
afc163 已提交
6
function getMessageInstance() {
A
afc163 已提交
7
  return Notification.newInstance({
翰文 已提交
8 9
    prefixCls: 'ant-message',
    transitionName: 'move-up',
A
afc163 已提交
10
    style: {}  // 覆盖原来的样式
翰文 已提交
11
  });
A
afc163 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
}

function notice(content, duration = defaultDuration, type) {
  let iconClass = ({
    'info': 'anticon-info-circle ant-message-info',
    'success': 'anticon-check-circle ant-message-success',
    'error': 'anticon-exclamation-circle ant-message-error'
  })[type];
  getMessageInstance().notice({
    key: 'simpleMessage',
    duration: duration,
    style: {},
    content: <div className="ant-message-custom-content">
      <i className={'anticon ' + iconClass}></i>
      <span>{content}</span>
    </div>
  });
}
翰文 已提交
30

A
afc163 已提交
31
export default {
A
afc163 已提交
32 33
  info(content, duration) {
    notice(content, duration, 'info');
翰文 已提交
34
  },
A
afc163 已提交
35 36
  success(content, duration) {
    notice(content, duration, 'success');
翰文 已提交
37
  },
A
afc163 已提交
38 39
  error(content, duration) {
    notice(content, duration, 'error');
翰文 已提交
40 41
  }
};