优化登录提示语,优化request错误返回提示语

This commit is contained in:
zhouyanli
2026-05-12 17:33:46 +08:00
parent f2f5c5e050
commit fa017d657f
8 changed files with 119 additions and 39 deletions

View File

@@ -176,7 +176,14 @@ const narBack = () => {
*/
const switchTab = (tab) => {
activeTab.value = tab
if (tab === 'list') {
resetAndLoad()
} else {
// 暂无审核功能,"我的活动"默认显示暂无数据
displayedActivities.value = []
hasMoreData.value = false
currentPage.value = 1
}
}
/**
@@ -185,7 +192,7 @@ const switchTab = (tab) => {
*/
const switchFilter = (filter) => {
myFilter.value = filter
resetAndLoad()
// resetAndLoad()
}
/**
@@ -287,7 +294,9 @@ const viewActivityDetail = (activity) => {
* 页面显示时刷新数据
*/
onShow(() => {
if (activeTab.value === 'list') {
getActivityListData(1) // 强制刷新第一页
}
})
/**
@@ -296,7 +305,7 @@ onShow(() => {
onLoad(() => {
// 监听详情页报名/取消报名后的刷新通知
uni.$on('refreshActivityList', (data) => {
console.log('收到活动列表刷新通知:', data)
// console.log('收到活动列表刷新通知:', data)
getActivityListData(1)
})
})
@@ -312,9 +321,7 @@ onUnload(() => {
* 监听我的活动筛选条件变化
*/
watch(() => myFilter.value, () => {
if (activeTab.value === 'my') {
resetAndLoad()
}
// 暂无审核功能,筛选条件暂不触发加载
})
</script>

View File

@@ -22,6 +22,10 @@ export const getResetPassword = (data) =>{
return post('/api/resident/auth/resetPassword',data)
}
// =========首页=======
// 获取bannar图
export const getBannarList = (data) =>{
return get('/resident/banner',data)
}
// 首页最新公告
export const getNoticeLatest = () =>{
return get('/api/resident/notice/latest')

View File

@@ -26,7 +26,7 @@ export default function request(url, data = {}, method = "GET") {
// HTTP 失败
if (res.statusCode !== 200) {
reject(`请求异常 ${res.statusCode}`);
reject({ msg: `请求异常 ${res.statusCode}`, code: res.statusCode });
return;
}
@@ -39,7 +39,7 @@ export default function request(url, data = {}, method = "GET") {
setTimeout(() => {
uni.reLaunch({ url: '/pageSubPack/loginSub/pwd-login' });
}, 1500);
reject('登录过期');
reject({ msg: '登录过期', code: 401 });
return;
}
@@ -47,14 +47,14 @@ export default function request(url, data = {}, method = "GET") {
if (resData.code === 200) {
resolve(resData);
}
// 业务失败:只 reject不弹窗
// 业务失败
else {
reject(resData); // 把完整错误返回给页面!
reject({ msg: resData.msg || '请求失败', code: resData.code, data: resData });
}
},
fail: (err) => {
uni.hideLoading();
reject(err);
reject({ msg: '网络异常', code: -1, raw: err });
}
});
});

View File

