代码优化
This commit is contained in:
@@ -8,21 +8,21 @@
|
||||
<view style="font-size: 58rpx;font-weight: bold;color: #333;margin-bottom: 48rpx;">重置密码</view>
|
||||
<view class="cu-form-group">
|
||||
<view class="title">手机号</view>
|
||||
<input class="input" type="number" :value="mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile"
|
||||
<input class="input" type="number" :value="data.mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile"
|
||||
@input="inputChange" />
|
||||
</view>
|
||||
<view class="cu-form-group">
|
||||
<text class="title">验证码</text>
|
||||
<view class="input flex">
|
||||
<input type="number" :value="code" placeholder="请输入验证码" maxlength="6" data-key="code"
|
||||
<input type="number" :value="data.code" placeholder="请输入验证码" maxlength="6" data-key="code"
|
||||
@input="inputChange" @confirm="reset" />
|
||||
<button class="send-msg" @click="sendMsg" :disabled="sending">{{ sendTime }}</button>
|
||||
<button class="send-msg" @click="sendMsg" :disabled="data.sending">{{ data.sendTime }}</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="cu-form-group">
|
||||
<text class="title">设置密码</text>
|
||||
<input class="input" type="password" :value="password" placeholder="请设置新密码" placeholder-class="input-empty"
|
||||
<input class="input" type="password" :value="data.password" placeholder="请设置新密码" placeholder-class="input-empty"
|
||||
maxlength="20" minlength="6" data-key="password" @input="inputChange" @confirm="reset" />
|
||||
</view>
|
||||
<button class="confirm-btn" @click="reset">立即重置</button>
|
||||
@@ -32,169 +32,148 @@
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup>
|
||||
import { reactive } from 'vue';
|
||||
import { onLoad} from '@dcloudio/uni-app'
|
||||
import http from '@/http/http.js';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
code: '',
|
||||
mobile: '',
|
||||
password: '',
|
||||
sending: false,
|
||||
sendTime: '获取验证码',
|
||||
count: 60,
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
methods: {
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*/
|
||||
sendMsg() {
|
||||
if (!this.mobile) {
|
||||
let data = reactive({
|
||||
code: '',
|
||||
mobile: '',
|
||||
password: '',
|
||||
sending: false,
|
||||
sendTime: '获取验证码',
|
||||
count: 60,
|
||||
})
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*/
|
||||
function sendMsg() {
|
||||
if (!data.mobile) {
|
||||
uni.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else if (data.mobile.length !== 11) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else {
|
||||
uni.showLoading({
|
||||
title: '正在发送验证码...'
|
||||
})
|
||||
http.request({
|
||||
url:'app/Login/sendMsg/' + data.mobile + '/forget',
|
||||
}).then(res => {
|
||||
if ( res.code == 0 ) {
|
||||
data.sending = true;
|
||||
uni.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else if (this.mobile.length !== 11) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的手机号',
|
||||
title: '验证码发送成功请注意查收',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
data.countDown();
|
||||
} else {
|
||||
uni.showLoading({
|
||||
title: '正在发送验证码...'
|
||||
})
|
||||
http.request({
|
||||
url:'app/Login/sendMsg/' + this.mobile + '/forget',
|
||||
}).then(res => {
|
||||
if ( res.code == 0 ) {
|
||||
this.sending = true;
|
||||
uni.showToast({
|
||||
title: '验证码发送成功请注意查收',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
this.countDown();
|
||||
} else {
|
||||
uni.showModal({
|
||||
showCancel: false,
|
||||
title: '短信发送失败',
|
||||
content: res.msg ? res.msg : '请一分钟后再获取验证码'
|
||||
});
|
||||
}
|
||||
|
||||
uni.hideLoading();
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 验证码倒计时
|
||||
*/
|
||||
countDown() {
|
||||
const { count } = this;
|
||||
if (count === 1) {
|
||||
this.count = 60;
|
||||
this.sending = false;
|
||||
this.sendTime = '获取验证码';
|
||||
} else {
|
||||
this.count = count - 1;
|
||||
this.sending = true;
|
||||
this.sendTime = count - 1 + '秒后重新获取';
|
||||
setTimeout(this.countDown.bind(this), 1000);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取手机号/验证码/密码
|
||||
* @param {Object} e
|
||||
*/
|
||||
inputChange(e) {
|
||||
const key = e.currentTarget.dataset.key;
|
||||
this[key] = e.detail.value;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
reset() {
|
||||
const {
|
||||
mobile,
|
||||
password,
|
||||
code
|
||||
} = this;
|
||||
if (!mobile) {
|
||||
// this.$queue.showToast("请输入手机号");
|
||||
uni.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else if (!code) {
|
||||
// this.$queue.showToast("密码位数必须大于六位");
|
||||
uni.showToast({
|
||||
title: '请输入验证码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else if (!password) {
|
||||
// this.$queue.showToast("请设置密码");
|
||||
uni.showToast({
|
||||
title: '请输入密码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else {
|
||||
this.loginIng = true;
|
||||
// this.$queue.showLoading("正在修改密码中...");
|
||||
uni.showLoading({
|
||||
title: '正在修改密码中...'
|
||||
})
|
||||
http.request({
|
||||
url: 'app/Login/forgetPwd?pwd=' + password + '&phone=' + mobile + '&msg=' + code,
|
||||
method: 'post'
|
||||
}).then(
|
||||
res => {
|
||||
// this.$Request.postJson("/appLogin/forgetPwd",{
|
||||
// pwd: password,
|
||||
// phone: mobile,
|
||||
// msg: code
|
||||
// }).then(res => {
|
||||
uni.hideLoading();
|
||||
if (res.code === 0) {
|
||||
uni.showToast({
|
||||
title: '密码找回成功',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(function() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
}, 1000)
|
||||
|
||||
} else {
|
||||
|
||||
uni.showModal({
|
||||
showCancel: false,
|
||||
title: '密码找回失败',
|
||||
content: res.msg,
|
||||
});
|
||||
}
|
||||
});
|
||||
uni.showModal({
|
||||
showCancel: false,
|
||||
title: '短信发送失败',
|
||||
content: res.msg ? res.msg : '请一分钟后再获取验证码'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
uni.hideLoading();
|
||||
})
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码倒计时
|
||||
*/
|
||||
function countDown() {
|
||||
if (data.count === 1) {
|
||||
data.count = 60;
|
||||
data.sending = false;
|
||||
data.sendTime = '获取验证码';
|
||||
} else {
|
||||
data.count = count - 1;
|
||||
data.sending = true;
|
||||
data.sendTime = count - 1 + '秒后重新获取';
|
||||
setTimeout(data.countDown.bind(data), 1000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取手机号/验证码/密码
|
||||
* @param {Object} e
|
||||
*/
|
||||
function inputChange(e) {
|
||||
const key = e.currentTarget.dataset.key;
|
||||
data[key] = e.detail.value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
function reset() {
|
||||
|
||||
if (!data.mobile) {
|
||||
uni.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else if (!data.code) {
|
||||
uni.showToast({
|
||||
title: '请输入验证码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else if (!data.password) {
|
||||
uni.showToast({
|
||||
title: '请输入密码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else {
|
||||
data.loginIng = true;
|
||||
uni.showLoading({
|
||||
title: '正在修改密码中...'
|
||||
})
|
||||
http.request({
|
||||
url: 'app/Login/forgetPwd?pwd=' + data.password + '&phone=' + data.mobile + '&msg=' + data.code,
|
||||
method: 'post'
|
||||
}).then(
|
||||
res => {
|
||||
|
||||
uni.hideLoading();
|
||||
if (res.code === 0) {
|
||||
uni.showToast({
|
||||
title: '密码找回成功',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(function() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
}, 1000)
|
||||
|
||||
} else {
|
||||
|
||||
uni.showModal({
|
||||
showCancel: false,
|
||||
title: '密码找回失败',
|
||||
content: res.msg,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" >
|
||||
|
||||
Reference in New Issue
Block a user