Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | 1x 14x 14x 14x 13x 14x 14x 14x 13x 39x | /**
* 信誉分卡片组件
*
* 显示用户的信誉分数、等级和详细分布
*/
import { memo, useMemo } from 'react';
import { View } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';
import { Card, Text, XStack, YStack } from 'tamagui';
import { IconSymbol } from '@/src/components/ui/IconSymbol';
import { BADGE_CONFIGS } from '@/src/constants/badges';
import { useThemeColors, useIsDarkMode } from '@/src/hooks/useThemeColors';
import type { ReputationSummary } from '@/src/lib/supabase/services/reputation';
interface ReputationCardProps {
reputation: ReputationSummary;
}
export const ReputationCard = memo(function ReputationCard({ reputation }: ReputationCardProps) {
const colors = useThemeColors();
const isDark = useIsDarkMode();
const badgeConfig = useMemo(() => {
return BADGE_CONFIGS[reputation.level];
}, [reputation.level]);
const scoreBreakdown = useMemo(
() => [
{
label: '资料完整度',
value: reputation.profileCompleteness,
max: 100,
weight: 0.2, // 权重20%
color: '#10B981',
icon: 'person.crop.circle.fill',
},
{
label: '评论质量',
value: reputation.reviewQuality,
max: 100,
weight: 0.4, // 权重40%
color: '#3B82F6',
icon: 'message.fill',
},
{
label: '社区贡献',
value: reputation.communityContribution,
max: 100,
weight: 0.4, // 权重40%
color: '#8B5CF6',
icon: 'heart.fill',
},
],
[reputation]
);
if (!badgeConfig) return null;
return (
<View testID="reputation-card">
<Card
backgroundColor={colors.cardBackground as any}
borderRadius={20}
padding="$4"
bordered
borderColor={colors.borderMuted as any}
>
<YStack gap="$4">
{/* 头部:等级徽章和分数 */}
<XStack alignItems="center" justifyContent="space-between">
<XStack alignItems="center" gap="$3">
{/* 等级徽章 */}
<View testID="reputation-level-badge">
<YStack
width={56}
height={56}
borderRadius={28}
alignItems="center"
justifyContent="center"
style={{
backgroundColor: badgeConfig.gradient
? 'transparent'
: badgeConfig.color + '20',
}}
>
{badgeConfig.gradient ? (
<LinearGradient
colors={badgeConfig.gradient}
style={{
width: 56,
height: 56,
borderRadius: 28,
alignItems: 'center',
justifyContent: 'center',
}}
>
<IconSymbol name={badgeConfig.icon as any} size={28} color="white" />
</LinearGradient>
) : (
<IconSymbol
name={badgeConfig.icon as any}
size={28}
color={badgeConfig.color}
/>
)}
</YStack>
</View>
{/* 等级信息 */}
<YStack>
<View testID="reputation-level">
<Text fontSize={18} fontWeight="700" color={colors.text as any}>
{badgeConfig.name}
</Text>
</View>
<Text fontSize={13} color={colors.textSecondary as any}>
{badgeConfig.description}
</Text>
</YStack>
</XStack>
{/* 总分 */}
<YStack alignItems="flex-end">
<View testID="reputation-score">
<Text fontSize={32} fontWeight="800" color={badgeConfig.color as any}>
{reputation.score}
</Text>
</View>
<Text fontSize={12} color={colors.textSecondary as any} fontWeight="600">
信誉分
</Text>
</YStack>
</XStack>
{/* 分数分布 */}
<YStack gap="$2.5">
{scoreBreakdown.map((item) => (
<YStack key={item.label} gap="$1">
<XStack alignItems="center" justifyContent="space-between">
<XStack alignItems="center" gap="$2">
<IconSymbol name={item.icon as any} size={14} color={item.color} />
<Text fontSize={13} color={colors.text as any} fontWeight="500">
{item.label}
</Text>
<Text fontSize={11} color={colors.textTertiary as any}>
(权重 {Math.round(item.weight * 100)}%)
</Text>
</XStack>
<Text fontSize={13} color={colors.textSecondary as any} fontWeight="600">
{item.value}分
</Text>
</XStack>
{/* 进度条 */}
<View testID="progress-bar">
<YStack
height={6}
backgroundColor={colors.backgroundMuted as any}
borderRadius={3}
overflow="hidden"
>
<YStack
height="100%"
width={`${Math.min((item.value / item.max) * 100, 100)}%`}
backgroundColor={item.color as any}
borderRadius={3}
/>
</YStack>
</View>
</YStack>
))}
</YStack>
</YStack>
</Card>
</View>
);
});
|