All files / app/detail/components BasicInfoSection.tsx

100% Statements 2/2
75% Branches 6/8
100% Functions 2/2
100% Lines 2/2

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 177 178 179 180 181 182 183 184 185                                                                                        6x                                                                                             2x                                                                                                                                                                                          
/**
 * 基本信息区域组件 - 现代购物App风格
 * 精美的产品数据展示
 */
import { LinearGradient } from 'expo-linear-gradient';
import { Text, XStack, YStack } from 'tamagui';
import { IconSymbol, type SymbolName } from '@/src/components/ui/IconSymbol';
import {
  warningScale,
  infoScale,
  errorScale,
  neutralScale,
  primaryScale,
} from '@/src/design-system/tokens';
 
interface BasicInfoSectionProps {
  brand: string;
  score: number | null;
  countNum: number;
  likeCount: number;
  catfoodId: number;
}
 
interface StatCardProps {
  icon: SymbolName;
  iconBgColor: string;
  iconColor: string;
  label: string;
  value: string;
  unit?: string;
  valueColor: string;
  bgGradient: readonly [string, string];
}
 
function StatCard({
  icon,
  iconBgColor,
  iconColor,
  label,
  value,
  unit,
  valueColor,
  bgGradient,
}: StatCardProps) {
  return (
    <YStack flex={1} borderRadius={16} overflow="hidden">
      <LinearGradient
        colors={bgGradient}
        start={{ x: 0, y: 0 }}
        end={{ x: 0, y: 1 }}
        style={{
          padding: 16,
          alignItems: 'center',
          gap: 10,
          borderRadius: 16,
        }}
      >
        {/* 图标容器 */}
        <YStack
          width={48}
          height={48}
          borderRadius={24}
          backgroundColor={iconBgColor as any}
          alignItems="center"
          justifyContent="center"
        >
          <IconSymbol name={icon} size={24} color={iconColor} />
        </YStack>
 
        {/* 数值 */}
        <XStack alignItems="baseline" gap={2}>
          <Text fontSize={28} fontWeight="900" color={valueColor as any} letterSpacing={-1}>
            {value}
          </Text>
          {unit && (
            <Text fontSize={12} fontWeight="600" color={valueColor as any} opacity={0.7}>
              {unit}
            </Text>
          )}
        </XStack>
 
        {/* 标签 */}
        <Text fontSize={12} color={neutralScale.neutral8} fontWeight="600">
          {label}
        </Text>
      </LinearGradient>
    </YStack>
  );
}
 
export function BasicInfoSection({ brand, score, countNum, likeCount }: BasicInfoSectionProps) {
  return (
    <YStack
      marginHorizontal="$3"
      marginBottom="$3"
      borderRadius={20}
      backgroundColor="white"
      overflow="hidden"
      borderWidth={1}
      borderColor={neutralScale.neutral3}
    >
      {/* 品牌信息 */}
      <XStack
        padding="$4"
        alignItems="center"
        gap="$3"
        borderBottomWidth={1}
        borderBottomColor={neutralScale.neutral2}
      >
        <YStack
          width={48}
          height={48}
          borderRadius={24}
          backgroundColor={primaryScale.primary2}
          alignItems="center"
          justifyContent="center"
        >
          <IconSymbol name="building.2.fill" size={22} color={primaryScale.primary8} />
        </YStack>
        <YStack flex={1} gap={2}>
          <Text fontSize={11} color={neutralScale.neutral8} fontWeight="500">
            品牌
          </Text>
          <Text fontSize="$5" fontWeight="800" color={neutralScale.neutral12} letterSpacing={-0.3}>
            {brand || '未知品牌'}
          </Text>
        </YStack>
        <YStack
          backgroundColor={primaryScale.primary2}
          paddingHorizontal="$3"
          paddingVertical="$1.5"
          borderRadius={20}
        >
          <Text fontSize={11} fontWeight="700" color={primaryScale.primary9}>
            官方认证
          </Text>
        </YStack>
      </XStack>
 
      {/* 产品数据统计 */}
      <YStack padding="$4" gap="$4">
        <XStack alignItems="center" gap="$2">
          <YStack width={4} height={16} borderRadius={2} backgroundColor={primaryScale.primary7} />
          <Text fontSize="$4" fontWeight="700" color={neutralScale.neutral11}>
            产品数据
          </Text>
        </XStack>
 
        <XStack gap="$3">
          <StatCard
            icon="star.fill"
            iconBgColor={warningScale.warning3}
            iconColor={warningScale.warning8}
            label="综合评分"
            value={score ? score.toFixed(1) : '0.0'}
            valueColor={warningScale.warning9}
            bgGradient={[warningScale.warning1, '#FFFFFF']}
          />
 
          <StatCard
            icon="person.2.fill"
            iconBgColor={infoScale.info3}
            iconColor={infoScale.info8}
            label="评价人数"
            value={`${countNum || 0}`}
            unit="人"
            valueColor={infoScale.info9}
            bgGradient={[infoScale.info1, '#FFFFFF']}
          />
 
          <StatCard
            icon="heart.fill"
            iconBgColor={errorScale.error3}
            iconColor={errorScale.error7}
            label="获赞数量"
            value={`${likeCount}`}
            valueColor={errorScale.error8}
            bgGradient={[errorScale.error1, '#FFFFFF']}
          />
        </XStack>
      </YStack>
    </YStack>
  );
}