新增食堂巡查

This commit is contained in:
hb 2025-07-21 20:09:51 +08:00
parent ee5e5c335f
commit 231ea614a6
2 changed files with 27 additions and 19 deletions

View File

@ -54,6 +54,15 @@ import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { jlzxFindByJlParamsApi, xxtsSaveByJlzxParamsApi } from "@/api/base/server";
//
interface ApiResponse<T = any> {
resultCode?: number;
result?: T;
resultMsg?: string;
rows?: T;
[key: string]: any;
}
interface StudentInfo {
id: string;
xsId: string;
@ -78,8 +87,7 @@ const studentList = ref<StudentInfo[]>([]);
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<any[]>;
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<any>;
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();

View File

@ -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;