el-form 表单修改重置密码

饿了么表单重置修改密码

<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 加上

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值