wangxy hace 6 meses
padre
commit
53aec96d4f

+ 13 - 0
components/points/uni-points.vue

@@ -0,0 +1,13 @@
+<template>
+	<view>
+		
+	</view>
+</template>
+
+<script setup>
+	
+</script>
+
+<style>
+	       
+</style>

+ 8 - 0
pages.json

@@ -19,6 +19,14 @@
 				"navigationBarTitleText": "学习",
 				"navigationStyle": "custom"
 			}
+		},
+		{
+			"path" : "pages/unitTest/index",
+			"style" : 
+			{
+				"navigationBarTitleText" : "单元测试",
+				"navigationStyle": "custom"
+			}
 		}
 	],
 	"tabBar": {

+ 3 - 0
pages/selectGradesTerms/index.vue

@@ -28,6 +28,9 @@
 		useSelectGrade
 	} from './useSelectGrade';
 
+	// 页面路由参数需要 年级Id+学期Id
+
+
 	const {
 		nianji_list,
 		xueqi_list,

+ 67 - 0
pages/unitTest/index.vue

@@ -0,0 +1,67 @@
+<template>
+	<view>
+		<uni-icons type="left" size="30"></uni-icons>
+		<text>单元测试</text>
+		<view><text>{{count}}</text>/<text>{{total}}</text></view>
+	</view>
+	<swiper class="swiper-box" @change="onChange" @animationfinish="onAnimationfinish" :current="current">
+		<swiper-item v-for="(item ,index) in list" :key="index">
+			<view class="swiper-item">
+				{{item}}
+			</view>
+		</swiper-item>
+	</swiper>
+	<button class="transition-button" v-if="!isLast" type="primary" @click="nextQuestion">next</button>
+	<button class="transition-button" v-if="!isFirst" type="primary" @click="prevQuestion">prev</button>
+	<button class="transition-button" v-if="isLast" type="primary" @click="handleSubmit">submit</button>
+</template>
+
+<script setup>
+	import {
+		useExam
+	} from './useUnit';
+	import {
+		ref,
+		onMounted
+	} from "vue";
+
+	const {
+		isFirst,
+		isLast,
+		count,
+		total,
+		current,
+		list,
+		rightAnswer,
+		wrongAnswer,
+		jifen,
+
+		nextQuestion,
+		prevQuestion,
+		handleSubmit,
+		initPage
+	} = useExam();
+	
+	// swiper change 回调
+	function onChange(e) {
+		current.value = e.detail.current;
+	}
+	// 查看答案
+	function checkAnswer() {}
+	// 继续学习
+	function goStudyContinue() {}
+</script>
+
+<style lang="scss" scoped>
+	.swiper-box {
+		height: 200px;
+	}
+
+	.swiper-item {
+		display: flex;
+		flex-direction: column;
+		justify-content: center;
+		align-items: center;
+		height: 200px;
+	}
+</style>

+ 134 - 0
pages/unitTest/useUnit.js

@@ -0,0 +1,134 @@
+import {
+	onLoad,
+	onReady,
+} from "@dcloudio/uni-app"
+import {
+	reactive,
+	ref,
+	computed,
+	toRefs,
+	onMounted,
+} from "vue";
+import {
+	catchError,
+	toast
+} from "@/utils/common.js"
+import request from "@/utils/request.js"
+
+// 获取单元测试数据
+function httpGetExamData() {
+	return request({
+		url: "/common/zhangjie/list",
+		method: "POST",
+		data: {
+			nianji: 1,
+			xueqi: 1
+		}
+	})
+}
+
+function useJifen() {
+	const data = reactive({
+		rightAnswer: 0, // 答对
+		wrongAnswer: 0, // 答错
+		jifen: 0, // 积分
+	})
+
+	function updateJifen({rightAnswer,wrongAnswer,jifen}) {
+		data.rightAnswer = rightAnswer;
+		data.wrongAnswer = wrongAnswer;
+		data.jifen = jifen;
+	}
+	
+	return {
+		...toRefs(data),
+		
+		updateJifen
+	}
+}
+
+export function useExam(dom) {
+	const {rightAnswer,wrongAnswer,jifen, updateJifen} = useJifen();
+	
+	const data = reactive({
+		count: 0, // 已答题数
+		total: 0, // 总题数
+		current: 0, // 当前试题序列
+		list: [], // 试题列表
+		jieId: null, // 节Id
+	})
+	
+	// 当前试题
+	const activeQa = computed(() => data.list.length ? data.list[data.current] : null);
+	// 第一题
+	const isFirst = computed(() => {
+		if (!activeQa.value) return false;
+		return activeQa.value.id === data.list[0].id;
+	})
+	// 最后一题
+	const isLast = computed(() => {
+		if (!activeQa.value) return false;
+		const clength = data.list.length;
+		return activeQa.value.id === data.list[clength - 1].id;
+	})
+
+	onLoad((options) => {
+		const {
+			jieId
+		} = options;
+		data.jieId = jieId;
+
+		// 初始化页面数据
+		initPage();
+	})
+
+	// 下一题
+	function nextQuestion() {
+		data.current = data.current + 1;
+	}
+
+	// 前一题
+	function prevQuestion() {
+		data.current = data.current - 1;
+	}
+
+	// 初始化页面数据
+	async function initPage() {
+		const [err, data] = await catchError(httpGetExamData());
+		if (err) {
+			toast("单元测试数据获取异常");
+			return;
+		}
+		refreshExam(data);
+	}
+
+	// 数据赋值
+	function refreshExam(list) {
+		// FIXME 模拟id 待删除
+		list.forEach((item, index) => item.id = index)
+		data.list = list;
+		data.total = list.length;
+	}
+
+	// 交卷
+	function handleSubmit() {}
+
+
+	return {
+		...toRefs(data),
+		activeQa,
+		isFirst,
+		isLast,
+		isFirst,
+		isLast,
+		
+		rightAnswer,
+		wrongAnswer,
+		jifen,
+
+		nextQuestion,
+		prevQuestion,
+		handleSubmit,
+		initPage
+	}
+}

+ 0 - 1
utils/common.js

@@ -44,7 +44,6 @@ export function tansParams(params) {
 export function catchError(promise) {
 	return new Promise((resolve,reject) => {
 		promise.then(data => {
-			console.log('response =>',data.data)
 			resolve([undefined, data.data]) 
 		}).catch(err => {
 			reject([err])