This commit is contained in:
给我
2026-04-16 14:21:25 +08:00
parent f8e99b7c77
commit c3b2a20ad0
14 changed files with 1026 additions and 572 deletions

View File

@ -28,7 +28,7 @@
<div class="preview-label">已拍照片</div>
<div class="photo-grid">
<div v-for="(photo, index) in photos" :key="index" class="photo-item">
<van-image :src="photo" fit="cover" class="photo-img">
<van-image :src="photo.base64" fit="cover" class="photo-img">
<template v-slot:loading>
<van-loading type="spinner" size="20" />
</template>
@ -68,7 +68,7 @@
<!-- 底部保存按钮 -->
<div class="submit-bar">
<van-button block round type="primary" class="submit-btn" @click="handleSave">
<van-button block round type="primary" class="submit-btn" :loading="isSubmitting" @click="handleSave">
保存
</van-button>
</div>
@ -76,9 +76,11 @@
</template>
<script setup>
import { ref, computed } from "vue";
import { ref, computed, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import { Toast } from "vant";
import { feedback, uploadFile } from "@/api/traffic";
import { hintToast } from "@/utils/tools";
const router = useRouter();
const route = useRoute();
@ -94,8 +96,10 @@ const pageTitle = computed(() => {
// 表单数据
const feedbackText = ref("");
const photos = ref([]);
// photos 存储 { base64, fileId } 对象base64 用于预览fileId 用于提交
const photos = ref(['http://220.166.58.28:172/profile/upload/2026/04/15/bb_total_active_20260415150856A001.png']);
const videos = ref([]);
const isSubmitting = ref(false);
// 返回
function goBack() {
@ -108,19 +112,17 @@ function handleTakePhoto() {
if (window.bridge && window.bridge.pZ) {
window.bridge.pZ("photo");
} else {
// H5 环境模拟
const mockPhoto = "https://picsum.photos/400/300?random=" + Date.now();
photos.value.push(mockPhoto);
hintToast("请使用APP进行拍照");
}
} catch (err) {
console.error("拍照失败:", err);
Toast("请使用APP进行拍照");
hintToast("请使用APP进行拍照");
}
}
// 录视频
function handleTakeVideo() {
Toast("视频录制功能开发中...");
hintToast("视频录制功能开发中...");
}
// 删除照片
@ -133,38 +135,81 @@ function deleteVideo(index) {
videos.value.splice(index, 1);
}
// 保存反馈
async function handleSave() {
if (photos.value.length === 0 && videos.value.length === 0 && !feedbackText.value) {
Toast("请至少上传照片或填写反馈内容");
return;
}
try {
Toast.loading({
message: "提交中...",
forbidClick: true,
duration: 0,
});
// 模拟提交
await new Promise((resolve) => setTimeout(resolve, 1500));
Toast.clear();
Toast.success("保存成功!");
setTimeout(() => {
router.back();
}, 1000);
} catch (error) {
Toast.clear();
Toast.fail("保存失败,请重试");
// 将 base64 转为 Blob
function base64ToBlob(base64) {
const parts = base64.split(',');
const mime = parts[0].match(/:(.*?);/)[1];
const byteString = atob(parts[1]);
const arrayBuffer = new ArrayBuffer(byteString.length);
const uint8Array = new Uint8Array(arrayBuffer);
for (let i = 0; i < byteString.length; i++) {
uint8Array[i] = byteString.charCodeAt(i);
}
return new Blob([arrayBuffer], { type: mime });
}
// 接收原生APP返回的图片
function setimagebase64(base64) {
photos.value.push(`data:image/jpeg;base64,${base64}`);
const preview = `data:image/jpeg;base64,${base64}`;
const tempId = `uploading_${Date.now()}`;
photos.value.push({ id: tempId, base64: preview, fileId: "" });
const blob = base64ToBlob(base64);
const fileName = `photo_${Date.now()}.jpg`;
const file = new File([blob], fileName, { type: blob.type });
uploadFile(file)
.then((res) => {
const idx = photos.value.findIndex((p) => p.id === tempId);
if (idx !== -1) {
photos.value[idx].fileId = res;
}
})
.catch((e) => {
console.error("图片上传失败:", e);
const idx = photos.value.findIndex((p) => p.id === tempId);
if (idx !== -1) {
photos.value.splice(idx, 1);
}
});
}
// 保存反馈
function handleSave() {
if (!feedbackText.value.trim()) {
hintToast("请输入反馈内容");
return;
}
if (isSubmitting.value) return;
isSubmitting.value = true;
Toast.loading({ message: "提交中...", forbidClick: true, duration: 0 });
const images = photos.value.map((p) => p.fileId).filter(Boolean).join(",");
feedback({
taskId: alertId,
feedback: feedbackText.value,
images,
video: "",
filesUrl: "",
singUrl: ""
})
.then(() => {
Toast.clear();
hintToast("保存成功");
setTimeout(() => {
router.back();
}, 1000);
})
.catch((e) => {
Toast.clear();
hintToast(e.message || "保存失败,请重试");
})
.finally(() => {
isSubmitting.value = false;
});
}
onMounted(() => {
window.setimagebase64 = setimagebase64;
});
</script>
<style lang="scss" scoped>