|
80 | 80 | alertTip,
|
81 | 81 | },
|
82 | 82 | methods: {
|
| 83 | + //登陆成功后保存用户信息 |
83 | 84 | ...mapMutations([
|
84 | 85 | 'RECORD_USERINFO',
|
85 | 86 | ]),
|
| 87 | + //改变登陆方式,默认手机登陆 |
86 | 88 | changeLoginWay(){
|
87 | 89 | this.loginWay = !this.loginWay;
|
88 | 90 | },
|
| 91 | + //用户名登陆时是否显示输入的密码 |
89 | 92 | changePassWordType(){
|
90 | 93 | this.showPassword = !this.showPassword;
|
91 | 94 | },
|
| 95 | + //输入手机号码时判断,输入正确的手机号码后方可点击获取短信验证码 |
92 | 96 | inputPhone(){
|
93 | 97 | if(/^1\d{10}$/gi.test(this.phoneNumber)){
|
94 | 98 | this.rightPhoneNumber = true;
|
95 | 99 | }else{
|
96 | 100 | this.rightPhoneNumber = false;
|
97 | 101 | }
|
98 | 102 | },
|
| 103 | + //获取验证码图片 |
99 | 104 | async getCaptchaCode(){
|
100 | 105 | let res = await getcaptchas();
|
101 | 106 |
|
102 | 107 | this.captchaCodeImg = 'https://mainsite-restapi.ele.me/v1/captchas/' + res.code;
|
103 | 108 | },
|
| 109 | + //获取手机验证码 |
104 | 110 | async getVerifyCode(){
|
105 | 111 | if (this.rightPhoneNumber) {
|
106 | 112 | this.computedTime = 30;
|
| 113 | + //30秒倒计时,30秒后可以重新获取验证码 |
107 | 114 | this.timer = setInterval(() => {
|
108 | 115 | this.computedTime --;
|
109 | 116 | if (this.computedTime == 0) {
|
110 | 117 | clearInterval(this.timer)
|
111 | 118 | }
|
112 | 119 | }, 1000)
|
| 120 | + //利用后台接口判断当前手机是否已注册 |
113 | 121 | let exsis = await checkExsis(this.phoneNumber, 'mobile');
|
114 | 122 | if (exsis.message) {
|
115 | 123 | this.showAlert = true;
|
|
120 | 128 | this.alertText = '您输入的手机号尚未绑定';
|
121 | 129 | return
|
122 | 130 | }
|
| 131 | + //返回的数据带message,说明登陆失败 |
123 | 132 | let res = await mobileCode(this.phoneNumber);
|
124 | 133 | if (res.message) {
|
125 | 134 | this.showAlert = true;
|
|
129 | 138 | this.validate_token = res.validate_token;
|
130 | 139 | }
|
131 | 140 | },
|
| 141 | + //登陆 |
132 | 142 | async mobileLogin(){
|
| 143 | + //手机登陆时进行简单的判断 |
133 | 144 | if (this.loginWay) {
|
134 | 145 | if (!this.rightPhoneNumber) {
|
135 | 146 | this.showAlert = true;
|
|
142 | 153 | }
|
143 | 154 | this.userInfo = await sendLogin(this.mobileCode, this.phoneNumber, this.validate_token);
|
144 | 155 | }else{
|
| 156 | + //用户名登陆时进行简单的判断 |
145 | 157 | if (!this.userAccount) {
|
146 | 158 | this.showAlert = true;
|
147 | 159 | this.alertText = '请输入手机号/邮箱/用户名';
|
|
158 | 170 |
|
159 | 171 | this.userInfo = await accountLogin(this.userAccount, this.passWord, this.codeNumber);
|
160 | 172 | }
|
| 173 | + //如果返回的信息没有user_id说明登陆失败,弹出提示 |
161 | 174 | if (!this.userInfo.user_id) {
|
162 | 175 | this.showAlert = true;
|
163 | 176 | this.alertText = this.userInfo.message;
|
164 | 177 | if (!this.loginWay) this.getCaptchaCode();
|
165 | 178 | }else{
|
| 179 | + //登陆成功保存用户信息,返回上一路游 |
166 | 180 | this.RECORD_USERINFO(this.userInfo);
|
167 | 181 | this.$router.go(-1);
|
168 | 182 |
|
169 | 183 | }
|
170 | 184 | },
|
| 185 | + //关闭弹出框 |
171 | 186 | closeTip(){
|
172 | 187 | this.showAlert = false;
|
173 | 188 | }
|
|
0 commit comments