element-ui#MessageBox JavaScript Examples

The following examples show how to use element-ui#MessageBox. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: preivew302.js    From maji with Apache License 2.0 6 votes vote down vote up
// 判断 弹出层存在

// 弹出消息,登录环境错误问题
export function openMessage(data) {
  // 只允许同时一个弹出窗
  if (loginTipsOpen) return
  loginTipsOpen = true
  MessageBox.confirm(`<div>
  <p>没有 ${data.message} 环境的cookie,需要登录 ${data.message} 环境,
  <a style="color:#409EFF;text-decoration:none" href="${data.loginLink}" target="_blank">前往登录</a></p>
  <p>完成登录操作后点击确认刷新页面</p>
</div>`, '登录提醒', {
    dangerouslyUseHTMLString: true,
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    loginTipsOpen = false
    window.location.reload()
  }).catch(() => {
    loginTipsOpen = false
  })
}
Example #2
Source File: confirm.js    From scan-login-demo with MIT License 6 votes vote down vote up
/**
 * @author 封装 element-ui 弹框
 * @param text
 * @param type
 * @returns {Promise}
 */
export function handleConfirm(text = "确定执行此操作吗?", type = "danger") {
  return MessageBox.confirm(text, "提示", {
    showClose: false,
    confirmButtonText: "确定",
    confirmButtonClass: "el-button--danger ",
    customClass: 'confirm',
    cancelButtonText: "取消",
    type: type
  });
}
Example #3
Source File: element.js    From wl-mfe with Apache License 2.0 6 votes vote down vote up
/**
 * 确认框,默认确定取消按钮,警告状态
 * @param {*} message 提示语
 * @param {*} title 标题
 * @param {*} options 配置
 */
export function wlConfirm(message, title = "提示", options = {}) {
  let _options = {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
    ...options
  }
  return MessageBox.confirm(message, title, _options)
}
Example #4
Source File: message-box.js    From wl-mfe with Apache License 2.0 6 votes vote down vote up
/**
 * 确认删除
 * @param {*} message 
 */
function confirm(message = "是否确认删除所选数据?") {
  return function (target, name, descriptor) {
    let oldValue = descriptor.value;
    descriptor.value = function (...args) {
      MessageBox.confirm(message, '提示')
        .then(oldValue.bind(this, ...args))
        .catch(() => { });
    };

    return descriptor;
  }
}
Example #5
Source File: element.js    From wl-mfe with Apache License 2.0 6 votes vote down vote up
/**
 * 确认框,默认确定取消按钮,警告状态
 * @param {*} message 提示语
 * @param {*} title 标题
 * @param {*} options 配置
 */
export function wlConfirm(message, title = "提示", options = {}) {
  let _options = {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
    ...options
  }
  return MessageBox.confirm(message, title, _options)
}
Example #6
Source File: index.js    From ffexplorer with MIT License 6 votes vote down vote up
document.addEventListener('DOMContentLoaded', () => {
    __webpack_public_path__ = FF_EXPLORER_DATA.path.root + 'administrator/components/com_ffexplorer/assets/explorer/dist/';

    locale.use(lang)

    Vue.use(Select);
    Vue.use(Option);
    Vue.use(Input);
    Vue.use(Button);
    Vue.use(Dialog);
    Vue.use(Upload);
    Vue.use(Pagination);
    Vue.use(Loading.directive);

    Vue.prototype.$loading = Loading.service;
    Vue.prototype.$msgbox = MessageBox;
    Vue.prototype.$alert = MessageBox.alert;
    Vue.prototype.$confirm = MessageBox.confirm;
    Vue.prototype.$prompt = MessageBox.prompt;
    Vue.prototype.$message = Message;

    Vue.prototype.$t = function(text) {
        return translate(text);
    }

    Vue.prototype.$ajax = function(options, method) {
        const $ = jQuery;
        const {path, params} = FF_EXPLORER_DATA;
        const url = path.ajax;
    
        return new Promise((resolve, reject) => {
            $.ajax({
                method: method ? method : 'post',
                url: url,
                dataType: 'json',
                data: $.extend({}, params, options),
            })
            .done(response => {
                resolve(response);
            })
            .fail(error => {
                reject(error);
            });
        });
    }

    new Vue({
        store,
        render: h => h(App)
    }).$mount('#explorer-app');
});
Example #7
Source File: element.js    From wl-admin with MIT License 6 votes vote down vote up
/**
 * 确认框,默认确定取消按钮,警告状态
 * @param {*} message 提示语
 * @param {*} title 标题
 * @param {*} options 配置
 */
