resetpassword.vue 4.59 KB
Newer Older
lxyang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
<template>
  <div class="reset">
    <el-form
      ref="loginForm"
      :model="loginForm"
      :rules="loginRules"
      class="reset-form"
      label-width="100px"
    >
      <h3 style="display: inline-block">重置密码</h3>
      &nbsp;<span>原密码已过期,需重置密码</span>
      <el-form-item label="登录账号">
        &#12288;
        <div style="display: inline-block">{{ loginForm.userName }}</div>
      </el-form-item>
      <el-form-item prop="oldPassword" label="原密码">
        &#12288;
        <el-input
          show-password
          style="width: 200px"
          v-model="loginForm.oldPassword"
          type="password"
          auto-complete="new-password"
          placeholder="请输入原密码"
        >
        </el-input>
      </el-form-item>
      <el-form-item prop="newPassword" label="新密码">
        &#12288;
        <el-input
          v-model="loginForm.newPassword"
          type="password"
          show-password
          style="width: 200px"
          auto-complete="new-password"
          placeholder="请输入新密码"
          @keyup.enter.native="certain"
        >
        </el-input>
      </el-form-item>
      <el-form-item prop="prePassword" label="确认新密码">
        &#12288;
        <el-input
          v-model="loginForm.prePassword"
          type="password"
          show-password
          auto-complete="new-password"
          style="width: 200px"
          placeholder="请再次输入新密码"
          @keyup.enter.native="certain"
        >
        </el-input>
      </el-form-item>
      <div class="footer">
        <el-button size="medium" type="primary" @click.native.prevent="certain">
          确定
        </el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-form>
    <!--  底部  -->
    <div class="el-login-footer">
      <span>Copyright © 2018-2019 AdsDesk All Rights Reserved.</span>
    </div>
  </div>
</template>

<script>
import { resetPassword } from "@/api/resetpassword";

export default {
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.loginForm.newPassword) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      loginForm: {
        oldPassword: "",
        newPassword: "",
        prePassword: "",
        userName: this.$route.query.username,
      },
      loginRules: {
        oldPassword: [
          { required: true, trigger: "blur", message: "原密码不能为空" },
        ],
        newPassword: [
          {
            required: true,
            trigger: "blur",
            message: "新密码不能为空",
          },
        ],
        prePassword: [{ trigger: "blur", validator: validatePass2 }],
      },
    };
  },
  created() {
    console.log(this.$route)
    this.loginForm.admin=this.$route.query.username
    
  },
  methods: {
    cancel() {
      this.$router.push({ path: "/login" });
    },
    certain() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.rePassword();
        } else {
          return false;
        }
      });
    },
    rePassword() {
      const {
        userName,
        oldPassword,
        newPassword,
        prePassword,
      } = this.loginForm;
      const data = {
        userName,
        oldPassword,
        newPassword,
        prePassword,
      };
      resetPassword(data).then((res) => {
        this.$notify({
          message: "操作成功!",
          type: "success",
        });
        this.$router.push({ path: "/login" });
      });
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss">
.reset {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/image/login-background.jpg");
  background-size: cover;
}

.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.reset-form {
  border-radius: 6px;
  background: #ffffff;
  width: 470px;
  padding: 25px 25px 5px 25px;
}

.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}

.login-code {
  width: 33%;
  height: 38px;
  float: right;

  img {
    cursor: pointer;
    vertical-align: middle;
  }
}

.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.el-form-item__error {
  left: 6%;
}
.footer {
  margin: auto;
  width: 48%;
  padding: 10px;
}
</style>