wangxy před 4 měsíci
rodič
revize
127d80cd19

+ 16 - 11
components/question/FillItem.vue

@@ -1,14 +1,17 @@
 <template>
-	<uni-popup type="bottom" background-color="#fff" ref="fillRef" class="FillPopup" :animation="false">
-		<view class="popup-content">
-			<input v-model.trim="result" @close="handleClose" :focus="true" placeholder="请输入答案" adjust-position="auto" style="position: z-index: 10;"
-				@blur="onBlur" @confirm="handleConfirm" class="my-textarea" type="text" />
-		</view>
-	</uni-popup>
+	<view>
+		<uni-popup type="bottom" background-color="#fff" ref="fillRef" class="FillPopup" :animation="true">
+			<view class="popup-content">
+				<input v-model.trim="result" @close="handleClose" :focus="focus" placeholder="请输入答案" :auto-blur="true" :adjust-position="true" style="position: z-index: 10;"
+					@blur="onBlur" @confirm="handleConfirm" class="my-textarea" type="text" />
+			</view>
+		</uni-popup>
+	</view>
 </template>
 
 <script setup>
 	import {
+		nextTick,
 		ref,
 		watch
 	} from "vue";
@@ -30,14 +33,18 @@
 		result.value = val;
 	})
 
+	function handleClear() {
+		result.value = '';
+	}
+
 	function handleClose() {
 		focus.value = false;
 	}
 
 	function showPopup() {
 	
-		focus.value = true;
 		fillRef.value && fillRef.value.open();
+		nextTick(() => focus.value = true);
 	}
 
 	function handleConfirm() {
@@ -61,17 +68,15 @@
 	})
 
 	defineExpose({
-		showPopup
+		showPopup,handleClear
 	})
 </script>
 
 <style lang="scss" scoped>
 	.popup-content {
-		padding-bottom: 20px;
-		padding-top: 20px;
+		padding: 10px;
 	}
 	.my-textarea {
-		padding: 0 5px;
 		height: 36px;
 		line-height: 36px;
 	}

+ 18 - 16
components/question/tiankong.vue

@@ -6,19 +6,18 @@
 		<view class="ezy-shiti-question" 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">
+	<!-- 	<template v-for="(placeholder, index) in placeholders" :key="index">
 			<FillItem :value="question.reply[index]" :ref="`popup${index}Ref`" :index="index" @blur="onBlur"></FillItem>
-		</template>
-
+		</template> -->
 	</view>
 </template>
 
 <script>
-	import FillItem from "./FillItem.vue";
+	// import FillItem from "./FillItem.vue";
 	export default {
-		components: {
-			FillItem
-		},
+		// components: {
+		// 	FillItem
+		// },
 		props: {
 			placeholders: { // 占位符
 				type: Array,
@@ -76,17 +75,20 @@
 				this.question.reply[index] = result;
 			},
 			onBlur(data) {
-				const {
-					index,
-					result
-				} = data;
-
 				this.setResult(data);
 			},
-			showPopup(str) {
-				this.$refs[str][0].showPopup();
+			showPopup({index}) {
+				// this.$refs[str][0].showPopup();
+				uni.$emit('tiankong-fillItem',{ index,question:this.question})
 			}
 		},
+		created() {
+			uni.$on('tiankong-setResult',({index,stId,result}) => {
+				if (this.question.stId === stId) {
+					this.setResult({index, result})
+				}
+			})
+		}
 	}
 </script>
 
@@ -108,8 +110,8 @@
 				this.initListener(this.myQ)
 			},
 			updateFn(e) {
-				const str = `popup${e.target.dataset.index}Ref`;
-				this.$ownerInstance.callMethod('showPopup', str);
+				// const str = `popup${e.target.dataset.index}Ref`;
+				this.$ownerInstance.callMethod('showPopup', {index: e.target.dataset.index});
 			},
 
 			watchQuestionChange(newValue, oldValue, ownerInstance, instance) {

+ 33 - 5
pages/unitTest/index.vue

@@ -16,9 +16,9 @@
 				</template>
 			</w-swiper>
 			<view class="exam-submit-btn" v-if="current === list.length-1" 
-				@click="handleSubmit(uniPointsRef,popupRef)"></view>
+				@click="handleSubmit(uniPointsRef)"></view>
 		</view>
-
+			
 		<!--  左右滑动  -->
 		<view class="tip-mask-box"  @click="handleCloseTishi" v-if="showTishi">
 			<view class="exam-tip-box">左右滑动查看更多题目</view>
@@ -29,12 +29,16 @@
 		<chengji ref="chengjiRef" :list="list"  @back="handleBack"></chengji>
 		<!-- 分数弹窗 -->
 		<uniPointsVue ref="uniPointsRef" @checkAnswer="checkAnswer" @goStudy="goStudyContinue" :isLastZhang="!!haveFlag" :studyFlag="studyFlag"></uniPointsVue>
+		<!-- 填空 -->
+		<FillItem :value="result" ref="popupRef" @blur="onBlur"></FillItem>
+
 
 	</view>
 
 </template>
 
 <script setup>
+	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";
@@ -52,7 +56,8 @@
 		ref,
 	} from "vue";
     import cacheManager from "@/utils/cacheManager";
-
+	import {onLoad} from "@dcloudio/uni-app"
+	
 	const {
 		count,
 		total,
@@ -76,8 +81,31 @@
 
 	const uniPointsRef = ref(null);
 	const chengjiRef = ref(null);
-	const popupRef = ref(null);
-
+	const popupRef= ref(null);
+	const result = ref('');
+	const curTiankong = ref(null);
+	
+	function getPopupRef() {
+		return popupRef.value;
+	}
+	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 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 checkAnswer() {
 		chengjiRef.value.showPopup();