Browse Source

快速评分弹出0的bug处理

刘洋 2 years ago
parent
commit
4484ae5e50
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/components/shared/ScoringPanelItem.vue

+ 9 - 3
src/components/shared/ScoringPanelItem.vue

@@ -33,7 +33,7 @@
             :value="currentScore"
             :value="currentScore"
             @focus="onInputFocus"
             @focus="onInputFocus"
             @blur="onBlur"
             @blur="onBlur"
-            @keydown="onValidScore"
+            @keydown="onValidScoreDebounce"
             @input="scoreChange"
             @input="scoreChange"
           />
           />
         </div>
         </div>
@@ -47,7 +47,7 @@
           :value="currentScore"
           :value="currentScore"
           @focus="onInputFocus"
           @focus="onInputFocus"
           @blur="onBlur"
           @blur="onBlur"
-          @keydown="onValidScore"
+          @keydown="onValidScoreDebounce"
           @input="scoreChange"
           @input="scoreChange"
         />
         />
       </div>
       </div>
@@ -68,6 +68,7 @@ import { watch, computed, ref, nextTick, withDefaults, defineComponent, useSlots
 import SvgIcon from '@/components/common/SvgIcon.vue'
 import SvgIcon from '@/components/common/SvgIcon.vue'
 import useVModel from '@/hooks/useVModel'
 import useVModel from '@/hooks/useVModel'
 import { getNumbers } from '@/utils/common'
 import { getNumbers } from '@/utils/common'
+import { debounce } from 'lodash-es'
 
 
 interface QuestionInfo {
 interface QuestionInfo {
   mainNumber: number
   mainNumber: number
@@ -206,7 +207,7 @@ const joinStringChart = (str: string, index: number, chart: string) => {
   return str.substring(0, index) + chart + str.substring(index + 1)
   return str.substring(0, index) + chart + str.substring(index + 1)
 }
 }
 
 
-const onValidScore = (e: KeyboardEvent) => {
+const onValidScore = (e: any) => {
   const target = e.target as HTMLInputElement
   const target = e.target as HTMLInputElement
   const oldScore = `${currentScore.value ?? ''}`
   const oldScore = `${currentScore.value ?? ''}`
   const start = target.selectionStart || 0
   const start = target.selectionStart || 0
@@ -221,6 +222,10 @@ const onValidScore = (e: KeyboardEvent) => {
   }
   }
 
 
   if ('Enter' === e.key) {
   if ('Enter' === e.key) {
+    let targetInputValue = e.target?.value
+    if (!targetInputValue) {
+      return
+    }
     if (oldScore && !scoreStrictValidFail(oldScore)) {
     if (oldScore && !scoreStrictValidFail(oldScore)) {
       nextTick(() => {
       nextTick(() => {
         emit('enter')
         emit('enter')
@@ -246,6 +251,7 @@ const onValidScore = (e: KeyboardEvent) => {
     e.preventDefault()
     e.preventDefault()
   }
   }
 }
 }
+const onValidScoreDebounce = debounce(onValidScore, 50)
 
 
 const scoreChange = (e: Event) => {
 const scoreChange = (e: Event) => {
   const target = e.target as HTMLInputElement
   const target = e.target as HTMLInputElement