|
|
|
@ -12,8 +12,6 @@ interface Props { |
|
|
|
|
type AnswerType = "true" | 'false' |
|
|
|
|
|
|
|
|
|
export const Single: FC<Props> = (props) => { |
|
|
|
|
if (!props.topic) return (<></>) |
|
|
|
|
|
|
|
|
|
let timer: NodeJS.Timeout |
|
|
|
|
const [lastState, setLastState] = useState<0 | 1>(0) // 0为竖屏,1为横屏
|
|
|
|
|
const [result, setResult] = useState<AnswerType | undefined>(undefined) |
|
|
|
@ -58,18 +56,19 @@ export const Single: FC<Props> = (props) => { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
// timer = setTimeout(() => {
|
|
|
|
|
// props.examination(false)
|
|
|
|
|
// }, 4000)
|
|
|
|
|
timer = setTimeout(() => { |
|
|
|
|
props.examination(false) |
|
|
|
|
}, 4000) |
|
|
|
|
}, [props.topic]) |
|
|
|
|
|
|
|
|
|
const style: React.CSSProperties = useMemo(() => ({ |
|
|
|
|
transform: lastState === 0 && props.full ? "rotate(-90deg)" : 'none' |
|
|
|
|
}), [lastState]) |
|
|
|
|
transform: lastState === 1 && props.full ? "rotate(90deg)" : 'none' |
|
|
|
|
}), [lastState, props.full]) |
|
|
|
|
|
|
|
|
|
function examination(result: AnswerType) { |
|
|
|
|
function examination(answer: AnswerType) { |
|
|
|
|
if (result) return; |
|
|
|
|
clearTimeout(timer) |
|
|
|
|
setResult(result) |
|
|
|
|
setResult(answer) |
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
props.examination(props.topic?.right_value === result) |
|
|
|
@ -78,24 +77,29 @@ export const Single: FC<Props> = (props) => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function judgment(answer: AnswerType): string { |
|
|
|
|
if (props.topic?.right_value === answer && result === answer) { |
|
|
|
|
if (result !== answer) return '' |
|
|
|
|
if (props.topic?.right_answer === answer && result === answer) { |
|
|
|
|
return styles.correct |
|
|
|
|
} |
|
|
|
|
return styles.mistake |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<View className={styles.singleCover} style={style}> |
|
|
|
|
<View>{props.topic.question}</View> |
|
|
|
|
<View className={judgment("true")} |
|
|
|
|
onClick={() => examination("true")}> |
|
|
|
|
{props.topic.right_value} |
|
|
|
|
</View> |
|
|
|
|
<View className={judgment("false")} |
|
|
|
|
onClick={() => examination("false")}> |
|
|
|
|
{props.topic.error_value} |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
<> |
|
|
|
|
{ |
|
|
|
|
props.topic && <View className={styles.singleCover} style={style}> |
|
|
|
|
<View>{props.topic.question}</View> |
|
|
|
|
<View className={judgment("true")} |
|
|
|
|
onClick={() => examination("true")}> |
|
|
|
|
{props.topic.right_value} |
|
|
|
|
</View> |
|
|
|
|
<View className={judgment("false")} |
|
|
|
|
onClick={() => examination("false")}> |
|
|
|
|
{props.topic.error_value} |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
} |
|
|
|
|
</> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|