chore: v3.0.0-40306202411280010quiz_out_class

main
刘东阳 2 months ago
parent 8ee6180906
commit f05f1bf448

@ -1,15 +1,3 @@
<Modal visible={change} style={{background: 'white'}} width="800px" title="编辑讨论内容"
onCancel={e=>{setChange(false)}}
onOk={e=>{setChange(false)}}
footer={<div>
<Button onClick={e=>{
const temp=[...taolonglist]
setyulan(taolonglist)
setChange(false)}}
>保存</Button>
<Button onClick={e=>setChange(false)}>关闭</Button>
</div>}
>
<Card
@ -584,5 +572,3 @@
添加
</Button>
</Card>
</Modal>

@ -129,6 +129,11 @@
"style": {
"navigationBarTitleText": "shnagke"
}
},{
"path": "pages/quiz_outclass/quiz_outclass",
"style": {
"navigationBarTitleText": "课程答题"
}
}
],
"tabBar": {

@ -66,7 +66,7 @@
{
name: '答题',
icon: '/static/student-course/quiz.png',
page: '/pages/quiz/quiz'
page: '/pages/quiz_outclass/quiz_outclass?uuid=b2d2ece7-2994-4580-b45d-b2288ecd80de'
},
{
name: '考试',

@ -140,6 +140,7 @@ const dx=ref('0');
const moredx=ref([])
const pdt=ref("none")
const tkt=ref([])
const uid=ref('122')
const dati_able=ref(true)
const intervalId = ref<number | null>(null); //
const endtime=ref('')
@ -188,7 +189,7 @@ function tkt_one_get(xx:string,index:number){
onLoad((options) => {
console.log('load', options)
if(options) {
uid.value=options.uuid;
console.log('options:', options.uuid)
uni.request({
url: 'http://localhost:3400/apistu/getinclassactive',
@ -206,6 +207,25 @@ onLoad((options) => {
}
});
}
uni.request({
url: 'http://localhost:3400/apistu/getinclassactivestu_ex',
method: 'GET',
data: { // GET `data` `params` :ml-citation{ref="8" data="citationList"}
uuid: options.uuid,
xuehao:'202413501062'
},
success: (res) => { /* ... */
console.log(res.data)
if(res.data.length>0) {
stopTimer();
dati_able.value=false
tijiao_type.value="已提交"
console.log(res.data)
}
}
});
if(question.value.tx==="填空题") {
tkt.value = new Array(question.value.tk.length).fill('');
}
@ -221,7 +241,8 @@ function moredx_one(xx:string){
}
const startTimer = () => {
intervalId.value = setInterval(() => {
if (totaltime.value >0) {
if (totaltime.value >0&&tijiao_type.value!=="已提交") {
totaltime.value=moment(endtime.value).diff(moment(),'seconds')
@ -349,7 +370,7 @@ function submitAnswers() {
zq=false;
}
})
if(question.value.morechoose.length===moredx.value.length){
if(question.value.morechoose.length!==moredx.value.length){
zq=false;
}
let dxt={stu:moredx.value,all:question.value.morechoose}
@ -389,7 +410,8 @@ function submitAnswers() {
if(pd_work!==question.value.onechoose)zq=false;
let dxt={stu:dx.value,all:question.value.onechoose}
let dxt={stu:pd_work,all:question.value.onechoose}
if(zq){
resulttm.stu=question.value.print
resulttm.all=question.value.print
@ -402,7 +424,7 @@ function submitAnswers() {
console.log(resulttm)
}
uni.request({
url: 'http://localhost:3400/apistu/addinactivestu_qiangda',
url: 'http://localhost:3400/apistu/inclassdati_tijiao',
method: 'POST',
data: { // GET `data` `params` :ml-citation{ref="8" data="citationList"}
uuid: uid.value,
@ -410,11 +432,12 @@ function submitAnswers() {
kctime:'n8z1A1',
xuehao: '202413501063',
time:moment().format('YYYY-MM-DD HH:mm:ss'),
starttime:starttime.value,
name:"刘东阳A",
touxiangcolor:"red"
name:"刘东阳",
touxiangcolor:"red",
tmresult:resulttm
},
success: (res) => { /* ... */
uni.$emit('finish_ex',{uuid:uid.value,wb:'已完成'})
console.log(res.data)
}

@ -0,0 +1,311 @@
<template>
<view class="quiz-container">
<!-- 顶部栏 -->
<view class="top-bar">
<view class="question-info">
<text class="question-text">{{ currentQuestion.lx }} ({{ currentQuestion.score }} )</text>
</view>
<button class="answer-card-btn" @click="showAnswerCard"></button>
</view>
<!-- 动态渲染题目 -->
<view v-for="(question, index) in quizData" :key="question.id" class="question">
<view v-show="activeIndex === index">
<!-- 题目文本 -->
<text class="question-text">{{ question.text }}</text>
<!-- 选项支持图片或文本 -->
<radio-group
v-if="question.type === 'single'"
:modelValue="userAnswers[question.id]"
@update:modelValue="handleRadioChange(question.id, $event)"
>
<label v-for="(option, i) in question.options" :key="i" class="option">
<radio :value="option.value" />
<image v-if="option.image" :src="option.image" mode="aspectFit" class="option-image" />
<text v-else>{{ option.text }}</text>
</label>
</radio-group>
<!-- 其他题型类似处理 -->
</view>
</view>
<!-- 答案反馈 -->
<view v-if="showResult" class="result">
<text v-for="(res, key) in results" :key="key" :style="{ color: res ? 'green' : 'red' }">
{{ key + 1 }} {{ res ? '✅ 正确' : '❌ 错误' }}
</text>
</view>
<!-- 答题卡 -->
<view v-if="showAnswerCardFlag" class="answer-card">
<view v-for="(question, index) in quizData" :key="question.id" class="card-item" @click="goToQuestion(index)">
<text> {{ index + 1 }} </text>
<text :style="{ color: userAnswers[question.id] ? 'blue' : 'gray' }">
{{ userAnswers[question.id] || '未作答' }}
</text>
</view>
</view>
<!-- 得分与正确答案展示 -->
<view v-if="showResult" class="score-and-answer">
<text>本题得分{{ score }}</text>
<text>正确答案{{ correctAnswer }}</text>
</view>
<!-- 底部控制按钮 -->
<view class="bottom-controls">
<button @click="prevQuestion"></button>
<button @click="submitAnswers" type="primary">提交答案</button>
<button @click="nextQuestion"></button>
</view>
</view>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import {onLoad} from "@dcloudio/uni-app";
//
const quizData = [
{
id: 1,
type: 'single',
lx: '单选题',
score: 5,
text: '计算由曲线 y=x?和直线y=x所围成的平面区域的面积,下列选项中正确的是()。',
options: [
{ value: 'A', text: '选项A' },
{ value: 'B', text: '选项B' },
{ value: 'C', text: '选项C' },
{ value: 'D', text: '选项D' }
],
answer: 'B'
},
{
id: 2,
type: 'single',
lx: '单选题',
score: 5,
text: '计算由曲线 y=x?和直线y=x所围成的平面区域的面积,下列选项中正确的是()。',
options: [
{ value: 'A', text: '选项A' },
{ value: 'B', text: 'B' },
{ value: 'C', text: '选项C' },
{ value: 'D', text: '选项D' }
],
answer: 'B'
}
]
//
const activeIndex = ref(0)
//
const showResult = ref(false)
// /
const showAnswerCardFlag = ref(false)
//
const currentQuestion = computed(() => {
return quizData[activeIndex.value] || {}
})
// ID
const userAnswers = ref<Record<number, any>>({})
// true/false
const results = ref<boolean[]>([])
//
function handleRadioChange(id: number, value: string) {
userAnswers.value[id] = value
}
//
function prevQuestion() {
if (activeIndex.value > 0) activeIndex.value--
}
//
function nextQuestion() {
if (activeIndex.value < quizData.length - 1) activeIndex.value++
}
//
function goToQuestion(index: number) {
activeIndex.value = index
showAnswerCardFlag.value = false //
}
//
function submitAnswers() {
//
results.value[activeIndex.value] = false
const currentQuestion = quizData[activeIndex.value]
const userAnswer = userAnswers.value[currentQuestion.id] ?? ''
const correctAnswer = String(currentQuestion.answer)
const normalizedUserAnswer = String(userAnswer).trim().toUpperCase()
const normalizedCorrectAnswer = correctAnswer.trim().toUpperCase()
const isCorrect = normalizedUserAnswer == normalizedCorrectAnswer
results.value[activeIndex.value] = isCorrect
showResult.value = true
}
//
const score = computed(() => {
const currentResult = results.value[activeIndex.value]
return currentResult ? currentQuestion.value.score : 0
})
//
const correctAnswer = computed(() => {
const currentQuestion = quizData[activeIndex.value]
if (!currentQuestion) return ''
const correctOption = currentQuestion.options.find(
option => option.value === currentQuestion.answer
)
return correctOption ? correctOption.text : ''
})
//
function showAnswerCard() {
showAnswerCardFlag.value = !showAnswerCardFlag.value
}
onLoad((options) => {
console.log(options)
})
</script>
<style scoped>
.quiz-container {
padding: 5px;
position: relative;
}
/* 顶部栏样式 */
.top-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 3px;
border-bottom: 1px solid #e0e0e0;
background-color: #d97e7e;
}
.question-text {
font-size: 16px;
color: #333;
font-weight: bold;
margin-left: 10px;
}
.answer-card-btn {
background-color: #63a2cf;
border: 1px solid #a8d5ff;
color: #000;
padding: 3px 6px;
border-radius: 4px;
font-size: 12px;
background-color: #4490ca;
margin-left: auto;
}
/* 新增左侧竖线装饰 */
.question-info::before {
content: '';
display: inline-block;
width: 4px;
height: 20px;
background-color: #007bff;
margin-right: 3px;
}
.question {
margin-bottom: 20px;
}
.question-text {
font-size: 16px;
margin-bottom: 10px;
}
.option {
display: flex;
align-items: center;
margin: 5px 0;
}
.option-image {
width: 50px;
height: 50px;
margin-left: 10px;
}
.result {
margin-top: 20px;
}
.answer-card {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 20px;
}
.card-item {
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
cursor: pointer;
background-color: #0ef306;
}
.score-and-answer {
margin-top: 20px;
background-color: #f0f0f0;
padding: 10px;
border-radius: 8px;
}
.bottom-controls {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background-color: #fff;
padding: 5px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.1);
}
.bottom-controls button {
padding: 5px 10px;
font-size: 14px;
border-radius: 4px;
background-color: #f0f0f0;
color: #333;
border: none;
transition: all 0.3s ease;
}
.bottom-controls button:hover {
background-color: #e0e0e0;
}
.bottom-controls button[type="primary"] {
background-color: #2196f3;
color: #fff;
}
.bottom-controls button[type="primary"]:hover {
background-color: #1976d2;
}
</style>
Loading…
Cancel
Save