code-storage.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="container">
  3. <view class="main-content">
  4. <view class="input-group">
  5. <u-input :customStyle="customStyle" :placeholder-style="placeholderStyle" v-model="form.isbn"
  6. placeholder="扫描/输入ISBN" border="surround" />
  7. <u-button :customStyle="customStyle" type="info" color="#a4adb3"
  8. @click="handleBarcode(form.isbn)" text="确定" />
  9. </view>
  10. </view>
  11. <view class="fixed-bottom">
  12. <u-button size="large" type="success" @click="scanCode" text="扫码" class="scan-button" />
  13. </view>
  14. </view>
  15. </template>
  16. <script setup>
  17. import {
  18. reactive,
  19. ref,
  20. onUnmounted
  21. } from 'vue';
  22. import {
  23. onLoad,
  24. onShow
  25. } from '@dcloudio/uni-app'
  26. const placeholderStyle = "font-size:32rpx"
  27. const customStyle = reactive({
  28. height: '90rpx'
  29. })
  30. const form = ref({
  31. "isbn": ""
  32. })
  33. function scanCode() {
  34. uni.scanCode({
  35. success: (res) => {
  36. form.value.isbn = res.result;
  37. handleBarcode(res.result)
  38. },
  39. fail: (err) => {
  40. uni.$u.toast('扫码失败')
  41. }
  42. });
  43. }
  44. function handleBarcode(code) {
  45. if (!code) return uni.$u.toast('请输入ISBN')
  46. // 这里可以添加ISBN查询逻辑
  47. uni.$u.toast('ISBN: ' + code);
  48. uni.$u.http.post('/activation/bookActivationInfo/queryBookBasicByIsbn/' + code).then(res => {
  49. if (res.code == 200) {
  50. // 处理查询成功的逻辑
  51. uni.navigateTo({
  52. url: '/pages/index/wms/code-storage-add?isbn=' + code
  53. })
  54. form.value.isbn = ""
  55. // 传递书籍信息到下一页
  56. uni.setStorageSync('bookInfo', res.data)
  57. } else {
  58. uni.$u.toast('未找到该书籍')
  59. }
  60. })
  61. }
  62. // #ifdef APP-PLUS
  63. const { unregister } = uni.$u.useEventListener((e) => {
  64. form.value.isbn = e.barcode
  65. handleBarcode(e.barcode)
  66. });
  67. // #endif
  68. onUnmounted(() => {
  69. // #ifdef APP-PLUS
  70. unregister();
  71. // #endif
  72. });
  73. </script>
  74. <style lang="scss" scoped>
  75. .main-content {
  76. padding: 20px;
  77. gap: 20px;
  78. }
  79. .input-group {
  80. display: flex;
  81. gap: 10px;
  82. margin-bottom: 30rpx;
  83. :deep(.u-button) {
  84. width: 160rpx
  85. }
  86. .u-input {
  87. background-color: #fff;
  88. }
  89. }
  90. .scan-button {
  91. width: 100%;
  92. }
  93. </style>