feat: 支持会员编号

This commit is contained in:
richarjiang
2025-09-26 08:48:31 +08:00
parent 94899fbc5c
commit ad98d78e18
2 changed files with 24 additions and 4 deletions

View File

@@ -212,6 +212,9 @@ export default function PersonalScreen() {
<TouchableOpacity onPress={handleUserNamePress} activeOpacity={0.7}> <TouchableOpacity onPress={handleUserNamePress} activeOpacity={0.7}>
<Text style={styles.userName}>{displayName}</Text> <Text style={styles.userName}>{displayName}</Text>
</TouchableOpacity> </TouchableOpacity>
{userProfile.memberNumber && (
<Text style={styles.userMemberNumber}>: {userProfile.memberNumber}</Text>
)}
</View> </View>
<TouchableOpacity style={styles.editButton} onPress={() => pushIfAuthedElseLogin('/profile/edit')}> <TouchableOpacity style={styles.editButton} onPress={() => pushIfAuthedElseLogin('/profile/edit')}>
<Text style={styles.editButtonText}>{isLoggedIn ? '编辑' : '登录'}</Text> <Text style={styles.editButtonText}>{isLoggedIn ? '编辑' : '登录'}</Text>
@@ -480,6 +483,11 @@ const styles = StyleSheet.create({
color: '#9370DB', color: '#9370DB',
fontWeight: '500', fontWeight: '500',
}, },
userMemberNumber: {
fontSize: 10,
color: '#6C757D',
marginTop: 4,
},
editButton: { editButton: {
backgroundColor: '#9370DB', backgroundColor: '#9370DB',
paddingHorizontal: 16, paddingHorizontal: 16,

View File

@@ -20,12 +20,16 @@ export async function preloadUserData() {
AsyncStorage.getItem(STORAGE_KEYS.authToken), AsyncStorage.getItem(STORAGE_KEYS.authToken),
]); ]);
let profile: UserProfile = {}; let profile: UserProfile = {
memberNumber: 0
};
if (profileStr) { if (profileStr) {
try { try {
profile = JSON.parse(profileStr) as UserProfile; profile = JSON.parse(profileStr) as UserProfile;
} catch { } catch {
profile = {}; profile = {
memberNumber: 0
};
} }
} }
@@ -40,7 +44,11 @@ export async function preloadUserData() {
return preloadedUserData; return preloadedUserData;
} catch (error) { } catch (error) {
console.error('预加载用户数据失败:', error); console.error('预加载用户数据失败:', error);
preloadedUserData = { token: null, profile: {}, privacyAgreed: false }; preloadedUserData = {
token: null, profile: {
memberNumber: 0
}, privacyAgreed: false
};
return preloadedUserData; return preloadedUserData;
} }
} }
@@ -57,6 +65,7 @@ export type UserProfile = {
name?: string; name?: string;
email?: string; email?: string;
gender?: Gender; gender?: Gender;
memberNumber: number
birthDate?: string; birthDate?: string;
weight?: string; weight?: string;
height?: string; height?: string;
@@ -108,6 +117,7 @@ const getInitialState = (): UserState => {
name: DEFAULT_MEMBER_NAME, name: DEFAULT_MEMBER_NAME,
isVip: false, isVip: false,
freeUsageCount: 3, freeUsageCount: 3,
memberNumber: 0,
maxUsageCount: 5, maxUsageCount: 5,
...preloaded.profile, // 合并预加载的用户资料 ...preloaded.profile, // 合并预加载的用户资料
}, },
@@ -340,7 +350,9 @@ const userSlice = createSlice({
}) })
.addCase(logout.fulfilled, (state) => { .addCase(logout.fulfilled, (state) => {
state.token = null; state.token = null;
state.profile = {}; state.profile = {
memberNumber: 0
};
}) })
.addCase(setPrivacyAgreed.fulfilled, (state) => { .addCase(setPrivacyAgreed.fulfilled, (state) => {
}) })