|
|
@@ -1,6 +1,6 @@
|
|
|
<!-- eslint-disable @typescript-eslint/no-unnecessary-type-assertion -->
|
|
|
<script setup lang='ts' generic="T extends Record<string, unknown>">
|
|
|
-import type {LDFilterTool, LDFilterToolMap} from './state';
|
|
|
+import type {LDFilterTool} from './state';
|
|
|
import {
|
|
|
LDFilterWrapper,
|
|
|
LDFilterInput,
|
|
|
@@ -17,7 +17,7 @@ defineOptions({name: 'LDFilterGroup'});
|
|
|
type Props = {
|
|
|
providerKey: symbol,
|
|
|
fixedTools: LDFilterTool<T>[];
|
|
|
- sourceMap?: LDFilterToolMap<T>;
|
|
|
+ extendsTools?: LDFilterTool<T>[];
|
|
|
sourceTools?: string;
|
|
|
isSearching?: boolean;
|
|
|
onSubmit: (e?: Event) => void;
|
|
|
@@ -29,17 +29,18 @@ const props = defineProps<Props>();
|
|
|
|
|
|
// #region 筛选框内容
|
|
|
const toolList = computed(function() {
|
|
|
- if (!props.sourceTools || !props.sourceMap) return props.fixedTools;
|
|
|
+ if (!props.sourceTools || !props.extendsTools) return props.fixedTools;
|
|
|
|
|
|
const arr = props.sourceTools.split(',');
|
|
|
|
|
|
const els = arr.map(function(id) {
|
|
|
- if (!props.sourceMap!.has(id))
|
|
|
+ const idx = props.extendsTools!.findIndex(val => val.id! === id);
|
|
|
+ if (idx < 0)
|
|
|
return;
|
|
|
|
|
|
- return {...props.sourceMap!.get(id)!, id: Number(id)};
|
|
|
+ return props.extendsTools![idx];
|
|
|
}).filter(Boolean)
|
|
|
- .sort((a, b) => a.id - b.id);
|
|
|
+ .sort((a, b) => Number(a.id) - Number(b.id));
|
|
|
|
|
|
return [...props.fixedTools, ...els];
|
|
|
});
|
|
|
@@ -89,10 +90,10 @@ const transferVisible = ref(false);
|
|
|
const transferOptions = computed(function() {
|
|
|
const data: {value: string; label: string}[] = [];
|
|
|
|
|
|
- if (!props.sourceMap) return data;
|
|
|
+ if (!props.extendsTools) return data;
|
|
|
|
|
|
- props.sourceMap.forEach(function({label}, id) {
|
|
|
- data.push({value: String(id), label});
|
|
|
+ props.extendsTools.forEach(function({label, id}) {
|
|
|
+ data.push({value: id!, label: label.value});
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
@@ -101,7 +102,8 @@ const transferOptions = computed(function() {
|
|
|
const transferValue = ref<string[]>([]);
|
|
|
|
|
|
watchEffect(function() {
|
|
|
- if (!props.sourceTools) return;
|
|
|
+ // 在sourceTools变化或者modal显示之后都要确保transferValue与sourceTools一致
|
|
|
+ if (!props.sourceTools || !transferVisible.value) return;
|
|
|
|
|
|
transferValue.value = props.sourceTools.split(',');
|
|
|
});
|
|
|
@@ -134,20 +136,20 @@ const onFilter = props.onFilterConfirm
|
|
|
v-if="state.type === 'field'"
|
|
|
:proiderKey="props.providerKey"
|
|
|
:name="(state.name as string)"
|
|
|
- :label="state.label"
|
|
|
+ :label="state.label.value"
|
|
|
/>
|
|
|
<LDFilterDate
|
|
|
v-if="state.type === 'date'"
|
|
|
:providerKey="props.providerKey"
|
|
|
:name="(state.name as [string, string])"
|
|
|
- :label="state.label"
|
|
|
+ :label="state.label.value"
|
|
|
/>
|
|
|
<LDFilterSelect
|
|
|
v-if="state.type === 'select'"
|
|
|
:providerKey="props.providerKey"
|
|
|
:name="(state.name as string)"
|
|
|
:options="state.options.value"
|
|
|
- :label="state.label"
|
|
|
+ :label="state.label.value"
|
|
|
:loading="state.loading?.value"
|
|
|
@search="state.onSearch"
|
|
|
/>
|