Browse Source

简答题输入文字时,保留已有的照片

Michael Wang 3 năm trước cách đây
mục cha
commit
0c4bb8ed44
1 tập tin đã thay đổi với 15 bổ sung1 xóa
  1. 15 1
      src/features/OnlineExam/Examing/TextQuestionView.vue

+ 15 - 1
src/features/OnlineExam/Examing/TextQuestionView.vue

@@ -85,8 +85,22 @@ function disableCtrl(e: KeyboardEvent) {
   return true;
 }
 
+let lastInputTime = Date.now();
 function textInput($event: Event) {
-  studentAnswer = (<HTMLDivElement>$event.target).innerHTML;
+  // 对 input 事件进行节流
+  if ($event instanceof InputEvent) {
+    if (Date.now() - lastInputTime < 3000) {
+      return;
+    } else {
+      lastInputTime = Date.now();
+    }
+  }
+  const sDom = document.createElement("div");
+  sDom.innerHTML = studentAnswer;
+  const photoDom = sDom.querySelector("photo-answers-block");
+  const photoStr = photoDom?.outerHTML ?? "";
+
+  studentAnswer = (<HTMLDivElement>$event.target).innerHTML + photoStr;
 }
 
 let copyNode: DocumentFragment;