quanyawei
2024-09-06 75c45150bcc5b1a3b45efe98ce6ec92b7b10aba3
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
<template>
  <a-modal
    title="编辑-账户"
    destoryOnClose
    :visible="visible"
    @cancel="handleCancel"
    @ok="handleOk"
    okText="保存"
  >
    <a-form style="margin-top:8px">
      <a-form-item :labelCol="{span:5}" :wrapperCol="{span:15}" label="用户名">
        <a-input v-model="changeInform.userName" disabled></a-input>
      </a-form-item>
 
      <a-form-item
        :labelCol="{span:5}"
        :wrapperCol="{span:15}"
        label="密码"
        has-feedback
        :validate-status="ruleState"
      >
        <a-input type="password"  placeholder="请输入新密码" v-model="changeInform.password"></a-input>
      </a-form-item>
      <a-form-item
        :labelCol="{span:5}"
        :wrapperCol="{span:15}"
        label="确认密码"
        has-feedback
        :validate-status="ruleStateTo"
        :help="helpErrorContent"
      >
        <a-input type="password" placeholder="再次输入新密码" v-model="changeInform.passnew"></a-input>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
 
<script lang="ts">
    import { Encrypt, Decrypt} from '../../../util/AES.js'
    import { get, post } from "@/util/request";
    import {
        Vue,
        Prop,
        Component,
        Emit,
        Watch
    } from "vue-property-decorator";
    //必须要写,注册成组件
    @Component({
        components: {}
    })
    export default class ChangePassword extends Vue {
        private changeInform:any={
            userName:null,
            password:null,
            passNew:null,
        }
        @Prop({
            type: Boolean,
            default: false
        })
        private visible!: boolean;
 
        @Prop({
            type:Object,
            default(){
                return{};
            }
        })
        private record!:any;
        private helpErrorContent:any=null;
        private ruleState:any=null;
        private ruleStateTo:any=null;
        @Watch('changeInform.password')
        private changePassword(newValue:any,oldValue:any):void{
            if(newValue==""||newValue==null||newValue.length<6){
                this.ruleState=''
            }
            else{
                //密码长度最短为6位
                if(newValue.length>=6){
               this.ruleState='success'
                }
 
            }
        }
        @Watch('changeInform.passnew')
        private changePassnew(newValue:any,oldValue:any):void{
            if(newValue==""||newValue==null){
                this.ruleStateTo=''
                this.helpErrorContent=null;
            }
            else if(newValue==this.changeInform.password){
                this.ruleStateTo='success';
                this.helpErrorContent=null;
            }
            else{
                this.ruleStateTo="error"
                this.helpErrorContent="两次输入密码不一致"
            }
        }
 
        @Watch('record',{
            immediate:true,
            deep:true,
        })
        //回调,拿到数据赋值
        private recordChange(value:any,oldValue:any):void{
            this.changeInform.userName=this.record.userName
 
        }
        //取消,清除密码
        private handleCancel():void{
            this.changeInform.password=null;
            this.changeInform.passn123ew=null;
            this.changVisible(false);
        }
        //保存,网络请求,修改数据库
        private handleOk():void{
 
            if((this.changeInform.password!=null&&this.changeInform.passnew!=null)&&(this.changeInform.password==this.changeInform.passnew)&&this.changeInform.password.length>=6&&this.changeInform.passnew.length>=6)
            {
                //修改数据库
                post("account/update",{
                    accountId:this.record.id,
                    password:Encrypt(this.changeInform.password)
                }).then(res=>{
 
                  if(res.data.code!=0){
                        this.$message.error(res.data.message)
                    }else{
                        this.changeInform.password=null;
                        this.changeInform.passnew=null;
                        //保存成功,组件刷新数据
 
                      this.$message.success(res.data.message)
                        this.$emit('updateData')
                        this.changVisible(false);
                    }
                }).catch(err=>{
                    console.log(err)
                })
            }
        }
        private changVisible(visible:boolean):void{
            this.$emit('update:visible', visible);
        }
    }
</script>