[pageNum].vue
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
<div class="p-10">
<!-- 推荐工具区 -->
<HomeRecommend
:recommendList="list"
:navTitle="findLabelByAlias(name as string, sortList as any)"
navIcon="tag"
:navTitleWidth="120.5"
/>
<el-pagination
background
layout="prev, pager, next"
:hide-on-single-page="true"
v-model:page-size="params.pageSize"
v-model:current-page="params.pageNum"
:total="total"
@current-change="onPageChange"
/>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
const sortList = useState("sortTree");
const route = useRoute();
const router = useRouter();
const { pageNum, name } = route.params;
const list = ref<any[]>([]);
const total = ref<number>(0);
const params = ref<any>({
pageNum: Number(pageNum),
pageSize: 5,
typeAlias: name as string,
});
// 返回分类名称
function findLabelByAlias<
T extends { alias?: string; label?: string; children?: T[] }
>(alias: string, data: T[], childrenKey: string = "children"): string {
if (!data || data.length === 0) {
return "";
}
// 1. 首先在当前层级查找
for (const item of data) {
if (item.alias === alias) {
return item.label || ""; // 返回 label 或空字符串
}
}
// 2. 如果当前层级没找到,递归查找子节点
for (const item of data) {
const children = (item as any)[childrenKey] as T[];
if (children && children.length > 0) {
const foundLabel = findLabelByAlias(alias, children, childrenKey);
if (foundLabel !== "") {
return foundLabel;
}
}
}
return "";
}
function onPageChange(pageNum: number) {
if (pageNum === 1) {
router.push({
path: "/category/" + name,
});
} else if (pageNum > 1) {
router.push({
path: route.path + "/page/" + pageNum,
});
}
}
const { data } = await useFetch(
"http://aitoolht.crgx.net/dh/app/listFrontApp",
{
method: "get",
params: params.value,
}
);
list.value = data.value.rows;
total.value = data.value.total;
</script>