From 99a3c5eff1f52bf07235e60c4a2a1922e45e3fcb Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期二, 23 九月 2025 16:46:01 +0800
Subject: [PATCH] 附件上传
---
/dev/null | 2
src/pages/production/wire/report/wire.vue | 10 ++-
src/pages/production/twist/report/index.vue | 16 ++--
src/pages/production/twist/attachment/index.vue | 56 ++++++++++++------
src/api/product/attachment.ts | 2
src/pages/production/wire/attachment/index.vue | 58 ++++++++++++------
6 files changed, 91 insertions(+), 53 deletions(-)
diff --git a/.husky/commit-msg b/.husky/commit-msg
deleted file mode 100644
index fd2bf70..0000000
--- a/.husky/commit-msg
+++ /dev/null
@@ -1 +0,0 @@
-npx --no-install commitlint --edit $1
diff --git a/.husky/pre-commit b/.husky/pre-commit
deleted file mode 100644
index a3ec6f2..0000000
--- a/.husky/pre-commit
+++ /dev/null
@@ -1,2 +0,0 @@
-echo "Running pre-commit hook..."
-pnpm run lint:lint-staged
diff --git a/src/api/product/attachment.ts b/src/api/product/attachment.ts
index 7776169..56ce2c1 100644
--- a/src/api/product/attachment.ts
+++ b/src/api/product/attachment.ts
@@ -63,7 +63,7 @@
},
// 鎶ュ伐娣诲姞闄勪欢
- addOutputAttachments(params: { id: number; attachmentIds: string }) {
+ addOutputAttachments(params: { id: number; attachmentId: string }) {
return request<BaseResult<any>>({
url: "/app/addOutputAttachments",
method: "POST",
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>
diff --git a/src/pages/production/twist/report/index.vue b/src/pages/production/twist/report/index.vue
index fe8e34b..16b6567 100644
--- a/src/pages/production/twist/report/index.vue
+++ b/src/pages/production/twist/report/index.vue
@@ -17,7 +17,7 @@
</template>
<ProductionCard :data="cardAttr" :value="item" />
<template #footer>
- <wd-button size="small" plain @click="toAttachment(item.id)" style="margin-right: 10px">
+ <wd-button size="small" plain @click="toAttachment(item)" style="margin-right: 10px">
闄勪欢
</wd-button>
<wd-button size="small" plain @click="toCheck(item.id)">鑷</wd-button>
@@ -103,17 +103,17 @@
dialog.visible = false;
};
-const toAttachment = (id: number) => {
+const toAttachment = (item: any) => {
uni.navigateTo({
- url: `/pages/production/twist/attachment/index?reportId=${id}`,
+ url: "/pages/production/twist/attachment/index",
+ success: () => {
+ // 椤甸潰璺宠浆鎴愬姛鍚庡彂閫佷簨浠朵紶閫掓暟鎹�
+ uni.$emit("detailData", item);
+ },
});
};
-const toCheck = (id: number) => {
- uni.navigateTo({
- url: `/pages/production/twist/selfInspect/index?id=${id}`,
- });
-};
+
// 鑾峰彇鎷変笣鎶ュ伐鍒楄〃
const getTwistReportList = async () => {
diff --git a/src/pages/production/wire/attachment/index.vue b/src/pages/production/wire/attachment/index.vue
index 8da86e7..1af3ac6 100644
--- a/src/pages/production/wire/attachment/index.vue
+++ b/src/pages/production/wire/attachment/index.vue
@@ -52,24 +52,30 @@
// 椤甸潰鍙傛暟
const reportId = ref("");
-const reportType = ref("鎷変笣");
+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>
diff --git a/src/pages/production/wire/report/wire.vue b/src/pages/production/wire/report/wire.vue
index b57634b..47dcbce 100644
--- a/src/pages/production/wire/report/wire.vue
+++ b/src/pages/production/wire/report/wire.vue
@@ -22,7 +22,7 @@
</template>
<ProductionCard :data="cardAttr" :value="item" />
<template #footer>
- <wd-button size="small" plain @click="toAttachment(item.id)" style="margin-right: 10px">
+ <wd-button size="small" plain @click="toAttachment(item)" style="margin-right: 10px">
闄勪欢
</wd-button>
<wd-button size="small" plain @click="toCheck(item.id)">鑷</wd-button>
@@ -123,9 +123,13 @@
dialog.visible = false;
};
-const toAttachment = (id: number) => {
+const toAttachment = (item: any) => {
uni.navigateTo({
- url: `/pages/production/wire/attachment/index?reportId=${id}`,
+ url: "/pages/production/wire/attachment/index",
+ success: () => {
+ // 椤甸潰璺宠浆鎴愬姛鍚庡彂閫佷簨浠朵紶閫掓暟鎹�
+ uni.$emit("detailData", item);
+ },
});
};
--
Gitblit v1.9.3