This commit is contained in:
nopy 2024-06-29 12:51:21 +08:00
commit 0d813ceaf9
5 changed files with 64 additions and 59 deletions

View File

@ -1,9 +1,12 @@
.pods table{ .list-pods-container {
width: 500px; width: 100%;
text-align: center; height: 100%;
border: 1px solid black; display: flex;
} justify-content: center;
.pods p{ align-items: center;
line-height: 0px; }
margin: 0px;
} h1 {
font-size: 2rem;
color: #333;
}

View File

@ -1,36 +1,28 @@
import './list_pods.css' import './list_pods.css'
import React, { useEffect, useState } from 'react';
function List_pods(){ function List_pods(){
const [seconds, setSeconds] = useState(60);
const handleStart = () => {
const intervalId = setInterval(() => {
if (seconds > 0) {
setSeconds(seconds - 1);
} else {
clearInterval(intervalId);
alert('考试时间到!');
}
}, 1000);
return( return () => {
<div className="pods"> clearInterval(intervalId);
<table> };
<tr> };
<td>Name</td>
<td>TestID</td> return (
<td>Train</td> <div className="App">
<td>Start</td> <h1>剩余时间{seconds}</h1>
<td>End</td> <button onClick={handleStart}>开始倒计时</button>
</tr> </div>
<tr> );
<td colSpan="5"><hr /></td>
</tr>
<tr>
<td>zhoutao</td>
<td>33</td>
<td>0</td>
<td>2024-7-1</td>
<td>2024-7-2</td>
</tr>
<tr>
<td>zhoutao</td>
<td>33</td>
<td>0</td>
<td>2024-7-1</td>
<td>2024-7-2</td>
</tr>
</table>
</div>
)
} }
export default List_pods export default List_pods

View File

@ -10,8 +10,9 @@ import top from '../img/top.jpg'
import axios from 'axios'; import axios from 'axios';
function Operation1() { function Operation1() {
const[isTrue,setisTrue]=useState(true)
const click=()=>{ const click=()=>{
console.log(TrainData['operateID'][3][0]); console.log(60 * parseInt(TrainData['operateID'][4]));
} }
const clear=()=>{ const clear=()=>{
localStorage.removeItem('choice_answers'); localStorage.removeItem('choice_answers');
@ -44,27 +45,29 @@ function Operation1() {
alert('TrainDataFunc出错') alert('TrainDataFunc出错')
} }
} }
useEffect(()=>{ useEffect(()=>{
TrainDataFunc() TrainDataFunc()
const RemainingTime=localStorage.getItem('RemainingTime')
if(!isNaN(RemainingTime) && RemainingTime !== '') {
setCountdown(RemainingTime);
} else {
setCountdown(60 * parseInt(TrainData['operateID'][4]));
}
},[]) },[])
//
const [countdown, setCountdown] = useState();
const [time,settime]=useState()
//
useEffect(()=>{
if(localStorage.getItem('time')){
setCountdown(localStorage.getItem('time'))
}else{
if(TrainData){
setCountdown(60 * parseInt(TrainData['operateID'][4]))
}
}
},[TrainData])
//
const [countdown, setCountdown] = useState(null);
// //
useEffect(() => { useEffect(() => {
let interval = setInterval(() => { let interval = setInterval(() => {
if (countdown != 0) { if (countdown > 0 ) {
setCountdown(countdown - 1); setCountdown(countdown - 1);
localStorage.setItem('RemainingTime',countdown) localStorage.setItem('time',countdown-1)
} else { } else {
clearInterval(interval); clearInterval(interval);
alert('考试时间到!'); alert('考试时间到!');

View File

@ -101,6 +101,7 @@
} }
/* 前进按钮 */ /* 前进按钮 */
.btn-out2{ .btn-out2{
cursor: pointer;
height: 50px; height: 50px;
position: absolute; position: absolute;
bottom: 50px; bottom: 50px;

View File

@ -12,7 +12,7 @@ import top from '../img/top.jpg'
function Operation2() { function Operation2() {
const { operateID } = useParams(); const { operateID } = useParams();
// //
const RemainingTime=localStorage.getItem('RemainingTime')
// //
@ -67,15 +67,15 @@ function Operation2() {
// //
useEffect(() => { useEffect(() => {
setCountdown(RemainingTime); setCountdown(localStorage.getItem('time'))
}, []); }, []);
// //
useEffect(() => { useEffect(() => {
let interval = setInterval(() => { let interval = setInterval(() => {
if (countdown != 0) { if (countdown !== 0) {
setCountdown(countdown - 1); setCountdown(countdown - 1);
localStorage.setItem('RemainingTime',countdown) localStorage.setItem('time',countdown-1)
} else { } else {
clearInterval(interval); clearInterval(interval);
alert('考试时间到!'); alert('考试时间到!');
@ -95,6 +95,12 @@ function Operation2() {
// //
const [isSubjectDropdownOpen, setIsSubjectDropdownOpen] = useState(false); const [isSubjectDropdownOpen, setIsSubjectDropdownOpen] = useState(false);
const tijiao = ()=>{
clearInterval()
localStorage.removeItem('time')
window.location.href='http://baidu.com'
}
return ( return (
<div> <div>
<div className='nav-operation2'> <div className='nav-operation2'>
@ -132,10 +138,10 @@ function Operation2() {
<p>上一页</p> <p>上一页</p>
<img src={arrowleft} alt="" width='40px' height='40px' /> <img src={arrowleft} alt="" width='40px' height='40px' />
</Link> </Link>
<Link className='btn-out2' style={{color:'#000',textDecoration:'none'}}> <button onClick={tijiao} className='btn-out2' style={{color:'#000',textDecoration:'none'}}>
<img src={arrowright} alt="" width='40px' height='40px' /> <img src={arrowright} alt="" width='40px' height='40px' />
<p>完成</p> <p>完成</p>
</Link> </button>
</div> </div>
</div> </div>
) )