✨ 每日一题系统
This commit is contained in:
parent
a193e3b66b
commit
c80b8507a1
@ -80,6 +80,7 @@
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-if="hasPermissions" command="admin-dashboard">系统管理</el-dropdown-item>
|
||||
<el-dropdown-item command="user">个人中心</el-dropdown-item>
|
||||
<el-dropdown-item command="answer">每日一题</el-dropdown-item>
|
||||
<el-dropdown-item command="drafts">我的草稿</el-dropdown-item>
|
||||
<el-dropdown-item command="wallet">我的钱包</el-dropdown-item>
|
||||
<el-dropdown-item command="user-info">设置</el-dropdown-item>
|
||||
|
128
pages/answer.vue
Normal file
128
pages/answer.vue
Normal file
@ -0,0 +1,128 @@
|
||||
<template>
|
||||
<el-row class="wrapper">
|
||||
<el-col v-for="answerRecord in answerRecords" :key="answerRecord.id">
|
||||
<el-col class="question-content">
|
||||
<span v-html="getQuestionContent(answerRecord.questionContent)"></span>
|
||||
</el-col>
|
||||
<el-col>
|
||||
<el-col v-if="answerRecord.subjectAnswerRecords">
|
||||
<el-col class="question-option">
|
||||
<el-radio-group v-model="answerRecord.subjectAnswerRecords[0].answer" :disabled="true">
|
||||
<template v-for="subjectOption in answerRecord.subjectOptionDTOList">
|
||||
<el-radio :key="subjectOption.optionName" :label="subjectOption.optionName">
|
||||
<span>{{ subjectOption.optionName }}.</span>
|
||||
<span>{{ subjectOption.optionContent }}</span>
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-radio-group>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
你的答案: <span class="question-answer">{{answerRecord.subjectAnswerRecords[0].answer}}</span>
|
||||
</el-col>
|
||||
<el-col class="question-operate" :span="8">
|
||||
<el-button type="primary" @click="getAnswer">查看答案</el-button>
|
||||
</el-col>
|
||||
<el-col v-if="correctAnswer">
|
||||
正确答案: <span class="question-answer">{{ correctAnswer }}</span>
|
||||
</el-col>
|
||||
</el-col>
|
||||
<el-col v-else>
|
||||
<el-col class="question-option">
|
||||
<el-radio-group v-model="answer">
|
||||
<template v-for="subjectOption in answerRecord.subjectOptionDTOList">
|
||||
<el-radio :key="subjectOption.optionName" :label="subjectOption.optionName">
|
||||
<span>{{ subjectOption.optionName }}.</span>
|
||||
<span>{{ subjectOption.optionContent }}</span>
|
||||
</el-radio>
|
||||
</template>
|
||||
</el-radio-group>
|
||||
</el-col>
|
||||
<el-col class="question-operate" :span="6">
|
||||
<el-button type="primary" @click="submitAnswer">提交答案</el-button>
|
||||
</el-col>
|
||||
</el-col>
|
||||
</el-col>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {mapState} from 'vuex';
|
||||
|
||||
export default {
|
||||
name: "answer",
|
||||
fetch({store, params, error}) {
|
||||
return Promise.all([
|
||||
store
|
||||
.dispatch('answer/fetchDetail', params)
|
||||
.catch(err => error({statusCode: 404}))
|
||||
])
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
answerRecords: state => state.answer.detail.answerRecords
|
||||
})
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
answer: '',
|
||||
correctAnswer: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getQuestionContent(questionContent) {
|
||||
questionContent = questionContent.replace("(", "");
|
||||
questionContent = questionContent.replace(")", "");
|
||||
return questionContent;
|
||||
},
|
||||
getAnswer() {
|
||||
let _ts = this;
|
||||
_ts.$axios.$get("/api/answer/get-answer", {
|
||||
params: {
|
||||
idSubjectQuestion: _ts.answerRecords[0].id
|
||||
}
|
||||
}).then(function (res) {
|
||||
if (res) {
|
||||
_ts.$set(_ts, 'correctAnswer', res.respData);
|
||||
}
|
||||
})
|
||||
},
|
||||
submitAnswer() {
|
||||
let _ts = this;
|
||||
_ts.$axios.$post("/api/answer/answer", {
|
||||
idSubjectQuestion: _ts.answerRecords[0].id,
|
||||
answer: _ts.answer
|
||||
}).then(function (res) {
|
||||
if (res) {
|
||||
if (res.respFlag) {
|
||||
_ts.$message(res.message);
|
||||
_ts.$store.dispatch('answer/fetchDetail');
|
||||
} else {
|
||||
_ts.$message(res.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$store.commit('setActiveMenu', 'answer');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.question-content {
|
||||
margin: 10px auto;
|
||||
}
|
||||
.question-option {
|
||||
margin: 10px auto;
|
||||
}
|
||||
.question-answer {
|
||||
font-size: 36px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
.question-operate {
|
||||
margin: 10px auto;
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
@ -1,3 +1,3 @@
|
||||
User-agent: *
|
||||
Disallow: /admin
|
||||
Disallow: /draft
|
||||
Disallow: /admin/
|
||||
Disallow: /draft/
|
||||
|
38
store/answer.js
Normal file
38
store/answer.js
Normal file
@ -0,0 +1,38 @@
|
||||
export const ANSWER_API_PATH = '/api/answer';
|
||||
|
||||
export const state = () => {
|
||||
return {
|
||||
fetching: false,
|
||||
detail: {}
|
||||
}
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
// 数据列表
|
||||
updateFetching(state, action) {
|
||||
state.fetching = action
|
||||
},
|
||||
updateDetailData(state, action) {
|
||||
state.detail = action
|
||||
}
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
// 获取文章列表
|
||||
fetchDetail({commit}, params = {}) {
|
||||
// 清空已有数据
|
||||
commit('updateDetailData', {});
|
||||
commit('updateFetching', true);
|
||||
|
||||
return this.$axios
|
||||
.$get(`${ANSWER_API_PATH}/today`)
|
||||
.then(response => {
|
||||
commit('updateFetching', false);
|
||||
commit('updateDetailData', response);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
commit('updateFetching', false);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user