Files
im/pages/common/scan.vue
T

100 lines
2.1 KiB
Vue
Raw Normal View History

2025-12-08 02:29:46 +08:00
<template>
2025-12-08 18:10:51 +08:00
<view class="scan_page" :style="{height:windowHeight+'px'}">
2026-01-01 04:15:30 +08:00
<uni-nav-bar left-icon="back" @clickLeft="back" fixed backgroundColor="#FFF" statusBar>
2025-12-08 18:10:51 +08:00
</uni-nav-bar>
2026-01-01 04:15:30 +08:00
<barcode id='1' class="barcode" ref="barcode" :autostart="true" background="rgb(0,0,0)" frameColor="#07c160"
scanbarColor="#07c160" :style="{height:windowHeight+'px'}" :filters="fil" @marked="success" @error="fail">
2025-12-08 18:10:51 +08:00
</barcode>
2025-12-08 02:29:46 +08:00
<view class="overlay">
<button class="btn" @click="toStart">开始扫码识别</button>
<button class="btn" @click="tocancel">取消扫码识别</button>
<button class="btn" @click="toFlash">开启闪光灯</button>
<button class="btn" @click="toscan">预览</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
2026-01-01 04:15:30 +08:00
fil: [0, 2, 1, 3, 4, 12],
windowHeight: 500,
2025-12-08 02:29:46 +08:00
}
},
2025-12-08 18:10:51 +08:00
onLoad() {
uni.scanCode({
complete(res) {
console.log(res)
}
})
},
created() {
const info = uni.getSystemInfoSync();
console.log(info);
this.windowHeight = info.screenHeight;
},
2025-12-08 02:29:46 +08:00
methods: {
2025-12-08 18:10:51 +08:00
success(e) {
2026-01-01 04:15:30 +08:00
//console.log("success1:" + JSO1N.stringify(e));
2025-12-08 02:29:46 +08:00
},
2025-12-08 18:10:51 +08:00
fail(e) {
2026-01-01 04:15:30 +08:00
//console.log("fail1:" + JSON1.stringify(e));
2025-12-08 02:29:46 +08:00
},
toStart: function() {
this.$refs.barcode.start({
conserve: true,
filename: '_doc/barcode/'
});
},
2026-01-01 04:15:30 +08:00
tocancel: function() {
2025-12-08 02:29:46 +08:00
this.$refs.barcode.cancel();
},
toFlash: function() {
this.$refs.barcode.setFlash(true);
},
toscan: function() {
console.log("scan:");
const barcodeModule = uni.requireNativePlugin('barcodeScan');
2026-01-01 04:15:30 +08:00
barcodeModule.scan("/static/barcode1.png", (e) => {
console.log("scan_error:", e);
2025-12-08 02:29:46 +08:00
});
2025-12-08 18:10:51 +08:00
},
2026-01-01 04:15:30 +08:00
back() {
2025-12-08 18:10:51 +08:00
uni.navigateBack();
2025-12-08 02:29:46 +08:00
}
}
}
</script>
<style lang="scss" scoped>
2026-01-01 04:15:30 +08:00
.scan_page {
2025-12-08 02:29:46 +08:00
width: 750rpx;
position: relative;
2026-01-01 04:15:30 +08:00
2025-12-08 02:29:46 +08:00
.barcode {
2025-12-08 18:10:51 +08:00
width: 750rpx;
2025-12-08 02:29:46 +08:00
background-color: #808080;
}
2026-01-01 04:15:30 +08:00
2025-12-08 02:29:46 +08:00
.btn {
top: 20rpx;
width: 730rpx;
margin-left: 10rpx;
margin-top: 10rpx;
background-color: #458B00;
border-radius: 10rpx;
}
2026-01-01 04:15:30 +08:00
.overlay {
2025-12-08 02:29:46 +08:00
background: rgba(0, 0, 0, 0.1);
2025-12-08 18:10:51 +08:00
position: absolute;
bottom: 100rpx;
left: 0;
right: 0;
height: 200rpx;
2025-12-08 02:29:46 +08:00
}
}
2026-01-01 04:15:30 +08:00
</style>