From 99a3c5eff1f52bf07235e60c4a2a1922e45e3fcb Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期二, 23 九月 2025 16:46:01 +0800
Subject: [PATCH] 附件上传
---
src/pages/production/twist/attachment/index.vue | 56 +++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/src/pages/production/twist/attachment/index.vue b/src/pages/production/twist/attachment/index.vue
index e6c26f5..1af3ac6 100644
--- a/src/pages/production/twist/attachment/index.vue
+++ b/src/pages/production/twist/attachment/index.vue
@@ -55,21 +55,27 @@
const reportType = ref("缁炵嚎");
const attachmentList = ref<any[]>([]);
+const detailData = ref<any>({});
// 鑾峰彇闄勪欢鍒楄〃
-const getAttachmentList = async () => {
+const getAttachmentList = async (data: any) => {
try {
+ detailData.value = data;
+ console.log(" detailData.value", detailData.value);
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = (currentPage as any).options;
- const currentReportId = options?.reportId;
+ const currentReportId = detailData.value.id;
if (currentReportId) {
reportId.value = currentReportId;
// 鐩存帴璋冪敤閫氱敤鏌ョ湅鎺ュ彛鏌ヨ闄勪欢鍒楄〃
// 浣跨敤绀轰緥涓殑闄勪欢ID鏁扮粍 [850,851]
- const attachmentIds: number[] = [850, 851]; // 浣跨敤HTTP鏂囦欢涓殑绀轰緥鏁版嵁
+ const attachmentIds: number[] = detailData.value.attachmentId !== null? detailData.value.attachmentId.split(",") : []; // 浣跨敤HTTP鏂囦欢涓殑绀轰緥鏁版嵁
+ if (attachmentIds.length === 0) {
+ return;
+ }
const { data } = await AttachmentAPI.listAttachmentFiles(attachmentIds);
attachmentList.value = data || [];
} else {
@@ -95,20 +101,30 @@
const filePaths = Array.isArray(res.tempFilePaths)
? res.tempFilePaths
: [res.tempFilePaths];
- const uploadResults = await AttachmentAPI.uploadAttachmentFiles(filePaths);
-
+ const uploadResults: any = await AttachmentAPI.uploadAttachmentFiles(filePaths);
+ const result = uploadResults.map((it) => {
+ return it.data;
+ });
+ console.log("result", result);
+ // 鏇存柊闄勪欢鍒楄〃
+ const flattenedResult = result.flat();
+ attachmentList.value.push(...flattenedResult);
+ console.log(attachmentList.value);
// 鎻愬彇闄勪欢ID
- const attachmentIds = uploadResults.map((result) => result.data.id).join(",");
+ const attachmentId = attachmentList.value.map((item: any) => item.id).join(",");
// 鍏宠仈鍒版姤宸�
- await AttachmentAPI.addOutputAttachments({
- id: parseInt(reportId.value),
- attachmentIds: attachmentIds,
- });
+ if (attachmentId) {
+ await AttachmentAPI.addOutputAttachments({
+ id: parseInt(detailData.value.id),
+ attachmentId: attachmentId,
+ });
+ detailData.value.attachmentId = attachmentId;
+ }
toast.show("涓婁紶鎴愬姛");
// 閲嶆柊鑾峰彇闄勪欢鍒楄〃
- await getAttachmentList();
+ // await getAttachmentList();
} catch (error) {
console.error("涓婁紶澶辫触:", error);
toast.show("涓婁紶澶辫触");
@@ -122,7 +138,7 @@
};
// 鍒犻櫎闄勪欢
-const deleteAttachment = async (attachmentId: number) => {
+const deleteAttachment = async (aid: number) => {
try {
uni.showModal({
title: "纭鍒犻櫎",
@@ -130,18 +146,17 @@
success: async (res) => {
if (res.confirm) {
// 鍓嶇鎵嬪姩鍒犻櫎锛氱洿鎺ヤ粠鍒楄〃涓Щ闄よ繖鏉℃暟鎹�
- attachmentList.value = attachmentList.value.filter((item) => item.id !== attachmentId);
+ attachmentList.value = attachmentList.value.filter((item) => item.id !== aid);
// 鑾峰彇鍓╀綑鐨勯檮浠禝D缁勫悎
- const remainingIds = attachmentList.value.map((item) => item.id);
- const attachmentIds = remainingIds.join(",");
+ const attachmentId = attachmentList.value.map((item) => item.id).join(",");
// 璋冪敤鎶ュ伐娣诲姞闄勪欢鎺ュ彛锛屾洿鏂伴檮浠跺叧鑱�
await AttachmentAPI.addOutputAttachments({
- id: parseInt(reportId.value),
- attachmentIds: attachmentIds,
+ id: parseInt(detailData.value.id),
+ attachmentId: attachmentId,
});
-
+ detailData.value.attachmentId = attachmentId;
toast.show("鍒犻櫎鎴愬姛");
}
},
@@ -235,7 +250,10 @@
};
onMounted(() => {
- getAttachmentList();
+ uni.$on("detailData", (data) => {
+ // 澶勭悊鎺ユ敹鍒扮殑鏁版嵁
+ getAttachmentList(data);
+ });
});
</script>
--
Gitblit v1.9.3