mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 14:41:29 +00:00
fix(baTable):修复表格自动识别筛选条件,query 改变不能触发重新筛选的问题
This commit is contained in:
parent
494f35e429
commit
aafa2303e8
@ -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
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
2
web/types/table.d.ts
vendored
2
web/types/table.d.ts
vendored
@ -44,6 +44,8 @@ declare global {
|
||||
dblClickNotEditColumn?: (string | undefined)[]
|
||||
// 是否展开所有子项,树状表格专用属性
|
||||
expandAll?: boolean
|
||||
// 当前表格所在页面的路由 path
|
||||
routePath?: string
|
||||
// 表格扩展数据,随意定义,以便一些自定义数据可以随baTable实例传递
|
||||
extend?: anyObj
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user