'use client'; import { useState } from 'react'; import { Box, Rating, Typography } from '@mui/material'; import StarIcon from '@mui/icons-material/Star'; import { useTranslation } from 'react-i18next'; /** * 五星评分组件 */ export default function StarRating({ value = 0, onChange, readOnly = false, size = 'medium', showLabel = true }) { const { t } = useTranslation(); const [hover, setHover] = useState(-1); const labels = { 0.5: t('rating.veryPoor', '很差'), 1: t('rating.poor', '差'), 1.5: t('rating.belowAverage', '偏差'), 2: t('rating.fair', '一般'), 2.5: t('rating.average', '中等'), 3: t('rating.good', '良好'), 3.5: t('rating.veryGood', '很好'), 4: t('rating.excellent', '优秀'), 4.5: t('rating.outstanding', '杰出'), 5: t('rating.perfect', '完美') }; const getLabelText = value => { return `${value} Star${value !== 1 ? 's' : ''}, ${labels[value]}`; }; return ( { if (!readOnly && onChange) { onChange(newValue || 0); } }} onChangeActive={(event, newHover) => { if (!readOnly) { setHover(newHover); } }} readOnly={readOnly} size={size} icon={} emptyIcon={} sx={{ '& .MuiRating-iconFilled': { color: '#ffc107' }, '& .MuiRating-iconHover': { color: '#ffb300' } }} /> {showLabel && ( {labels[hover !== -1 ? hover : value] || (value === 0 ? t('rating.unrated', '未评分') : '')} )} ); }