|
|
@@ -49,8 +49,8 @@ const props = withDefaults(
|
|
|
searchFormRowItems?: VbFormRowItem[]
|
|
|
searchFormItems?: VbFormItem[]
|
|
|
searchFormSpan?: number
|
|
|
- customSearchFun?: () => void
|
|
|
- resetSearchFormFun?: () => void
|
|
|
+ customSearchFun?: (query?: any) => void
|
|
|
+ resetSearchFormFun?: (query: any) => void
|
|
|
/* left toolbar */
|
|
|
handleBtns?: ToolBtn[]
|
|
|
handlePerm?: string
|
|
|
@@ -177,8 +177,8 @@ const emits = defineEmits<{
|
|
|
const tableBoxRef = ref()
|
|
|
const tableContentRef = ref()
|
|
|
const id = ref("")
|
|
|
-
|
|
|
-const { data, queryParams, searchFormRowItems, searchFormItems } = toRefs(props)
|
|
|
+const emptyQueryParams = JSON.stringify(props.queryParams ? props.queryParams : {})
|
|
|
+const { data, searchFormRowItems, searchFormItems } = toRefs(props)
|
|
|
const leftFixedRef = ref()
|
|
|
const tableResponsiveRef = ref()
|
|
|
const rightFixedRef = ref()
|
|
|
@@ -250,6 +250,15 @@ const loading: WritableComputedRef<boolean> = computed({
|
|
|
emits("update:loading", value)
|
|
|
}
|
|
|
})
|
|
|
+const _innerQueryParams = ref<any>()
|
|
|
+const innerQueryParams: WritableComputedRef<any> = computed({
|
|
|
+ get(): boolean {
|
|
|
+ return _innerQueryParams.value ?? props.queryParams
|
|
|
+ },
|
|
|
+ set(value: any): void {
|
|
|
+ _innerQueryParams.value = value
|
|
|
+ }
|
|
|
+})
|
|
|
|
|
|
const rowColumns = computed(() => {
|
|
|
const rowCols: Header[] = []
|
|
|
@@ -381,7 +390,7 @@ const defaultHandleFuns = {
|
|
|
if (props.exportUrl) {
|
|
|
download(
|
|
|
props.exportUrl,
|
|
|
- { ...queryParams },
|
|
|
+ { ...innerQueryParams },
|
|
|
`${props.exportName ? props.exportName + "_" : ""}${new Date().getTime()}.xlsx`
|
|
|
)
|
|
|
} else {
|
|
|
@@ -396,8 +405,11 @@ const resetData = () => {
|
|
|
|
|
|
const remote = (id?: string) => {
|
|
|
const params = props.noPage
|
|
|
- ? queryParams.value
|
|
|
- : Object.assign({ pageIndex: currentPage.value, pageSize: pageSize.value }, queryParams.value)
|
|
|
+ ? innerQueryParams.value
|
|
|
+ : Object.assign(
|
|
|
+ { pageIndex: currentPage.value, pageSize: pageSize.value },
|
|
|
+ innerQueryParams.value
|
|
|
+ )
|
|
|
if (sortParams.value.length) {
|
|
|
sortParams.value.forEach((v: any) => {
|
|
|
if (v.order && v.label) {
|
|
|
@@ -468,8 +480,8 @@ const remote = (id?: string) => {
|
|
|
loading.value = false
|
|
|
if (props.isLazy) {
|
|
|
if (props.isLazySearch) {
|
|
|
- Object.keys(queryParams.value).forEach((v) => {
|
|
|
- queryParams.value[v] = undefined
|
|
|
+ Object.keys(innerQueryParams.value).forEach((v) => {
|
|
|
+ innerQueryParams.value[v] = undefined
|
|
|
})
|
|
|
if (!data.length) {
|
|
|
const item = {}
|
|
|
@@ -563,7 +575,7 @@ const loadHandleBtns = () => {
|
|
|
}
|
|
|
const customSearch = () => {
|
|
|
if (props.customSearchFun) {
|
|
|
- props.customSearchFun()
|
|
|
+ props.customSearchFun(innerQueryParams.value)
|
|
|
} else {
|
|
|
search()
|
|
|
}
|
|
|
@@ -589,6 +601,12 @@ function calcTableBoxStyle() {
|
|
|
}
|
|
|
return style
|
|
|
}
|
|
|
+function query(query?: any) {
|
|
|
+ if (query) {
|
|
|
+ innerQueryParams.value = Object.assign({}, query)
|
|
|
+ }
|
|
|
+ search()
|
|
|
+}
|
|
|
function search(isReset = true) {
|
|
|
if (isReset) {
|
|
|
resetData()
|
|
|
@@ -600,6 +618,9 @@ function search(isReset = true) {
|
|
|
remote(props.isLazy ? props.rootId : undefined)
|
|
|
}
|
|
|
}
|
|
|
+function getQueryParams() {
|
|
|
+ return innerQueryParams.value
|
|
|
+}
|
|
|
function getSelected() {
|
|
|
return getSelecteds()[0]
|
|
|
}
|
|
|
@@ -614,7 +635,7 @@ function getData() {
|
|
|
}
|
|
|
provide(symbolKeys.tableBox, tableBoxRef)
|
|
|
provide(symbolKeys.searchFrom, {
|
|
|
- queryParams,
|
|
|
+ queryParams: innerQueryParams,
|
|
|
searchFormRowItems,
|
|
|
searchFormItems,
|
|
|
searchFormSpan: props.searchFormSpan
|
|
|
@@ -753,7 +774,8 @@ const onRowDbClick = (v: any) => {
|
|
|
props.rowDbClick && props.rowDbClick(row)
|
|
|
}
|
|
|
const onReset = () => {
|
|
|
- props.resetSearchFormFun && props.resetSearchFormFun()
|
|
|
+ innerQueryParams.value = JSON.parse(emptyQueryParams)
|
|
|
+ props.resetSearchFormFun && props.resetSearchFormFun(innerQueryParams.value)
|
|
|
customSearch()
|
|
|
}
|
|
|
const onTreeToggle = (v: any) => {
|
|
|
@@ -902,14 +924,22 @@ onMounted(init)
|
|
|
onUnmounted(() => {
|
|
|
tableResponsiveRef.value?.removeEventListener("scroll", onFixedScrollX, true)
|
|
|
})
|
|
|
-watch(() => props.queryParams, customSearch, { deep: props.autoSearch })
|
|
|
+watch(
|
|
|
+ () => props.queryParams,
|
|
|
+ (val: any) => {
|
|
|
+ innerQueryParams.value = val
|
|
|
+ customSearch()
|
|
|
+ },
|
|
|
+ { deep: props.autoSearch }
|
|
|
+)
|
|
|
defineExpose({
|
|
|
tableRef: tableBoxRef,
|
|
|
- search,
|
|
|
+ query,
|
|
|
getSelected,
|
|
|
getSelectedIds,
|
|
|
getSelecteds,
|
|
|
getData,
|
|
|
+ getQueryParams,
|
|
|
defaultHandleFuns
|
|
|
})
|
|
|
</script>
|