13 changed files with 325 additions and 113 deletions
@ -0,0 +1,81 @@ |
|||
<template> |
|||
<div class="address_edit"> |
|||
<!-- 导航栏 --> |
|||
<div class="header_body"> |
|||
<header-nav |
|||
:slefBack="true" |
|||
@goBack="goBack" |
|||
:titelText="`统计分析`" |
|||
> |
|||
</header-nav> |
|||
</div> |
|||
<!-- 中间 --> |
|||
<div class="warp_body"> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script setup name="addressEdit"> |
|||
|
|||
import util from "@/util/area"; |
|||
const { useMy } = $globalStore |
|||
|
|||
const router = useRouter(); |
|||
const route = useRoute(); |
|||
let queryaddressId = ref(""); |
|||
const data = reactive({ |
|||
searchResult: [], |
|||
areaList: util.areaList, |
|||
addressInfo: {}, |
|||
areaColumns: ["请选择", "请选择", "请选择"], |
|||
}); |
|||
|
|||
// 返回 |
|||
const goBack = () => { |
|||
router.go(-1); |
|||
}; |
|||
|
|||
// 保存地址操作 |
|||
const onSave = () => { |
|||
router.replace({ name: "addressList" }); |
|||
}; |
|||
|
|||
// 删除地址操作 |
|||
const onDelete = () => { |
|||
router.replace({ name: "addressList" }); |
|||
}; |
|||
|
|||
// 修改详细地址 |
|||
const onChangeDetail = () => {}; |
|||
|
|||
// 获取编辑地址数据 |
|||
const getEditdata = async (addressId) => { |
|||
const res = await useMy.getAddressedit({ addressId: addressId }); |
|||
if (res.code === 20000) { |
|||
data.addressInfo = res?.data; |
|||
data.areaColumns = [res?.data?.province, res?.data?.city, res?.data?.area]; |
|||
} |
|||
}; |
|||
watchEffect(() => { |
|||
if (route?.query?.addressId) { |
|||
queryaddressId = route?.query?.addressId; |
|||
} |
|||
}); |
|||
onMounted(() => { |
|||
route?.query?.addressId && getEditdata(route?.query?.addressId); |
|||
nextTick(() => { |
|||
if (!route?.query?.addressId) { |
|||
data.addressInfo = {}; |
|||
} |
|||
}); |
|||
}); |
|||
</script> |
|||
<style lang="less" scoped> |
|||
.address_edit { |
|||
display: flex; |
|||
flex-direction: column; |
|||
height: 100%; |
|||
overflow: hidden; |
|||
background-color: #f4f4f4; |
|||
} |
|||
</style> |
|||
@ -1,119 +1,211 @@ |
|||
<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 class="page bgc-f4f4f4"> |
|||
<header-nav |
|||
:slefBack="true" |
|||
@goBack="goBack" |
|||
> |
|||
</header-nav> |
|||
<div class="video-show" /> |
|||
<video id="video" ref="video" class="video vjs-fluid" autoplay /> |
|||
<span class="change" @click="change"> |
|||
<i class="el-icon-refresh" /> |
|||
</span> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import { BrowserMultiFormatReader } from '@zxing/library'; |
|||
import { Toast, Dialog, Notify } from 'vant'; |
|||
|
|||
// 看到这个没,这个是一个小插件,能在手机上打开控制台,你打印的控制台信息和报错都能在这显示,具体方法自己百度 |
|||
// import Vconsole from "vconsole"; |
|||
import { BrowserMultiFormatReader } from "@zxing/library"; |
|||
export default { |
|||
name: 'ScanCodePage', // 扫码页面 |
|||
name: "QrCodeSearch", |
|||
components: {}, |
|||
data() { |
|||
return { |
|||
codeReader: null, |
|||
tipShow: false, // 是否展示提示 |
|||
tipMsg: '', // 提示文本内容 |
|||
scanText: '', // 扫码结果文本内容 |
|||
} |
|||
loadingShow: false, |
|||
// 这个就是从@zxing/library导出来的方法,new一个实例 |
|||
codeReader: new BrowserMultiFormatReader(), |
|||
// 这个,用来储存扫码得到的结果 |
|||
textContent: null, |
|||
// 这个,就是当前调用的摄像头的索引,为什么是6,我会在后面说的 |
|||
num: 0, |
|||
// 这个就是扫描到的摄像头的数量 |
|||
videoLength: "" |
|||
}; |
|||
}, |
|||
created() { |
|||
// const vconsole = new Vconsole(); |
|||
// vconsole; |
|||
// 让我们调用这个方法尝试打开摄像头 |
|||
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; |
|||
// 开打开打 |
|||
async openScan() { |
|||
const that = this; |
|||
// 这个就是data里的哪个new出来的玩意,调用里面的方法 |
|||
that.codeReader |
|||
.getVideoInputDevices() |
|||
.then(videoInputDevices => { |
|||
// 记录一下扫描到的摄像头数量,这个videoInputDevices是个数组,里面有扫描到的摄像头数据 |
|||
this.videoLength = videoInputDevices.length; |
|||
console.log(JSON.stringify(videoInputDevices)); |
|||
console.log(videoInputDevices.length); |
|||
that.num = videoInputDevices.length |
|||
// 这步我们来决定一下调用第几个摄像头,看到这个num没,这就是data里的 |
|||
const firstDeviceId = videoInputDevices[this.videoLength -1].deviceId; |
|||
// 这调用另一个方法 |
|||
that.decodeFromInputVideoFunc( |
|||
firstDeviceId, |
|||
videoInputDevices.length |
|||
); |
|||
}) |
|||
// 失败回调,为什么这里的失败回调这么写,后面会说的 |
|||
.catch(err => { |
|||
this.num = 1; |
|||
that.openScan(); |
|||
console.error(err); |
|||
}); |
|||
}, |
|||
decodeFromInputVideoFunc(firstDeviceId) { // 使用摄像头扫描 |
|||
this.codeReader.reset(); // 重置 |
|||
this.codeReader.decodeFromInputVideoDeviceContinuously(firstDeviceId, 'video', (result, err) => { |
|||
this.tipMsg = '正在尝试识别...'; |
|||
//这就是在openScan里调的另一个方法,传入想调用的摄像头id和摄像头数量 |
|||
decodeFromInputVideoFunc(firstDeviceId, length) { |
|||
const that = this; |
|||
that.codeReader.reset(); // 重置 |
|||
that.textContent = null; // 重置 |
|||
// 看不懂不重要,打印出来自己琢磨琢磨 |
|||
that.codeReader.decodeFromInputVideoDeviceContinuously( |
|||
firstDeviceId, |
|||
"video", |
|||
(result, err) => { |
|||
that.textContent = null; |
|||
// 扫描成功 这个result就是扫描结果,长啥样自己打印出来看看 |
|||
if (result) { |
|||
console.log('扫码结果', result); |
|||
this.scanText = result.text; |
|||
if (this.scanText) { |
|||
this.tipShow = false; |
|||
Dialog.confirm({ // 获取到扫码结果进行弹窗提示,这部分接下去的代码根据需要,读者自行编写了 |
|||
title: '扫码结果', |
|||
message: this.scanText, |
|||
}).then(() => { // 点击确认 |
|||
|
|||
}).catch(() => { // 点击取消 |
|||
|
|||
that.textContent = result; |
|||
// 这里写你要对扫描结果做什么,我这里扫描出来的是个网址,写的页面跳转 |
|||
if (that.textContent) { |
|||
setTimeout(() => { |
|||
// 跳转页面至登录页面 |
|||
router.push({ |
|||
path: "/sign", |
|||
query: { |
|||
enterpriseNumber: that.textContent, |
|||
} |
|||
}); |
|||
// 记得重置,不然在微信里用会有问题 |
|||
that.textContent = null; |
|||
that.codeReader && that.codeReader.reset(); |
|||
}, 100); |
|||
} |
|||
} |
|||
}); |
|||
// 扫描失败,我这里是直接找下一个摄像头,其实可以不写 |
|||
if (err && !err) { |
|||
this.num++; |
|||
setTimeout(() => { |
|||
that.tipShow = false; |
|||
}, 2000); |
|||
if (this.num <= length) { |
|||
that.openScan(); |
|||
} |
|||
console.error(err); |
|||
} |
|||
} |
|||
); |
|||
}, |
|||
clickIndexLeft(){ // 返回上一页 |
|||
// this.$destroy(); |
|||
this.$router.go(-1); |
|||
// window.location.href = document.referrer; |
|||
// 点击切换前后摄像头 |
|||
change() { |
|||
const that = this; |
|||
if (this.videoLength > 2) { |
|||
if (this.num < 2) { |
|||
this.num = 6; |
|||
} else { |
|||
this.num = 1; |
|||
} |
|||
that.textContent = null; |
|||
that.codeReader && that.codeReader.reset(); |
|||
that.openScan(); |
|||
} else { |
|||
if (that.num === 0) { |
|||
that.num = 1; |
|||
} else { |
|||
that.num = 0; |
|||
} |
|||
that.textContent = null; |
|||
that.codeReader && that.codeReader.reset(); |
|||
that.openScan(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
// 返回 |
|||
const goBack = () => { |
|||
router.go(-1); |
|||
}; |
|||
</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; |
|||
.video { |
|||
width: 100vw; |
|||
height: 100vh; |
|||
z-index: 1; |
|||
} |
|||
.video-show { |
|||
position: absolute; |
|||
left: 50%; |
|||
top: 50%; |
|||
transform: translate(-50%, -50%); |
|||
width: 70vw; |
|||
height: 70vw; |
|||
z-index: 2; |
|||
background: linear-gradient(to left, #fff, #fff) left top no-repeat, |
|||
linear-gradient(to bottom, #fff, #fff) left top no-repeat, |
|||
linear-gradient(to left, #fff, #fff) right top no-repeat, |
|||
linear-gradient(to bottom, #fff, #fff) right top no-repeat, |
|||
linear-gradient(to left, #fff, #fff) left bottom no-repeat, |
|||
linear-gradient(to bottom, #fff, #fff) left bottom no-repeat, |
|||
linear-gradient(to left, #fff, #fff) right bottom no-repeat, |
|||
linear-gradient(to left, #fff, #fff) right bottom no-repeat; |
|||
background-size: 2px 20px, 20px 2px, 2px 20px, 20px 2px; |
|||
} |
|||
.tip { |
|||
width: 10vw; |
|||
height: 10vw; |
|||
background-color: rgb(45, 236, 45); |
|||
border: 1px solid #ffffff; |
|||
border-radius: 50%; |
|||
position: absolute; |
|||
left: 50%; |
|||
top: 50%; |
|||
transform: translate(-50%, -50%); |
|||
z-index: 10; |
|||
} |
|||
.scan-page{ |
|||
min-height: 100vh; |
|||
|
|||
.bgc-f4f4f4 { |
|||
background-color: #363636; |
|||
overflow-y: hidden; |
|||
.scan-video{ |
|||
height: 85vh; |
|||
} |
|||
.scan-tip{ |
|||
width: 100vw; |
|||
|
|||
.page { |
|||
position: relative; |
|||
overflow-y: auto; |
|||
position: relative; |
|||
height: 100vh; |
|||
} |
|||
.change { |
|||
z-index: 100; |
|||
position: fixed; |
|||
bottom: 40px; |
|||
left: 50%; |
|||
transform: translateX(-50%); |
|||
color: #fff; |
|||
text-align: center; |
|||
color: white; |
|||
font-size: 5vw; |
|||
background-color: #fff; |
|||
width: 50px; |
|||
height: 50px; |
|||
border-radius: 50%; |
|||
line-height: 60px; |
|||
/* align-content: center; */ |
|||
} |
|||
.el-icon-refresh { |
|||
color: #000; |
|||
font-size: 25px; |
|||
} |
|||
</style> |
|||
Loading…
Reference in new issue