Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我的页 #48

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 86 additions & 23 deletions app/(tabs)/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { useSafeResponseSolve } from '@/hooks/useSafeResponseSolve';
import { JWCH_USER_INFO_KEY } from '@/lib/constants';
import { clearUserStorage } from '@/utils/user';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Link } from 'expo-router';
import { Href, Link } from 'expo-router';
import { useCallback, useEffect, useState } from 'react';
import { Alert, ScrollView, View } from 'react-native';
import { Alert, Image, ImageSourcePropType, ScrollView, TouchableOpacity, View } from 'react-native';

export default function HomePage() {
const { handleError } = useSafeResponseSolve();
Expand All @@ -35,6 +35,41 @@ export default function HomePage() {
major: '所属专业',
};

interface MenuItem {
icon: ImageSourcePropType;
name: string; // 菜单项名称
link: Href; // 跳转链接
}

// 菜单项数据
const menuItems: MenuItem[] = [
{
icon: require('assets/images/my/ic_homework.png'),
name: '我的作业',
link: '/my/grades' as Href,
},
{
icon: require('assets/images/my/ic_note.png'),
name: '备忘录',
link: '/my/gpa' as Href,
},
{
icon: require('assets/images/my/ic_calendar.png'),
name: '校历',
link: '/my/credits' as Href,
},
{
icon: require('assets/images/my/ic_ecard.png'),
name: '一卡通',
link: '/my/unified-exam' as Href,
},
{
icon: require('assets/images/my/ic_help.png'),
name: '帮助与反馈',
link: '/my/plan' as Href,
},
];

// 从 AsyncStorage 加载用户信息
const loadUserInfoFromStorage = useCallback(async () => {
try {
Expand Down Expand Up @@ -105,30 +140,58 @@ export default function HomePage() {

return (
<ThemedView className="flex-1">
<ScrollView contentContainerStyle={{ padding: 16 }}>
{/* 个人信息列表 */}
<View className="gap-4">
{Object.entries(userInfo).map(([key, value]) => (
<View key={key} className="mb-2 flex-row items-center justify-between border-b border-gray-300 pb-2">
<Text className="capitalize text-gray-500">{userInfoLabels[key] || key}:</Text>
<Text className="text-black">{value}</Text>
</View>
))}
<ScrollView>
<View className="flex-row items-center p-8">
<Image source={require('@/assets/images/my/avatar_default.png')} className="mr-6 h-24 w-24 rounded-full" />
<View>
<Text className="text-xl font-bold">{userInfo.name}</Text>
<Text className="mt-2 text-sm text-gray-500">这是一条签名</Text>
</View>
</View>

{/* 按钮部分 */}
<View className="mt-6">
<Button onPress={getUserInfo} disabled={isRefreshing} className="mb-4">
<Text>{isRefreshing ? '刷新中...' : '刷新个人信息'}</Text>
</Button>
<Button onPress={logout} className="mb-4">
<Text>退出当前账户</Text>
</Button>
<Link href="/devtools" asChild>
<Button>
<Text>开发者选项</Text>
<View className="h-full rounded-tr-4xl bg-white px-8">
<View className="mt-6">
<View className="w-full flex-row justify-between">
<Text>{userInfo.college}</Text>
<Text>{userInfo.stu_id}</Text>
</View>
<View className="mt-2 w-full flex-row justify-between">
<Text className="text-muted-foreground">2024年1学期</Text>
<Text className="text-muted-foreground">第 22 周</Text>
</View>
</View>

{/* 菜单列表 */}
<View className="mt-4 space-y-4">
{menuItems.map((item, index) => (
<Link key={index} href={item.link} asChild>
<TouchableOpacity className="flex-row items-center justify-between py-4">
{/* 图标和名称 */}
<View className="flex-row items-center space-x-4">
<Image source={item.icon} className="h-7 w-7" />
<Text className="ml-5 text-lg text-foreground">{item.name}</Text>
</View>
{/* 右侧箭头 */}
<Image source={require('assets/images/misc/ic_arrow_right.png')} className="h-5 w-5" />
</TouchableOpacity>
</Link>
))}
</View>

{/* 按钮部分 */}
<View className="mt-6">
<Button onPress={getUserInfo} disabled={isRefreshing} className="mb-4">
<Text>{isRefreshing ? '刷新中...' : '刷新个人信息'}</Text>
</Button>
<Button onPress={logout} className="mb-4">
<Text>退出当前账户</Text>
</Button>
</Link>
<Link href="/devtools" asChild>
<Button>
<Text>开发者选项</Text>
</Button>
</Link>
</View>
</View>
</ScrollView>
</ThemedView>
Expand Down
Binary file added assets/images/my/avatar_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes