import { Message } from 'element-ui'

const DgMessage = function (options) {
  // 简单封装message  error报错提示信息样式，之后可继续完善优化
  if (options.type === 'error') {
    return Message({
      dangerouslyUseHTMLString: true,
      message: `<strong>errcode: ${options.code || ''}</strong><br/><br/>${options.message || '错误信息'}`,
      type: 'error',
    })
  } else return Message(options)
}

let messageType = ['success', 'warning', 'info', 'error']
messageType.forEach((type) => {
  DgMessage[type] = (options) => {
    if (typeof options === 'string') {
      options = {
        message: options,
      }
    }
    options.type = type
    return DgMessage(options)
  }
})

DgMessage.install = (Vue) => {
  Vue.prototype.$dgMessage = DgMessage
}

export default DgMessage

export { DgMessage }
