hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
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
<template>
  <div class="use_pwd">
    <v-header title="修改密码"></v-header>
    <div class="fm">
      <section class="sec">
        <p class="label">用户名称:</p>
        <article>
          <b>{{ user.name }}</b>
        </article>
      </section>
      <section class="sec">
        <p class="label">原密码:</p>
        <article>
          <el-input
            size="small"
            v-model="os.oldPassword"
            placeholder="请输入原密码"
            show-password
          ></el-input>
        </article>
      </section>
      <section class="sec">
        <p class="label">新密码:</p>
        <article>
          <el-input
            size="small"
            v-model="os.newPassword"
            placeholder="请输入新密码"
            show-password
            @keyup.native.13="sub"
          ></el-input>
        </article>
      </section>
    </div>
    <div class="btn">
      <el-button size="small" type="primary" @click="sub">确认</el-button>
      <el-button size="small" @click="$router.go(-1)">取消</el-button>
    </div>
  </div>
</template>
 
<script>
export default {
  props: {},
  components: {},
  data() {
    return {
      os: { newPassword: "", oldPassword: "" },
      user: {},
    };
  },
  watch: {},
  methods: {
    sub() {
      var testPassword =
        /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*.`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&.*`~()-+=]+$)(?![0-9\W_!@#$%^.&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&.*`~()-+=]{8,16}$/;
      let x = {
        data: this.os,
        code: 1,
      };
      if (!testPassword.test(x.data.newPassword)) {
        demo.toast(
          "密码强度过低,请将密码长度设置为8-16位,且包含字母、数字、字符"
        );
        return;
      }
      if (!x.code) {
        demo.toast(x.err);
        return 0;
      }
      this.$api.put("changepassword", x.data, (res) => {
        demo.toast("重置成功");
        demo.$local.set("token", "");
        demo.$local.set("r-token", "");
        demo.$session.set("user", "");
        this.$nextTick(() => {
          this.$router.push(this.$nav.url("/login"));
        });
      });
    },
  },
  mounted() {
    this.user = demo.$session.get("user") || {};
  },
};
</script>
<style lang='less' scoped>
.use_pwd {
  font-size: 14px;
  color: #333;
  .fm {
    width: 400px;
  }
  .btn {
    padding: 10px 20px;
  }
  article {
    b {
      line-height: 32px;
    }
  }
}
</style>