function wlConfirm(message, title = "提示", options = {}) {
  let _options = {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    ...options
  };
  return MessageBox.confirm(message, title, _options);
}
Example #8
Source File: request.js    From iota-payment-module with MIT License 5 votes vote down vote up
// response interceptor
service.interceptors.response.use(
  /**
   * If you want to get http information such as headers or status
   * Please return  response => response
  */

  /**
   * Determine the request status by custom code
   * Here is just an example
   * You can also judge the status by HTTP Status Code
   */
  response => {
    const data = response.data
    console.log('response', response)
    console.log('data', data)
    // if the status code is not 200, it is judged as an error.
    if (response.status !== 200) {
      Message({
        message: data.message || 'Error',
        type: 'error',
        duration: 5 * 1000
      })

      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
      if (response.status === 50008 || response.status === 50012 || response.status === 50014) {
        // to re-login
        MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
          confirmButtonText: 'Re-Login',
          cancelButtonText: 'Cancel',
          type: 'warning'
        }).then(() => {
          store.dispatch('user/resetToken').then(() => {
            location.reload()
          })
        })
      }
      return Promise.reject(new Error(data.message || 'Error'))
    } else {
      return data
    }
  },
  error => {
    console.log('err: ' + error) // for debug
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)
Example #9
Source File: request.js    From ferry_web with GNU Lesser General Public License v3.0 5 votes vote down vote up
// response interceptor
service.interceptors.response.use(
  /**
   * If you want to get http information such as headers or status
   * Please return  response => response
  */

  /**
   * Determine the request status by custom code
   * Here is just an example
   * You can also judge the status by HTTP Status Code
   */
  response => {
    const code = response.data.code
    if (code === 401) {
      store.dispatch('user/resetToken')
      if (location.href.indexOf('login') !== -1) {
        location.reload() // 为了重新实例化vue-router对象 避免bug
      } else {
        MessageBox.confirm(
          '登录状态已过期,您可以继续留在该页面,或者重新登录',
          '系统提示',
          {
            confirmButtonText: '重新登录',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).then(() => {
          location.reload() // 为了重新实例化vue-router对象 避免bug
        })
      }
    } else if (code === 6401) {
      store.dispatch('user/resetToken')
      MessageBox.confirm(
        '登录状态已过期,您可以继续留在该页面,或者重新登录',
        '系统提示',
        {
          confirmButtonText: '重新登录',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        location.reload() // 为了重新实例化vue-router对象 避免bug
      })
      return false
    } else if (code === 400 || code === 403 || code !== 200) {
      Message({
        message: response.data.msg,
        type: 'error',
        duration: 5 * 1000
      })
      return Promise.reject('error')
    } else {
      return response.data
    }
  },
  error => {
    if (error.message === 'Network Error') {
      Message({
        message: '服务器连接异常,请检查服务器!',
        type: 'error',
        duration: 5 * 1000
      })
      return
    }

    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })

    return Promise.reject(error)
  }
)
Example #10
Source File: request.js    From fund_management-eastmoney with Apache License 2.0 5 votes vote down vote up
// response interceptor
service.interceptors.response.use(
  /**
   * If you want to get http information such as headers or status
   * Please return  response => response
  */

  /**
   * Determine the request status by custom code
   * Here is just an example
   * You can also judge the status by HTTP Status Code
   */
  response => {
    const res = response.data

    // if the custom code is not 20000, it is judged as an error.
    if (res.code !== 20000) {
      Message({
        message: res.message || 'Error',
        type: 'error',
        duration: 5 * 1000
      })

      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
      if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
        // to re-login
        MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
          confirmButtonText: 'Re-Login',
          cancelButtonText: 'Cancel',
          type: 'warning'
        }).then(() => {
          store.dispatch('user/resetToken').then(() => {
            location.reload()
          })
        })
      }
      return Promise.reject(new Error(res.message || 'Error'))
    } else {
      return res
    }
  },
  error => {
    console.log('err' + error) // for debug
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)
Example #11
Source File: request.js    From yshop-gin-vue with Apache License 2.0 5 votes vote down vote up
// response 拦截器
service.interceptors.response.use(
  response => {
    const code = response.status
    console.log("request")
    console.log(code)
    //console.log(response.data.status)
    const newCode = response.data.status
    console.log(newCode)
    // if (newCode != 200 || code < 200 || code > 300) {
    //   Notification.error({
    //     title: response.data.msg
    //   })
    //   return Promise.reject('error')
    // } else {
      return response.data
    //}
  },
  error => {
    console.log("errror")
    let code = 0
    try {
      code = error.response.status
    } catch (e) {
      if (error.toString().indexOf('Error: timeout') !== -1) {
        Notification.error({
          title: '网络请求超时',
          duration: 5000
        })
        return Promise.reject(error)
      }
    }
    if (code) {
      if (code === 401) {
        MessageBox.confirm(
          '登录状态已过期,您可以继续留在该页面,或者重新登录',
          '系统提示',
          {
            confirmButtonText: '重新登录',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).then(() => {
          store.dispatch('LogOut').then(() => {
            location.reload() // 为了重新实例化vue-router对象 避免bug
          })
        })
      } else if (code === 403) {
        router.push({ path: '/401' })
      } else {
        const errorMsg = error.response.data.msg
        if (errorMsg !== undefined) {
          Notification.error({
            title: errorMsg,
            duration: 5000
          })
        }
      }
    } else {
      Notification.error({
        title: '接口请求失败',
        duration: 5000
      })
    }
    return Promise.reject(error)
  }
)
Example #12
Source File: request.js    From report with Apache License 2.0 5 votes vote down vote up
// response 拦截器
service.interceptors.response.use(
  response => {
    /**
     * code为非20000是抛错 可结合自己业务进行修改
     */
    const res = response.data
    // 50008:非法的token; 50012:其他客户端登录了;  50014:Token 过期了;
    if (res.code == '50008' || res.code == '50012' || res.code == '50014') {
      MessageBox.confirm(
        '你已被登出,可以取消继续留在该页面,或者重新登录',
        '重新登录',
        {
          confirmButtonText: '重新登录',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        sessionStorage.clear()
        localStorage.clear()
        window.location.href = "/";
      })
    }
    else if (res.code !== '200') {
      Message({
        message: res.message,
        type: 'error',
        duration: 5 * 1000
      })
      return response.data
    } else {
      return response.data
    }
  },
  error => {
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)
Example #13
Source File: upload.js    From report with Apache License 2.0 5 votes vote down vote up
// response interceptor
service.interceptors.response.use(
  response => {
    const res = response.data;
    if (res.repCode == '0000') {
      return res
    }
    else if (res.repCode == '0024') {
     
      //登录超时或被登出,弹确认框,用户确认后,跳转到登录页面
      MessageBox({
        message: "当前登录已失效或异地登录,请重新登录",
        type: 'error',
        duration: 3 * 1000,
      }).then(() => {
        console.log(1)
        sessionStorage.clear();
        localStorage.clear();
        // location.reload();
        window.location.href = "/";
      }).catch(err => {
        console.log(2)
      })
    }else if(res.repCode == "3100" || res.repCode == "3101"){
      return res;
    }
    else {
      Message({
        message: res.repMsg,
        type: 'error',
        duration: 3 * 1000
      })
      return res;
    }
  },
  error => {
    var errorStatus = error.response.status;
    var errorData = error.response.data;
    var messageTxt = "";
    if (errorStatus != 200) {
      messageTxt = "服务器内部错误,请联系管理员";
    } else {
      messageTxt = '失败原因:' + errorData.repCode + '--' + errorData.repMsg;
    }
    Message({
      message: messageTxt,
      type: 'error',
      duration: 5 * 1000
    })
  }
)
Example #14
Source File: axios.js    From report with Apache License 2.0 5 votes vote down vote up
// response interceptor
service.interceptors.response.use(
  response => {
    const res = response.data;
    if (res.code == 200) {
      return res
    }

    else if (res.code == '50014') {
      //登录超时或被登出,弹确认框,用户确认后,跳转到登录页面
      MessageBox({
        message: "当前登录已失效或异地登录,请重新登录",
        type: 'error',
        duration: 3 * 1000,
      }).then(() => {
        sessionStorage.clear();
        localStorage.clear();
        window.location.href = "/";
      }).catch(err => {
      })
    } else if (res.code == "3100" || res.code == "3101") {
      return res;
    }
    else {
      Message({
        message: res.repMsg || res.message,
        type: 'error',
        duration: 3 * 1000
      })
      return res;
    }
  },
  error => {
    var errorStatus = error.response.code;
    var errorData = error.response.data;
    var messageTxt = "";
    if (errorStatus != 200) {
      messageTxt = "服务器内部错误,请联系管理员";
    } else {
      messageTxt = '失败原因:' + errorData.code + '--' + errorData.repMsg;
    }
    Message({
      message: messageTxt,
      type: 'error',
      duration: 5 * 1000
    })
  }
)
Example #15
Source File: element.js    From vue-shop with MIT License 5 votes vote down vote up
Vue.prototype.$confirm = MessageBox.confirm
Example #16
Source File: vab.js    From vue-admin-better-template with Mozilla Public License 2.0 4 votes vote down vote up
install = (Vue, opts = {}) => {
  /* 全局accessToken */
  Vue.prototype.$baseAccessToken = () => {
    return accessToken || getAccessToken()
  }
  /* 全局标题 */
  Vue.prototype.$baseTitle = (() => {
    return title
  })()
  /* 全局加载层 */
  Vue.prototype.$baseLoading = (index, text) => {
    let loading
    if (!index) {
      loading = Loading.service({
        lock: true,
        text: text || loadingText,
        background: 'hsla(0,0%,100%,.8)',
      })
    } else {
      loading = Loading.service({
        lock: true,
        text: text || loadingText,
        spinner: 'vab-loading-type' + index,
        background: 'hsla(0,0%,100%,.8)',
      })
    }
    return loading
  }
  /* 全局多彩加载层 */
  Vue.prototype.$baseColorfullLoading = (index, text) => {
    let loading
    if (!index) {
      loading = Loading.service({
        lock: true,
        text: text || loadingText,
        spinner: 'dots-loader',
        background: 'hsla(0,0%,100%,.8)',
      })
    } else {
      switch (index) {
        case 1:
          index = 'dots'
          break
        case 2:
          index = 'gauge'
          break
        case 3:
          index = 'inner-circles'
          break
        case 4:
          index = 'plus'
          break
      }
      loading = Loading.service({
        lock: true,
        text: text || loadingText,
        spinner: index + '-loader',
        background: 'hsla(0,0%,100%,.8)',
      })
    }
    return loading
  }
  /* 全局Message */
  Vue.prototype.$baseMessage = (message, type) => {
    Message({
      offset: 60,
      showClose: true,
      message: message,
      type: type,
      dangerouslyUseHTMLString: true,
      duration: messageDuration,
    })
  }

  /* 全局Alert */
  Vue.prototype.$baseAlert = (content, title, callback) => {
    MessageBox.alert(content, title || '温馨提示', {
      confirmButtonText: '确定',
      dangerouslyUseHTMLString: true,
      callback: (action) => {
        if (callback) {
          callback()
        }
      },
    })
  }

  /* 全局Confirm */
  Vue.prototype.$baseConfirm = (content, title, callback1, callback2) => {
    MessageBox.confirm(content, title || '温馨提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      closeOnClickModal: false,
      type: 'warning',
    })
      .then(() => {
        if (callback1) {
          callback1()
        }
      })
      .catch(() => {
        if (callback2) {
          callback2()
        }
      })
  }

  /* 全局Notification */
  Vue.prototype.$baseNotify = (message, title, type, position) => {
    Notification({
      title: title,
      message: message,
      position: position || 'top-right',
      type: type || 'success',
      duration: messageDuration,
    })
  }

  /* 全局TableHeight */
  Vue.prototype.$baseTableHeight = (formType) => {
    let height = window.innerHeight
    let paddingHeight = 400
    const formHeight = 50

    if (layout === 'vertical') {
      paddingHeight = 340
    }

    if ('number' == typeof formType) {
      height = height - paddingHeight - formHeight * formType
    } else {
      height = height - paddingHeight
    }
    return height
  }

  /* 全局lodash */
  Vue.prototype.$baseLodash = lodash
  /* 全局事件总线 */
  Vue.prototype.$baseEventBus = new Vue()
}
Example #17
Source File: request.js    From scan-login-demo with MIT License 4 votes vote down vote up
// response interceptor
service.interceptors.response.use(
  /**
   * Determine the request status by custom code
   * Here is just an example
   * You can also judge the status by HTTP Status Code
   */
  response => {
    const res = response.data

    // if the custom code is not 200, it is judged as an error.
    if (res.code !== 0) {
      const side = judgeSide()
      if (side === 2) {
        Toast.fail(res.msg || '出错啦')
      } else {
        Message({
          message: res.msg || '出错啦',
          type: 'error',
          duration: 2 * 1000
        })
      }
      return Promise.reject(new Error(res.msg || '出错啦'))
    } else {
      return res
    }
  },
  error => {
    const side = judgeSide()
    if (error.message.includes('timeout')) {
      Message({
        message: '网络异常',
        type: 'error',
        duration: 2 * 1000
      })
      return Promise.reject(error)
    }
    if (error.response.status == 403) {
      // to re-login
      if (side === 1) {
        MessageBox.alert('您的登录信息已过期,点击确定重新登录', {
          confirmButtonText: '确定',
          callback: action => {
            store.dispatch('spamst/resetToken').then(() => {
              location.reload()
            })
          }
        })
      } else {
        if (side === 2) {
          Toast({
            type: 'fail',
            message: '您的登录信息已过期,即将重新登录',
            onClose: function() {
              store.dispatch('user/logout').then(() => {
                location.replace('/wx_login')
              })
            }
          })
        } else {
          MessageBox.alert('您的登录信息已过期,点击确定重新登录', {
            confirmButtonText: '确定',
            confirmButtonClass: 'el-button--danger ',
            callback: action => {
              store.dispatch('user/logout').then(() => {
                location.reload()
              })
            }
          })
        }
      }
    } else {
      if (side === 2) {
        Toast.fail(error.response.data.msg || '出错啦')
      } else {
        Message({
          message: error.response.data.msg || '出错啦',
          type: 'error',
          duration: 2 * 1000
        })
      }
    }
    return Promise.reject(error)
  }
)