diff --git a/web/src/utils/baTable.ts b/web/src/utils/baTable.ts index f83da674..91d59fba 100644 --- a/web/src/utils/baTable.ts +++ b/web/src/utils/baTable.ts @@ -1,11 +1,11 @@ -import { reactive } from 'vue' +import { reactive, watch } from 'vue' import { auth, getArrayKey } from '/@/utils/common' import type { baTableApi } from '/@/api/common' import Sortable from 'sortablejs' import { findIndexRow } from '/@/components/table' import { ElNotification, FormInstance, TableColumnCtx } from 'element-plus' -import { onBeforeRouteUpdate, useRoute } from 'vue-router' -import { cloneDeep, isUndefined } from 'lodash-es' +import { useRoute } from 'vue-router' +import { cloneDeep } from 'lodash-es' import { i18n } from '/@/lang/index' export default class baTable { @@ -64,9 +64,6 @@ export default class baTable { this.table = Object.assign(this.table, table) this.before = before this.after = after - - const route = useRoute() - this.initComSearch(!isUndefined(route) ? route.query : {}) } /** @@ -474,11 +471,25 @@ export default class baTable { mount = () => { if (this.runBefore('mount') === false) return - // 监听路由变化,响应通用搜索更新 - onBeforeRouteUpdate((to) => { - this.initComSearch(to.query) - this.getIndex() - }) + const route = useRoute() + this.table.routePath = route.path + + // 初始化公共搜索数据 + this.initComSearch(route?.query ? route.query : {}) + + // 路由未改变,而 query 改变了,重新筛选数据 + let routeFlag = route.path + Object.entries(route.query).toString() + watch( + () => route.query, + () => { + const newRouteFlag = route.path + Object.entries(route.query).toString() + if (route.path == this.table.routePath && routeFlag != newRouteFlag) { + this.initComSearch(route.query) + this.getIndex() + routeFlag = newRouteFlag + } + } + ) } /** diff --git a/web/types/table.d.ts b/web/types/table.d.ts index 9f1a690e..3bd1e2cd 100644 --- a/web/types/table.d.ts +++ b/web/types/table.d.ts @@ -44,6 +44,8 @@ declare global { dblClickNotEditColumn?: (string | undefined)[] // 是否展开所有子项,树状表格专用属性 expandAll?: boolean + // 当前表格所在页面的路由 path + routePath?: string // 表格扩展数据,随意定义,以便一些自定义数据可以随baTable实例传递 extend?: anyObj }