对接切换小区接口

This commit is contained in:
zhouyanli
2026-04-22 18:00:48 +08:00
parent c71102f256
commit 057758772e
9 changed files with 493 additions and 404 deletions

View File

@@ -157,9 +157,8 @@
<script setup>
import { ref } from 'vue'
import {onLoad,onUnload} from '@dcloudio/uni-app'
import {getNoticeList} from "/pageSubPack/api/api.js"
import {onLoad,onUnload,onShow} from '@dcloudio/uni-app'
import {getNoticeLatest,getCurrentVillage} from "/pageSubPack/api/api.js"
// 列表数据状态
@@ -187,14 +186,17 @@ const activityList = ref([
// },
])
const currentCommunity = ref('碧桂园小区')
const currentCommunity = ref('请认证小区')
const currentVillageId = ref('')
const bannerList = ref([
'http://47.104.199.163:9090/images/home/banner.png',
])
const noticeText = ref('公告公告本小区今天安装了摄像头')
const noticeText = ref('暂无公告')
const noticeId = ref('')
// =======方法=======
// 公告跳转
const getNoticeMore = () =>{
uni.setStorageSync('sourcePage',"index")
uni.navigateTo({
@@ -203,31 +205,82 @@ const getNoticeMore = () =>{
}
// 接收选择小区返回的参数
const slelctHomeData = (data) =>{
// console.log('收到B页面返回的数据', data)
currentCommunity.value = data.name
console.log('收到B页面返回的数据', data)
if(data.name){
currentCommunity.value = data.name
}
if(data.villageId){
currentVillageId.value = data.villageId
}
getCurrentCommunityData()
}
// 获取当前认证小区的方法
const getCurrentCommunityData = () => {
getCurrentVillage().then(res =>{
if(res.code === 200 && res.data && res.data.villageId){
currentCommunity.value = res.data.villageName || '未命名小区'
currentVillageId.value = res.data.villageId
uni.setStorageSync('currentVillageId',res.data.villageId)
}else{
currentCommunity.value = '请认证小区'
currentVillageId.value = ''
}
}).catch(err =>{
uni.showToast({
title: '网络异常',
icon: 'error'
});
})
}
// 获取小区公告
// const getNoticeData = () =>{
// getNoticeList().then(res =>{
// if(res.code === 200){
// noticeText.value = res.data.noticeTitle
// }else{
// noticeText.value = ''
// }
// }).catch(err =>{
// uni.showToast({
// title: '网络异常',
// icon: 'error'
// });
// })
// }
const getNoticeData = async() =>{
try{
const res = await getNoticeLatest()
if (res.code === 200) {
if(res.data){
noticeText.value = res.data.noticeTitle || ''
noticeId.value = res.data.noticeId || ''
}else{
noticeText.value = ''
noticeId.value = ''
}
} else {
uni.showToast({
title: res.msg || '获取通知失败',
icon: 'none',
duration: 2000
})
}
} catch (err) {
// console.error('获取通知数据异常:', err)
uni.showToast({
title: err.msg,
icon: 'error',
duration: 1000
})
noticeText.value = ''
noticeId.value = ''
}
}
onShow(() =>{
})
onLoad(() => {
// 绑定全局事件监听
uni.$on('confirm', slelctHomeData)
// getNoticeData()
// 页面加载时先判断是否有token有则获取认证小区
const token = uni.getStorageSync('token') || '';
const currentVillageId = uni.getStorageSync('currentVillageId');
if (token && currentVillageId && currentVillageId !== '0' && currentVillageId !== 0) {
getCurrentCommunityData(); // 加载时获取认证小区
}
getNoticeData()
})
// 页面销毁时移除监听(防止内存泄漏)
@@ -250,33 +303,32 @@ const payMentClick =() =>{
})
}
// 点击小区选择
// const navigateToPage = () => {
// // 获取登录状态 / token
// const token = uni.getStorageSync('token') || '';
// // 获取是否已经认证
// const userInfo = uni.getStorageSync('userInfo') || {};
// // 未登录 / 未认证 → 去我的页面(去认证)
// // 已登录 / 已认证 → 去选择小区
// if (!token || !userInfo.isAuth) {
// uni.showToast({
// title: '请先完成实名认证',
// icon: 'none'
// });
// // 跳转到我的页面
// uni.switchTab({
// url: '/pages/myIndex/myIndex'
// });
// } else {
// uni.navigateTo({
// url: '/pageSubPack/notice-list/selectHome'
// });
// }
// };
const navigateToPage = () => {
uni.navigateTo({
url: '/pageSubPack/notice-list/selectHome'
})
}
const token = uni.getStorageSync('token') || '';
const cachedVillageId = uni.getStorageSync('currentVillageId');
// 未登录 或 未绑定小区 → 去我的页面认证
if (!token || !cachedVillageId || cachedVillageId === '0' || cachedVillageId === 0) {
currentCommunity.value = '请去认证小区';
uni.setStorageSync('currentCommunity', '请去认证小区');
uni.showToast({
title: '请先绑定小区',
icon: 'none',
duration: 1500
});
setTimeout(() => {
uni.switchTab({
url: '/pages/myIndex/myIndex',
});
}, 1500);
} else {
// 已登录且已绑定小区 → 去选择小区
uni.navigateTo({
url: `/pageSubPack/notice-list/selectHome?villageId=${cachedVillageId}`
});
}
};
const onlineRepairClick = () =>{
uni.setStorageSync('sourcePage',"index")
uni.navigateTo({