Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ const props = withDefaults(
modelValue?: boolean;
noWidth?: boolean;
value?: string;
dimmed?: boolean;
}>(),
{
noWidth: false,
dimmed: false,
},
);
const emit = defineEmits<{
Expand Down Expand Up @@ -38,6 +40,7 @@ const isSelected = computed({
:class="{
selected: isSelected,
'no-width': noWidth,
dimmed,
}"
class="checkbox-container"
@click="
Expand Down Expand Up @@ -75,4 +78,7 @@ const isSelected = computed({
.no-width {
width: initial;
}
.dimmed {
opacity: 0.45;
}
</style>
3 changes: 3 additions & 0 deletions src/components/FilterRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const props = withDefaults(
noWidth?: boolean;
someSelected?: boolean;
modelValue?: Record<string, boolean>;
dimmedLabels?: Record<string, boolean>;
}>(),
{
modelValue: () => ({}),
dimmedLabels: () => ({}),
},
);
const emit = defineEmits<{
Expand Down Expand Up @@ -87,6 +89,7 @@ const removeAll = () => {
:key="label"
:value="label"
:no-width="noWidth"
:dimmed="dimmedLabels?.[label]"
>
{{ label }}
</Checkbox>
Expand Down
55 changes: 55 additions & 0 deletions src/widgets/CharList/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ const currDataTypes: Ref<Record<string, boolean>> = ref({
const displayModes = ref(["表格", "半身像", "头像"]);
const currDisplayMode = ref("表格");

const dimmedMaps: Record<string, any>[][] = reactive(
props.filters.map((fg) => fg.filter.map(() => ({}))),
);

const toggleCollapse = (index: number) => {
expanded.value[index] = !expanded.value[index];
Cookies.set("opFilterExpandState", JSON.stringify(expanded.value), {
Expand Down Expand Up @@ -246,6 +250,56 @@ const oridata = computed(() => {
}
return result;
});

function computeDimmedMaps() {
for (let fi = 0; fi < props.filters.length; fi++) {
const fg = props.filters[fi];
for (let fj = 0; fj < fg.filter.length; fj++) {
const f = fg.filter[fj];
const labels = flat(f.cbt);
const map: Record<string, boolean> = {};

// 创建 states 副本
const tempStates = states.map((group) =>
group.map((s) => ({
both: s.both,
selected: { ...s.selected },
meta: s.meta,
})),
);

const originalSelected = tempStates[fi][fj].selected;

for (const label of labels) {
// 临时替换选中项为仅包含当前 label
tempStates[fi][fj].selected = { [label]: true };

const exists = props.source.some((char) => {
for (const g of tempStates) {
for (const sf of g) {
if (!predicate(sf as State, char)) return false;
}
}
return true;
});
map[label] = !exists;
}

tempStates[fi][fj].selected = originalSelected;
dimmedMaps[fi][fj] = map;
}
}
}
Comment on lines +254 to +292
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The computeDimmedMaps function has O(n³) complexity with nested loops over filters, labels, and source data. This could cause performance issues with large datasets. Consider implementing memoization or debouncing to avoid unnecessary recalculations, especially since it runs on every state change.

Copilot uses AI. Check for mistakes.

computeDimmedMaps();
watch(
states,
() => {
computeDimmedMaps();
},
{ deep: true },
);
Comment on lines +294 to +301
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deep watcher on states triggers computeDimmedMaps() on every state change, which could be expensive. Consider using nextTick or debouncing to batch multiple rapid changes, or implement more granular watching to only recompute when relevant parts of the state change.

Copilot uses AI. Check for mistakes.

watch(oridata, () => {
page.value.index = 1;
});
Expand Down Expand Up @@ -395,6 +449,7 @@ watch(data, () => {
:labels="flat(v2.cbt)"
:show-both="v2.both"
:no-width="i === 2"
:dimmed-labels="dimmedMaps[i][i2]"
/>
</NCollapseTransition>
</div>
Expand Down