Просмотр исходного кода

refactor(pay): 增强支付码输入兼容性并处理冗余字符

针对扫码设备可能自动追加回车或空格的问题,对支付码的处理流程进行重构,确保数据清洗的一致性。

- 在 `salesQuery.vue` 和 `confirmMixin.js` 中引入 `.trim()` 处理,过滤支付码首尾空白字符。
- 优化 `submitOnlinePay` 逻辑,确保清洗后的支付码被正确传递至提交函数。
- 修正长度校验逻辑,防止因不可见字符导致的校验偏差。
LaveyD 1 месяц назад
Родитель
Сommit
1b2c97618d

+ 3 - 2
src/pages/queryReport/salesQuery.vue

@@ -2236,13 +2236,14 @@ export default {
       }
     },
     submitPayCode () {
-      if (!this.payCode) {
+      // 扫码盒子通常会在码值末尾追加回车/空格,提交前需要去掉
+      const qrcode = (this.payCode || '').trim()
+      if (!qrcode) {
         this.$message.error('请输入付款码')
         return
       }
       this.payCodeDialogVisible = false
       const row = this.currentRegisterOrder
-      const qrcode = this.payCode
       this.payCode = ''
       this.doConfirmRegisterOrder(row, qrcode)
     },

+ 6 - 4
src/pages/sellManage/common/confirmMixin.js

@@ -252,7 +252,7 @@ export default {
         this.params.guideName = this.params.guestId
         this.params.guestId = null
       }
-      this.params.qrCode = qrcode
+      this.params.qrCode = (qrcode || '').trim()
       this.params.discount = cardInfo ? cardInfo.discount : ''
       this.params.password = cardInfo ? cardInfo.password : ''
       this.params.memberSystemId = cardInfo ? cardInfo.memberSystemId : ''
@@ -272,13 +272,15 @@ export default {
       })
     },
     submitOnlinePay () {
-      if (!this.payCode) {
+      // 扫码盒子通常会在码值末尾追加回车/空格,提交前需要去掉
+      const payCode = (this.payCode || '').trim()
+      if (!payCode) {
         this.$message.error('请输入支付码')
         return
       }
       this.payCodeDialogVisible = false
       // 直接调用 handleSubmit,避免被 submit 的 1000ms 前置节流吞掉(扫码盒子输入极快时必现)
-      this.handleSubmit(this.payCode)
+      this.handleSubmit(payCode)
       // this.createOrder(this.params, true)
     },
     cancelOnlinePay () {
@@ -395,7 +397,7 @@ export default {
     handlePayCodeInput (e) {
       this.timer && clearTimeout(this.timer)
       this.timer = setTimeout(() => {
-        if (this.payCode.length > 10) {
+        if ((this.payCode || '').trim().length > 10) {
           this.submitOnlinePay()
         }
       }, 200)