初始化页面结构
This commit is contained in:
21
src/components/Draw.vue
Normal file
21
src/components/Draw.vue
Normal file
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<div class="DrawPage">
|
||||
抽奖页面
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { debounceTap } from '@/plugins'
|
||||
|
||||
// 页面配置初始化
|
||||
const emit = defineEmits(["DrawPage"]);
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.DrawPage {
|
||||
@include fixed();
|
||||
background-color: azure;
|
||||
}
|
||||
</style>
|
||||
21
src/components/Result.vue
Normal file
21
src/components/Result.vue
Normal file
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<div class="ResultPage">
|
||||
结果页
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { debounceTap } from '@/plugins'
|
||||
|
||||
// 页面配置初始化
|
||||
const emit = defineEmits(["ResultPage"]);
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.ResultPage {
|
||||
@include fixed();
|
||||
background-color: azure;
|
||||
}
|
||||
</style>
|
||||
21
src/components/Rule.vue
Normal file
21
src/components/Rule.vue
Normal file
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<div class="RulePage">
|
||||
规则页面
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { debounceTap } from '@/plugins'
|
||||
|
||||
// 页面配置初始化
|
||||
const emit = defineEmits(["RulePage"]);
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.RulePage {
|
||||
@include fixed();
|
||||
background-color: azure;
|
||||
}
|
||||
</style>
|
||||
@@ -1,64 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>随机题目与答案统计</h2>
|
||||
<div v-for="question in shuffledQuestions" :key="question.id">
|
||||
<h3>{{ question.question }}</h3>
|
||||
<ul>
|
||||
<li v-for="answer in question.answers" :key="answer">
|
||||
{{ answer }} <button @click="recordAnswer(question.id, answer)">提交</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<h3>统计结果</h3>
|
||||
<div v-for="stat in stats" :key="stat.id">
|
||||
<h4>{{ stat.question }} 答案统计</h4>
|
||||
<ul>
|
||||
<li v-for="(count, answer) in stat.answers" :key="answer">
|
||||
{{ answer }}: {{ count }} 次
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref, computed } from 'vue';
|
||||
// import data from '../data'; // 引入题目和答案数据
|
||||
let data = [
|
||||
|
||||
|
||||
]
|
||||
export default {
|
||||
setup() {
|
||||
const questions = ref([
|
||||
{ id: 1, question: "问题1", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 2, question: "问题2", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 3, question: "问题3", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 4, question: "问题4", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 5, question: "问题5", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 6, question: "问题6", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 7, question: "问题7", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 8, question: "问题8", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 9, question: "问题9", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 10, question: "问题10", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 11, question: "问题11", answers: ["答案A", "答案B", "答案C"] },
|
||||
{ id: 12, question: "问题12", answers: ["答案A", "答案B", "答案C"] },
|
||||
]); // 引用题目和答案数据
|
||||
const stats = ref([]); // 初始化统计结果数组为空数组
|
||||
const currentQuestion = ref(0); // 当前显示的题目索引,初始化为0
|
||||
const shuffledQuestions = computed(() => { // 计算属性,用于获取随机打乱的题目顺序
|
||||
const allQuestions = [...questions]; // 复制题目数组,防止修改原始数据
|
||||
allQuestions.sort(() => Math.random() - 0.5); // 随机打乱顺序
|
||||
return allQuestions;
|
||||
});
|
||||
const recordAnswer = (id, answer) => { // 方法,用于记录用户选择的答案并更新统计结果
|
||||
const question = shuffledQuestions.value.find(q => q.id === id); // 找到当前题目对象
|
||||
if (!stats.value[id]) { // 如果当前题目的统计结果为空,则初始化统计结果对象
|
||||
stats.value[id] = { question, answers: {} };
|
||||
}
|
||||
stats.value[id].answers[answer] = (stats.value[id].answers[answer] || 0) + 1; // 更新答案统计次数
|
||||
};
|
||||
return { shuffledQuestions, stats, currentQuestion, recordAnswer }; // 将计算属性和方法暴露给模板使用
|
||||
}
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user