fix(material): 增强edit_id自动弹窗的调试日志和容错逻辑
This commit is contained in:
@ -1592,20 +1592,34 @@ onMounted(() => {
|
||||
getList();
|
||||
getOptionsList();
|
||||
|
||||
// 【新增】:处理外部跳转自动打开编辑弹窗(来自入库编辑的'前往修改基础信息')
|
||||
if (route.query.edit_id) {
|
||||
const editId = Number(route.query.edit_id);
|
||||
listMaterialBase({ id: editId }).then((res: any) => {
|
||||
const rows = res?.data?.list ?? res?.data ?? [];
|
||||
if (rows.length > 0) {
|
||||
setTimeout(() => {
|
||||
handleEdit(rows[0]);
|
||||
}, 300);
|
||||
}
|
||||
}).catch((error: any) => {
|
||||
console.error('自动获取物料详情失败', error);
|
||||
});
|
||||
}
|
||||
// 【优化】:处理外部跳转自动打开编辑弹窗
|
||||
console.log('--- 准备检测外部跳转参数 ---', route.query);
|
||||
if (route.query.edit_id) {
|
||||
const editId = Number(route.query.edit_id);
|
||||
console.log('检测到 edit_id:', editId);
|
||||
|
||||
// 为了防止 API 不支持直接传 id,我们改用 keyword 搜索(因为大部分 list 接口都支持 keyword)
|
||||
// 或者直接请求列表,拿到第一页数据进行比对
|
||||
listMaterialBase({ page: 1, pageSize: 50, id: editId }).then((res: any) => {
|
||||
const rows = res?.data?.list ?? res?.data ?? [];
|
||||
console.log('API 返回的匹配数据:', rows);
|
||||
|
||||
// 尝试在返回的列表中精确寻找这个 ID
|
||||
const targetRow = rows.find((r: any) => r.id === editId) || rows[0];
|
||||
|
||||
if (targetRow) {
|
||||
console.log('找到目标物料,准备弹窗:', targetRow);
|
||||
// 加大延迟,确保 DOM 和弹窗组件完全挂载
|
||||
setTimeout(() => {
|
||||
handleEdit(targetRow);
|
||||
}, 800);
|
||||
} else {
|
||||
console.warn('未在返回数据中找到该物料');
|
||||
}
|
||||
}).catch((error: any) => {
|
||||
console.error('自动获取物料详情失败', error);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user