fix: 以图搜图跳转物料页面用 watch 接管查询,防止 URL 参数残留
This commit is contained in:
@ -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;
|
||||
queryParams.searchField = 'all';
|
||||
}
|
||||
// 以图搜图跳转:监听路由 keyword 参数,自动搜索并清理 URL
|
||||
watch(
|
||||
() => route.query.keyword,
|
||||
(newKeyword) => {
|
||||
if (newKeyword) {
|
||||
queryParams.keyword = newKeyword as string;
|
||||
queryParams.searchField = 'all';
|
||||
getList();
|
||||
// 清理 URL 参数,防止刷新后重复触发搜索
|
||||
router.replace({ path: route.path, query: {} });
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 先根据权限初始化列显示状态
|
||||
onMounted(() => {
|
||||
initColumnPermissions();
|
||||
// 此时 getList 会带着正确的 keyword 向后端请求过滤后的数据
|
||||
getList();
|
||||
// 无外部 keyword 参数时执行默认查询;有 keyword 则由上方的 watch 接管
|
||||
if (!route.query.keyword) {
|
||||
getList();
|
||||
}
|
||||
getOptionsList();
|
||||
|
||||
// 2. 修复弹窗锁定逻辑
|
||||
|
||||
Reference in New Issue
Block a user