饿了么表单重置修改密码
<el-table>
......
<el-table-column fixed="right" label="操作" width="190">
<template slot-scope="scope">
<el-button
style="color: #409eff"
@click="handleClick(scope.row.userId)"
type="text"
size="small"
>修改</el-button
>
<el-button
style="color: #e6a23c"
@click="pwdRestClick(scope.row.userId)"
type="text"
size="small"
>密码重置</el-button
>
<el-button
style="color: #f56c6c"
type="text"
size="small"
@click="editPwdClick(scope.row.userId)"
>修改密码</el-button
>
</template>
</el-table-column>
</el-table>
<el-dialog
class="dialog"
:visible.sync="dialogVisible"
width="35%"
:before-close="close"
>
<div slot="title" class="header">
<span class="header_title">密码修改</span>
</div>
<div class="line"></div>
<el-form ref="ruleForm" :model="ruleForm" :rules="rules">
<el-form-item label="旧密码" prop="oldPwd">
<el-input
show-password
v-model="ruleForm.oldPwd"
placeholder="请输入旧密码"
>
</el-input>
</el-form-item>
<el-form-item label="新密码" prop="newPwd">
<el-input
show-password
v-model="ruleForm.newPwd"
placeholder="请输入新密码"
>
</el-input>
</el-form-item>
<el-form-item label="重复密码" prop="confirmPwd">
<el-input
show-password
v-model="ruleForm.confirmPwd"
placeholder="请再次输入密码"
>
</el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="close">取 消</el-button>
<el-button type="primary" @click="submit">确 定</el-button>
</span>
</el-dialog>
......
methods:{
pwdRestClick(userId) {
this.$confirm("确定要将此用户密码重置吗?", "密码重置提醒", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
this.$api.userResetPwd({ userId: userId }).then((result) => {
if (result.code == 0) {
this.$message.success("密码重置成功!");
}
});
})
.catch(() => {});
},
editPwdClick(userId) {
console.log(userId);
this.dialogVisible = true;
this.userId = userId;
this.ruleForm = {
oldPwd: "",
newPwd: "",
confirmPwd: "",
};
},
submit() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
delete this.ruleForm.confirmPwd;
this.$api
.userModifyPassword({ ...this.ruleForm, userId: this.userId })
.then((result) => {
console.log(result);
if (result.code == 0) {
this.$message.success("密码修改成功");
this.loadDataList();
}
});
}
});
},
close() {
this.dialogVisible = false;
},
}
修改密码时候传递参数为
{
"oldPwd": "3456",
"newPwd": "password01!",
"userId": "admin"
}
delete this.ruleForm.confirmPwd;// 删除confirmPwd字段
this.$api.userModifyPassword({ ...this.ruleForm, userId: this.userId })
...this.ruleForm 解构 ruleForm,并把 userId: this.userId 加上