fix: 以图搜图跳转物料页面用 watch 接管查询,防止 URL 参数残留

This commit is contained in:
DXC
2026-05-26 08:50:53 +08:00
parent 9406669f1c
commit e564c5a5d2

View File

@ -642,7 +642,7 @@
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, nextTick, computed } from 'vue';
import { ref, reactive, onMounted, nextTick, computed, watch } from 'vue';
import { Plus, Document, Refresh, Setting, Rank, Camera, Link, Download, Bell, CircleCheck, Files, ZoomIn, Delete, Picture } from '@element-plus/icons-vue';
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
@ -1736,17 +1736,27 @@ const resetAdvancedFilter = () => {
getList();
};
onMounted(() => {
// 1. 修复背景联动:直接对 reactive 对象赋值
if (route.query.keyword) {
queryParams.keyword = route.query.keyword as string;
// 以图搜图跳转:监听路由 keyword 参数,自动搜索并清理 URL
watch(
() => route.query.keyword,
(newKeyword) => {
if (newKeyword) {
queryParams.keyword = newKeyword as string;
queryParams.searchField = 'all';
}
// 先根据权限初始化列显示状态
initColumnPermissions();
// 此时 getList 会带着正确的 keyword 向后端请求过滤后的数据
getList();
// 清理 URL 参数,防止刷新后重复触发搜索
router.replace({ path: route.path, query: {} });
}
},
{ immediate: true }
);
onMounted(() => {
initColumnPermissions();
// 无外部 keyword 参数时执行默认查询;有 keyword 则由上方的 watch 接管
if (!route.query.keyword) {
getList();
}
getOptionsList();
// 2. 修复弹窗锁定逻辑