7 changed files with 385 additions and 26 deletions
|
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,119 @@ |
|||||
|
<template> |
||||
|
<div class="scan-page"> |
||||
|
<!-- 返回导航栏 --> |
||||
|
<!-- left-text="取消" --> |
||||
|
<van-nav-bar title="扫描二维码/条形码" left-arrow |
||||
|
fixed class="scan-index-bar" @click-left="clickIndexLeft()" |
||||
|
></van-nav-bar> |
||||
|
<!-- 扫码区域 --> |
||||
|
<video ref="video" id="video" class="scan-video" autoplay></video> |
||||
|
<!-- 提示语 --> |
||||
|
<div v-show="tipShow" class="scan-tip">{{ tipMsg }}</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import { BrowserMultiFormatReader } from '@zxing/library'; |
||||
|
import { Toast, Dialog, Notify } from 'vant'; |
||||
|
|
||||
|
export default { |
||||
|
name: 'ScanCodePage', // 扫码页面 |
||||
|
data() { |
||||
|
return { |
||||
|
codeReader: null, |
||||
|
tipShow: false, // 是否展示提示 |
||||
|
tipMsg: '', // 提示文本内容 |
||||
|
scanText: '', // 扫码结果文本内容 |
||||
|
} |
||||
|
}, |
||||
|
created() { |
||||
|
this.openScan(); |
||||
|
}, |
||||
|
watch: { |
||||
|
'$route'(to, from) { |
||||
|
if(to.path == '/ScanCodePage'){ // 当处于该页面时 |
||||
|
this.openScan(); |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
destroyed(){ |
||||
|
this.codeReader.reset(); |
||||
|
this.codeReader = null; |
||||
|
}, |
||||
|
methods: { |
||||
|
async openScan() { // 初始化摄像头 |
||||
|
this.codeReader = await new BrowserMultiFormatReader(); |
||||
|
this.codeReader.getVideoInputDevices().then(videoDevices => { |
||||
|
this.tipMsg = '正在调用摄像头...'; |
||||
|
this.tipShow = true; |
||||
|
console.log('get-videoDevices', videoDevices); |
||||
|
|
||||
|
// 默认获取摄像头列表里的最后一个设备id,通过几部测试机发现一般前置摄像头位于列表里的前面几位,所以一般获取最后一个的是后置摄像头 |
||||
|
let firstDeviceId = videoDevices[videoDevices.length - 1].deviceId; |
||||
|
// 一般获取了手机的摄像头列表里不止一个,有的手机摄像头高级多层,会有变焦摄像头等情况,需要做处理 |
||||
|
if (videoDevices.length > 1) { |
||||
|
// 一般通过判断摄像头列表项里的 label 字段,'camera2 0, facing back' 字符串含有 'back' 和 '0',大部分机型是这样,如果有些机型没有,那就还是默认获取最后一个 |
||||
|
firstDeviceId = videoDevices.find(el => { return el.label.indexOf('back') > -1 && el.label.indexOf('0') > -1 }) ? |
||||
|
videoDevices.find(el => { return el.label.indexOf('back') > -1 && el.label.indexOf('0') > -1 }).deviceId : |
||||
|
videoDevices[videoDevices.length - 1].deviceId; |
||||
|
} |
||||
|
console.log('get-firstDeviceId', firstDeviceId); |
||||
|
|
||||
|
this.decodeFromInputVideoFunc(firstDeviceId); |
||||
|
}).catch(err => { |
||||
|
this.tipShow = false; |
||||
|
console.error(err); |
||||
|
}); |
||||
|
}, |
||||
|
decodeFromInputVideoFunc(firstDeviceId) { // 使用摄像头扫描 |
||||
|
this.codeReader.reset(); // 重置 |
||||
|
this.codeReader.decodeFromInputVideoDeviceContinuously(firstDeviceId, 'video', (result, err) => { |
||||
|
this.tipMsg = '正在尝试识别...'; |
||||
|
if (result) { |
||||
|
console.log('扫码结果', result); |
||||
|
this.scanText = result.text; |
||||
|
if (this.scanText) { |
||||
|
this.tipShow = false; |
||||
|
Dialog.confirm({ // 获取到扫码结果进行弹窗提示,这部分接下去的代码根据需要,读者自行编写了 |
||||
|
title: '扫码结果', |
||||
|
message: this.scanText, |
||||
|
}).then(() => { // 点击确认 |
||||
|
|
||||
|
}).catch(() => { // 点击取消 |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}, |
||||
|
clickIndexLeft(){ // 返回上一页 |
||||
|
// this.$destroy(); |
||||
|
this.$router.go(-1); |
||||
|
// window.location.href = document.referrer; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss"> |
||||
|
.scan-index-bar{ |
||||
|
background-image: linear-gradient( -45deg, #42a5ff ,#59cfff); |
||||
|
.van-nav-bar__title, .van-nav-bar__arrow, .van-nav-bar__text{ |
||||
|
color: #fff !important; |
||||
|
} |
||||
|
} |
||||
|
.scan-page{ |
||||
|
min-height: 100vh; |
||||
|
background-color: #363636; |
||||
|
overflow-y: hidden; |
||||
|
.scan-video{ |
||||
|
height: 85vh; |
||||
|
} |
||||
|
.scan-tip{ |
||||
|
width: 100vw; |
||||
|
text-align: center; |
||||
|
color: white; |
||||
|
font-size: 5vw; |
||||
|
} |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,256 @@ |
|||||
|
<template> |
||||
|
<div class="home app_content"> |
||||
|
<!-- 导航栏 --> |
||||
|
<div class="header_body"> |
||||
|
<!-- <header-nav :leftArrow="false" titelText="扫码入企"></header-nav> --> |
||||
|
<header-nav |
||||
|
:slefBack="true" |
||||
|
@goBack="goBack" |
||||
|
:titelText="`扫码入企`" |
||||
|
> |
||||
|
</header-nav> |
||||
|
</div> |
||||
|
|
||||
|
<!-- 中间 --> |
||||
|
<div class="warp_body"> |
||||
|
<!-- <refresh-list v-model:freshMap="freshMap" @refresh="onRefresh" @onLoad="onLoad"> --> |
||||
|
<div class="carousel_box"> |
||||
|
<div class="box-scan-one"> |
||||
|
<span class="box-scan-text">扫一扫企业二维码</span> |
||||
|
</div> |
||||
|
<div class="box-scan-two"> |
||||
|
<span class="box-scan-text">即可查看企业信息</span> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="boutique_box"> |
||||
|
<!-- <van-cell :border="false" title="精品" /> --> |
||||
|
<div class="boutique_body"> |
||||
|
<!-- <goodsCard :goodsList="boutique" :cardAttr="boutiqueAttr"></goodsCard> --> |
||||
|
<div class="box-qr-code" @click="toScanPageView"> |
||||
|
<img src="../../assets/images/scan.png" /> |
||||
|
<span class="box-qr-code-text">执法监督码</span> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<!-- <div class="recommend_box"> |
||||
|
<van-cell :border="false" title="推荐" /> |
||||
|
<div class="recommend_body"> |
||||
|
<goodsCard :goodsList="recommend"></goodsCard> |
||||
|
</div> |
||||
|
</div> --> |
||||
|
<!-- </refresh-list> --> |
||||
|
</div> |
||||
|
|
||||
|
<!-- 底部 --> |
||||
|
<!-- <div class="footer_body"> |
||||
|
<footer-nav></footer-nav> |
||||
|
</div> --> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script setup name="Home"> |
||||
|
import {getEnterpriseMerchantAuthorization} from '@/api/Home'; |
||||
|
const { useCommon } = $globalStore; |
||||
|
const router = useRouter(); |
||||
|
let carouselList = reactive([]); // 轮播列表 |
||||
|
let boutique = reactive([]); // 精品数据 |
||||
|
let recommend = reactive([]); // 推荐 |
||||
|
let freshMap = reactive({ |
||||
|
refreshLoad: false, // 是否刷新 |
||||
|
listLoading: false, // 是否加载中 |
||||
|
listFinished: false, // 是否加载完成标识 |
||||
|
}); |
||||
|
const data = reactive({}); |
||||
|
const boutiqueAttr = reactive({ |
||||
|
columnNum: 4, |
||||
|
itemClass: "boutique_item", |
||||
|
goodsCradclass: "boutique-crad", |
||||
|
}); // 商品卡片展示 |
||||
|
|
||||
|
//获取轮播 |
||||
|
const getCarousel = async () => { |
||||
|
// const res = await useHome.getCarousel(); |
||||
|
// if (res?.code === 20000) { |
||||
|
// carouselList = res?.data; |
||||
|
// } |
||||
|
}; |
||||
|
|
||||
|
//精品 |
||||
|
const boutiqueGoods = async () => { |
||||
|
// const res = await useHome.boutiqueGoods(); |
||||
|
// if (res?.code === 20000) { |
||||
|
// boutique = res?.data; |
||||
|
// } |
||||
|
}; |
||||
|
|
||||
|
const toScanPageView = async() =>{ |
||||
|
router.push({ |
||||
|
path: "/enforce/scanPage", |
||||
|
query: {} |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
const toRegistrationListView = async() =>{ |
||||
|
router.push({ |
||||
|
path: "/enterprise/registrationList", |
||||
|
}); |
||||
|
} |
||||
|
const toComplaintView = async() =>{ |
||||
|
router.push({ |
||||
|
path: "/enterprise/complaint", |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
//下拉刷新 |
||||
|
const onRefresh = () => { |
||||
|
freshMap.listFinished = false; |
||||
|
freshMap.listLoading = true; |
||||
|
freshMap.refreshLoad = true; |
||||
|
// Promise.all([getCarousel(), boutiqueGoods(), recommendGoods()]).then(() => { |
||||
|
// freshMap.refreshLoad = false; |
||||
|
// }); |
||||
|
}; |
||||
|
|
||||
|
// 触底加载 |
||||
|
const onLoad = () => { |
||||
|
// recommendGoods(true); |
||||
|
}; |
||||
|
|
||||
|
onMounted(() => { |
||||
|
getEnterpriseMerchantAuthorization({merchantTel: useCommon.phonenumber},success =>{ |
||||
|
if(!(success.data == null && success.data.length == 0)){ |
||||
|
useCommon.SET_USER_ENTERPRISE_NUMBER(success.data[0].enterpriseNumber); |
||||
|
} |
||||
|
},error =>{ |
||||
|
}) |
||||
|
}) |
||||
|
// 返回 |
||||
|
const goBack = () => { |
||||
|
router.go(-1); |
||||
|
}; |
||||
|
</script> |
||||
|
|
||||
|
<style lang="less" scoped> |
||||
|
.home { |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
height: 100%; |
||||
|
overflow: hidden; |
||||
|
background-color: #f4f4f4; |
||||
|
|
||||
|
.warp_body { |
||||
|
background-color: rgb(163, 156, 156); |
||||
|
background-size: cover; |
||||
|
position: relative; |
||||
|
.carousel_box { |
||||
|
height: 150px; |
||||
|
width: 100%; |
||||
|
padding-bottom: 10px; |
||||
|
position: relative; |
||||
|
.box-scan-one{ |
||||
|
position: absolute; |
||||
|
top: 30%; |
||||
|
left: 15%; |
||||
|
font-size: 14px; |
||||
|
background-color: beige; |
||||
|
height: 100px; |
||||
|
width: 30%; |
||||
|
.box-scan-text{ |
||||
|
margin-top: 70%; |
||||
|
display: block; |
||||
|
font-size: 12px; |
||||
|
width: 100%; |
||||
|
text-align: center |
||||
|
} |
||||
|
} |
||||
|
.box-scan-two{ |
||||
|
position: absolute; |
||||
|
top: 30%; |
||||
|
right: 15%; |
||||
|
font-size: 14px; |
||||
|
background-color: beige; |
||||
|
height: 100px; |
||||
|
width: 30%; |
||||
|
.box-scan-text{ |
||||
|
margin-top: 70%; |
||||
|
display: block; |
||||
|
font-size: 12px; |
||||
|
width: 100%; |
||||
|
text-align: center |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
.boutique_box { |
||||
|
position: absolute; |
||||
|
width: 100%; |
||||
|
bottom: 30%; |
||||
|
.boutique_body { |
||||
|
padding: 0px 0px 10px 0px; |
||||
|
display: flex; |
||||
|
justify-content: center; |
||||
|
}; |
||||
|
.box-qr-code{ |
||||
|
width: 47%; |
||||
|
text-align: right; |
||||
|
height: 4.66667rem; |
||||
|
background-color: var(--van-primary-color); |
||||
|
border-radius: 0.26667rem; |
||||
|
// background-size: cover; |
||||
|
border-radius: 50%; |
||||
|
// background-image: url("@/assets/images/scan.png"); |
||||
|
.box-qr-code-text{ |
||||
|
margin-right: 25%; |
||||
|
margin-top: 70%; |
||||
|
display: block; |
||||
|
font-size: 0.45333rem; |
||||
|
} |
||||
|
img{ |
||||
|
position: absolute; |
||||
|
top: 0%; |
||||
|
left: 34%; |
||||
|
} |
||||
|
} |
||||
|
.box-info{ |
||||
|
width: 52%; |
||||
|
text-align: right; |
||||
|
height: 3.66667rem; |
||||
|
background-color: #ff976a; |
||||
|
border-radius: 10px; |
||||
|
background: url("@/assets/images/item_check.png"); |
||||
|
background-size: cover; |
||||
|
|
||||
|
.box-info-text{ |
||||
|
margin-right: 3%; |
||||
|
margin-top: 2%; |
||||
|
display: block; |
||||
|
font-size: 17px |
||||
|
} |
||||
|
} |
||||
|
.box-complaint{ |
||||
|
width: 36%; |
||||
|
text-align: right; |
||||
|
height: 3.66667rem; |
||||
|
background-color: #ff976a; |
||||
|
border-radius: 10px; |
||||
|
margin-left: 2%; |
||||
|
background: url("@/assets/images/item_complain.png"); |
||||
|
background-size: cover; |
||||
|
.box-complaint-text{ |
||||
|
margin-right: 5%; |
||||
|
margin-top: 3%; |
||||
|
display: block; |
||||
|
font-size: 17px |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.recommend_box { |
||||
|
.recommend_body { |
||||
|
width: 100%; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</style> |
||||
Loading…
Reference in new issue