From 97e8811cabc1fa5191e4a7aa5b4db8b8106fe411 Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Wed, 15 Nov 2023 18:13:49 +0800 Subject: [PATCH] [Core] [Metadata] Add filter component data postback --- core/datacap-web/src/model/TableFilter.ts | 7 ++ .../source/components/TableColumnFilter.vue | 107 ++++++++++-------- .../admin/source/components/TableData.vue | 36 ++++-- 3 files changed, 93 insertions(+), 57 deletions(-) diff --git a/core/datacap-web/src/model/TableFilter.ts b/core/datacap-web/src/model/TableFilter.ts index a773cf7e..b21f4ed7 100644 --- a/core/datacap-web/src/model/TableFilter.ts +++ b/core/datacap-web/src/model/TableFilter.ts @@ -10,6 +10,7 @@ export class TableFilter original?: Map; preview?: boolean; value?: string; + filter: Filter; } export enum SqlType @@ -36,3 +37,9 @@ export class ColumnFilter operations: Array; value: any } + +export class Filter +{ + condition: string; + filters: Array; +} diff --git a/core/datacap-web/src/views/admin/source/components/TableColumnFilter.vue b/core/datacap-web/src/views/admin/source/components/TableColumnFilter.vue index 6adcac9c..9344a2d5 100644 --- a/core/datacap-web/src/views/admin/source/components/TableColumnFilter.vue +++ b/core/datacap-web/src/views/admin/source/components/TableColumnFilter.vue @@ -30,51 +30,50 @@ :style="{margin: '0'}"> {{ $t('source.manager.filter') }} - + + + + + + + + + + + + + + + + + {{ $t('common.cancel') }} + @@ -103,6 +106,7 @@ import {defineComponent, watch} from "vue"; import CircularLoading from "@/components/loading/CircularLoading.vue"; import {ColumnFilter} from "@/model/TableFilter"; +import {cloneDeep} from "lodash"; export default defineComponent({ name: "TableFilter", @@ -116,10 +120,16 @@ export default defineComponent({ }, types: { type: Array + }, + configure: { + type: Object } }, created() { + if (this.configure) { + this.formState = cloneDeep(this.configure); + } this.watchId(); }, data() @@ -142,7 +152,7 @@ export default defineComponent({ { this.formState.filters.splice(index, 1); }, - handlerFetchOperations(value, filter: ColumnFilter) + handlerFetchOperations(value: number, filter: ColumnFilter) { const type = this.types[value]; filter.column = this.columns[value]; @@ -153,6 +163,11 @@ export default defineComponent({ filter.operations = ['=', '!=', 'LIKE', 'NOT LIKE', 'IS NULL', 'IS NOT NULL']; } }, + handlerApplyFilter() + { + this.$emit('apply', this.formState); + this.handlerCancel(); + }, handlerCancel() { this.visible = false; diff --git a/core/datacap-web/src/views/admin/source/components/TableData.vue b/core/datacap-web/src/views/admin/source/components/TableData.vue index a59e0b30..53bce4d8 100644 --- a/core/datacap-web/src/views/admin/source/components/TableData.vue +++ b/core/datacap-web/src/views/admin/source/components/TableData.vue @@ -172,6 +172,8 @@ :isVisible="filterConfigure.show" :columns="filterConfigure.columns" :types="filterConfigure.types" + :configure="filterConfigure.configure" + @apply="handlerApplyFilter" @close="handlerFilterConfigure(false)"> @@ -251,7 +253,11 @@ export default defineComponent({ filterConfigure: { show: false, columns: [], - types: [] + types: [], + configure: { + condition: 'AND', + filters: [] + } } } }, @@ -314,9 +320,7 @@ export default defineComponent({ }, handlerSortChanged() { - const configure: TableFilter = new TableFilter(); - this.getSortConfigure(configure) - this.handlerRefererData(configure) + this.handlerRefererData(this.getConfigure()); }, handlerCellValueChanged(event: { data: any; colDef: { field: string; }; oldValue: any; newValue: any; }) { @@ -387,9 +391,7 @@ export default defineComponent({ { this.visibleColumn.show = show; if (event) { - const configure: TableFilter = new TableFilter() - this.getSortConfigure(configure) - this.getVisibleColumn(configure) + const configure: TableFilter = this.getConfigure(); const columns = event.map((item: string) => ({column: item})) configure.columns = columns // Remove the reduced column is not selected @@ -409,15 +411,19 @@ export default defineComponent({ handlerColumnMoved(event: { finished: any; }) { if (event.finished) { - const configure: TableFilter = new TableFilter() - this.getSortConfigure(configure) - this.getVisibleColumn(configure) - this.handlerRefererData(configure) + this.handlerRefererData(this.getConfigure()); } }, handlerFilterConfigure(show: boolean) { this.filterConfigure.show = show; + if (!show) { + this.handlerRefererData(this.getConfigure()); + } + }, + handlerApplyFilter(value: any) + { + this.filterConfigure.configure = value; }, getSortConfigure(configure: TableFilter) { @@ -436,6 +442,14 @@ export default defineComponent({ .map((item: { colId: any; }) => ({column: item.colId})) configure.columns = columns }, + getConfigure(): TableFilter + { + const configure: TableFilter = new TableFilter(); + configure.filter = this.filterConfigure.configure; + this.getSortConfigure(configure); + this.getVisibleColumn(configure); + return configure; + }, watchId() { watch(