zjs_project 10 月之前
父節點
當前提交
c056433289
共有 1 個文件被更改,包括 20 次插入1 次删除
  1. 20 1
      src/pages/webgl_rxdz_recognizer_houseList/webgl_rxdz_recognizer_houseList.vue

+ 20 - 1
src/pages/webgl_rxdz_recognizer_houseList/webgl_rxdz_recognizer_houseList.vue

@@ -268,6 +268,10 @@
                 const parts = text.split('第')[1]; // 分割并获取数字部分  
                 return parts ? parseInt(parts, 10) : null; // 转换为整数  
             },
+            backwardNumber(text) {
+                const parts = text.split('倒数第')[1]; // 分割并获取数字部分  
+                return parts ? parseInt(parts, 10) : null; // 转换为整数  
+            },
             async textChange(text) {
                 text = text.replaceAll(/ |,|。/ig, "");
                 if (!text) {
@@ -285,6 +289,16 @@
                 //全匹配轮一遍
                 text = this.convertChineseToArabic(text);
                 let houseIndex = this.extractNumber(text);//获取文字里面的数字 第三个 类似这样的
+                if(!houseIndex){
+                    houseIndex = this.backwardNumber(text);//获取倒数的个数
+                    houseIndex = this.houseList.length - houseIndex;
+                    if(houseIndex < 0){//越界了
+                        Toast({
+                            message: '数据不合法,请再说一次',
+                        });
+                        return false; 
+                    }
+                }
                 // let curSpace = this.houseList.find(space => {
                 //     return text.includes(space.houseType)
                 // })
@@ -310,7 +324,6 @@
                         houseIndex = index; //
                     }
                 }
-
                 //没有找到语音操作对象
                 if (!houseIndex) {
                     Toast({
@@ -318,6 +331,12 @@
                     });
                     return false;
                 }
+                if(houseIndex > this.houseList.length){
+                    Toast({
+                        message: '数据不合法,请再说一次',
+                    });
+                   return false; 
+                }
                 this.changeHouse(houseIndex - 1);
                 console.log("textChange:", houseIndex);