对接活动实况接口;注掉登录接口代码

This commit is contained in:
zhouyanli
2026-04-27 13:38:24 +08:00
parent ae9465cc0e
commit d52cbbd51b
8 changed files with 256 additions and 115 deletions

View File

@@ -249,7 +249,7 @@ const loadMoreData = () => {
*/
const formatDate = (date) => {
if (!date) return ''
return moment(date).format('YYYY-MM-DD HH:mm:ss')
return moment(date).format('YYYY-MM-DD HH:mm')
}
/**

View File

@@ -37,20 +37,20 @@
<view class="info-section">
<view class="info-item">
<view class="info-label">报名截止时间</view>
<view class="info-value">{{activityConent.applyDeadline}}</view>
<view class="info-value">{{formatTime(activityConent.applyDeadline)}}</view>
</view>
<view class="info-item">
<view class="info-label">活动时间</view>
<view class="info-value">
<text>{{activityConent.startTime}} {{activityConent.endTime}}</text>
<text>{{formatTime(activityConent.startTime)}} {{formatTime(activityConent.endTime)}}</text>
</view>
</view>
<view class="info-item">
<view class="info-label">签到时间</view>
<view class="info-value">
<text>{{activityConent.signinStartTime}} {{activityConent.signinEndTime}}</text>
<text>{{formatTime(activityConent.signinStartTime)}} {{formatTime(activityConent.signinEndTime)}}</text>
</view>
</view>
@@ -97,7 +97,7 @@
<view class="section" style="margin-bottom: 40rpx;">
<view class="section-title">活动详情</view>
<view class="section-content">
<view>{{activityConent.content}}</view>
<view>{{activityConent.content || "暂无"}}</view>
<view></view>
</view>
</view>
@@ -168,7 +168,7 @@
</button>
<!-- 活动实况页显示添加实况按钮 -->
<button class="action-btn add-status-btn" v-if="activeTab === 'status'" @click="liveClick">添加实况</button>
<button class="action-btn add-status-btn" v-if="hasSigned &&activeTab === 'status'" @click="liveClick">添加实况</button>
</view>
<!-- 报名确认模态框 -->
@@ -244,14 +244,32 @@ const liveRecords = ref([
// }
])
// 接受参数
// ========方法=====
// 时间格式化函数
const formatTime = (timeStr) => {
if (!timeStr) return ''
// 格式化YYYY-MM-DD HH:mm:ss → 简化为 YYYY-MM-DD HH:mm
return moment(timeStr).format('YYYY-MM-DD HH:mm')
}
// ---接收参数---
onLoad((option) =>{
navTitle.value = option?.title
curActivityId.value = option?.id
// 处理applied参数可能是字符串类型需要转布尔
hasSigned.value = option?.applied === 'true' || option?.applied === true
// console.log('hasSigned.value',hasSigned.value)
getActivityDetailsData(curActivityId.value)
// 2. 初始化数据
if (curActivityId.value) {
getActivityDetailsData(curActivityId.value) // 获取活动详情
getLiveActivityList() // 获取实况列表
}
// 3. 监听实况列表刷新事件
uni.$on('refreshLiveList', () => {
getLiveActivityList()
})
})
// 获取列表详情
@@ -356,7 +374,7 @@ const cancelActivityData = async () =>{
try{
const res = await cancelActivity(curActivityId.value)
if(res.code === 200){
hasSigned.value = true // 报名成功后更新状态
hasSigned.value = false // 报名成功后更新状态
uni.showToast({
title: '取消报名成功',
icon:"success"
@@ -364,7 +382,7 @@ const cancelActivityData = async () =>{
setTimeout(() =>{
uni.$emit('refreshActivityList', {
activityId: curActivityId.value,
isSigned: true
isSigned: false
})
uni.navigateBack()
},1500)
@@ -414,12 +432,6 @@ const liveClick = () =>{
// 监听实况列表刷新
// ---------
onLoad(() =>{
uni.$on('refreshLiveList', () => {
getLiveActivityList();
});
getLiveActivityList()
})
onUnload(() => {
uni.$off('refreshLiveList')
})
@@ -446,6 +458,12 @@ const showToastMessage = (message) => {
flex-direction: column;
background: linear-gradient(to bottom left, #E2F0FF 0%, #ffffff 50%)
}
/* 状态栏 */
.status_bar {
height: 46px;
width: 100%;
}
/* 顶部导航栏 */
.nav-bar {
height: 90rpx;
@@ -489,10 +507,6 @@ const showToastMessage = (message) => {
overflow-y: auto;
margin-bottom: 120rpx;
}
.status_bar {
height: 46px;
width: 100%;
}
/* 选项卡 */
.tabs {

View File

@@ -98,29 +98,113 @@ const chooseImg = () => {
};
// 删除图片
const deleteImg = (index) => {
imgList.value.splice(index, 1);
};
const deleteImg = (index) => {
imgList.value.splice(index, 1);
};
// 重新定位
const reLocate = () => {
uni.showLoading({ title: '定位中...' });
uni.getLocation({
type: 'gcj02',
success: (res) => {
uni.hideLoading();
longitude.value = res.longitude;
latitude.value = res.latitude;
location.value = `${res.longitude},${res.latitude}`;
uni.showToast({ title: '定位成功', icon: 'success' });
},
fail: (err) => {
uni.hideLoading();
uni.showToast({ title: '定位失败,请检查权限', icon: 'none' });
console.error('定位失败:', err);
}
});
};
// 重新定位
// 定位并获取具体地点名称
const reLocate = () => {
uni.showLoading({ title: '定位中...' });
// 第一步:获取经纬度
uni.getLocation({
type: 'gcj02', // 微信地图专用坐标系,必须用这个
success: (locRes) => {
// 第二步:通过经纬度逆解析为具体地址
uni.request({
url: 'https://apis.map.qq.com/ws/geocoder/v1/', // 腾讯地图逆地理编码接口(免费)
data: {
location: `${locRes.latitude},${locRes.longitude}`, // 纬度,经度
key: 'XCNBZ-TJ46B-BCJUZ-JBMIM-LZWRJ-SBBWW', // 替换成你自己的Key下面教你怎么获取
get_poi: 0 // 0=只返回基础地址1=返回周边POI
},
success: (geoRes) => {
uni.hideLoading();
if (geoRes.data.status === 0) {
// 解析成功,获取具体地址
const address = geoRes.data.result.address; // 完整地址北京市海淀区中关村南大街5号
const formattedAddress = geoRes.data.result.formatted_addresses.recommend; // 推荐地址(更简洁)
const province = geoRes.data.result.address_component.province; // 省
const city = geoRes.data.result.address_component.city; // 市
const district = geoRes.data.result.address_component.district; // 区
const street = geoRes.data.result.address_component.street; // 街道
// 保存数据(按需选择)
longitude.value = locRes.longitude;
latitude.value = locRes.latitude;
location.value = address; // 把location改为存储具体地址而非经纬度
// 也可以自定义格式location.value = `${city}${district}${street}`;
// 提示定位成功并显示地址
uni.showToast({ title: `定位成功:${formattedAddress}`, icon: 'success', duration: 2000 });
console.log('完整地址:', address);
console.log('省市区:', province, city, district);
} else {
// 解析地址失败,降级显示经纬度
location.value = `${locRes.longitude},${locRes.latitude}`;
uni.showToast({ title: '定位成功,但无法解析地址', icon: 'none' });
}
},
fail: (geoErr) => {
uni.hideLoading();
// 接口请求失败,降级显示经纬度
location.value = `${locRes.longitude},${locRes.latitude}`;
uni.showToast({ title: '定位成功,地址解析失败', icon: 'none' });
console.error('地址解析失败:', geoErr);
}
});
},
fail: (locErr) => {
uni.hideLoading();
uni.showToast({ title: '定位失败,请检查权限', icon: 'none' });
console.error('定位失败:', locErr);
}
});
};
// const reLocate = () => {
// // 调用微信原生选择位置接口(自带地址解析,无调用上限)
// uni.chooseLocation({
// success: (res) => {
// // res.address = 具体地址XX市XX区XX街道XX小区
// // res.name = 地点名称XX小区
// longitude.value = res.longitude;
// latitude.value = res.latitude;
// location.value = res.address; // 显示具体地址
// uni.showToast({ title: `定位成功:${res.name}`, icon: 'success' });
// },
// fail: (err) => {
// // 处理权限拒绝/定位失败
// if (err.errMsg.includes('auth deny')) {
// uni.showModal({
// title: '需要定位权限',
// content: '请允许获取位置信息以显示具体地点',
// confirmText: '去设置',
// success: (modalRes) => {
// if (modalRes.confirm) {
// uni.openSetting({
// success: (settingRes) => {
// // 用户开启权限后重新定位
// if (settingRes.authSetting['scope.userLocation']) {
// reLocate();
// }
// }
// });
// }
// }
// });
// } else {
// uni.hideLoading();
// uni.showToast({ title: '定位失败,请重试', icon: 'none' });
// console.error('定位失败:', err);
// }
// }
// });
// };
// 上传所有图片
const uploadAllImages = async () => {

View File

@@ -93,7 +93,7 @@ const phoneNumber = ref('');
const verifyCode = ref('');
const placeholderStyle = ref('font-size:24rpx')
// 是否同意协议
const agreeAgreement = ref(true); // 默认勾选
const agreeAgreement = ref(false); // 默认勾选
// 倒计时(秒)
const countDown = ref(0);
// 定时器
@@ -173,42 +173,50 @@ const handleLogin = () => {
smsCode:'123456',
scene:'login',
}
getLoginBySms(params).then(res =>{
if(res.code === 200){
if(res.data){
uni.setStorageSync('token', res.data.token);
// 存用户ID
if(res.data.userId) {
uni.setStorageSync('userId', res.data.userId);
}
// 存当前绑定的小区ID0 表示未绑定
const currentVillageId = res.data.currentVillageId || 0;
uni.setStorageSync('currentVillageId', currentVillageId);
uni.hideLoading();
uni.showToast({ title: '登录成功', icon: 'success' });
setTimeout(() =>{
uni.switchTab({ url: '/pages/index/index' });
},1500)
}else{
uni.showToast({ title: '登录失败', icon: 'error' });
}
// getLoginBySms(params).then(res =>{
// if(res.code === 200){
// if(res.data){
// uni.setStorageSync('token', res.data.token);
// // 存用户ID
// if(res.data.userId) {
// uni.setStorageSync('userId', res.data.userId);
// }
// // 存当前绑定的小区ID0 表示未绑定
// const currentVillageId = res.data.currentVillageId || 0;
// uni.setStorageSync('currentVillageId', currentVillageId);
// uni.hideLoading();
// uni.showToast({ title: '登录成功', icon: 'success' });
// setTimeout(() =>{
// uni.switchTab({ url: '/pages/index/index' });
// },1500)
// }else{
// uni.showToast({ title: '登录失败', icon: 'error' });
// }
}else{
uni.showToast({ title:'登录失败', icon: 'error' });
}
// }else{
// uni.showToast({ title:'登录失败', icon: 'error' });
// }
}).catch(err => {
uni.showToast({
title: '网络异常,请重试',
icon: 'error'
});
})
// }).catch(err => {
// uni.showToast({
// title: '网络异常,请重试',
// icon: 'error'
// });
// })
// 模拟登录请求
// uni.showLoading({
// title: '登录中...'
// });
uni.showLoading({
title: '登录中...'
});
uni.showToast({
title:"登录成功",
icon:'success'
})
setTimeout(() =>{
uni.switchTab({ url: '/pages/index/index' });
},1500)
uni.hideLoading()
};
// ========== 生命周期 ==========

View File

@@ -72,7 +72,7 @@ import {getLoginPassword} from '../api/api.js'
// 响应式数据
const phoneNumber = ref('');
const password = ref('');
const agreeAgreement = ref(true); // 默认勾选
const agreeAgreement = ref(false); // 默认勾选
const placeholderStyle = ref('font-size:24rpx')
// 计算属性:是否可登录(帐号+密码+协议都满足)
@@ -118,43 +118,43 @@ const handleLogin = () => {
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
if(res.data) {
// 存当前绑定的小区ID0 表示未绑定
const currentVillageId = res.data.currentVillageId || 0;
uni.setStorageSync('currentVillageId', currentVillageId);
}
uni.hideLoading();
uni.showToast({ title: '登录成功', icon: 'success' });
setTimeout(() =>{
uni.switchTab({
url: '/pages/index/index'
},1000);
})
}else{
uni.showToast({ title: res.msg, icon: 'error' });
}
// getLoginPassword(params).then(res =>{
// // console.log('33333',res)
// if(res.code === 200){
// uni.setStorageSync('token', res.data.token);
// // 存用户ID
// if(res.data) {
// // 存当前绑定的小区ID0 表示未绑定
// const currentVillageId = res.data.currentVillageId || 0;
// uni.setStorageSync('currentVillageId', currentVillageId);
// }
// uni.hideLoading();
// uni.showToast({ title: '登录成功', icon: 'success' });
// setTimeout(() =>{
// uni.switchTab({
// url: '/pages/index/index'
// },1000);
// })
// }else{
// uni.showToast({ title: res.msg, icon: 'error' });
// }
}).catch(err => {
uni.showToast({
title: '网络异常',
icon: 'error'
});
})
// }).catch(err => {
// uni.showToast({
// title: '网络异常',
// icon: 'error'
// });
// })
// 测试
// uni.showLoading({
// title: '登录中...',
// mask:true
// });
// setTimeout(() => {
// uni.switchTab({ url: '/pages/index/index' });
// }, 1500);
// uni.hideLoading()
uni.showLoading({
title: '登录中...',
mask:true
});
setTimeout(() => {
uni.switchTab({ url: '/pages/index/index' });
}, 1500);
uni.hideLoading()
};
</script>

View File

@@ -147,7 +147,7 @@ const submitForm = () => {
uni.showToast({ title: '提交成功', icon: 'success' })
// 提交成功后重置表单/返回上一页
// form.value = { title: '', desc: '', phone: '', images: [] }
form.value = { title: '', desc: '', phone: '', images: [] }
// 或返回上一页
uni.navigateBack({ delta: 3 })
}, 1000)