quick-unpack.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. onShow
  31. } from '@dcloudio/uni-app'
  32. //跳转至扫码页面
  33. function goScan() {
  34. uni.navigateTo({
  35. url: '/pages/index/express/scan'
  36. })
  37. }
  38. const unpackCode = ref('');
  39. function confirmTrackingNumber(code) {
  40. uni.$u.http.post('/app/ordersign/unpackingSign', {
  41. packageCode: code
  42. }).then(res => {
  43. if (res.code == 200) {
  44. let text = code + '拆包成功'
  45. uni.$u.ttsModule.speak(text)
  46. } else {
  47. let text = code + res.msg
  48. uni.$u.ttsModule.speak(text)
  49. }
  50. })
  51. }
  52. function scanCode() {
  53. uni.scanCode({
  54. success: (res) => {
  55. unpackCode.value = res.result;
  56. confirmTrackingNumber(res.result)
  57. // 处理扫码结果
  58. console.log('扫码结果:', res.result);
  59. },
  60. fail: (err) => {
  61. console.error('扫码失败:', err);
  62. }
  63. });
  64. }
  65. import keymap from './components/keymap.js'
  66. const inputCache = ref('');
  67. const keypress = (e) => {
  68. if (e.keyCode === 66 || e.key =='Enter') {
  69. unpackCode.value = inputCache.value;
  70. confirmTrackingNumber(unpackCode.value)
  71. inputCache.value = '';
  72. } else {
  73. inputCache.value += keymap[e.keyCode] || ''
  74. }
  75. }
  76. onLoad(() => {
  77. // #ifdef APP-PLUS
  78. uni.$u.useGlobalEvent((e) => {
  79. unpackCode.value = e.barcode;
  80. confirmTrackingNumber(e.barcode);
  81. });
  82. // #endif
  83. // Initialize Bluetooth
  84. // #ifdef APP-PLUS
  85. plus.key.addEventListener("keyup", keypress);
  86. // #endif
  87. // #ifdef H5
  88. document.addEventListener("keyup", keypress);
  89. // #endif
  90. });
  91. onUnload(()=>{
  92. // #ifdef APP-PLUS
  93. plus.key.removeEventListener("keyup", keypress);
  94. // #endif
  95. // #ifdef H5
  96. document.removeEventListener("keyup", keypress);
  97. // #endif
  98. })
  99. onShow(() => {
  100. uni.$u.updateActivePageOnShow()
  101. })
  102. </script>
  103. <style lang="scss" scoped>
  104. .main-content {
  105. padding: 20px;
  106. gap: 20px;
  107. }
  108. .input-group {
  109. display: flex;
  110. gap: 10px;
  111. margin-bottom: 30rpx;
  112. :deep(.u-button) {
  113. width: 160rpx
  114. }
  115. .u-input {
  116. background-color: #fff;
  117. }
  118. }
  119. </style>