lyh
2026-01-19 22c3bf8b939cd907f171bb4435ad1fc71548d8f7
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
<template>
  <el-dialog
    :visible.sync="dialogVisible"
    width="25%"
    :show-close="false"
    :close-on-click-modal="false"
  >
    <span slot="title" style="display: flex;justify-content: start;font-size: 18px;margin-bottom: 40px">
      修改初始密码
    </span>
    <el-form :model="setPasswordData" label-width="100px" :rules="rules" ref="ruleForm">
      <el-row>
        <el-form-item label="原密码" prop="oldPassword">
          <el-input v-model="setPasswordData.oldPassword" placeholder="请输入原密码" type="password"></el-input>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="新密码" prop="newPassword">
          <el-input v-model="setPasswordData.newPassword" placeholder="请输入新密码" id="newkey" type="password"></el-input>
        </el-form-item>
      </el-row>
    </el-form>
    <span slot="footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="onSubmit" :loading="isloading">保 存</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
  import * as homeApi from '../api/home';
 
  export default {
    name: "init_password",
    components: {},
    props: {
      username: {
        type: String
      }
    },
    data() {
      var validatePass2 = (rule, value, callback) => {
        if (value === "") {
          callback(new Error("请再次输入密码"));
        } else if (value !== this.setPasswordData.newPassword) {
          callback(new Error("两次输入密码不一致!"));
        } else {
          callback();
        }
      };
      return {
        rules: {
          oldPassword: [{required: true, message: "请输入原密码", trigger: 'blur'}],
          newPassword: [
            {
              required: true,
              message: "请输入新密码",
              trigger: 'blur'
            },
            {
              pattern: /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,./]).{8,}$/,
              message: '密码由8位数字、大小写字母和特殊符号组成!',
            }],
        },
        setPasswordData: {
          newPassword: '',
          oldPassword: '',
          userName: ''
        },
        isloading: false,
        dialogVisible: false
      }
    },
    methods: {
      initDialogData() {
        if (this.$refs.ruleForm) this.$refs.ruleForm.resetFields()
      },
 
      onSubmit() {
        this.setPasswordData.userName = this.username
        this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            this.isloading = true
            homeApi.update_password(this.setPasswordData)
              .then((res) => {
                if (res.success) {
                  this.$message.success(res.message);
                  this.$emit('reLogin')
                  this.dialogVisible = false
                } else {
                  this.$message.warning(res.message);
                }
              })
              .catch(err => {
                this.$message.error(err.message);
              })
              .finally(() => {
                this.isloading = false
              })
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        // this.$refs[formName].resetFields();
 
        ``
      },
 
    }
  }
</script>
 
<style scoped>
 
</style>