quick-unpack.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="container">
  3. <!-- <view class="container">
  4. <button @click="initBluetooth" :disabled="isInitializing">初始化蓝牙</button>
  5. <button @click="startDiscovery" :disabled="isDiscovering || !isBluetoothOpened">开始搜索设备</button>
  6. <button @click="connectDevice" :disabled="!selectedDevice || isConnecting">连接设备</button>
  7. <button @click="startDataMonitor" :disabled="!isConnected">开始监听数据</button>
  8. <view v-if="scanData">扫描结果: {{ scanData }}</view>
  9. </view> -->
  10. <u-button type="primary" @click="goScan" text="扫码" />
  11. <view class="main-content">
  12. <view class="input-group">
  13. <u-input placeholder-style="font-size:32rpx" v-model="unpackCode" placeholder="扫描/输入物流单号"
  14. border="surround" />
  15. <u-button type="primary" @click="confirmTrackingNumber(unpackCode)" text="确定" />
  16. </view>
  17. </view>
  18. <view class="fixed-bottom">
  19. <u-button size="large" type="success" @click="scanCode" text="扫码" class="scan-button" />
  20. </view>
  21. </view>
  22. </template>
  23. <script setup>
  24. import {
  25. ref
  26. } from 'vue';
  27. import {
  28. onLoad,
  29. onUnload
  30. } from '@dcloudio/uni-app'
  31. //跳转至扫码页面
  32. function goScan() {
  33. uni.navigateTo({
  34. url: '/pages/index/express/scan'
  35. })
  36. }
  37. const unpackCode = ref('');
  38. function confirmTrackingNumber(code) {
  39. uni.$u.http.post('/app/ordersign/unpackingSign', {
  40. packageCode: code
  41. }).then(res => {
  42. if (res.code == 200) {
  43. let text = code + '拆包成功'
  44. uni.$u.ttsModule.speak(text)
  45. } else {
  46. let text = code + '订单不存在'
  47. uni.$u.ttsModule.speak(text)
  48. }
  49. })
  50. }
  51. function scanCode() {
  52. uni.scanCode({
  53. success: (res) => {
  54. unpackCode.value = res.result;
  55. confirmTrackingNumber(res.result)
  56. // 处理扫码结果
  57. console.log('扫码结果:', res.result);
  58. },
  59. fail: (err) => {
  60. console.error('扫码失败:', err);
  61. }
  62. });
  63. }
  64. import keymap from './components/keymap.js'
  65. const inputCache = ref('');
  66. const keypress = (e) => {
  67. if (e.keyCode === 66 || e.key =='Enter') {
  68. unpackCode.value = inputCache.value;
  69. confirmTrackingNumber(unpackCode.value)
  70. inputCache.value = '';
  71. } else {
  72. inputCache.value += keymap[e.keyCode] || ''
  73. }
  74. }
  75. onLoad(() => {
  76. // #ifdef APP-PLUS
  77. uni.$u.useGlobalEvent((e) => {
  78. unpackCode.value = e.barcode;
  79. confirmTrackingNumber(e.barcode);
  80. });
  81. // #endif
  82. // Initialize Bluetooth
  83. // #ifdef APP-PLUS
  84. plus.key.addEventListener("keyup", keypress);
  85. // #endif
  86. // #ifdef H5
  87. document.addEventListener("keyup", keypress);
  88. // #endif
  89. });
  90. onUnload(()=>{
  91. // #ifdef APP-PLUS
  92. plus.key.removeEventListener("keyup", keypress);
  93. // #endif
  94. // #ifdef H5
  95. document.removeEventListener("keyup", keypress);
  96. // #endif
  97. })
  98. </script>
  99. <style lang="scss" scoped>
  100. .main-content {
  101. padding: 20px;
  102. gap: 20px;
  103. }
  104. .input-group {
  105. display: flex;
  106. gap: 10px;
  107. margin-bottom: 30rpx;
  108. :deep(.u-button) {
  109. width: 160rpx
  110. }
  111. .u-input {
  112. background-color: #fff;
  113. }
  114. }
  115. </style>