对接活动、实况等接口

This commit is contained in:
zhouyanli
2026-04-25 17:23:57 +08:00
parent 06a391a668
commit ae9465cc0e
6 changed files with 746 additions and 723 deletions

View File

@@ -54,16 +54,27 @@
<script setup>
import { ref } from 'vue';
// import { chooseImage, uploadFile, getLocation } from '@dcloudio/uni-app';
import { onLoad } from '@dcloudio/uni-app';
import { addActivityLive, signinActivityLive, uploadImage } from '../api/api.js';
// 活动ID
const activityId = ref('');
// 实况描述内容
const statusDesc = ref('');
// 输入字符长度
const currentLength = ref(0);
// 图片列表
// 图片列表(本地临时路径)
const imgList = ref([]);
// 定位信息
const location = ref('山东省日照市东港区学院路');
// 经纬度
const longitude = ref('');
const latitude = ref('');
// 接收活动ID
onLoad((option) => {
activityId.value = option?.id || '';
});
// 监听输入框字数变化
const handleTextInput = (e) => {
@@ -73,11 +84,10 @@ const handleTextInput = (e) => {
// 选择图片
const chooseImg = () => {
uni.chooseImage({
count: 3 - imgList.value.length, // 最多可选择的数量
count: 3 - imgList.value.length,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
// 临时文件路径转存到图片列表
imgList.value = [...imgList.value, ...res.tempFilePaths];
},
fail: (err) => {
@@ -99,8 +109,9 @@ const reLocate = () => {
type: 'gcj02',
success: (res) => {
uni.hideLoading();
// 实际项目中可调用逆地理编码接口转换为具体地址,这里模拟
location.value = '山东省日照市东港区学院路(新定位)';
longitude.value = res.longitude;
latitude.value = res.latitude;
location.value = `${res.longitude},${res.latitude}`;
uni.showToast({ title: '定位成功', icon: 'success' });
},
fail: (err) => {
@@ -111,34 +122,58 @@ const reLocate = () => {
});
};
// 上传所有图片
const uploadAllImages = async () => {
if (imgList.value.length === 0) return [];
const uploadPromises = imgList.value.map(img => uploadImage(img));
const results = await Promise.all(uploadPromises);
return results.map(res => res.data?.url || res.data);
};
// 提交实况
const submitStatus = () => {
// 简单校验
const submitStatus = async () => {
if (!statusDesc.value.trim()) {
uni.showToast({ title: '请输入实况描述', icon: 'none' });
return;
}
if (!activityId.value) {
uni.showToast({ title: '活动ID缺失', icon: 'none' });
return;
}
// 模拟提交逻辑(实际项目中可上传图片+提交表单)
uni.showLoading({ title: '提交中...' });
// 如需上传图片可循环调用uploadFile
// 示例:
// const uploadPromises = imgList.value.map(img => {
// return uploadFile({
// url: '你的上传接口',
// filePath: img,
// name: 'file'
// });
// });
// Promise.all(uploadPromises).then(res => { /* 处理上传结果 */ });
uni.showLoading({ title: '提交中...', mask: true });
try {
// 上传图片
const imageUrls = await uploadAllImages();
// 提交实况
const liveData = {
content: statusDesc.value.trim(),
images: imageUrls,
location: location.value,
longitude: longitude.value,
latitude: latitude.value
};
await addActivityLive(activityId.value, liveData);
// 同时签到
await signinActivityLive(activityId.value, {
location: location.value,
longitude: longitude.value,
latitude: latitude.value
});
setTimeout(() => {
uni.hideLoading();
uni.showToast({ title: '添加成功', icon: 'success' });
// 提交成功后可返回上一页
uni.navigateBack();
}, 1000);
uni.$emit('refreshLiveList');
setTimeout(() => {
uni.navigateBack();
}, 1500);
} catch (err) {
uni.hideLoading();
uni.showToast({ title: err || '提交失败', icon: 'none' });
}
};
</script>