wangxy 5 месяцев назад
Родитель
Сommit
8f40f07187

+ 2 - 2
components/question/FillItem.vue

@@ -1,7 +1,7 @@
 <template>
 	<uni-popup background-color="#fff" ref="fillRef">
 		<view class="popup-content">
-			<input v-model.trim="result" placeholder="请输入答案" style="width: 100%" @blur="onBlur" type="text" class="input-box" />
+			<input v-model.trim="result" :focus="true" placeholder="请输入答案" style="width: 100%" @blur="onBlur" type="text" class="input-box" />
 		</view>
 	</uni-popup>
 </template>
@@ -39,6 +39,6 @@
 
 <style lang="scss" scoped>
 .popup-content {
-	padding: 10px;
+	padding: 20px;
 }
 </style>

+ 17 - 11
components/question/tiankong.vue

@@ -1,12 +1,22 @@
 <template>
 	<view class="fill-in-the-blank">
 		<!-- 显示填空后的文本 -->
-		<view class="formatted-text" v-html="formattedText" :question="question" :myflag="myflag" :change:myflag="TK.updateFlag" :change:question="TK.watchQuestionChange"></view>
+		<view class="formatted-text" v-html="formattedText" :question="question" :myflag="myflag"
+			:change:myflag="TK.updateFlag" :change:question="TK.watchQuestionChange"></view>
+		<!-- 提供与占位符数量相匹配的输入框 -->
+		<template v-for="(placeholder, index) in placeholders" :key="index">
+			<FillItem :value="question.reply[index]" :ref="`popup${index}Ref`" :index="index" @blur="onBlur"></FillItem>
+		</template>
+
 	</view>
 </template>
 
 <script>
+	import FillItem from "./FillItem.vue";
 	export default {
+		components: {
+			FillItem
+		},
 		props: {
 			placeholders: { // 占位符
 				type: Array,
@@ -72,30 +82,26 @@
 				this.setResult(data);
 			},
 			showPopup(str) {
-				uni.$emit('tiankongItemShow', {index: str, value: this.question.reply[str],question: this.question})
+				this.$refs[str][0].showPopup();
 			}
 		},
-		created() {
-				uni.$on('tiankongItemBlur', (data) => {
-					if (data.question.stId === this.question.stId) {
-						this.setResult({index: data.index,result: data.value});
-					}
-				})
-		}
 	}
 </script>
 
 <script module="TK" lang="renderjs">
 	export default {
 		data() {
-			return {myQ: null}
+			return {
+				myQ: null
+			}
 		},
 		methods: {
 			updateFlag() {
 				this.initListener(this.myQ)
 			},
 			updateFn(e) {
-				this.$ownerInstance.callMethod('showPopup',+e.target.dataset.index);
+				const str = `popup${e.target.dataset.index}Ref`;
+				this.$ownerInstance.callMethod('showPopup', str);
 			},
 
 			watchQuestionChange(newValue, oldValue, ownerInstance, instance) {

+ 3 - 6
pages/unitTest/index.vue

@@ -29,8 +29,6 @@
 		<chengji ref="chengjiRef" :list="list"  @back="handleBack"></chengji>
 		<!-- 分数弹窗 -->
 		<uniPointsVue ref="uniPointsRef" @checkAnswer="checkAnswer" @goStudy="goStudyContinue" :isLastZhang="!!haveFlag"></uniPointsVue>
-		<!-- 填空题选项 -->
-		<FillItem :value="tiankongValue" :ref="`popupRef`" :index="index" @blur="onBlur"></FillItem>
 	</view>
 
 </template>
@@ -47,13 +45,12 @@
 		catchError,
 	} from "@/utils/common.js"
 	import {
-		useExam,useTiankongItem
+		useExam
 	} from './useUnit';
 	import {
 		ref,
 	} from "vue";
-  import cacheManager from "@/utils/cacheManager";
-  import FillItem from "@/components/question/FillItem.vue";
+    import cacheManager from "@/utils/cacheManager";
   
 	const {
 		count,
@@ -77,7 +74,7 @@
 	const uniPointsRef = ref(null);
 	const chengjiRef = ref(null);
 	const popupRef = ref(null);
-	const {index,tiankongValue,onBlur} = useTiankongItem(popupRef)
+
 	// 查看答案
 	function checkAnswer() {
 		chengjiRef.value.showPopup();

+ 0 - 35
pages/unitTest/useUnit.js

@@ -211,38 +211,3 @@ function useTishiLeftRight() {
 	}
 }
 
-export function useTiankongItem(popupRef) {
-
-
-	const index = ref(null);
-	const tiankongValue = ref(null);
-	const question = ref(null);
-
-	function refreshFn(data) {
-		index.value = +data.index;
-		tiankongValue.value = data.value;
-		question.value = data.question;
-	}
-
-	function onBlur(dd) {
-		tiankongValue.value = dd.result;
-		uni.$emit('tiankongItemBlur', {
-			index: dd.index,
-			value: dd.result,
-			question: question.value
-		})
-		nextTick(() => {
-			tiankongValue.value = "";
-		})
-	}
-	uni.$on('tiankongItemShow', (data) => {
-		refreshFn(data);
-		popupRef.value.showPopup();
-	})
-
-	return {
-		index,
-		tiankongValue,
-		onBlur
-	}
-}