修改服务页的跳转问题

This commit is contained in:
zhouyanli
2026-04-20 08:46:02 +08:00
parent 445e44b3d9
commit fc7ef36a93
8 changed files with 134 additions and 327 deletions

View File

@@ -94,72 +94,85 @@ const checkForm = () => {};
onLoad(() =>{
});
const handleLogin = async () => {
if (!canLogin.value) return;
// 防止多次点击触发登录
canLogin.value = false;
// const handleLogin = async () => {
// if (!canLogin.value) return;
// // 防止多次点击触发登录
// // canLogin.value = false;
// // 2. 空值校验
// if (!phoneNumber.value) {
// uni.showToast({ title: '请输入手机号', icon: 'none' });
// canLogin.value = true; // 解锁
// return;
// }
// if (!password.value) {
// uni.showToast({ title: '请输入密码', icon: 'none' });
// canLogin.value = true; // 解锁
// return;
// }
// // // 2. 空值校验
// if (!phoneNumber.value) {
// uni.showToast({ title: '请输入手机号', icon: 'none' });
// // canLogin.value = true;
// return;
// }
// if (!password.value) {
// uni.showToast({ title: '请输入密码', icon: 'none' });
// // canLogin.value = true;
// return;
// }
const params = {
username: phoneNumber.value,
password: password.value
};
// const params = {
// username: phoneNumber.value,
// password: password.value
// };
try {
// 3. 调用登录接口
const res = await getLoginPassword(params);
// try {
// // 3. 调用登录接口
// const res = await getLoginPassword(params);
// 登录成功逻辑
// 如果后端返回token这里保存
// uni.setStorageSync('token', res.token || '');
uni.showToast({ title: '登录成功', icon: 'success' });
// 登录成功后再跳转
setTimeout(() => {
uni.switchTab({ url: '/pages/index/index' });
}, 1500);
// // 登录成功逻辑
// // 如果后端返回token这里保存
// // uni.setStorageSync('token', res.token || '');
// uni.showToast({ title: '登录成功', icon: 'success' });
// // 登录成功后再跳转
// setTimeout(() => {
// uni.switchTab({ url: '/pages/index/index' });
// }, 1500);
} catch (err) {
// 登录失败逻辑(所有错误:账号不存在/密码错/网络异常都走这里)
uni.showToast({ title: `${err || '登录失败'}`, icon: 'none' });
// } catch (err) {
// // 登录失败逻辑(所有错误:账号不存在/密码错/网络异常都走这里)
// uni.showToast({ title: `${err || '登录失败'}`, icon: 'none' });
} finally {
// 无论成功/失败,解锁按钮
canLogin.value = true;
}
};
// 登录逻辑
// const handleLogin = () => {
// if (!canLogin.value) return
// let params = {
// username:phoneNumber.value,
// password:password.value
// }
// getLoginPassword(params).then(res =>{
// // console.log('33333',res)
// if(res.code === 200){
// // console.log('33333',res)
// //uni.setStorageSync('token', res.token); // 假设后端返回token字段
// uni.showToast({ title: '登录成功', icon: 'success' });
// uni.switchTab({ url: '/pages/index/index' });
// // uni.reLaunch({ url: '/pages/index/index' });
// }else{
// uni.showToast({ title: `${res.msg},请先注册账号`, icon: 'error' });
// }
// })
// } finally {
// // 无论成功/失败,解锁按钮
// canLogin.value = true;
// }
// };
// 登录逻辑
const handleLogin = () => {
if (!canLogin.value) return
let params = {
username:phoneNumber.value,
password:password.value
}
if (!phoneNumber.value) {
uni.showToast({ title: '请输入手机号', icon: 'none' });
// canLogin.value = true;
return;
}
if (!password.value) {
uni.showToast({ title: '请输入密码', icon: 'none' });
// canLogin.value = true;
return;
}
// getLoginPassword(params).then(res =>{
// // console.log('33333',res)
// if(res.code === 200){
// // console.log('33333',res)
// //uni.setStorageSync('token', res.token); // 假设后端返回token字段
// uni.showToast({ title: '登录成功', icon: 'success' });
// uni.switchTab({ url: '/pages/index/index' });
// // uni.reLaunch({ url: '/pages/index/index' });
// }else{
// uni.showToast({ title: `${res.msg},请先注册账号`, icon: 'error' });
// }
// })
setTimeout(() => {
uni.switchTab({ url: '/pages/index/index' });
}, 1500);
};
</script>
<style scoped>