quick-unpack.vue 3.5 KB

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