element $prompt封装二验框

进行删除或者编辑等重要操作时,需要输入密码确认权限,弹出密码验证框,验证通过后再执行删除或编辑操作

1、utils.js方法封装
  var ConfirmPass = function (text, that, ok) {
    // 二验框
    that.$prompt(text, '密码', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      inputType: 'password',
      inputErrorMessage: "请输入密码",
      inputValidator: (value) => {
        if (!value) {
          return '请输入密码'
        }
      },
      beforeClose: (action, instance, done)=> {
        if (action === 'confirm') {
          // 密码验证接口,自定义
          let loginObj = {
            username: JSON.parse(this.getSession('userInfo')).username,
            password: instance.inputValue
          }
          whcPost(whcCont.urlLogin, loginObj, function(data, textStatus) {
            let dataInfo = whcPostParse(data, that)
            // 验证通过执行done()关闭弹框,进行下一步操作
            if (dataInfo) done()
          }, this)
        } else {
           // 取消验证,执行done()关闭弹框
          done()
        }
      }
    }).then(() => {
      // 验证通过后操作
      ok('ok')
    }).catch((err) => {
      console.log('err', err);
      that.$message({
        type: 'info',
        message: '已取消'
      })
    })
  },
2、引用
let that = this
ConfirmPass('请输入密码', that, ok => {
  // 验证通过后的操作
})
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容