|
|
@@ -61,7 +61,7 @@
|
|
|
</van-col>
|
|
|
<van-col span="18" class="table-container">
|
|
|
<van-cell-group class="custom-cell-group">
|
|
|
- <van-cell title="系统提示:" :value="message" />
|
|
|
+ <van-cell title="系统提示:" :value="message" :value-class="{'success-message': message && message.includes('扫描成功')}"/>
|
|
|
</van-cell-group>
|
|
|
|
|
|
<div class="waterfall-table">
|
|
|
@@ -74,6 +74,7 @@
|
|
|
</div>
|
|
|
|
|
|
<van-pull-refresh
|
|
|
+ ref="pullRefreshRef"
|
|
|
v-model="refreshing"
|
|
|
success-text="刷新成功"
|
|
|
@refresh="onRefresh"
|
|
|
@@ -143,11 +144,11 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { onMounted, onUnmounted, ref, watch } from 'vue'
|
|
|
+import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
|
import { closeListener, openListener, scanInit } from '@/utils/keydownListener'
|
|
|
import { scanSuccess, scanError } from '@/utils/android'
|
|
|
import { getVersionName, checkUpdate, saveUserId, getUserId, scanRepeat, saveMacAddress, listErrRecords, reLoginTip,
|
|
|
- readMacAddress, pageDelivery, addDelivery, isDeliveryNoExists, markAsPushed, getErrRecordsCount, removeUserId } from '@/utils/androidPiece'
|
|
|
+ readMacAddress, pageDelivery, addDelivery, isDeliveryNoExists, markAsPushed, getErrRecordsCount, removeUserId, scanErr } from '@/utils/androidPiece'
|
|
|
import { showLoadingToast, showNotify } from 'vant'
|
|
|
import { getUserIdByCert, getUserNameById } from '@/api/login/index'
|
|
|
import { receive, getScanDriverInfo } from '@/api/scan/index'
|
|
|
@@ -270,11 +271,25 @@ const getFrogPosition = () => {
|
|
|
const _openScan = () => {
|
|
|
openListener()
|
|
|
setTimeout(() => {
|
|
|
- scanInit(_handlerScan)
|
|
|
+ scanInit(debounceScan)
|
|
|
},300)
|
|
|
}
|
|
|
|
|
|
const pushing = ref(false)
|
|
|
+const pullRefreshRef = ref(null)
|
|
|
+const scanDebounceTimeout = ref(null)
|
|
|
+
|
|
|
+const debounceScan = (code) => {
|
|
|
+ // 清除之前的防抖计时器
|
|
|
+ if (scanDebounceTimeout.value) {
|
|
|
+ clearTimeout(scanDebounceTimeout.value)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置新的防抖计时器
|
|
|
+ scanDebounceTimeout.value = setTimeout(() => {
|
|
|
+ _handlerScan(code)
|
|
|
+ }, 300) // 300ms 防抖时间
|
|
|
+}
|
|
|
const _handlerScan = (code) => {
|
|
|
code = fixDuplicateText(code)
|
|
|
// 校验扫描的是否为登录二维码
|
|
|
@@ -292,6 +307,31 @@ const _handlerScan = (code) => {
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
+ // 检查长度是否在11到25个字符之间
|
|
|
+ if (typeof code !== 'string' || code.length < 11 || code.length > 25) {
|
|
|
+ console.log(code)
|
|
|
+ scanErr()
|
|
|
+ showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '请扫描正确的快递单号!' });
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 数字0-9,大写字母A-Z,部分特殊字符(空格、! " % & ' ( ) * + , - . / : ; < = > ? _)
|
|
|
+ const code128BPattern = /^[\x20-\x7F]+$/;
|
|
|
+ // 检查是否只包含有效字符
|
|
|
+ if (!code128BPattern.test(code)) {
|
|
|
+ console.log(code)
|
|
|
+ scanErr()
|
|
|
+ showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '请扫描正确的快递单号!' });
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 添加滚动到顶部的逻辑
|
|
|
+ nextTick(() => {
|
|
|
+ if (pullRefreshRef.value.$el) {
|
|
|
+ pullRefreshRef.value.$el.scrollTo({
|
|
|
+ top: 0,
|
|
|
+ behavior: 'smooth' // 平滑滚动效果
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
// 校验是否已登录
|
|
|
if (!userInfo.value.userId) {
|
|
|
scanError()
|
|
|
@@ -300,13 +340,13 @@ const _handlerScan = (code) => {
|
|
|
}
|
|
|
// 校验是否为空
|
|
|
if (!code) {
|
|
|
- scanError()
|
|
|
+ scanErr()
|
|
|
showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '请先扫描快递单号!' });
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if (pushing.value) {
|
|
|
- scanError()
|
|
|
+ scanErr()
|
|
|
showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '正在提交中,请稍后扫描!' });
|
|
|
return
|
|
|
}
|
|
|
@@ -330,11 +370,10 @@ const _handlerScan = (code) => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- let status = false
|
|
|
- showLoadingToast({
|
|
|
+ const toast = showLoadingToast({
|
|
|
message: '上传中...',
|
|
|
forbidClick: true,
|
|
|
- closeToast: status
|
|
|
+ duration: 0 // 禁止自动关闭
|
|
|
});
|
|
|
// 校验是否已存在
|
|
|
const currentTime = formatDateTime(new Date())
|
|
|
@@ -359,12 +398,13 @@ const _handlerScan = (code) => {
|
|
|
return
|
|
|
}
|
|
|
if (result === -2) {
|
|
|
- scanError()
|
|
|
+ scanErr()
|
|
|
showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '添加失败,请联系开发人员!' });
|
|
|
return
|
|
|
}
|
|
|
preDeliveryNo.value = code
|
|
|
scanSuccess()
|
|
|
+ message.value = code + '扫描成功!'
|
|
|
list.value.unshift(dto)
|
|
|
showNotify({ type: 'success', style: 'font-size: 30px !important;height:50px', message: '扫描成功!' });
|
|
|
}
|
|
|
@@ -373,11 +413,11 @@ const _handlerScan = (code) => {
|
|
|
userInfo.value = {}
|
|
|
reLoginTip()
|
|
|
} else {
|
|
|
- scanError()
|
|
|
+ scanErr()
|
|
|
}
|
|
|
showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: `扫描失败!${err.message}` });
|
|
|
}).finally(() => {
|
|
|
- status = true
|
|
|
+ toast.close();
|
|
|
pushing.value = false
|
|
|
})
|
|
|
}
|
|
|
@@ -770,6 +810,9 @@ span
|
|
|
color: red
|
|
|
font-size: 13px
|
|
|
text-align: left
|
|
|
+ .success-message
|
|
|
+ font-size: 12px
|
|
|
+ color: #2ed573 !important
|
|
|
|
|
|
.van-notice-bar
|
|
|
background-color: #f8f9fa
|