Bladeren bron

非法字符校验

wfg 2 weken geleden
bovenliggende
commit
8f6dad10e6
2 gewijzigde bestanden met toevoegingen van 100 en 5 verwijderingen
  1. 47 4
      src/util/date.js
  2. 53 1
      src/views/iosBasicData/SeafreightExportF/bills/billsDetails.vue

+ 47 - 4
src/util/date.js

@@ -233,9 +233,9 @@ function addZero(num) {
   }
   return num;
 }
-//验证英文
+//验证英文,允许 TAB 存在
 export function verifyEnglish(str) {
-  const regex = /^[A-Za-z0-9\r\n .,!?:()|/+-_;'"$&@%*#]+$/;
+  const regex = /^[A-Za-z0-9\r\n\t .,!?:()|/+-_;'"$&@%*#]+$/;
   return regex.test(str ? str : null);
 }
 //验证符号
@@ -244,7 +244,7 @@ export function verifySymbol(str) {
   return regex.test(str ? str : null);
 }
 // 匹配常见全角符号的正则表达式(包括标点、字母、数字等)
-export function checkFullWidthSymbols(text) {
+export function checkFullWidthSymbols_bak(text) {
   if (text) {
     const fullWidthRegex = /[\u3000-\u303F\uFF01-\uFF5E\uFFE0-\uFFE5]/g;
     const matchesItem = [];
@@ -280,6 +280,49 @@ export function checkFullWidthSymbols(text) {
     };
   }
 }
+// wfg
+export function checkFullWidthSymbols(text) {
+    if (text) {
+        const fullWidthRegex = /[\u4e00-\u9fa5\u3000-\u303f\uff00-\uffef\u3400-\u4dbf]/g;
+        const matchesItem = [];
+        // TAB 键转为空格
+        let lines = text.trimEnd().replaceAll("\t", " ").split('\n')
+        let match;
+        lines.forEach((ln, index, array) => {
+            ln=ln.trimEnd();
+            lines[index]=ln
+            while ((match = fullWidthRegex.exec(ln)) !== null) {
+                matchesItem.push({
+                    row: index + 1,         // 行号
+                    index: match.index,     // 符号的位置
+                    symbol: match[0],       // 符号本身
+                    input: match.input      // 行
+                });
+            }
+        })
+        let resetText = lines.join("\n")
+        let isResetText = resetText != text
+        let message=[]
+        matchesItem.forEach(m=>{
+            message.push(`第 ${m.row} 行第 ${m.index} 个字符 ${m.symbol} 不符合要求,存在全角字符或汉字等!`)
+        })
+        return {
+            hasFullWidth: matchesItem.length > 0, // 是否包含全角符号
+            positions: matchesItem,               // 符号的详细位置和内容
+            message: message.join("<br>"),
+            isResetText: isResetText,  // 是否重设文本
+            resetText: resetText,      // 重设的文本
+        };
+    } else {
+        return {
+            hasFullWidth: false, // 是否包含全角符号
+            positions: [],                // 符号的详细位置和内容
+            message: "",
+            isResetText:false,  // 是否重设文本
+            resetText: "",      // 重设的文本
+        };
+    }
+}
 //判断是否超过设置天数
 export function overdueJudgment(date) {
   const overDay = localStorage.getItem('lockTermDays')
@@ -295,4 +338,4 @@ export function overdueJudgment(date) {
   } else {
     return false
   }
-}
+}

+ 53 - 1
src/views/iosBasicData/SeafreightExportF/bills/billsDetails.vue

@@ -1242,6 +1242,7 @@ export default {
                 });
                 return
             }
+
             if (!verifyEnglish(this.form.detail.hshipperDetails)) {
                 msgsList.push('发货人')
             }
@@ -1273,6 +1274,7 @@ export default {
                 this.$message.error(`请正确输入${msgsList.join(",")}的英文`);
                 return;
             }
+
             this.saveLoading = true
             editypesSendingEdi(row).then(res => {
                 this.saveLoading = false
@@ -2094,6 +2096,7 @@ export default {
                         return;
                     }
                     if (this.verifySymbolStatus == 1) {
+                        /*
                         let msgsList = []
                         if (checkFullWidthSymbols(this.form.detail.hshipperDetails).hasFullWidth) {
                             let msg = []
@@ -2152,7 +2155,6 @@ export default {
                                 return
                             }
                         }
-
                         if (checkFullWidthSymbols(this.form.detail.mconsigneeDetails).hasFullWidth) {
                             let msg = []
                             for (let item of checkFullWidthSymbols(this.form.detail.mconsigneeDetails).positions) {
@@ -2237,6 +2239,56 @@ export default {
                                 return
                             }
                         });
+                        */
+                        let fldNames = 'hshipperDetails,hconsigneeDetails,hnotifyDetails,mshipperDetails,mconsigneeDetails,mnotifyDetails'.split(",");
+                        let fldDescs = '发货人,收货人,通知人,MBL 发货人,MBL 收货人,MBL 通知人'.split(",");
+                        let msgsList = []
+                        fldNames.forEach((fld, idx)=>{
+                            const cfs = checkFullWidthSymbols(this.form.detail[fld]);
+                            if(cfs.hasFullWidth){
+                                if(cfs.isResetText){
+                                    this.$set(this.form.detail, fld, cfs.resetText);
+                                }
+                                msgsList.push(fldDescs[idx] + ": " + cfs.message)
+                            }
+                        })
+
+                        fldNames = 'marks,commodityDescr,forwarding,siRemarks,bookingRemarks'.split(",");
+                        fldDescs = '唛头,货描,FORWARDING,SI 备注,订舱备注'.split(",");
+                        fldNames.forEach((fld, idx)=>{
+                            const cfs = checkFullWidthSymbols(this.form[fld]);
+                            console.log(fldDescs[idx], cfs)
+                            if(cfs.isResetText===true){
+                                console.log("set", fld, this.form[fld], cfs.resetText)
+                                this.$set(this.form, fld, cfs.resetText);
+                            }
+                            if(cfs.hasFullWidth){
+                                msgsList.push(fldDescs[idx] + ": " + cfs.message)
+                            }
+                        })
+
+                        fldNames = 'placeReceiptNamePrint,polNamePrint,podNamePrint,destinationNamePrint,placeDeliveryNamePrint,potNamePrint'.split(",");
+                        fldDescs = '收货地,装货港,卸货港,目的地,交货地,中转港'.split(",");
+                        fldNames.forEach((fld, idx)=>{
+                            const cfs = checkFullWidthSymbols(this.form[fld]);
+                            if(cfs.hasFullWidth){
+                                if(cfs.isResetText){
+                                    this.$set(this.form, fld, cfs.resetText);
+                                }
+                                msgsList.push(fldDescs[idx] + ": " + cfs.message)
+                            }
+                        })
+
+                        if (msgsList.length > 0) {
+                            this.$message({
+                                dangerouslyUseHTMLString: true,
+                                message: `${msgsList.join("<br/><br/>")}`,
+                                type: 'error'
+                            });
+                            return;
+                        }
+
+                        msgsList=[]
                         console.log(this.form.detail)
                         if (!verifyEnglish(this.form.detail.hshipperDetails)) {
                             msgsList.push('发货人')