@@ -62,7 +62,6 @@
<!-- 登录按钮 -->
<button
class="login-btn"
:disabled="!canLogin"
@click="handleLogin"
>
登录
@@ -166,7 +165,26 @@ const getVerifyCode = () => {
// 登录处理
const handleLogin = () => {
if (!canLogin.value) return;
if (!phoneNumber.value) {
uni.showToast({ title: '请输入手机号', icon: 'none' });
return;
}
if (!/^1[3-9]\d{9}$/.test(phoneNumber.value)) {
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
return;
}
if (!verifyCode.value) {
uni.showToast({ title: '请输入验证码', icon: 'none' });
return;
}
if (!/^\d{6}$/.test(verifyCode.value)) {
uni.showToast({ title: '验证码为 6 位数字', icon: 'none' });
return;
}
if (!agreeAgreement.value) {
uni.showToast({ title: '请勾选协议', icon: 'none' });
return;
}
uni.showLoading({ title: '登录中...', mask: true });
let params = {
phone:phoneNumber.value,

View File

@@ -55,7 +55,6 @@
<!-- 登录按钮 -->
<button
class="login-btn"
:disabled="!canLogin"
@click="handleLogin"
>
登录
@@ -109,30 +108,37 @@ onLoad(() =>{
// 登录逻辑
const handleLogin = () => {
// if (!canLogin.value) {
// uni.showToast({ title: '请输入账号和密码', icon: 'none' });
// return
// }
if (!phoneNumber.value) {
uni.showToast({ title: '请输入账号', icon: 'none' });
return;
}
if (phoneNumber.value.length < 4 || phoneNumber.value.length > 16) {
uni.showToast({ title: '账号长度需为 4-16 位', icon: 'none' });
return;
}
if (!password.value) {
uni.showToast({ title: '请输入密码', icon: 'none' });
return;
}
if (password.value.length < 6) {
uni.showToast({ title: '密码至少输入 6 位', icon: 'none' });
return;
}
if (password.value.length > 16) {
uni.showToast({ title: '密码不能超过 16 位', icon: 'none' });
return;
}
if(!agreeAgreement.value){
uni.showToast({ title: '请勾选协议', icon: 'none' });
return;
}
// uni.showLoading({ title: '登录中...', mask: true });
uni.showLoading({ title: '登录中...', mask: true });
let params = {
username:phoneNumber.value,
password:password.value
}
getLoginPassword(params).then(res =>{
// console.log('33333',res)
if(res.code === 200){
uni.setStorageSync('token', res.data.token);
// 存用户ID
@@ -160,16 +166,6 @@ const handleLogin = () => {
});
})
// 测试
// uni.showLoading({
// title: '登录中...',
// mask:true
// });
// setTimeout(() => {
// uni.switchTab({ url: '/pages/index/index' });
// }, 1500);
// uni.hideLoading()
};
</script>

View File

@@ -74,7 +74,7 @@
<!-- 立即注册按钮 -->
<button class="register-btn" :disabled="!canRegister" @click="handleRegister">
<button class="register-btn" @click="handleRegister">
立即注册
</button>
@@ -191,7 +191,46 @@
// 处理注册逻辑
const handleRegister = () => {
if (!canRegister.value) return;
if (!phoneNumber.value) {
uni.showToast({ title: '请输入手机号', icon: 'none' });
return;
}
if (!/^1[3-9]\d{9}$/.test(phoneNumber.value)) {
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
return;
}
if (!verifyCode.value) {
uni.showToast({ title: '请输入验证码', icon: 'none' });
return;
}
if (!/^\d{6}$/.test(verifyCode.value)) {
uni.showToast({ title: '验证码为 6 位数字', icon: 'none' });
return;
}
if (!account.value) {
uni.showToast({ title: '请输入账号', icon: 'none' });
return;
}
if (account.value.length < 4 || account.value.length > 20) {
uni.showToast({ title: '账号长度需为 4-20 位', icon: 'none' });
return;
}
if (!password.value) {
uni.showToast({ title: '请输入密码', icon: 'none' });
return;
}
if (password.value.length < 6) {
uni.showToast({ title: '密码至少输入 6 位', icon: 'none' });
return;
}
if (password.value.length > 16) {
uni.showToast({ title: '密码不能超过 16 位', icon: 'none' });
return;
}
if (!agreeAgreement.value) {
uni.showToast({ title: '请勾选协议', icon: 'none' });
return;
}
uni.showLoading({
title: '注册中...',
mask: true

View File

@@ -267,11 +267,12 @@ const previewImage = (url) => {
.photo-item {
width: 80px;
height: 80px;
border: 1px dashed #ccc;
/* border: 1px solid #ccc; */
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
background-color: #f5f5f5;
}
.btn-container {

View File

@@ -165,7 +165,7 @@
import { ref } from 'vue'
import {onLoad,onUnload,onShow} from '@dcloudio/uni-app'
import moment from 'moment'
import {getNoticeLatest,getCurrentVillage,getActivitylatest} from "/pageSubPack/api/api.js"
import {getNoticeLatest,getCurrentVillage,getActivitylatest,getBannarList} from "/pageSubPack/api/api.js"
// 列表数据状态
@@ -176,7 +176,7 @@ const currentCommunity = ref('请认证小区')
const currentVillageId = ref('')
const bannerList = ref([
// 'http://47.104.199.163:9090/images/home/banner.png',
"http://47.104.199.163:9090/images/propertyImgs/serviceImg2.png"
// "http://47.104.199.163:9090/images/propertyImgs/serviceImg2.png"
])
const noticeText = ref('暂无公告')
@@ -195,6 +195,20 @@ const getNoticeMore = () =>{
url:"/pageSubPack/notice-list/noticeList"
})
}
// 获取bannar列表
const getbannarData = async () =>{
try{
const res = await getBannarList({villageId:uni.getStorageSync('currentVillageId')})
if(res.code === 200){
bannerList.value = res.data.map(item =>item.url)
}else{
uni.showToast({title:'获取失败',icon:'error'})
}
}catch (err){
const msg = err?.msg || (typeof err === 'string' ? err : '获取失败')
uni.showToast({title: msg,icon:'error'})
}
}
// 接收选择小区返回的参数
const slelctHomeData = (data) =>{
// console.log('收到B页面返回的数据', data)
@@ -221,7 +235,7 @@ const getCurrentCommunityData = () => {
}
}).catch(err =>{
uni.showToast({
title: '网络异常',
title: err.msg || '网络异常',
icon: 'error'
});
})
@@ -251,7 +265,7 @@ const getNoticeData = async() =>{
} catch (err) {
// console.error('获取通知数据异常:', err)
uni.showToast({
title: err.msg,
title: err.msg || '网络异常',
icon: 'error',
duration: 1000
})
@@ -276,6 +290,7 @@ onLoad(() => {
}
getNoticeData()
getNewActivityList()
getbannarData()
})
// 页面销毁时移除监听(防止内存泄漏)