diff --git a/src/app/equipment/page.tsx b/src/app/equipment/page.tsx index 0efdfb0..8e6b9f1 100755 --- a/src/app/equipment/page.tsx +++ b/src/app/equipment/page.tsx @@ -9,7 +9,32 @@ interface Equipment { export default async () => { const { data } = (await getPageConfigDataByNameAPI('equipment')) || { data: {} as Config }; - const { list } = data.value as { list: Equipment[] }; + const value = (data?.value as { list: Equipment[] }) || { list: [] }; + + const defaultItem = { + name: '未命名设备', + image: '', + price: '0', + description: '暂无描述', + color: '#f5f5f5', + }; + + const defaultGroup = { + category: '未分类', + description: '暂无描述', + items: [] as Equipment['items'], + }; + + const safeList: Equipment[] = (value.list || []).map((group) => ({ + ...defaultGroup, + ...group, + items: (group?.items || []).map((item) => ({ + ...defaultItem, + ...item, + price: `${item.price ?? defaultItem.price}`, + color: item.color || defaultItem.color, + })), + })); return ( <> @@ -18,7 +43,7 @@ export default async () => {
{group.description}
diff --git a/src/app/my/page.tsx b/src/app/my/page.tsx index 2c8b8be..efc0b47 100755 --- a/src/app/my/page.tsx +++ b/src/app/my/page.tsx @@ -14,7 +14,42 @@ import InfoOne from './component/InfoOne'; export default async () => { const { data } = (await getPageConfigDataByNameAPI('my')) || { data: {} as Config }; - const { info_style, info_one, info_two, character, goals, project, technology_stack, hometown } = data.value as MyData; + const value = (data?.value as MyData) || ({} as MyData); + + const defaultInfoOne = { + name: '未命名', + notes: '', + avatar: '', + profession: '', + introduction: '', + }; + + const defaultInfoTwo = { + author: '未提供作者', + know_me: '#', + left_tags: [] as string[], + right_tags: [] as string[], + avatar_url: '', + }; + + const defaultCharacter = [] as MyData['character']; + const defaultGoals = [] as MyData['goals']; + const defaultProject = [] as MyData['project']; + const defaultTechStack = [] as MyData['technology_stack']; + 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, + }; + + const { info_style, info_one, info_two, character, goals, project, technology_stack, hometown } = safeData; return ( <> @@ -34,7 +69,7 @@ export default async () => {{advantage}
@@ -151,9 +203,9 @@ export default ({ data }: { data: Resume }) => {- {education?.major} | {education?.degree} + {safeEducation.major || '未提供专业'} | {safeEducation.degree || '未提供学历'}
{/*{education?.period} @@ -161,7 +213,7 @@ export default ({ data }: { data: Resume }) => {
{job.position}
+{job.position || '未提供职位'}
{project.role}
+{project.role || '未提供角色'}