mirror of
https://github.com/LiuYuYang01/ThriveX-Blog.git
synced 2026-09-03 06:24:24 +08:00
增强数据处理和错误管理
1.更新文章页面,未找到文章时返回默认参数。 2. 通过确保链接数据的排序和处理安全,改进好友页面中的错误处理。 3. 确保设备页面安全访问列表数据,防止潜在错误。 4. 重构我的页面以安全地访问用户数据中的嵌套属性。 5. 增强墙页处理类别列表可能不是数组的情况。
This commit is contained in:
@@ -39,11 +39,12 @@ interface Props {
|
||||
export async function generateStaticParams() {
|
||||
try {
|
||||
const { data } = await getArticlePagingCacheAPI({ pageNum: 1, pageSize: 80 });
|
||||
return (data?.result ?? [])
|
||||
const params = (data?.result ?? [])
|
||||
.filter((article) => article.id != null)
|
||||
.map((article) => ({ id: String(article.id) }));
|
||||
return params.length ? params : [{ id: '0' }];
|
||||
} catch {
|
||||
return [];
|
||||
return [{ id: '0' }];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +113,7 @@ export default async (props: Props) => {
|
||||
|
||||
const errorCodes = [400, 404, 611];
|
||||
|
||||
if (errorCodes.includes(code ?? 200)) {
|
||||
if (errorCodes.includes(code ?? 200) || !data?.title) {
|
||||
return <NotFound />;
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ export default async (props: Props) => {
|
||||
|
||||
<div className="flex flex-wrap items-center justify-center gap-x-4 gap-y-1 text-xs sm:gap-x-10 sm:text-sm">
|
||||
<div className="flex items-center">
|
||||
<span>{data?.cateList[0]?.name}</span>
|
||||
<span>{data?.cateList?.[0]?.name}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center">
|
||||
|
||||
@@ -32,7 +32,7 @@ export default async () => {
|
||||
items: [] as Equipment['items'],
|
||||
};
|
||||
|
||||
const safeList: Equipment[] = (value.list ?? []).map((group) => ({
|
||||
const safeList: Equipment[] = (value?.list ?? []).map((group) => ({
|
||||
...defaultGroup,
|
||||
...group,
|
||||
items: (group?.items ?? []).map((item) => ({
|
||||
|
||||
@@ -17,15 +17,15 @@ export default async () => {
|
||||
getWebTypeListCacheAPI(),
|
||||
getAppConfigCacheAPI(),
|
||||
]);
|
||||
const linkList = linkRes?.data ?? [];
|
||||
const linkList = linkRes?.data ?? { result: [] };
|
||||
const typeList = typeRes?.data ?? [];
|
||||
|
||||
let data: { [string: string]: { order: number; list: WebLink[] } } = {};
|
||||
|
||||
linkList.result.sort((a: WebLink, b: WebLink) => a.order - b.order);
|
||||
(linkList.result ?? []).sort((a: WebLink, b: WebLink) => a.order - b.order);
|
||||
|
||||
// 给每个数据进行分组处理
|
||||
linkList?.result?.forEach((item: WebLink) => {
|
||||
(linkList.result ?? []).forEach((item: WebLink) => {
|
||||
if (data[item.type.name]) {
|
||||
data[item.type.name].list.push(item);
|
||||
} else {
|
||||
|
||||
@@ -45,14 +45,14 @@ export default async () => {
|
||||
const defaultHometown = [0, 0] as MyData['hometown'];
|
||||
|
||||
const safeData: MyData = {
|
||||
info_style: value.info_style || 'info_one',
|
||||
info_one: { ...defaultInfoOne, ...(value.info_one || {}) },
|
||||
info_two: { ...defaultInfoTwo, ...(value.info_two || {}) },
|
||||
character: value.character ?? defaultCharacter,
|
||||
goals: value.goals ?? defaultGoals,
|
||||
project: value.project ?? defaultProject,
|
||||
technology_stack: value.technology_stack ?? defaultTechStack,
|
||||
hometown: value.hometown ?? defaultHometown,
|
||||
info_style: value?.info_style || 'info_one',
|
||||
info_one: { ...defaultInfoOne, ...(value?.info_one || {}) },
|
||||
info_two: { ...defaultInfoTwo, ...(value?.info_two || {}) },
|
||||
character: value?.character ?? defaultCharacter,
|
||||
goals: value?.goals ?? defaultGoals,
|
||||
project: value?.project ?? defaultProject,
|
||||
technology_stack: value?.technology_stack ?? defaultTechStack,
|
||||
hometown: value?.hometown ?? defaultHometown,
|
||||
};
|
||||
|
||||
const { info_style, info_one, info_two, character, goals, project, technology_stack, hometown } = safeData;
|
||||
|
||||
@@ -13,7 +13,7 @@ interface Props {
|
||||
export default async (props: Props) => {
|
||||
const { cate } = await props.params;
|
||||
const { data: cateList } = await getWallCateListCacheAPI();
|
||||
const sorted = [...(cateList ?? [])].sort((a, b) => a.order - b.order);
|
||||
const sorted = [...(Array.isArray(cateList) ? cateList : [])].sort((a, b) => a.order - b.order);
|
||||
const activeCate = cate || sorted[0]?.mark || '';
|
||||
const cateId = sorted.find((item) => item.mark === activeCate)?.id ?? sorted[0]?.id ?? 0;
|
||||
const { data: wallsData } = await getCateWallListCacheAPI(cateId);
|
||||
|
||||
Reference in New Issue
Block a user