rewriteNotify.js 1.27 KB
Newer Older
fukai committed
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 38 39 40 41 42 43 44 45 46 47 48 49 50
import Vue from 'vue'
import {
  MessageBox,
  Notification,

} from 'element-ui'


//将错误提示改为Message居中
function notifyClone(options){
  if(typeof options == 'object' && options.type == 'error'){
    errorNotify(options)
    return;
  }
  return Notification(options)
}

//错误实现函数
let errorNotify=options =>{
  if(typeof options == 'string' ||
    //Vnode的判断
    (typeof options == 'object' && options.hasOwnProperty('componentOptions'))){
    options = {message:options}
  }
  options.title = options.title||"错误"
  options.type = 'error'
  options.confirmButtonText = '确定'
  return MessageBox.alert(options.message,options)
}

export default function rewriteNotify(){
  
  ['success', 'warning', 'info'].forEach(type => {
    notifyClone[type] = function(options){
      if(typeof options == 'string' ||
        //Vnode的判断
        (typeof options == 'object' && options.hasOwnProperty('componentOptions'))){
        options = {message:options}
      }
      options.type = type
      return Notification(options)
    }
  })
  notifyClone['close']=function(id, userOnClose){
    Notification.close(id, userOnClose)
  }
  notifyClone['closeAll'] = ()=>Notification.closeAll()
  notifyClone['error'] = errorNotify
  // Vue.prototype.$notify = notifyClone
}