massage.js 764 字节
Newer Older
!阳仔's avatar
!阳仔 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

import {
  Message
} from 'element-ui'
let messageInstance = null
let time = ''
const resetMessage = (options) => {
  if (messageInstance) {
    messageInstance.close()
  }
  if (typeof options === 'string') {
    options = {
      message: options
    }
  }
  if (options.duration === 0) {
    time = 0
  } else if (options.duration === 5000) {
    time = 5000
  } else {
    time = 1500
  }
  messageInstance = Message({ ...options, duration: time })
  return messageInstance
}
;['error', 'success', 'info', 'warning'].forEach(type => {
  resetMessage[type] = options => {
    if (typeof options === 'string') {
      options = {
        message: options
      }
    }
    options.type = type
    return resetMessage(options)
  }
})
export default resetMessage