存档点
This commit is contained in:
373
pages/category-question/category-question.vue
Normal file
373
pages/category-question/category-question.vue
Normal file
@@ -0,0 +1,373 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view v-if="question" class="question-card">
|
||||
<view class="question-header">
|
||||
<text class="question-title">题目</text>
|
||||
<view class="question-meta">
|
||||
<view class="meta-tag category-tag">
|
||||
<text class="meta-text">{{ getCategoryText(question.category) }}</text>
|
||||
</view>
|
||||
<view class="meta-tag difficulty-tag" :class="getDifficultyClass(question.difficulty)">
|
||||
<text class="meta-text">{{ getDifficultyText(question.difficulty) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</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>
|
||||
</view>
|
||||
<view v-else class="empty-state">
|
||||
<text class="empty-text">暂无题目</text>
|
||||
<button class="refresh-btn" @click="refreshQuestion">刷新</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import storage from '../../utils/storage.js'
|
||||
import api from '../../utils/api.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
categorySn: '',
|
||||
categoryName: '',
|
||||
question: null,
|
||||
answered: false,
|
||||
correctAnswer: '',
|
||||
selectedAnswer: '',
|
||||
explanation: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.categorySn = options.categorySn || ''
|
||||
this.categoryName = options.categoryName || ''
|
||||
this.refreshQuestion()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (this.question) {
|
||||
this.checkAnsweredQuestion()
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
loadQuestion() {
|
||||
const question = storage.getQuestion()
|
||||
if (question) {
|
||||
this.question = question
|
||||
this.resetAnswer()
|
||||
}
|
||||
},
|
||||
|
||||
checkAnsweredQuestion() {
|
||||
if (this.question && storage.isQuestionAnswered(this.question.sn)) {
|
||||
this.refreshQuestion()
|
||||
}
|
||||
},
|
||||
|
||||
resetAnswer() {
|
||||
this.answered = false
|
||||
this.correctAnswer = ''
|
||||
this.selectedAnswer = ''
|
||||
this.explanation = ''
|
||||
},
|
||||
|
||||
getCategoryText(category) {
|
||||
return category || '其他'
|
||||
},
|
||||
|
||||
getDifficultyText(difficulty) {
|
||||
if (!difficulty && difficulty !== 0) return '简单'
|
||||
if (difficulty <= 30) return '简单'
|
||||
if (difficulty <= 60) return '中等'
|
||||
if (difficulty <= 80) return '困难'
|
||||
return '极难'
|
||||
},
|
||||
|
||||
getDifficultyClass(difficulty) {
|
||||
if (!difficulty && difficulty !== 0) return 'difficulty-easy'
|
||||
if (difficulty <= 30) return 'difficulty-easy'
|
||||
if (difficulty <= 60) return 'difficulty-medium'
|
||||
if (difficulty <= 80) return 'difficulty-hard'
|
||||
return 'difficulty-extreme'
|
||||
},
|
||||
|
||||
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(this.categorySn)
|
||||
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'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.question-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.question-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 30rpx;
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 2rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.question-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.question-meta {
|
||||
display: flex;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.meta-tag {
|
||||
padding: 8rpx 20rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.category-tag {
|
||||
background: #e3f2fd;
|
||||
}
|
||||
|
||||
.difficulty-tag {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.difficulty-easy {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.difficulty-medium {
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
|
||||
.difficulty-hard {
|
||||
background: #fd7e14;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.difficulty-extreme {
|
||||
background: #dc3545;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.meta-text {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.question-content {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.question-text {
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.options-list {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.option-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 24rpx 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12rpx;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.option-item:active {
|
||||
background: #e9ecef;
|
||||
}
|
||||
|
||||
.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;
|
||||
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;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
width: 200rpx;
|
||||
height: 70rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
border-radius: 35rpx;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
162
pages/category/category.vue
Normal file
162
pages/category/category.vue
Normal file
@@ -0,0 +1,162 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view v-if="loading" class="loading">
|
||||
<text class="loading-text">加载中...</text>
|
||||
</view>
|
||||
<view v-else-if="categories.length > 0" class="category-list">
|
||||
<view
|
||||
v-for="item in categories"
|
||||
:key="item.sn"
|
||||
class="category-item"
|
||||
@click="handleCategory(item)"
|
||||
>
|
||||
<view class="category-icon">{{ getCategoryIcon(item.category) }}</view>
|
||||
<text class="category-name">{{ item.category }}</text>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="empty-state">
|
||||
<text class="empty-text">暂无类目</text>
|
||||
<button class="refresh-btn" @click="loadCategories">刷新</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import api from '../../utils/api.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
categories: [],
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadCategories()
|
||||
},
|
||||
|
||||
methods: {
|
||||
async loadCategories() {
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await api.getAllCategory()
|
||||
if (res.data && res.data.categories) {
|
||||
this.categories = res.data.categories
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取类目列表失败:', error)
|
||||
uni.showToast({
|
||||
title: '获取类目失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
getCategoryIcon(category) {
|
||||
const iconMap = {
|
||||
'传统文化': '🏮',
|
||||
'动物世界': '🦁',
|
||||
'地理自然': '🌍',
|
||||
'文学历史': '📜',
|
||||
'文学成语': '📖',
|
||||
'生活常识': '🏠',
|
||||
'科技常识': '🔬',
|
||||
'美食文化': '🍜',
|
||||
'自然科学': '🧬'
|
||||
}
|
||||
return iconMap[category] || '📚'
|
||||
},
|
||||
|
||||
handleCategory(item) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/category-question/category-question?categorySn=${item.sn}&categoryName=${item.category}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 60vh;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.category-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 30rpx;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.category-item:active {
|
||||
transform: scale(0.98);
|
||||
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.category-icon {
|
||||
font-size: 60rpx;
|
||||
margin-right: 30rpx;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
flex: 1;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 50rpx;
|
||||
color: #ccc;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 60vh;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
width: 200rpx;
|
||||
height: 70rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
border-radius: 35rpx;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
190
pages/gameplay/gameplay.vue
Normal file
190
pages/gameplay/gameplay.vue
Normal file
@@ -0,0 +1,190 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="header">
|
||||
<view class="welcome">
|
||||
<text class="welcome-title">欢迎来到答题挑战</text>
|
||||
<text class="welcome-subtitle">多种玩法,等你来挑战</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="gameplay-list">
|
||||
<view class="gameplay-item" @click="handleRandom">
|
||||
<view class="gameplay-icon random-icon">🎲</view>
|
||||
<view class="gameplay-info">
|
||||
<text class="gameplay-title">随机答题</text>
|
||||
<text class="gameplay-desc">随机抽取题目,自由挑战</text>
|
||||
</view>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="gameplay-item" @click="handleCategory">
|
||||
<view class="gameplay-icon category-icon">📚</view>
|
||||
<view class="gameplay-info">
|
||||
<text class="gameplay-title">类目答题</text>
|
||||
<text class="gameplay-desc">按类目分类,系统学习</text>
|
||||
</view>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="gameplay-item" @click="handleQuick">
|
||||
<view class="gameplay-icon quick-icon">⚡</view>
|
||||
<view class="gameplay-info">
|
||||
<text class="gameplay-title">快速答题</text>
|
||||
<text class="gameplay-desc">限时挑战,速度比拼</text>
|
||||
</view>
|
||||
<text class="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>
|
||||
export default {
|
||||
methods: {
|
||||
handleRandom() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/random/random'
|
||||
})
|
||||
},
|
||||
|
||||
handleCategory() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/category/category'
|
||||
})
|
||||
},
|
||||
|
||||
handleQuick() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/quick/quick'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.welcome {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.welcome-title {
|
||||
display: block;
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.welcome-subtitle {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.gameplay-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 30rpx;
|
||||
}
|
||||
|
||||
.gameplay-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.15);
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.gameplay-item:active {
|
||||
transform: scale(0.98);
|
||||
box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.gameplay-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 50rpx;
|
||||
margin-right: 30rpx;
|
||||
}
|
||||
|
||||
.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%);
|
||||
}
|
||||
|
||||
.gameplay-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.gameplay-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.gameplay-desc {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.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;
|
||||
color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
@@ -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>
|
||||
|
||||
@@ -1,38 +1,30 @@
|
||||
<template>
|
||||
<view class="login-container">
|
||||
<view class="login-box">
|
||||
<view class="title">欢迎登录</view>
|
||||
|
||||
<view class="form-item">
|
||||
<view class="label">手机号</view>
|
||||
<input
|
||||
class="input"
|
||||
type="number"
|
||||
v-model="phone"
|
||||
placeholder="请输入手机号"
|
||||
maxlength="11"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="form-item">
|
||||
<view class="label">验证码</view>
|
||||
<input
|
||||
class="input"
|
||||
type="number"
|
||||
v-model="code"
|
||||
placeholder="请输入验证码"
|
||||
maxlength="6"
|
||||
/>
|
||||
<view class="logo-section">
|
||||
<image class="logo" src="/static/logo.png" mode="aspectFit"></image>
|
||||
<view class="app-name">趣味答题</view>
|
||||
<view class="app-desc">海量题库,轻松学习</view>
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="login-btn"
|
||||
class="wx-login-btn"
|
||||
:class="{ 'disabled': isLoading }"
|
||||
:disabled="isLoading"
|
||||
@click="handleLogin"
|
||||
open-type="getUserInfo"
|
||||
@getuserinfo="handleWxLogin"
|
||||
>
|
||||
{{ isLoading ? '登录中...' : '登录' }}
|
||||
<text class="wx-icon">👤</text>
|
||||
<text>{{ isLoading ? '登录中...' : '微信一键登录' }}</text>
|
||||
</button>
|
||||
|
||||
<view class="skip-btn" @click="handleSkip">
|
||||
<text>暂不登录</text>
|
||||
</view>
|
||||
|
||||
<view class="tips">
|
||||
登录即表示同意《用户协议》和《隐私政策》
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -44,82 +36,149 @@ import storage from '../../utils/storage.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
phone: '',
|
||||
code: '',
|
||||
isLoading: false
|
||||
isLoading: false,
|
||||
redirectUrl: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
if (options.redirect) {
|
||||
this.redirectUrl = decodeURIComponent(options.redirect)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
async handleLogin() {
|
||||
if (!this.phone) {
|
||||
uni.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!/^1[3-9]\d{9}$/.test(this.phone)) {
|
||||
uni.showToast({
|
||||
title: '手机号格式不正确',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.code) {
|
||||
uni.showToast({
|
||||
title: '请输入验证码',
|
||||
icon: 'none'
|
||||
})
|
||||
async handleWxLogin(e) {
|
||||
if (this.isLoading) {
|
||||
return
|
||||
}
|
||||
|
||||
this.isLoading = true
|
||||
|
||||
try {
|
||||
const res = await api.login(this.phone, this.code)
|
||||
uni.showLoading({
|
||||
title: '登录中...',
|
||||
mask: true
|
||||
})
|
||||
|
||||
if (res.data && res.data.accessToken) {
|
||||
storage.setToken(res.data.accessToken)
|
||||
|
||||
const userInfo = {
|
||||
...res.data,
|
||||
phone: this.phone
|
||||
}
|
||||
storage.setUserInfo(userInfo)
|
||||
|
||||
try {
|
||||
const questionRes = await api.getQuestion()
|
||||
if (questionRes.data) {
|
||||
storage.setQuestion(questionRes.data)
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: async (loginRes) => {
|
||||
console.log('uni.login 成功:', loginRes)
|
||||
|
||||
if (!loginRes.code) {
|
||||
throw new Error('获取微信登录凭证失败')
|
||||
}
|
||||
} catch (questionError) {
|
||||
console.error('获取题目失败:', questionError)
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
|
||||
try {
|
||||
const res = await api.wxLogin(loginRes.code)
|
||||
console.log('后端登录返回:', res)
|
||||
|
||||
if (res.data && res.data.accessToken) {
|
||||
storage.setToken(res.data.accessToken)
|
||||
|
||||
const userInfo = {
|
||||
...res.data,
|
||||
nickName: res.data.nickName || '微信用户',
|
||||
avatarUrl: res.data.avatarUrl || ''
|
||||
}
|
||||
storage.setUserInfo(userInfo)
|
||||
|
||||
try {
|
||||
const questionRes = await api.getQuestion()
|
||||
if (questionRes.data) {
|
||||
storage.setQuestion(questionRes.data)
|
||||
}
|
||||
} catch (questionError) {
|
||||
console.error('获取题目失败:', questionError)
|
||||
}
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
this.navigateAfterLogin()
|
||||
}, 1500)
|
||||
} else {
|
||||
throw new Error(res.message || '登录失败')
|
||||
}
|
||||
} catch (apiError) {
|
||||
console.error('登录接口调用失败:', apiError)
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: apiError.message || '登录失败,请重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('uni.login 失败:', err)
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '微信登录失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}, 1500)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.message || '登录失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('登录失败:', error)
|
||||
console.error('登录异常:', error)
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '登录失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.isLoading = false
|
||||
}
|
||||
},
|
||||
|
||||
handleSkip() {
|
||||
if (this.redirectUrl) {
|
||||
if (this.isTabBarPage(this.redirectUrl)) {
|
||||
uni.switchTab({
|
||||
url: this.redirectUrl
|
||||
})
|
||||
} else {
|
||||
uni.redirectTo({
|
||||
url: this.redirectUrl
|
||||
})
|
||||
}
|
||||
} else {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
navigateAfterLogin() {
|
||||
if (this.redirectUrl) {
|
||||
if (this.isTabBarPage(this.redirectUrl)) {
|
||||
uni.switchTab({
|
||||
url: this.redirectUrl
|
||||
})
|
||||
} else {
|
||||
uni.redirectTo({
|
||||
url: this.redirectUrl
|
||||
})
|
||||
}
|
||||
} else {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
isTabBarPage(url) {
|
||||
const tabBarPages = [
|
||||
'/pages/index/index',
|
||||
'/pages/gameplay/gameplay',
|
||||
'/pages/mine/mine'
|
||||
]
|
||||
return tabBarPages.some(page => url.includes(page))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,55 +199,72 @@ export default {
|
||||
max-width: 600rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 60rpx 40rpx;
|
||||
padding: 80rpx 40rpx;
|
||||
box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.title {
|
||||
.logo-section {
|
||||
text-align: center;
|
||||
margin-bottom: 80rpx;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.app-name {
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
border: 2rpx solid #e0e0e0;
|
||||
border-radius: 12rpx;
|
||||
padding: 0 24rpx;
|
||||
font-size: 32rpx;
|
||||
box-sizing: border-box;
|
||||
transition: all 0.3s;
|
||||
.app-desc {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
.wx-login-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
height: 96rpx;
|
||||
background: linear-gradient(135deg, #07c160 0%, #06ae56 100%);
|
||||
color: #ffffff;
|
||||
font-size: 32rpx;
|
||||
border-radius: 12rpx;
|
||||
border-radius: 48rpx;
|
||||
border: none;
|
||||
margin-top: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(7, 193, 96, 0.3);
|
||||
}
|
||||
|
||||
.login-btn.disabled {
|
||||
.wx-login-btn.disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.wx-icon {
|
||||
font-size: 36rpx;
|
||||
margin-right: 12rpx;
|
||||
}
|
||||
|
||||
.skip-btn {
|
||||
text-align: center;
|
||||
padding: 20rpx 0;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.skip-btn text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.tips {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
text-align: center;
|
||||
line-height: 1.6;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="user-info">
|
||||
<view class="avatar">
|
||||
<text class="avatar-text">{{ userInfo ? userInfo.name.charAt(0).toUpperCase() : 'U' }}</text>
|
||||
<view class="user-info" @click="handleUserInfoClick">
|
||||
<image v-if="userInfo.avatarUrl" class="avatar" :src="userInfo.avatarUrl" mode="aspectFill"></image>
|
||||
<view v-else class="avatar">
|
||||
<text class="avatar-text">{{ userInfo.nickName ? userInfo.nickName.charAt(0) : 'U' }}</text>
|
||||
</view>
|
||||
<view class="info">
|
||||
<text class="username">{{ userInfo ? userInfo.name : '未登录' }}</text>
|
||||
<text class="username">{{ userInfo.nickName || '未登录' }}</text>
|
||||
<text v-if="!userInfo.nickName" class="login-tip">点击登录,保存答题记录</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="menu-list">
|
||||
<view class="menu-item" @click="handleLogout">
|
||||
<text class="menu-text">退出登录</text>
|
||||
<view class="menu-item">
|
||||
<text class="menu-text">关于我们</text>
|
||||
<text class="arrow">></text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="userInfo.nickName" class="action-section">
|
||||
<button class="logout-btn" @click="handleLogout">退出登录</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -24,14 +30,10 @@ import storage from '../../utils/storage.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
userInfo: null
|
||||
userInfo: {}
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadUserInfo()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadUserInfo()
|
||||
},
|
||||
@@ -41,18 +43,39 @@ export default {
|
||||
const userInfo = storage.getUserInfo()
|
||||
if (userInfo) {
|
||||
this.userInfo = userInfo
|
||||
} else {
|
||||
this.userInfo = {}
|
||||
}
|
||||
},
|
||||
|
||||
handleUserInfoClick() {
|
||||
if (!this.userInfo.nickName) {
|
||||
this.handleLogin()
|
||||
}
|
||||
},
|
||||
|
||||
handleLogin() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/mine/mine')
|
||||
})
|
||||
},
|
||||
|
||||
handleLogout() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要退出登录吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
storage.clearAll()
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
storage.removeToken()
|
||||
storage.removeUserInfo()
|
||||
storage.removeQuestion()
|
||||
storage.clearAnsweredQuestions()
|
||||
|
||||
this.userInfo = {}
|
||||
|
||||
uni.showToast({
|
||||
title: '已退出登录',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -65,7 +88,6 @@ export default {
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
@@ -75,6 +97,10 @@ export default {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.user-info:active {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
@@ -105,8 +131,8 @@ export default {
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.phone {
|
||||
font-size: 28rpx;
|
||||
.login-tip {
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
@@ -136,4 +162,26 @@ export default {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.action-section {
|
||||
margin-top: 60rpx;
|
||||
padding: 0 40rpx;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background: #ffffff;
|
||||
color: #ff4d4f;
|
||||
font-size: 32rpx;
|
||||
border-radius: 12rpx;
|
||||
border: 2rpx solid #ff4d4f;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.logout-btn:active {
|
||||
background: #fff1f0;
|
||||
}
|
||||
</style>
|
||||
|
||||
533
pages/quick/quick.vue
Normal file
533
pages/quick/quick.vue
Normal file
@@ -0,0 +1,533 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view v-if="gameState === 'prepare'" class="prepare-screen">
|
||||
<view class="countdown-circle">
|
||||
<text class="countdown-text">{{ prepareCountdown }}</text>
|
||||
</view>
|
||||
<text class="prepare-text">准备开始</text>
|
||||
</view>
|
||||
|
||||
<view v-else-if="gameState === 'playing'" class="game-screen">
|
||||
<view class="timer-bar">
|
||||
<view class="timer-progress" :style="{ width: timerProgress + '%' }"></view>
|
||||
<text class="timer-text">{{ countdown }}s</text>
|
||||
</view>
|
||||
|
||||
<view class="stats-bar">
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">正确</text>
|
||||
<text class="stat-value correct">{{ correctCount }}</text>
|
||||
</view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">错误</text>
|
||||
<text class="stat-value wrong">{{ wrongCount }}</text>
|
||||
</view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-label">正确率</text>
|
||||
<text class="stat-value">{{ accuracy }}%</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="question" class="question-card">
|
||||
<view class="question-header">
|
||||
<text class="question-title">题目</text>
|
||||
<view class="question-meta">
|
||||
<view class="meta-tag category-tag">
|
||||
<text class="meta-text">{{ getCategoryText(question.category) }}</text>
|
||||
</view>
|
||||
<view class="meta-tag difficulty-tag" :class="getDifficultyClass(question.difficulty)">
|
||||
<text class="meta-text">{{ getDifficultyText(question.difficulty) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</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>
|
||||
</view>
|
||||
|
||||
<view v-else-if="gameState === 'finished'" class="result-screen">
|
||||
<view class="result-card">
|
||||
<text class="result-title">答题结束</text>
|
||||
<view class="result-stats">
|
||||
<view class="result-stat-item">
|
||||
<text class="result-stat-label">答题总数</text>
|
||||
<text class="result-stat-value">{{ totalCount }}</text>
|
||||
</view>
|
||||
<view class="result-stat-item">
|
||||
<text class="result-stat-label">正确</text>
|
||||
<text class="result-stat-value correct">{{ correctCount }}</text>
|
||||
</view>
|
||||
<view class="result-stat-item">
|
||||
<text class="result-stat-label">错误</text>
|
||||
<text class="result-stat-value wrong">{{ wrongCount }}</text>
|
||||
</view>
|
||||
<view class="result-stat-item">
|
||||
<text class="result-stat-label">正确率</text>
|
||||
<text class="result-stat-value">{{ accuracy }}%</text>
|
||||
</view>
|
||||
</view>
|
||||
<button class="restart-btn" @click="restartGame">再来一次</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import api from '../../utils/api.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
gameState: 'prepare',
|
||||
prepareCountdown: 5,
|
||||
countdown: 60,
|
||||
timerProgress: 100,
|
||||
question: null,
|
||||
answered: false,
|
||||
correctAnswer: '',
|
||||
selectedAnswer: '',
|
||||
correctCount: 0,
|
||||
wrongCount: 0,
|
||||
totalCount: 0,
|
||||
prepareTimer: null,
|
||||
gameTimer: null
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
accuracy() {
|
||||
if (this.totalCount === 0) return 0
|
||||
return Math.round((this.correctCount / this.totalCount) * 100)
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.startPrepare()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
this.clearTimers()
|
||||
},
|
||||
|
||||
methods: {
|
||||
startPrepare() {
|
||||
this.gameState = 'prepare'
|
||||
this.prepareCountdown = 5
|
||||
this.prepareTimer = setInterval(() => {
|
||||
this.prepareCountdown--
|
||||
if (this.prepareCountdown <= 0) {
|
||||
this.clearTimers()
|
||||
this.startGame()
|
||||
}
|
||||
}, 1000)
|
||||
},
|
||||
|
||||
startGame() {
|
||||
this.gameState = 'playing'
|
||||
this.countdown = 60
|
||||
this.timerProgress = 100
|
||||
this.correctCount = 0
|
||||
this.wrongCount = 0
|
||||
this.totalCount = 0
|
||||
this.loadQuestion()
|
||||
|
||||
this.gameTimer = setInterval(() => {
|
||||
this.countdown--
|
||||
this.timerProgress = (this.countdown / 60) * 100
|
||||
if (this.countdown <= 0) {
|
||||
this.clearTimers()
|
||||
this.finishGame()
|
||||
}
|
||||
}, 1000)
|
||||
},
|
||||
|
||||
async loadQuestion() {
|
||||
try {
|
||||
const res = await api.getQuestion()
|
||||
if (res.data) {
|
||||
this.question = res.data
|
||||
this.resetAnswer()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取题目失败:', error)
|
||||
}
|
||||
},
|
||||
|
||||
resetAnswer() {
|
||||
this.answered = false
|
||||
this.correctAnswer = ''
|
||||
this.selectedAnswer = ''
|
||||
},
|
||||
|
||||
getCategoryText(category) {
|
||||
return category || '其他'
|
||||
},
|
||||
|
||||
getDifficultyText(difficulty) {
|
||||
if (!difficulty && difficulty !== 0) return '简单'
|
||||
if (difficulty <= 30) return '简单'
|
||||
if (difficulty <= 60) return '中等'
|
||||
if (difficulty <= 80) return '困难'
|
||||
return '极难'
|
||||
},
|
||||
|
||||
getDifficultyClass(difficulty) {
|
||||
if (!difficulty && difficulty !== 0) return 'difficulty-easy'
|
||||
if (difficulty <= 30) return 'difficulty-easy'
|
||||
if (difficulty <= 60) return 'difficulty-medium'
|
||||
if (difficulty <= 80) return 'difficulty-hard'
|
||||
return 'difficulty-extreme'
|
||||
},
|
||||
|
||||
async handleAnswer(option, index) {
|
||||
if (this.answered) return
|
||||
|
||||
const answer = String.fromCharCode(65 + index)
|
||||
this.selectedAnswer = answer
|
||||
this.answered = true
|
||||
this.totalCount++
|
||||
|
||||
try {
|
||||
const res = await api.answerQuestion(this.question.sn, answer)
|
||||
if (res.data) {
|
||||
this.correctAnswer = res.data.answer || answer
|
||||
|
||||
if (this.correctAnswer === answer) {
|
||||
this.correctCount++
|
||||
} else {
|
||||
this.wrongCount++
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
this.loadQuestion()
|
||||
}, 500)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('提交答案失败:', error)
|
||||
this.wrongCount++
|
||||
setTimeout(() => {
|
||||
this.loadQuestion()
|
||||
}, 500)
|
||||
}
|
||||
},
|
||||
|
||||
finishGame() {
|
||||
this.gameState = 'finished'
|
||||
},
|
||||
|
||||
restartGame() {
|
||||
this.startPrepare()
|
||||
},
|
||||
|
||||
clearTimers() {
|
||||
if (this.prepareTimer) {
|
||||
clearInterval(this.prepareTimer)
|
||||
this.prepareTimer = null
|
||||
}
|
||||
if (this.gameTimer) {
|
||||
clearInterval(this.gameTimer)
|
||||
this.gameTimer = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.prepare-screen {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 80vh;
|
||||
}
|
||||
|
||||
.countdown-circle {
|
||||
width: 300rpx;
|
||||
height: 300rpx;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.countdown-text {
|
||||
font-size: 120rpx;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.prepare-text {
|
||||
font-size: 40rpx;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.game-screen {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 30rpx;
|
||||
}
|
||||
|
||||
.timer-bar {
|
||||
position: relative;
|
||||
height: 80rpx;
|
||||
background: #e0e0e0;
|
||||
border-radius: 40rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.timer-progress {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
.timer-text {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.stats-bar {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 30rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.stat-value.correct {
|
||||
color: #28a745;
|
||||
}
|
||||
|
||||
.stat-value.wrong {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.question-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.question-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 30rpx;
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 2rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.question-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.question-meta {
|
||||
display: flex;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.meta-tag {
|
||||
padding: 8rpx 20rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.category-tag {
|
||||
background: #e3f2fd;
|
||||
}
|
||||
|
||||
.difficulty-tag {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.difficulty-easy {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.difficulty-medium {
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
|
||||
.difficulty-hard {
|
||||
background: #fd7e14;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.difficulty-extreme {
|
||||
background: #dc3545;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.meta-text {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.question-content {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.question-text {
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.options-list {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.option-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 24rpx 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12rpx;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.option-item:active {
|
||||
background: #e9ecef;
|
||||
}
|
||||
|
||||
.option-item.correct {
|
||||
background: #d4edda;
|
||||
border: 2rpx solid #28a745;
|
||||
}
|
||||
|
||||
.option-item.wrong {
|
||||
background: #f8d7da;
|
||||
border: 2rpx solid #dc3545;
|
||||
}
|
||||
|
||||
.option-text {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.result-screen {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 80vh;
|
||||
}
|
||||
|
||||
.result-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 60rpx 40rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.result-title {
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.result-stats {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 30rpx;
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.result-stat-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20rpx 30rpx;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.result-stat-label {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.result-stat-value {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.result-stat-value.correct {
|
||||
color: #28a745;
|
||||
}
|
||||
|
||||
.result-stat-value.wrong {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.restart-btn {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #ffffff;
|
||||
font-size: 32rpx;
|
||||
border-radius: 40rpx;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
368
pages/random/random.vue
Normal file
368
pages/random/random.vue
Normal file
@@ -0,0 +1,368 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view v-if="question" class="question-card">
|
||||
<view class="question-header">
|
||||
<text class="question-title">题目</text>
|
||||
<view class="question-meta">
|
||||
<view class="meta-tag category-tag">
|
||||
<text class="meta-text">{{ getCategoryText(question.category) }}</text>
|
||||
</view>
|
||||
<view class="meta-tag difficulty-tag" :class="getDifficultyClass(question.difficulty)">
|
||||
<text class="meta-text">{{ getDifficultyText(question.difficulty) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</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>
|
||||
</view>
|
||||
<view v-else class="empty-state">
|
||||
<text class="empty-text">暂无题目</text>
|
||||
<button class="refresh-btn" @click="refreshQuestion">刷新</button>
|
||||
</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()
|
||||
}
|
||||
},
|
||||
|
||||
checkAnsweredQuestion() {
|
||||
if (this.question && storage.isQuestionAnswered(this.question.sn)) {
|
||||
this.refreshQuestion()
|
||||
}
|
||||
},
|
||||
|
||||
resetAnswer() {
|
||||
this.answered = false
|
||||
this.correctAnswer = ''
|
||||
this.selectedAnswer = ''
|
||||
this.explanation = ''
|
||||
},
|
||||
|
||||
getCategoryText(category) {
|
||||
return category || '其他'
|
||||
},
|
||||
|
||||
getDifficultyText(difficulty) {
|
||||
if (!difficulty && difficulty !== 0) return '简单'
|
||||
if (difficulty <= 30) return '简单'
|
||||
if (difficulty <= 60) return '中等'
|
||||
if (difficulty <= 80) return '困难'
|
||||
return '极难'
|
||||
},
|
||||
|
||||
getDifficultyClass(difficulty) {
|
||||
if (!difficulty && difficulty !== 0) return 'difficulty-easy'
|
||||
if (difficulty <= 30) return 'difficulty-easy'
|
||||
if (difficulty <= 60) return 'difficulty-medium'
|
||||
if (difficulty <= 80) return 'difficulty-hard'
|
||||
return 'difficulty-extreme'
|
||||
},
|
||||
|
||||
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'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.question-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.question-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 30rpx;
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 2rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.question-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.question-meta {
|
||||
display: flex;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.meta-tag {
|
||||
padding: 8rpx 20rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.category-tag {
|
||||
background: #e3f2fd;
|
||||
}
|
||||
|
||||
.difficulty-tag {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.difficulty-easy {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.difficulty-medium {
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
|
||||
.difficulty-hard {
|
||||
background: #fd7e14;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.difficulty-extreme {
|
||||
background: #dc3545;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.meta-text {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.question-content {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.question-text {
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.options-list {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.option-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 24rpx 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
background: #f8f9fa;
|
||||
border-radius: 12rpx;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.option-item:active {
|
||||
background: #e9ecef;
|
||||
}
|
||||
|
||||
.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;
|
||||
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;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
width: 200rpx;
|
||||
height: 70rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
border-radius: 35rpx;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user