wangxy 1 month ago
parent
commit
5d2cac3eab
4 changed files with 296 additions and 9 deletions
  1. 12 0
      api/chanpinShuxue.js
  2. 13 9
      pages.json
  3. 148 0
      pages/chanpinXuanze/components/useShuxueUnitTest.js
  4. 123 0
      pages/chanpinXuanze/unitTest.vue

+ 12 - 0
api/chanpinShuxue.js

@@ -31,4 +31,16 @@ export function getShuxueChanpinBanbenInfo(data = {}) {
         data,
         timeout: 20000
     })
+}
+
+export function getShuxueChanpinShitiList(data = {}) {
+    return request({
+        'url': '/app/shuxue/chanpin/shiti/list',
+        headers: {
+            isToken: true
+        },
+        method: 'post',
+        data,
+        timeout: 20000
+    })
 }

+ 13 - 9
pages.json

@@ -84,7 +84,7 @@
 			"style": {
 				"navigationStyle": "custom"
 			}
-		},{
+		}, {
 			"path": "pages/my/headImg",
 			"style": {
 				"navigationStyle": "custom"
@@ -94,12 +94,12 @@
 			"style": {
 				"navigationStyle": "custom"
 			}
-		},{
+		}, {
 			"path": "pages/my/xuexishichang",
 			"style": {
 				"navigationStyle": "custom"
 			}
-		},{
+		}, {
 			"path": "pages/my/yingyongshezhi",
 			"style": {
 				"navigationStyle": "custom"
@@ -148,16 +148,20 @@
 			}
 		},
 		{
-			"path" : "pages/chanpinXuanze/index",
-			"style" : 
-			{
+			"path": "pages/chanpinXuanze/index",
+			"style": {
+				"navigationStyle": "custom"
+			}
+		},
+		{
+			"path": "pages/chanpinXuanze/banben",
+			"style": {
 				"navigationStyle": "custom"
 			}
 		},
 		{
-			"path" : "pages/chanpinXuanze/banben",
-			"style" : 
-			{
+			"path": "pages/chanpinXuanze/unitTest",
+			"style": {
 				"navigationStyle": "custom"
 			}
 		}

+ 148 - 0
pages/chanpinXuanze/components/useShuxueUnitTest.js

@@ -0,0 +1,148 @@
+import * as httpApi from "@/api/chanpinShuxue.js"
+import {
+	reactive,
+	watch
+} from "vue"
+import {
+	onLoad
+} from "@dcloudio/uni-app"
+import {
+	catchError,
+	toast
+} from "@/utils/common.js"
+
+
+export function useShuxueTest() {
+
+
+	const data = reactive({
+		list: [],
+		total: 0,
+		current: 0,
+		jieId: null,
+		rightAnswer: 0, // 答对
+		wrongAnswer: 0, // 答错
+	})
+
+	watch(() => data.list, (val) => {
+		const list = data.list.filter(item => {
+			if (item.type == 3) {
+				// 填空题 所有试题答完
+				return !item.reply.some(citem => citem.trim() == '');
+			} else {
+				return item.reply !== null
+			}
+		});
+		data.count = list.length;
+	}, {
+		deep: true
+	})
+	// 更新试题对错
+	function updateRightWrong({
+		rightAnswer,
+		wrongAnswer,
+	}) {
+		data.rightAnswer = rightAnswer;
+		data.wrongAnswer = wrongAnswer;
+	}
+
+	// 初始化页面数据
+	async function initPage() {
+		const [err, cdata] = await catchError(httpApi.getShuxueChanpinShitiList({
+			jieId: data.jieId
+		}))
+
+		if (err) {
+			toast("单元测试数据获取异常");
+			return;
+		}
+
+		refreshExam(cdata);
+	}
+
+	function formatListToUse(list) {
+		list.forEach((item, index) => {
+			item.mta_show = false;
+			item.reply = null;
+			if (item.type == 3) {
+				item.result = JSON.parse(item.result);
+				item.placeholders = item.result.map((item, cindex) => `[bank${cindex+1}]`)
+				item.reply = item.reply ? JSON.parse(item.reply) : item.result.map(() => '');
+			}
+		})
+	}
+
+
+	// 数据赋值
+	function refreshExam(list) {
+		const cList = list;
+		formatListToUse(cList)
+		data.list = cList;
+		data.total = cList.length;
+	}
+
+	// 交卷
+	async function handleSubmit() {
+
+		const result = [];
+		data.list.forEach(item => {
+			if (item.type == 1) {
+				result.push({
+					reply: item.reply,
+					stId: item.stId
+				})
+			} else if (item.type == 2) {
+				result.push({
+					reply: item.reply,
+					stId: item.stId
+				})
+			} else if (item.type == 3) {
+				result.push({
+					reply: item.reply ? JSON.stringify(item.reply) : '',
+					stId: item.stId
+				})
+			} else if (item.type == 4) {
+				result.push({
+					reply: item.reply,
+					stId: item.stId
+				})
+			}
+
+		})
+		uni.showLoading({
+			title: '交卷中...'
+		});
+		const [error, cdata] = await catchError(httpUnit.getExamSubmit({
+			jieId: data.jieId,
+			shitiList: result
+		}));
+		uni.hideLoading()
+		if (error) {
+			toast("单元测试数据提交异常");
+			return;
+		}
+
+		// 执行跳页
+		uni.$emit('unitShuxueTest-submit', {
+			right: cdata.dui,
+			wrong: cdata.cuo,
+		})
+
+		uni.redirectTo({
+			url: `/pages/chanpinXuanze/unitTest?rigth=${cdata.dui}&wrong=${cdata.cuo}&jieId=${data.jieId}`
+		})
+
+	}
+
+	onLoad((options) => {
+		data.jieId = options.jieId
+		initPage()
+	})
+
+
+	return {
+		data,
+		handleSubmit,
+		updateRightWrong
+	}
+}

+ 123 - 0
pages/chanpinXuanze/unitTest.vue

@@ -0,0 +1,123 @@
+<template>
+	<view class="ezy-exam-page">
+		<view class="icon-title-navBar-box">
+			<view @click="handleBack" class="nav-bar-icon"></view>
+			<text class="nav-bar-title">单元测试</text>
+		</view>
+
+		<view>
+			<view>
+				<view>当前学习进度</view>
+				<view>{{data.current+1}}/{{data.total}}</view>
+			</view>
+			<progress :percent="data.current/data.total * 100" :border-radius="30" stroke-width="10" />
+		</view>
+
+		<view class="shiti-frame-box">
+			<w-swiper :list="data.list" :current="data.current" class="ezy-exam-swiper" @change="onSwiperChange">
+				<template v-slot:default="{item}">
+					<view>
+						<text v-if="item.type == '1'">单选题</text>
+						<text v-if="item.type == '2'">判断题</text>
+						<text v-if="item.type == '3'">填空题</text>
+					</view>
+					<view class="body" v-if="item.mta_show">
+						<danxuan :question="item" v-if="item.type == '1'"></danxuan>
+						<panduan :question="item" v-if="item.type == '2'"></panduan>
+						<tiankong :question="item" v-if="item.type == '3'" :placeholders="item.placeholders"></tiankong>
+					</view>
+				</template>
+			</w-swiper>
+		</view>
+
+		<!--  左右滑动提示  -->
+		<view>
+			<view>
+				< <text>左右滑动查看更多题目</text>>
+			</view>
+		</view>
+
+		<!-- 填空 -->
+		<FillItem :value="result" ref="popupRef" @blur="onBlur"></FillItem>
+	</view>
+</template>
+
+<script setup>
+	import mtaRadio from '@/components/question/yingyu/mtaRadio.vue'
+	import FillItem from "@/components/question/FillItem.vue";
+	import wSwiper from '@/components/wSwiper/wSwiper.vue';
+	import danxuan from "@/components/question/danxuan.vue";
+	import panduan from "@/components/question/panduan.vue";
+	import tiankong from "@/components/question/tiankong.vue";
+
+	import * as httpApi from "@/api/chanpinShuxue.js"
+	import {
+		reactive,
+		ref
+	} from "vue"
+	import {
+		onLoad
+	} from "@dcloudio/uni-app"
+	import {
+		useShuxueTest
+	} from "./components/useShuxueUnitTest.js"
+	const {
+		data
+	} = useShuxueTest()
+
+	const curTiankong = ref(null);
+	const result = ref('');
+	const popupRef = ref(null);
+
+	onLoad(() => {
+		uni.$on('tiankong-fillItem', (val) => {
+			const {
+				index,
+				question
+			} = val;
+			curTiankong.value = val;
+			result.value = question.reply[index];
+			const dom = getPopupRef();
+			dom && dom.showPopup();
+		})
+	})
+
+	function getPopupRef() {
+		return popupRef.value;
+	}
+
+	function onBlur({
+		result
+	}) {
+		if (curTiankong.value) {
+			uni.$emit('tiankong-setResult', {
+				index: curTiankong.value.index,
+				stId: curTiankong.value.question.stId,
+				result
+			});
+		}
+		const dom = getPopupRef();
+		dom && dom.handleClear();
+	}
+
+	function handleBack() {}
+
+	function onSwiperChange(index) {
+		current.value = index;
+		uni.$emit('swiper-change', index)
+	}
+</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>