diff --git a/frontend/src/components/pure/ms-table/base-table.vue b/frontend/src/components/pure/ms-table/base-table.vue index 3167ae7241..fbc6ab0086 100644 --- a/frontend/src/components/pure/ms-table/base-table.vue +++ b/frontend/src/components/pure/ms-table/base-table.vue @@ -847,10 +847,6 @@ columnSelectorVisible.value = true; }; - const filterData = computed(() => { - return { ...(attrs.filter || {}) } as Record; - }); - const handleFilterConfirm = ( value: string[] | (string | number | boolean)[] | undefined, dataIndex: string, @@ -906,6 +902,10 @@ return disableKey ? record[disableKey] : false; } + const filterData = computed(() => { + return { ...(attrs.filter || {}) } as Record; + }); + function hasSelectedFilter(item: MsTableColumnData) { if (item.filterConfig && item.dataIndex) { return (filterData.value[item.dataIndex] || []).length > 0; @@ -958,10 +958,21 @@ }); }; + function initDefaultFilter() { + currentColumns.value.forEach((e) => { + const dataIndexKey = e.dataIndex as string; + // 初始化配置了filterConfig默认值回显已选项 + if (e.filterConfig?.options && filterData.value[dataIndexKey] && filterData.value[dataIndexKey].length) { + e.filterCheckedList = filterData.value[dataIndexKey]; + } + }); + } + onMounted(async () => { await initColumn(); updateAllTagVisibility(); batchLeft.value = getBatchLeft(); + initDefaultFilter(); }); const updateColumnWidth = throttle(async (dataIndex: string, width: number) => { diff --git a/frontend/src/components/pure/ms-table/comp/defaultFilter.vue b/frontend/src/components/pure/ms-table/comp/defaultFilter.vue index c8feba628a..7185871728 100644 --- a/frontend/src/components/pure/ms-table/comp/defaultFilter.vue +++ b/frontend/src/components/pure/ms-table/comp/defaultFilter.vue @@ -221,18 +221,6 @@ } ); - watch( - () => props.filter, - (val) => { - if (!val[props.dataIndex as string] || val[props.dataIndex as string]?.length === 0) { - checkedList.value = []; // 清空选择 - } else { - // 如果有过滤条件,更新 checkedList - checkedList.value = val[props.dataIndex as string]; - } - } - ); - const searchItem = debounce(() => { filterListOptions.value = originFilterList.value.filter((item: SelectOptionData) => item.label?.includes(filterKeyword.value) diff --git a/frontend/src/views/api-test/management/components/management/api/apiTable.vue b/frontend/src/views/api-test/management/components/management/api/apiTable.vue index 72f78a0da2..3165a3a51d 100644 --- a/frontend/src/views/api-test/management/components/management/api/apiTable.vue +++ b/frontend/src/views/api-test/management/components/management/api/apiTable.vue @@ -32,6 +32,7 @@ @selected-change="handleTableSelect" @batch-action="handleTableBatch" @drag-change="handleTableDragSort" + @filter-change="filterChange" >