diff --git a/app/(enterprise)/_layout.tsx b/app/(enterprise)/_layout.tsx index 2373dda..d09d196 100644 --- a/app/(enterprise)/_layout.tsx +++ b/app/(enterprise)/_layout.tsx @@ -1,7 +1,8 @@ import { Ionicons } from '@expo/vector-icons'; import { Tabs } from 'expo-router/js-tabs'; import type { BottomTabBarProps } from 'expo-router/js-tabs'; -import { useEffect, useRef } from 'react'; +import { useFocusEffect } from 'expo-router'; +import { useCallback, useEffect, useRef } from 'react'; import { Animated, Easing, Pressable, StyleSheet, View } from 'react-native'; import { colors } from '../../src/theme'; import { useRole } from '../../src/context/RoleContext'; @@ -142,9 +143,13 @@ function TabBar({ state, descriptors, navigation, insets }: BottomTabBarProps) { export default function EnterpriseTabLayout() { const { setRole } = useRole(); - useEffect(() => { - setRole('enterprise'); - }, [setRole]); + // 用 useFocusEffect:进入/返回该端时随焦点写入角色, + // 避免「切换到企业端」后返回时 layout 未重新挂载导致 role 残留 candidate。 + useFocusEffect( + useCallback(() => { + setRole('enterprise'); + }, [setRole]), + ); return ( { + setRole('candidate'); + router.replace('/(tabs)/jobs'); + }} + hitSlop={4} + > + + + + + 切换到求职端 + 返回求职者端,浏览岗位与你的竞争力数据 + + 去求职端 → + + ); +} + /* ===================== 页面主组件 ===================== */ export default function EnterpriseOverviewScreen() { @@ -254,6 +285,7 @@ export default function EnterpriseOverviewScreen() { + @@ -520,4 +552,45 @@ const styles = StyleSheet.create({ fontWeight: '500', color: colors.textPrimary, }, + candidateCard: { + flexDirection: 'row', + alignItems: 'center', + backgroundColor: colors.white, + borderRadius: 16, + padding: 16, + marginBottom: 16, + shadowColor: colors.shadow, + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.04, + shadowRadius: 6, + elevation: 2, + }, + candidateIconWrap: { + width: 44, + height: 44, + borderRadius: 12, + backgroundColor: colors.primaryLight, + justifyContent: 'center', + alignItems: 'center', + marginRight: 12, + }, + candidateText: { + flex: 1, + }, + candidateTitle: { + fontSize: 15, + fontWeight: '600', + color: colors.textPrimary, + marginBottom: 2, + }, + candidateDesc: { + fontSize: 12, + color: colors.textSecondary, + }, + candidateAction: { + fontSize: 13, + fontWeight: '600', + color: colors.primary, + marginLeft: 8, + }, }); diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index 2bbb289..7ebc81b 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -1,7 +1,8 @@ import { Ionicons } from '@expo/vector-icons'; import { Tabs } from 'expo-router/js-tabs'; import type { BottomTabBarProps } from 'expo-router/js-tabs'; -import { useEffect, useRef } from 'react'; +import { useFocusEffect } from 'expo-router'; +import { useCallback, useEffect, useRef } from 'react'; import { Animated, Easing, Pressable, StyleSheet, View } from 'react-native'; import { colors } from '../../src/theme'; import { useRole } from '../../src/context/RoleContext'; @@ -164,9 +165,13 @@ function TabBar({ state, descriptors, navigation, insets }: BottomTabBarProps) { export default function TabLayout() { const { setRole } = useRole(); - useEffect(() => { - setRole('candidate'); - }, [setRole]); + // 用 useFocusEffect:进入/返回该端时随焦点写入角色, + // 避免「从企业端返回求职端」时 layout 未重新挂载导致 role 残留 enterprise。 + useFocusEffect( + useCallback(() => { + setRole('candidate'); + }, [setRole]), + ); return ( router.push('/enterprise-overview')}> + { + setRole('enterprise'); + router.push('/enterprise-overview'); + }} + hitSlop={4} + > diff --git a/src/api/api.ts b/src/api/api.ts index d41efcd..fd758e0 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -3290,7 +3290,7 @@ const MOCK_IDENTITY_OPTIONS: IdentityOption[] = [ title: '我是企业 / HR', desc: '发布岗位、筛选人才、管理评价、展示企业形象', icon: 'briefcase-outline', - role: 'hr', + role: 'enterprise', }, ]; diff --git a/src/types/tools.ts b/src/types/tools.ts index 2826a61..79cb95d 100644 --- a/src/types/tools.ts +++ b/src/types/tools.ts @@ -343,6 +343,6 @@ export interface IdentityOption { desc: string; /** 图标名(Ionicons) */ icon: string; - /** 角色:求职者 / HR */ - role: 'candidate' | 'hr'; + /** 角色:求职者 / 企业(HR) */ + role: 'candidate' | 'enterprise'; }