网络安全行业的11个市场机遇

核心内容摘要

Vue3项目实战:用ECharts GL打造炫酷3D江苏地图(附完整代码)
汽车主断面设计详解:结构关系与后续设计控制,断面定位与标注指南,学习提升必备参考

Mixly vs Arduino IDE:图形化与代码编程控制LED灯的全方位对比(含实操步骤)

1实现一个hooksimport { onMounted, onUnmounted, ref } from vue interface ScanOptions { threshold?: number minLength?: number onScanProgress?: (buffer: string) void onScanSuccess: (code: string) void } export function useScanGun(options: ScanOptions) { const { threshold 100, minLength 6, onScanProgress, onScanSuccess } options const codeBuffer ref() const lastScanned ref() let lastTime 0 let timer: ReturnTypetypeof setTimeout | null null const commit (preventDefaultEvent?: KeyboardEvent) { const value codeBuffer.value if (value.length minLength) { lastScanned.value value onScanSuccess(value) if (preventDefaultEvent) preventDefaultEvent.preventDefault() } codeBuffer.value lastTime 0 } const handleKeyDown (event: KeyboardEvent) { const currentTime Date.now() if (timer ! null) { clearTimeout(timer) timer null } if (event.metaKey || event.ctrlKey || event.altKey) return const limit event.key Enter ? threshold * 2 : threshold if (lastTime ! 0 currentTime - lastTime limit) { codeBuffer.value } if (event.key Enter) { commit(event) return } if (event.key.length

{ codeBuffer.value event.key onScanProgress?.(codeBuffer.value) } lastTime currentTime timer setTimeout(() { commit() }, threshold *

} onMounted(() { window.addEventListener(keydown, handleKeyDown, true) }) onUnmounted(() { if (timer ! null) { clearTimeout(timer) timer null } window.removeEventListener(keydown, handleKeyDown, true) }) return { codeBuffer, lastScanned } }2 在app.vue中全局监听扫码的结果script setup langts import zhCn from element-plus/es/locale/lang/zh-cn import { onMounted, ref } from vue import { recordProgress, signRegister } from /apis import { useScanGun } from /hooks/useScan const SCANNER_PREFIXES [A|, B|, C|, D|, E|, F|] as const type ScannerPrefix (typeof SCANNER_PREFIXES)[number] const parseScannerPayload (raw: string): { prefix: ScannerPrefix; payload: string } | null { const text String(raw ?? ).trim() if (!text) return null for (const prefix of SCANNER_PREFIXES) { if (text.startsWith(prefix)) return { prefix, payload: text.slice(prefix.length) } } return null } const code ref() useScanGun({ threshold: 200, onScanProgress: (buffer) { console.log(codeBuffer, buffer) }, onScanSuccess: (result) { console.log(app---扫码成功, result) const parsed parseScannerPayload(result) const rawPayload (parsed?.payload ?? result).trim() if (!rawPayload) return const rawParts rawPayload.split(-) const orderNo rawParts[0]?.trim() || const cardNo rawParts.length 2 ? rawParts.slice(

.join(-).trim() : const inputValue cardNo || rawPayload code.value inputValue window.dispatchEvent( new CustomEvent(global-scan, { detail: { raw: result, prefix: parsed?.prefix, rawPayload, orderNo, cardNo, payload: inputValue } }) ) const active document.activeElement if (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement) { active.value inputValue active.dispatchEvent(new Event(input, { bubbles: true })) } //工位一扫码只得到客户邮寄的订单信息 if (parsed?.prefix A|) { signRegister({ logisticsNo: orderNo || rawPayload }) .then((res) console.log(signRegister success:, res)) .catch((err) console.error(signRegister error:, err)) return } //其他工位单独区分... if (parsed) { recordProgress({ orderNo: orderNo || rawPayload, cardNos: cardNo ? [cardNo] : [] }) .then((res) console.log(recordProgress success:, res)) .catch((err) console.error(recordProgress error:, err)) } } }) onMounted(() { console.log(扫码枪已就绪) }) /script template el-config-provider :localezhCn router-view/router-view /el-config-provider /template style scoped/style注意这里 const SCANNER_PREFIXES [A|, B|, C|, D|, E|, F|] as const的目的是为了区分不同的扫描枪。

扫描枪扫码以后得到的数据前会出现A|xxxx,B|xxxxx等。

这是通过scan123这个软件设置的。

比如扫描枪一设置返回的数据前缀为A|那么扫描枪1最后通过扫码的结果就是A|XXX,,扫描枪二同理...这时我们在代码里就可以区分不同的扫描枪。

让他们去做不同的业务逻辑const active document.activeElement if (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement) { active.value inputValue active.dispatchEvent(new Event(input, { bubbles: true })) }这里的代码是当用户关闭定位在输入框时可以自动填充扫码枪的结果

尕老太最新视频合集-尕老太最新视频合集应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123