1
hao
2025-05-20 8e24c6fea30d9b179375ee2893710cdec2443b13
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
/**
 * 修改用户密码
 * */
//获取路径uri
var picCode;
$(function(){
    picCode = drawPic();
    //监控(发送验证码)
    layui.use(['form' ,'layer'], function() {
        var form = layui.form;
        var layer = layui.layer;
        //监控提交
        form.on("submit(getMsg)",function (data) {
            //sendMsg();
            var flag=checkData();
            if(flag!=false){
                sendMessage(this,true);
            }
            return false;
        });
        //确认手机号
        form.on("submit(updatePwd)",function () {
            updatePwd();
            return false;
        });
        //确认修改密码
        form.on("submit(setPwd)",function () {
            setPwd();
            return false;
        });
    })
})
function checkData(){
//  校验
    var mobile=$("#telephone").val();
    var code=$("#picCode").val();
    if("ok"!=ValidateUtils.checkMobile(mobile)){
        //tips层-右
        layer.tips(ValidateUtils.checkMobile(mobile), '#telephone', {
            tips: [2, '#78BA32'], //还可配置颜色
            tipsMore: true
        });
        return false;
    }
    if("ok"!=ValidateUtils.checkPicCode(code)){
        //tips层-右
        layer.tips(ValidateUtils.checkPicCode(code), '#canvas', {
            tips: [2, '#78BA32'], //还可配置颜色
            tipsMore: true
        });
        return false;
    }
    if(picCode.toLowerCase()!=code.toLowerCase()){
        //tips层-右
        layer.tips("请您输入正确的验证码", '#canvas', {
            tips: [2, '#78BA32'], //还可配置颜色
            tipsMore: true
        });
        return false;
    }
}
var wait=60;
function sendMessage(o,flag){
    if (!flag) {
        return false;
    }
    //第一次秒数
    if (wait == 60) {
        o.setAttribute("disabled", true);
        //自定义验证规则
        $.post("/user/sendMessage", {"mobile":$("#telephone").val(),"picCode":$("#picCode").val()}, function (data) {
 
            if (data.code == "1000") {
                layer.msg("发送短信成功");
            } else {
                picCode = drawPic();
                $("#picCode").val("");
                layer.alert(data.message);
                //禁用发送短信验证码按钮
                o.removeAttribute("disabled");
                //o.value = "获取验证码";
                wait = 60;
                flag = false;
            }
            return false;
        });
    }
    if (wait == 0) {
        o.removeAttribute("disabled");
        $("#getMsgBtn").html("获取验证码");
        wait = 60;
    } else {
        o.setAttribute("disabled", true);
        if (wait <60) {
            $("#getMsgBtn").html("<span style='margin-left: -12px;'>"+wait + "s后可重新发送</span>");
        }
        wait--;
        setTimeout(function () {
            if (wait == 0) {
                flag = true
            };
            send(o, flag)
        }, 1000)
    }
}
function updatePwd(){
    var flag=checkData();
    if(flag!=false){
        var mobileCode=$("#mobileCode").val();
        if("ok"!=ValidateUtils.checkCode(mobileCode)){
            //tips层-右
            layer.tips("请您输入正确的验证码", '#getMsgBtn', {
                tips: [2, '#78BA32'], //还可配置颜色
                tipsMore: true
            });
            return false;
        }
        $.post("/user/updatePwd",{"mobile":$("#telephone").val(),"picCode":$("#picCode").val(),"mobileCode":mobileCode},function(data){
         
            if(data.code=="1000"){
                layer.closeAll();
                layer.open({
                    type:1,
                    title: "设置新密码",
                    fixed:false,
                    resize :false,
                    shadeClose: true,
                    area: ['450px'],
                    content:$('#pwdDiv')
                });
            }else{
                picCode=drawPic();
                $("#picCode").val("");
                $("#mobileCode").val("");
                layer.alert(data.message);
            }
        });
 
    }
}
function setPwd(){
    var pwd=$("#pwd").val();
    var isPwd=$("#isPwd").val();
    if(pwd!=isPwd){
        //tips层-右
        $("#isPwd").val("");
        $("#isPwd").val("");
        layer.tips("两次输入的密码不一致", '#isPwd', {
            tips: [2, '#78BA32'], //还可配置颜色
            tipsMore: true
        });
        return false;
    }
    if("ok"!=ValidateUtils.checkSimplePassword(pwd) || "ok"!=ValidateUtils.checkSimplePassword(isPwd)){
        //tips层-右
        $("#pwd").val("");
        $("#pwd").val("");
        $("#isPwd").val("");
        $("#isPwd").val("");
        layer.alert("密码格式有误,请您重新输入");
        return false;
    }
    $.post("/user/setPwd",{"pwd":pwd,"isPwd":isPwd},function(data){
       
        if(data.code=="1000"){
            layer.alert("操作成功",function () {
                layer.closeAll();
                window.location.href="/logout";
            });
        }else{
            layer.alert(data.message,function () {
                layer.closeAll();
                //window.location.href="/index";
            });
        }
    });
}