曹睿
2025-04-18 912b764830b165ff3b92267570ea43ef9dad58bf
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
<template>
  <view class="page">
    <CardTitle title="单丝领用" :hideAction="false">
      <template #action>
        <wd-button type="icon" icon="scan" color="#0D867F" @click="scanCode"></wd-button>
      </template>
    </CardTitle>
    <view class="list_box">
      <MonofilCard v-for="(item, index) in 4" :key="index" />
    </view>
    <scan />
  </view>
</template>
 
<script setup lang="ts">
import CardTitle from "@/components/card-title/index.vue";
import MonofilCard from "../components/MonofilCard.vue";
import scan from "@/components/scan/index.vue";
import { onLoad, onUnload } from "@dcloudio/uni-app";
 
const cardList = ref<any[]>([]);
 
const BroadcastScanningToObtainData = (res: any) => {
  console.log("获取次数", res.code);
  let barcode = res.code;
  console.log("打印数据", barcode);
};
 
const scanCode = () => {
  uni.scanCode({
    onlyFromCamera: true,
    success: (res) => {
      console.log("条码类型:" + res.scanType);
      console.log("条码内容:" + res.result);
      cardList.value.push(res.result);
    },
  });
};
 
onLoad(() => {
  // 开启广播监听事件
  uni.$on("scan", BroadcastScanningToObtainData);
});
onUnload(() => {
  // 开启广播监听事件
  uni.$off("scan", BroadcastScanningToObtainData);
});
</script>
 
<style lang="scss" scoped>
.page {
  background: #f3f9f8;
  .list_box {
    height: calc(100% - 100px);
    overflow: scroll;
  }
}
:deep(.wd-button__content) {
  color: #0d867f;
}
</style>