进行删除或者编辑等重要操作时,需要输入密码确认权限,弹出密码验证框,验证通过后再执行删除或编辑操作
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 => {
// 验证通过后的操作
})