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

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

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

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>
  });
}
翰文 已提交
33

A
afc163 已提交
34
export default {
A
afc163 已提交
35 36
  info(content, duration) {
    notice(content, duration, 'info');
翰文 已提交
37
  },
A
afc163 已提交
38 39
  success(content, duration) {
    notice(content, duration, 'success');
翰文 已提交
40
  },
A
afc163 已提交
41 42
  error(content, duration) {
    notice(content, duration, 'error');
A
afc163 已提交
43 44 45 46 47
  },
  config(options) {
    if (options.top) {
      top = options.top;
    }
翰文 已提交
48 49
  }
};