初次提交
This commit is contained in:
296
pages/index/index.vue
Normal file
296
pages/index/index.vue
Normal file
@@ -0,0 +1,296 @@
|
||||
<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>
|
||||
</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 = ''
|
||||
},
|
||||
|
||||
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 {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.question-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.question-header {
|
||||
margin-bottom: 30rpx;
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 2rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.question-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.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>
|
||||
194
pages/login/login.vue
Normal file
194
pages/login/login.vue
Normal file
@@ -0,0 +1,194 @@
|
||||
<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>
|
||||
|
||||
<button
|
||||
class="login-btn"
|
||||
:class="{ 'disabled': isLoading }"
|
||||
:disabled="isLoading"
|
||||
@click="handleLogin"
|
||||
>
|
||||
{{ isLoading ? '登录中...' : '登录' }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import api from '../../utils/api.js'
|
||||
import storage from '../../utils/storage.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
phone: '',
|
||||
code: '',
|
||||
isLoading: false
|
||||
}
|
||||
},
|
||||
|
||||
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'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.isLoading = true
|
||||
|
||||
try {
|
||||
const res = await api.login(this.phone, this.code)
|
||||
|
||||
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)
|
||||
}
|
||||
} catch (questionError) {
|
||||
console.error('获取题目失败:', questionError)
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}, 1500)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.message || '登录失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('登录失败:', error)
|
||||
} finally {
|
||||
this.isLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.login-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.login-box {
|
||||
width: 100%;
|
||||
max-width: 600rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 60rpx 40rpx;
|
||||
box-shadow: 0 10rpx 40rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.title {
|
||||
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;
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #ffffff;
|
||||
font-size: 32rpx;
|
||||
border-radius: 12rpx;
|
||||
border: none;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.login-btn.disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
139
pages/mine/mine.vue
Normal file
139
pages/mine/mine.vue
Normal file
@@ -0,0 +1,139 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="user-info">
|
||||
<view class="avatar">
|
||||
<text class="avatar-text">{{ userInfo ? userInfo.name.charAt(0).toUpperCase() : 'U' }}</text>
|
||||
</view>
|
||||
<view class="info">
|
||||
<text class="username">{{ userInfo ? userInfo.name : '未登录' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="menu-list">
|
||||
<view class="menu-item" @click="handleLogout">
|
||||
<text class="menu-text">退出登录</text>
|
||||
<text class="arrow">></text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import storage from '../../utils/storage.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
userInfo: null
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadUserInfo()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadUserInfo()
|
||||
},
|
||||
|
||||
methods: {
|
||||
loadUserInfo() {
|
||||
const userInfo = storage.getUserInfo()
|
||||
if (userInfo) {
|
||||
this.userInfo = userInfo
|
||||
}
|
||||
},
|
||||
|
||||
handleLogout() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要退出登录吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
storage.clearAll()
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 80rpx 40rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 30rpx;
|
||||
}
|
||||
|
||||
.avatar-text {
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.phone {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.menu-list {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
background: #ffffff;
|
||||
padding: 30rpx 40rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.menu-item:active {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.menu-text {
|
||||
font-size: 32rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user