| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <template>
- <view class="container">
- <!-- <view class="container">
- <button @click="initBluetooth" :disabled="isInitializing">初始化蓝牙</button>
- <button @click="startDiscovery" :disabled="isDiscovering || !isBluetoothOpened">开始搜索设备</button>
- <button @click="connectDevice" :disabled="!selectedDevice || isConnecting">连接设备</button>
- <button @click="startDataMonitor" :disabled="!isConnected">开始监听数据</button>
- <view v-if="scanData">扫描结果: {{ scanData }}</view>
- </view> -->
- <u-button type="primary" @click="goScan" text="扫码" />
- <view class="main-content">
- <view class="input-group">
- <u-input placeholder-style="font-size:32rpx" v-model="unpackCode" placeholder="扫描/输入物流单号"
- border="surround" />
- <u-button type="primary" @click="confirmTrackingNumber(unpackCode)" text="确定" />
- </view>
- </view>
- <view class="fixed-bottom">
- <u-button size="large" type="success" @click="scanCode" text="扫码" class="scan-button" />
- </view>
- </view>
- </template>
- <script setup>
- import {
- ref
- } from 'vue';
- import {
- onLoad,
- onUnload
- } from '@dcloudio/uni-app'
- //跳转至扫码页面
- function goScan() {
- uni.navigateTo({
- url: '/pages/index/express/scan'
- })
- }
- const unpackCode = ref('');
- function confirmTrackingNumber(code) {
- uni.$u.http.post('/app/ordersign/unpackingSign', {
- packageCode: code
- }).then(res => {
- if (res.code == 200) {
- let text = code + '拆包成功'
- uni.$u.ttsModule.speak(text)
- } else {
- let text = code + '订单不存在'
- uni.$u.ttsModule.speak(text)
- }
- })
- }
- function scanCode() {
- uni.scanCode({
- success: (res) => {
- unpackCode.value = res.result;
- confirmTrackingNumber(res.result)
- // 处理扫码结果
- console.log('扫码结果:', res.result);
- },
- fail: (err) => {
- console.error('扫码失败:', err);
- }
- });
- }
- import keymap from './components/keymap.js'
- const inputCache = ref('');
- const keypress = (e) => {
- if (e.keyCode === 66 || e.key =='Enter') {
- unpackCode.value = inputCache.value;
- confirmTrackingNumber(unpackCode.value)
- inputCache.value = '';
- } else {
- inputCache.value += keymap[e.keyCode] || ''
- }
- }
- onLoad(() => {
- // #ifdef APP-PLUS
- uni.$u.useGlobalEvent((e) => {
- unpackCode.value = e.barcode;
- confirmTrackingNumber(e.barcode);
- });
- // #endif
- // Initialize Bluetooth
- // #ifdef APP-PLUS
- plus.key.addEventListener("keyup", keypress);
- // #endif
- // #ifdef H5
- document.addEventListener("keyup", keypress);
- // #endif
- });
- onUnload(()=>{
- // #ifdef APP-PLUS
- plus.key.removeEventListener("keyup", keypress);
- // #endif
- // #ifdef H5
- document.removeEventListener("keyup", keypress);
- // #endif
- })
- </script>
- <style lang="scss" scoped>
- .main-content {
- padding: 20px;
- gap: 20px;
- }
- .input-group {
- display: flex;
- gap: 10px;
- margin-bottom: 30rpx;
- :deep(.u-button) {
- width: 160rpx
- }
- .u-input {
- background-color: #fff;
- }
- }
- </style>
|