Newer
Older
KaiFengH5 / src / views / home / editPassword.vue
@鲁yixuan 鲁yixuan on 9 Jul 2 KB update
<template>
  <!-- 修改密码 -->
  <div class="editPass">
    <div class="main">
      <van-form @submit="onSubmit" class="form">
        <van-cell-group>
          <van-field
            v-model="allData.password"
            type="password"
            name="password"
            label="旧密码"
            placeholder="旧密码"
            :rules="[{ required: true, message: '请输入' }]"
          />
          <van-field
            v-model="allData.newPassword"
            type="password"
            name="newPassword"
            label="新密码"
            placeholder="新密码"
            :rules="[{ pattern, required: true, message: '请输入由字母+数字组成的6-16位密码' }]"
          />
          <van-field
            v-model="allData.newPassword2"
            type="password"
            name="newPassword2"
            label="确认新密码"
            placeholder="确认新密码"
            :rules="[{ pattern, required: true, message: '请输入由字母+数字组成的6-16位密码' }]"
          />
        </van-cell-group>
        <div class="btns">
          <van-button class="btn" type="primary" block native-type="submit">确定</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script setup name="editPass">
// import { updateUserPwd } from '@/api/publicApi.js';
// import { EncryptAES } from '@/utils/AES.js';
import { useRouter } from 'vue-router';

const { proxy } = getCurrentInstance();
const router = useRouter();
const allData = reactive({
  password: '',
  newPassword: '',
  newPassword2: '',
  defaultUrl: '',
});

// 密码校验 字母+数字组成的6-16位密码
const pattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;

const onSubmit = async (values) => {
  if (allData.newPassword != allData.newPassword2) {
    proxy.showFailToast('新密码和确认密码不一致');
    return;
  }
  if (allData.password == allData.newPassword || allData.password == allData.newPassword2) {
    proxy.showFailToast('新密码和旧密码不能相同');
    return;
  }
  let params = {
    password: allData.password,
    newpassword: allData.newPassword,
    againpassword: allData.newPassword,
    userNo: localStorage.getItem('userNo'),
  };
  // let res = await updateUserPwd({ data: params });
  // if (res && res.data.code == 1) {
  //   proxy.showSuccessToast('密码修改成功');
  //   localStorage.setItem('passwordGCApp', allData.password);
  //   router.push('/login');
  // }
};
onMounted(() => {});
</script>
<style lang="less">
.editPass {
  width: 100%;
  .main {
    .form {
      margin: 40px auto;
      width: 90%;
      .btns {
        margin-top: 80px;
        .btn {
          width: 100%;
          margin: 30px auto;
        }
      }
    }
  }
}
</style>