feat: 解决方案列表页标签排序
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m1s

- 为SolutionType添加Sort字段用于排序
- 解决方案列表按照sort升序排序
This commit is contained in:
2025-11-08 15:46:37 +08:00
parent 308a080ea4
commit 0363a88785
5 changed files with 67 additions and 26 deletions

View File

@ -19,14 +19,14 @@
</div>
</el-tab-pane>
<el-tab-pane
v-for="(group, type) in groupedSolutions"
:key="type"
:label="type || '未分类'"
:name="type || 'no-category'"
v-for="[key, value] in Object.entries(groupedSolutions)"
:key="key"
:label="key || '未分类'"
:name="key || 'no-category'"
>
<div class="solution-list">
<solution-card
v-for="solution in group"
v-for="solution in value.data"
:key="solution.id"
:document-id="solution.id.toString()"
:cover-url="getImageUrl(solution.cover || '')"
@ -63,22 +63,19 @@
// 按类型分组
const groupedSolutions = computed(() => {
const gourps: Record<string, SolutionListView[]> = {};
const groups: Record<string, { data: SolutionListView[]; sort: number }> =
{};
for (const sol of solutions.value) {
let typeKey = '';
if (typeof sol.solution_type === 'string') {
typeKey = sol.solution_type;
} else if (
sol.solution_type &&
typeof sol.solution_type === 'object' &&
'type' in sol.solution_type
) {
typeKey = sol.solution_type || '';
const typeKey = sol.solution_type?.name ?? '';
if (!groups[typeKey]) {
groups[typeKey] = { data: [], sort: sol.solution_type?.sort ?? 999 };
}
if (!gourps[typeKey]) gourps[typeKey] = [];
gourps[typeKey]?.push(sol);
groups[typeKey]?.data.push(sol);
}
return gourps;
const sortedGroups = Object.fromEntries(
Object.entries(groups).sort(([, a], [, b]) => a.sort - b.sort)
);
return sortedGroups;
});
watch(error, (value) => {