From 9fa471f68ae59d8ba5451619bd0b4c212f93b9c3 Mon Sep 17 00:00:00 2001 From: DXC Date: Mon, 27 Apr 2026 14:41:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=89=A9=E6=96=99?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=B7=B3=E8=BD=AC=E8=81=94=E5=8A=A8=E4=B8=8E?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E5=AE=9A=E4=BD=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-web/src/views/material/list.vue | 67 ++++++++++--------- inventory-web/src/views/stock/inbound/buy.vue | 4 +- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/inventory-web/src/views/material/list.vue b/inventory-web/src/views/material/list.vue index d77f192..2c7eae3 100644 --- a/inventory-web/src/views/material/list.vue +++ b/inventory-web/src/views/material/list.vue @@ -1587,47 +1587,48 @@ const resetAdvancedFilter = () => { }; onMounted(() => { + // 1. 修复背景联动:直接对 reactive 对象赋值 + if (route.query.keyword) { + queryParams.keyword = route.query.keyword as string; + queryParams.searchField = 'all'; + } + // 先根据权限初始化列显示状态 initColumnPermissions(); + // 此时 getList 会带着正确的 keyword 向后端请求过滤后的数据 getList(); getOptionsList(); - // 【优化】:处理外部跳转自动打开编辑弹窗 - console.log('--- 准备检测外部跳转参数 ---', route.query); - if (route.query.edit_id) { - const editId = Number(route.query.edit_id); - console.log('检测到 edit_id:', editId); + // 2. 修复弹窗锁定逻辑 + console.log('--- 准备检测外部跳转参数 ---', route.query); + if (route.query.edit_id) { + const editId = Number(route.query.edit_id); + const searchKeyword = (route.query.keyword as string) || ''; + console.log('检测到 edit_id:', editId, '使用 keyword 搜索:', searchKeyword); - // 为了防止 API 不支持直接传 id,我们改用 keyword 搜索(因为大部分 list 接口都支持 keyword) - // 或者直接请求列表,拿到第一页数据进行比对 - listMaterialBase({ page: 1, pageSize: 50, id: editId }).then((res: any) => { - // 1. 尝试获取各种可能的数据结构 - let rawData = res?.data?.list ?? res?.data?.items ?? res?.data ?? []; + // 改用 keyword 而不是无效的 id 去向后端请求数据,确保目标物料在返回的列表中 + listMaterialBase({ page: 1, pageSize: 50, keyword: searchKeyword }).then((res: any) => { + let rawData = res?.data?.list ?? res?.data?.items ?? res?.data ?? []; + if (!Array.isArray(rawData) && typeof rawData === 'object' && rawData !== null) { + rawData = [rawData]; + } + const rows = Array.isArray(rawData) ? rawData : []; - // 2. 如果后端聪明地直接返回了单条数据(对象),把它包装成数组 - if (!Array.isArray(rawData) && typeof rawData === 'object' && rawData !== null) { - rawData = [rawData]; - } + // 3. 去掉危险的 rows[0] 兜底,严格匹配 ID + const targetRow = rows.find((r: any) => r.id === editId); - // 3. 终极兜底,确保 rows 绝对是数组 - const rows = Array.isArray(rawData) ? rawData : []; - console.log('兼容处理后的数组数据:', rows); - - // 4. 寻找目标行并弹窗 - const targetRow = rows.find((r: any) => r.id === editId) || rows[0]; - - if (targetRow) { - console.log('找到目标物料,准备弹窗:', targetRow); - setTimeout(() => { - handleEdit(targetRow); - }, 800); - } else { - console.warn('未在返回数据中找到该物料'); - } - }).catch((error: any) => { - console.error('自动获取物料详情失败', error); - }); - } + if (targetRow) { + console.log('找到精准目标物料,准备弹窗:', targetRow); + setTimeout(() => { + handleEdit(targetRow); + }, 800); + } else { + console.warn('未能在搜索结果中匹配到对应 ID 的物料,可能 keyword 与 ID 不匹配'); + } + }).catch((error: any) => { + console.error('自动获取物料详情失败', error); + }); + } }); diff --git a/inventory-web/src/views/stock/inbound/buy.vue b/inventory-web/src/views/stock/inbound/buy.vue index 3ed9448..2dd8772 100644 --- a/inventory-web/src/views/stock/inbound/buy.vue +++ b/inventory-web/src/views/stock/inbound/buy.vue @@ -1414,7 +1414,9 @@ const openMaterialInNewTab = () => { const routeUrl = router.resolve({ path: '/material', query: { - edit_id: form.base_id + edit_id: form.base_id, + // 【新增】:优先传递规格型号,如果没有则传名称,用于背景表格过滤 + keyword: form.spec_model || form.material_name || '' } }) window.open(routeUrl.href, '_blank')