存档点
This commit is contained in:
@@ -1,147 +1,74 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view v-if="question" class="question-card">
|
||||
<view class="question-header">
|
||||
<text class="question-title">题目</text>
|
||||
</view>
|
||||
<view class="question-content">
|
||||
<text class="question-text">{{ question.question }}</text>
|
||||
</view>
|
||||
<view v-if="question.options" class="options-list">
|
||||
<view
|
||||
v-for="(option, index) in question.options"
|
||||
:key="index"
|
||||
class="option-item"
|
||||
:class="{
|
||||
'correct': answered && correctAnswer === String.fromCharCode(65 + index),
|
||||
'wrong': answered && selectedAnswer === String.fromCharCode(65 + index) && correctAnswer !== String.fromCharCode(65 + index)
|
||||
}"
|
||||
@click="handleAnswer(option, index)"
|
||||
>
|
||||
<text class="option-text">{{ option }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="answered && explanation" class="explanation">
|
||||
<view class="explanation-title">解析</view>
|
||||
<text class="explanation-text">{{ explanation }}</text>
|
||||
</view>
|
||||
<view class="action-buttons">
|
||||
<button class="next-btn" @click="refreshQuestion">下一题</button>
|
||||
<view class="header">
|
||||
<view class="welcome">
|
||||
<text class="welcome-title">欢迎来到答题挑战</text>
|
||||
<text class="welcome-subtitle">多种玩法,等你来挑战</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="empty-state">
|
||||
<text class="empty-text">暂无题目</text>
|
||||
<button class="refresh-btn" @click="refreshQuestion">刷新</button>
|
||||
|
||||
<view class="game-modes">
|
||||
<view class="mode-card" @click="goToRandom">
|
||||
<view class="mode-icon random-icon">🎲</view>
|
||||
<view class="mode-info">
|
||||
<text class="mode-title">随机答题</text>
|
||||
<text class="mode-desc">随机抽取题目,自由挑战</text>
|
||||
</view>
|
||||
<text class="mode-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="mode-card" @click="goToCategory">
|
||||
<view class="mode-icon category-icon">📚</view>
|
||||
<view class="mode-info">
|
||||
<text class="mode-title">类目答题</text>
|
||||
<text class="mode-desc">按类目分类,系统学习</text>
|
||||
</view>
|
||||
<text class="mode-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="mode-card" @click="goToQuick">
|
||||
<view class="mode-icon quick-icon">⚡</view>
|
||||
<view class="mode-info">
|
||||
<text class="mode-title">快速答题</text>
|
||||
<text class="mode-desc">限时挑战,速度比拼</text>
|
||||
</view>
|
||||
<text class="mode-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="tips">
|
||||
<view class="tip-item">
|
||||
<text class="tip-icon">💡</text>
|
||||
<text class="tip-text">每日坚持答题,提升知识储备</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import storage from '../../utils/storage.js'
|
||||
import api from '../../utils/api.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
question: null,
|
||||
answered: false,
|
||||
correctAnswer: '',
|
||||
selectedAnswer: '',
|
||||
explanation: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadQuestion()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadQuestion()
|
||||
this.checkAnsweredQuestion()
|
||||
},
|
||||
|
||||
methods: {
|
||||
loadQuestion() {
|
||||
const question = storage.getQuestion()
|
||||
if (question) {
|
||||
this.question = question
|
||||
this.resetAnswer()
|
||||
}
|
||||
goToRandom() {
|
||||
uni.switchTab({
|
||||
url: '/pages/random/random'
|
||||
})
|
||||
},
|
||||
|
||||
checkAnsweredQuestion() {
|
||||
if (this.question && storage.isQuestionAnswered(this.question.sn)) {
|
||||
this.refreshQuestion()
|
||||
}
|
||||
goToCategory() {
|
||||
uni.switchTab({
|
||||
url: '/pages/category/category'
|
||||
})
|
||||
},
|
||||
|
||||
resetAnswer() {
|
||||
this.answered = false
|
||||
this.correctAnswer = ''
|
||||
this.selectedAnswer = ''
|
||||
this.explanation = ''
|
||||
},
|
||||
|
||||
async handleAnswer(option, index) {
|
||||
if (this.answered) return
|
||||
|
||||
const answer = String.fromCharCode(65 + index)
|
||||
this.selectedAnswer = answer
|
||||
|
||||
try {
|
||||
const res = await api.answerQuestion(this.question.sn, answer)
|
||||
if (res.data) {
|
||||
this.answered = true
|
||||
this.correctAnswer = res.data.answer || answer
|
||||
this.explanation = res.data.explanation || ''
|
||||
|
||||
storage.addAnsweredQuestion(this.question.sn)
|
||||
|
||||
if (this.correctAnswer === answer) {
|
||||
uni.showToast({
|
||||
title: '回答正确',
|
||||
icon: 'success'
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '回答错误',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('提交答案失败:', error)
|
||||
uni.showToast({
|
||||
title: '提交失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async refreshQuestion() {
|
||||
try {
|
||||
const res = await api.getQuestion()
|
||||
if (res.data) {
|
||||
if (storage.isQuestionAnswered(res.data.sn)) {
|
||||
this.refreshQuestion()
|
||||
return
|
||||
}
|
||||
storage.setQuestion(res.data)
|
||||
this.question = res.data
|
||||
this.resetAnswer()
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '暂无题目',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取题目失败:', error)
|
||||
uni.showToast({
|
||||
title: '刷新失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
goToQuick() {
|
||||
uni.switchTab({
|
||||
url: '/pages/quick/quick'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,147 +77,119 @@ export default {
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.question-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
.header {
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.question-header {
|
||||
margin-bottom: 30rpx;
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 2rpx solid #f0f0f0;
|
||||
.welcome {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.question-title {
|
||||
font-size: 32rpx;
|
||||
.welcome-title {
|
||||
display: block;
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
color: #ffffff;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.question-content {
|
||||
margin-bottom: 40rpx;
|
||||
.welcome-subtitle {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.question-text {
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
line-height: 1.8;
|
||||
.game-modes {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 30rpx;
|
||||
}
|
||||
|
||||
.options-list {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.option-item {
|
||||
.mode-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 24rpx 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.15);
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.option-item:active {
|
||||
background: #e9ecef;
|
||||
.mode-card:active {
|
||||
transform: scale(0.98);
|
||||
box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.option-item.correct {
|
||||
background: #d4edda;
|
||||
border: 2rpx solid #28a745;
|
||||
}
|
||||
|
||||
.option-item.wrong {
|
||||
background: #f8d7da;
|
||||
border: 2rpx solid #dc3545;
|
||||
}
|
||||
|
||||
.option-label {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
margin-right: 20rpx;
|
||||
min-width: 40rpx;
|
||||
}
|
||||
|
||||
.option-item.correct .option-label {
|
||||
color: #28a745;
|
||||
}
|
||||
|
||||
.option-item.wrong .option-label {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.option-text {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.explanation {
|
||||
margin-top: 40rpx;
|
||||
padding: 30rpx;
|
||||
background: #fff3cd;
|
||||
border-radius: 12rpx;
|
||||
border-left: 4rpx solid #ffc107;
|
||||
}
|
||||
|
||||
.explanation-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #856404;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.explanation-text {
|
||||
font-size: 28rpx;
|
||||
color: #856404;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
margin-top: 40rpx;
|
||||
.mode-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 20rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.next-btn {
|
||||
width: 200rpx;
|
||||
height: 70rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
border-radius: 35rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 60vh;
|
||||
font-size: 50rpx;
|
||||
margin-right: 30rpx;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
.random-icon {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
}
|
||||
|
||||
.category-icon {
|
||||
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
||||
}
|
||||
|
||||
.quick-icon {
|
||||
background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
|
||||
}
|
||||
|
||||
.mode-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.mode-title {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
margin-bottom: 40rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
width: 200rpx;
|
||||
height: 70rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #ffffff;
|
||||
.mode-desc {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.mode-arrow {
|
||||
font-size: 50rpx;
|
||||
color: #ccc;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.tips {
|
||||
margin-top: 60rpx;
|
||||
}
|
||||
|
||||
.tip-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.tip-icon {
|
||||
font-size: 36rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.tip-text {
|
||||
font-size: 28rpx;
|
||||
border-radius: 35rpx;
|
||||
border: none;
|
||||
color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user