新增食堂巡查
This commit is contained in:
parent
ee5e5c335f
commit
231ea614a6
@ -54,6 +54,15 @@ import { ref } from "vue";
|
|||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
import { jlzxFindByJlParamsApi, xxtsSaveByJlzxParamsApi } from "@/api/base/server";
|
import { jlzxFindByJlParamsApi, xxtsSaveByJlzxParamsApi } from "@/api/base/server";
|
||||||
|
|
||||||
|
// 统一接口返回类型声明
|
||||||
|
interface ApiResponse<T = any> {
|
||||||
|
resultCode?: number;
|
||||||
|
result?: T;
|
||||||
|
resultMsg?: string;
|
||||||
|
rows?: T;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
interface StudentInfo {
|
interface StudentInfo {
|
||||||
id: string;
|
id: string;
|
||||||
xsId: string;
|
xsId: string;
|
||||||
@ -78,8 +87,7 @@ const studentList = ref<StudentInfo[]>([]);
|
|||||||
const isPushing = ref(false);
|
const isPushing = ref(false);
|
||||||
|
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
|
if (options && options.jlId && options.jlId !== 'null' && options.jlId !== 'undefined') {
|
||||||
if (options.jlId && options.jlId !== 'null' && options.jlId !== 'undefined') {
|
|
||||||
jlId.value = options.jlId;
|
jlId.value = options.jlId;
|
||||||
loadStudentList();
|
loadStudentList();
|
||||||
} else {
|
} else {
|
||||||
@ -95,7 +103,7 @@ const loadStudentList = async () => {
|
|||||||
try {
|
try {
|
||||||
uni.showLoading({ title: "加载学生信息中..." });
|
uni.showLoading({ title: "加载学生信息中..." });
|
||||||
|
|
||||||
const response = await jlzxFindByJlParamsApi({ jlId: jlId.value });
|
const response = await jlzxFindByJlParamsApi({ jlId: jlId.value }) as ApiResponse<any[]>;
|
||||||
|
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
|
|
||||||
@ -129,7 +137,7 @@ const handleConfirmPush = async () => {
|
|||||||
isPushing.value = true;
|
isPushing.value = true;
|
||||||
uni.showLoading({ title: "推送中..." });
|
uni.showLoading({ title: "推送中..." });
|
||||||
|
|
||||||
const response = await xxtsSaveByJlzxParamsApi({ jlId: jlId.value });
|
const response = await xxtsSaveByJlzxParamsApi({ jlId: jlId.value }) as ApiResponse<any>;
|
||||||
|
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
isPushing.value = false;
|
isPushing.value = false;
|
||||||
@ -148,7 +156,7 @@ const handleConfirmPush = async () => {
|
|||||||
});
|
});
|
||||||
}, 2000);
|
}, 2000);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(response?.resultMsg || "推送失败");
|
throw new Error((response as any)?.resultMsg || "推送失败");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
|
|||||||
@ -150,13 +150,12 @@ const chooseImage = () => {
|
|||||||
sourceType: ['album', 'camera'],
|
sourceType: ['album', 'camera'],
|
||||||
success: async (res) => {
|
success: async (res) => {
|
||||||
// 添加临时图片到列表
|
// 添加临时图片到列表
|
||||||
const newImages = res.tempFilePaths.map(path => ({
|
const tempFilePaths = res.tempFilePaths as string[];
|
||||||
|
const newImages = tempFilePaths.map((path: string) => ({
|
||||||
tempPath: path,
|
tempPath: path,
|
||||||
name: path.split('/').pop() || 'image.jpg'
|
name: path.split('/').pop() || 'image.jpg'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
imageList.value = [...imageList.value, ...newImages];
|
imageList.value = [...imageList.value, ...newImages];
|
||||||
|
|
||||||
// 自动上传图片
|
// 自动上传图片
|
||||||
await uploadImages(newImages);
|
await uploadImages(newImages);
|
||||||
}
|
}
|
||||||
@ -191,7 +190,7 @@ const uploadImages = async (images: ImageItem[]) => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('图片上传失败:', error);
|
console.error('图片上传失败:', error);
|
||||||
showToast(`${image.name || '图片'}上传失败`, 'none');
|
showToast({ title: `${image.name || '图片'}上传失败`, icon: 'none' });
|
||||||
|
|
||||||
// 从列表中移除上传失败的图片
|
// 从列表中移除上传失败的图片
|
||||||
const index = imageList.value.findIndex(img => img.tempPath === image.tempPath);
|
const index = imageList.value.findIndex(img => img.tempPath === image.tempPath);
|
||||||
@ -203,11 +202,11 @@ const uploadImages = async (images: ImageItem[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hideLoading();
|
hideLoading();
|
||||||
showToast('图片上传完成', 'success');
|
showToast({ title: '图片上传完成', icon: 'success' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
console.error('批量上传图片失败:', error);
|
console.error('批量上传图片失败:', error);
|
||||||
showToast('图片上传失败,请重试', 'none');
|
showToast({ title: '图片上传失败,请重试', icon: 'none' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -215,7 +214,7 @@ const uploadImages = async (images: ImageItem[]) => {
|
|||||||
const previewImage = (index: number) => {
|
const previewImage = (index: number) => {
|
||||||
const urls = imageList.value.map(img =>
|
const urls = imageList.value.map(img =>
|
||||||
img.url ? imagUrl(img.url) : img.tempPath
|
img.url ? imagUrl(img.url) : img.tempPath
|
||||||
).filter(url => url);
|
).filter((url): url is string => !!url);
|
||||||
|
|
||||||
uni.previewImage({
|
uni.previewImage({
|
||||||
urls: urls,
|
urls: urls,
|
||||||
@ -237,19 +236,19 @@ const onTimeChange = (e: any) => {
|
|||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
// 验证必填字段
|
// 验证必填字段
|
||||||
if (!formData.value.gzmc.trim()) {
|
if (!formData.value.gzmc.trim()) {
|
||||||
showToast('请输入工作名称', 'none');
|
showToast({ title: '请输入工作名称', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!formData.value.tjtime) {
|
if (!formData.value.tjtime) {
|
||||||
showToast('请选择提交时间', 'none');
|
showToast({ title: '请选择提交时间', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否有图片正在上传
|
// 检查是否有图片正在上传
|
||||||
const hasUploadingImages = imageList.value.some(img => img.tempPath && !img.url);
|
const hasUploadingImages = imageList.value.some(img => img.tempPath && !img.url);
|
||||||
if (hasUploadingImages) {
|
if (hasUploadingImages) {
|
||||||
showToast('请等待图片上传完成', 'none');
|
showToast({ title: '请等待图片上传完成', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,8 +260,9 @@ const handleSubmit = async () => {
|
|||||||
let tjfj = '';
|
let tjfj = '';
|
||||||
const uploadedImages = imageList.value.filter(img => img.url);
|
const uploadedImages = imageList.value.filter(img => img.url);
|
||||||
if (uploadedImages.length > 0) {
|
if (uploadedImages.length > 0) {
|
||||||
// 使用服务器路径,用逗号分隔
|
// 使用服务器路径,用逗号分隔,过滤掉 undefined 值
|
||||||
tjfj = uploadedImages.map(img => img.url).join(',');
|
const imageUrls = uploadedImages.map(img => img.url).filter((url): url is string => !!url);
|
||||||
|
tjfj = imageUrls.join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
const submitData = {
|
const submitData = {
|
||||||
@ -273,7 +273,7 @@ const handleSubmit = async () => {
|
|||||||
await hcSaveApi(submitData);
|
await hcSaveApi(submitData);
|
||||||
|
|
||||||
hideLoading();
|
hideLoading();
|
||||||
showToast('提交成功', 'success');
|
showToast({ title: '提交成功', icon: 'success' });
|
||||||
|
|
||||||
// 返回列表页
|
// 返回列表页
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -282,7 +282,7 @@ const handleSubmit = async () => {
|
|||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
showToast('提交失败,请重试', 'none');
|
showToast({ title: '提交失败,请重试', icon: 'none' });
|
||||||
console.error('提交失败:', error);
|
console.error('提交失败:', error);
|
||||||
} finally {
|
} finally {
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user