曹睿
2025-04-21 1e5646aadae902d9f9043cc0d79395bf6b06a38c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<template>
  <view class="page">
    <CardTitle title="单丝领用" :hideAction="false">
      <template #action>
        <wd-button type="icon" icon="scan" color="#0D867F" @click="openScan"></wd-button>
      </template>
    </CardTitle>
    <view class="list_box">
      <MonofilCard v-for="(item, index) in cardList" :key="index" />
    </view>
    <Scan ref="scanRef" />
  </view>
</template>
 
<script setup lang="ts">
import CardTitle from "@/components/card-title/index.vue";
import MonofilCard from "../components/MonofilCard.vue";
import { onLoad, onUnload, onShow, onHide } from "@dcloudio/uni-app";
import Scan from "@/components/scan/index.vue";
// import { useZebraScan } from "@/hooks/useZebraScan";
 
// const { init, start, stop, triggerScan } = useZebraScan();
 
const scanRef = ref();
const cardList = ref<any[]>([]);
 
const getScanCode = (code: any) => {
  // let parseData = code.trim();
  console.log("自定义扫描的结果回调函数:", code);
  cardList.value.push({});
};
 
const openScan = () => {
  // uni.scanCode({
  //   onlyFromCamera: true,
  //   success: (res) => {
  //     console.log("条码类型:" + res.scanType);
  //     console.log("条码内容:" + res.result);
  //     cardList.value.push(res.result);
  //   },
  // });
  // triggerScan();
  scanRef.value.triggerScan();
};
 
onLoad(() => {
  // 开启广播监听事件
  uni.$on("scan", getScanCode);
  // init(getScanCode);
});
onUnload(() => {
  // 开启广播监听事件
  uni.$off("scan", getScanCode);
  // stop();
});
 
onShow(() => {
  // start();
});
 
onHide(() => {
  // stop();
});
</script>
 
<style lang="scss" scoped>
.page {
  background: #f3f9f8;
  .list_box {
    height: calc(100% - 100px);
    overflow: scroll;
  }
}
:deep(.wd-button__content) {
  color: #0d867f;
}
</style>