From 231ea614a68032977038154219ebc3f3b91d8887 Mon Sep 17 00:00:00 2001 From: hb Date: Mon, 21 Jul 2025 20:09:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A3=9F=E5=A0=82=E5=B7=A1?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/view/notice/push-list.vue | 18 +++++++++---- src/pages/view/routine/ShiTangXunCha/add.vue | 28 ++++++++++---------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/pages/view/notice/push-list.vue b/src/pages/view/notice/push-list.vue index 03023fb..04059cd 100644 --- a/src/pages/view/notice/push-list.vue +++ b/src/pages/view/notice/push-list.vue @@ -54,6 +54,15 @@ import { ref } from "vue"; import { onLoad } from "@dcloudio/uni-app"; import { jlzxFindByJlParamsApi, xxtsSaveByJlzxParamsApi } from "@/api/base/server"; +// 统一接口返回类型声明 +interface ApiResponse { + resultCode?: number; + result?: T; + resultMsg?: string; + rows?: T; + [key: string]: any; +} + interface StudentInfo { id: string; xsId: string; @@ -78,8 +87,7 @@ const studentList = ref([]); const isPushing = ref(false); onLoad((options) => { - - if (options.jlId && options.jlId !== 'null' && options.jlId !== 'undefined') { + if (options && options.jlId && options.jlId !== 'null' && options.jlId !== 'undefined') { jlId.value = options.jlId; loadStudentList(); } else { @@ -95,7 +103,7 @@ const loadStudentList = async () => { try { uni.showLoading({ title: "加载学生信息中..." }); - const response = await jlzxFindByJlParamsApi({ jlId: jlId.value }); + const response = await jlzxFindByJlParamsApi({ jlId: jlId.value }) as ApiResponse; uni.hideLoading(); @@ -129,7 +137,7 @@ const handleConfirmPush = async () => { isPushing.value = true; uni.showLoading({ title: "推送中..." }); - const response = await xxtsSaveByJlzxParamsApi({ jlId: jlId.value }); + const response = await xxtsSaveByJlzxParamsApi({ jlId: jlId.value }) as ApiResponse; uni.hideLoading(); isPushing.value = false; @@ -148,7 +156,7 @@ const handleConfirmPush = async () => { }); }, 2000); } else { - throw new Error(response?.resultMsg || "推送失败"); + throw new Error((response as any)?.resultMsg || "推送失败"); } } catch (error) { uni.hideLoading(); diff --git a/src/pages/view/routine/ShiTangXunCha/add.vue b/src/pages/view/routine/ShiTangXunCha/add.vue index 18946dd..6750802 100644 --- a/src/pages/view/routine/ShiTangXunCha/add.vue +++ b/src/pages/view/routine/ShiTangXunCha/add.vue @@ -150,13 +150,12 @@ const chooseImage = () => { sourceType: ['album', 'camera'], success: async (res) => { // 添加临时图片到列表 - const newImages = res.tempFilePaths.map(path => ({ + const tempFilePaths = res.tempFilePaths as string[]; + const newImages = tempFilePaths.map((path: string) => ({ tempPath: path, name: path.split('/').pop() || 'image.jpg' })); - imageList.value = [...imageList.value, ...newImages]; - // 自动上传图片 await uploadImages(newImages); } @@ -191,7 +190,7 @@ const uploadImages = async (images: ImageItem[]) => { } } catch (error) { console.error('图片上传失败:', error); - showToast(`${image.name || '图片'}上传失败`, 'none'); + showToast({ title: `${image.name || '图片'}上传失败`, icon: 'none' }); // 从列表中移除上传失败的图片 const index = imageList.value.findIndex(img => img.tempPath === image.tempPath); @@ -203,11 +202,11 @@ const uploadImages = async (images: ImageItem[]) => { } hideLoading(); - showToast('图片上传完成', 'success'); + showToast({ title: '图片上传完成', icon: 'success' }); } catch (error) { hideLoading(); console.error('批量上传图片失败:', error); - showToast('图片上传失败,请重试', 'none'); + showToast({ title: '图片上传失败,请重试', icon: 'none' }); } }; @@ -215,7 +214,7 @@ const uploadImages = async (images: ImageItem[]) => { const previewImage = (index: number) => { const urls = imageList.value.map(img => img.url ? imagUrl(img.url) : img.tempPath - ).filter(url => url); + ).filter((url): url is string => !!url); uni.previewImage({ urls: urls, @@ -237,19 +236,19 @@ const onTimeChange = (e: any) => { const handleSubmit = async () => { // 验证必填字段 if (!formData.value.gzmc.trim()) { - showToast('请输入工作名称', 'none'); + showToast({ title: '请输入工作名称', icon: 'none' }); return; } if (!formData.value.tjtime) { - showToast('请选择提交时间', 'none'); + showToast({ title: '请选择提交时间', icon: 'none' }); return; } // 检查是否有图片正在上传 const hasUploadingImages = imageList.value.some(img => img.tempPath && !img.url); if (hasUploadingImages) { - showToast('请等待图片上传完成', 'none'); + showToast({ title: '请等待图片上传完成', icon: 'none' }); return; } @@ -261,8 +260,9 @@ const handleSubmit = async () => { let tjfj = ''; const uploadedImages = imageList.value.filter(img => img.url); if (uploadedImages.length > 0) { - // 使用服务器路径,用逗号分隔 - tjfj = uploadedImages.map(img => img.url).join(','); + // 使用服务器路径,用逗号分隔,过滤掉 undefined 值 + const imageUrls = uploadedImages.map(img => img.url).filter((url): url is string => !!url); + tjfj = imageUrls.join(','); } const submitData = { @@ -273,7 +273,7 @@ const handleSubmit = async () => { await hcSaveApi(submitData); hideLoading(); - showToast('提交成功', 'success'); + showToast({ title: '提交成功', icon: 'success' }); // 返回列表页 setTimeout(() => { @@ -282,7 +282,7 @@ const handleSubmit = async () => { } catch (error) { hideLoading(); - showToast('提交失败,请重试', 'none'); + showToast({ title: '提交失败,请重试', icon: 'none' }); console.error('提交失败:', error); } finally { submitting.value = false;