index.vue
4.2 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<template>
<div class="md:p-10 p-4 pt-0" style="min-height: calc(100vh - 320px)">
<h1 style="font-size: 0; margin: 0">
{{ findLabelByAlias(name as string, sortList) }}
</h1>
<HomeRecommend
:recommendList="list"
:navTitle="findLabelByAlias(name as string, sortList)"
navIcon="tag"
/>
<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 type { appType } from "~/api/types/app";
import { getAppList } from "~/api/app";
import type { classifyType } from "~/api/types/classify";
import type { webSiteType } from "~/api/types/webSite";
const sortList = useState<classifyType[]>("sortTree");
const webSite = useState<webSiteType>("webSite");
const route = useRoute();
const router = useRouter();
const config = useRuntimeConfig();
const { name } = route.params;
const list = ref<appType[]>([]);
const total = ref<number>(0);
const params = ref<any>({
pageNum: 1,
pageSize: 30,
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 "";
}
for (const item of data) {
if (item.alias === alias) {
return item.label || "";
}
}
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 "";
}
const categoryLabel = findLabelByAlias(name as string, sortList.value);
function onPageChange(pageNum: number) {
router.push({
path: route.path + "/page/" + pageNum,
});
}
const res = await getAppList(params.value);
list.value = res.rows;
total.value = res.total;
useHead({
title: `${categoryLabel} - ${webSite.value.webname}`,
meta: [
{
name: "description",
content: `${categoryLabel}分类下的AI工具推荐,精选优质${categoryLabel}相关AI工具,助您高效完成工作。`,
},
{
name: "keywords",
content: `${categoryLabel},AI工具,${categoryLabel}AI,人工智能,${webSite.value.webkeywords}`,
},
{ name: "robots", content: "index, follow" },
{
property: "og:title",
content: `${categoryLabel} - ${webSite.value.webname}`,
},
{
property: "og:description",
content: `${categoryLabel}分类下的AI工具推荐,精选优质${categoryLabel}相关AI工具。`,
},
{ property: "og:type", content: "website" },
{ property: "og:url", content: config.public.baseUrl + route.fullPath },
{ property: "og:site_name", content: webSite.value.webname },
],
link: [{ rel: "canonical", href: config.public.baseUrl + route.fullPath }],
script: [
{
type: "application/ld+json",
children: JSON.stringify({
"@context": "https://schema.org",
"@graph": [
{
"@type": "CollectionPage",
"@id": config.public.baseUrl + route.fullPath + "#collectionpage",
url: config.public.baseUrl + route.fullPath,
name: `${categoryLabel} - ${webSite.value.webname}`,
description: `${categoryLabel}分类下的AI工具推荐`,
isPartOf: {
"@id": "https://aiboxgo.com/#website",
},
about: {
"@type": "Thing",
name: categoryLabel,
},
},
{
"@type": "BreadcrumbList",
"@id": config.public.baseUrl + route.fullPath + "#breadcrumb",
itemListElement: [
{
"@type": "ListItem",
position: 1,
name: "首页",
item: "https://aiboxgo.com/",
},
{
"@type": "ListItem",
position: 2,
name: categoryLabel,
},
],
},
],
}),
},
],
});
</script>