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> |
<template> |
||||
<div class="scan-page"> |
<div class="page bgc-f4f4f4"> |
||||
<!-- 返回导航栏 --> |
<header-nav |
||||
<!-- left-text="取消" --> |
:slefBack="true" |
||||
<van-nav-bar title="扫描二维码/条形码" left-arrow |
@goBack="goBack" |
||||
fixed class="scan-index-bar" @click-left="clickIndexLeft()" |
> |
||||
></van-nav-bar> |
</header-nav> |
||||
<!-- 扫码区域 --> |
<div class="video-show" /> |
||||
<video ref="video" id="video" class="scan-video" autoplay></video> |
<video id="video" ref="video" class="video vjs-fluid" autoplay /> |
||||
<!-- 提示语 --> |
<span class="change" @click="change"> |
||||
<div v-show="tipShow" class="scan-tip">{{ tipMsg }}</div> |
<i class="el-icon-refresh" /> |
||||
|
</span> |
||||
</div> |
</div> |
||||
</template> |
</template> |
||||
|
|
||||
<script> |
<script> |
||||
import { BrowserMultiFormatReader } from '@zxing/library'; |
// 看到这个没,这个是一个小插件,能在手机上打开控制台,你打印的控制台信息和报错都能在这显示,具体方法自己百度 |
||||
import { Toast, Dialog, Notify } from 'vant'; |
// import Vconsole from "vconsole"; |
||||
|
import { BrowserMultiFormatReader } from "@zxing/library"; |
||||
export default { |
export default { |
||||
name: 'ScanCodePage', // 扫码页面 |
name: "QrCodeSearch", |
||||
data() { |
components: {}, |
||||
return { |
data() { |
||||
codeReader: null, |
return { |
||||
tipShow: false, // 是否展示提示 |
loadingShow: false, |
||||
tipMsg: '', // 提示文本内容 |
// 这个就是从@zxing/library导出来的方法,new一个实例 |
||||
scanText: '', // 扫码结果文本内容 |
codeReader: new BrowserMultiFormatReader(), |
||||
} |
// 这个,用来储存扫码得到的结果 |
||||
}, |
textContent: null, |
||||
created() { |
// 这个,就是当前调用的摄像头的索引,为什么是6,我会在后面说的 |
||||
this.openScan(); |
num: 0, |
||||
}, |
// 这个就是扫描到的摄像头的数量 |
||||
watch: { |
videoLength: "" |
||||
'$route'(to, from) { |
}; |
||||
if(to.path == '/ScanCodePage'){ // 当处于该页面时 |
}, |
||||
this.openScan(); |
created() { |
||||
} |
// const vconsole = new Vconsole(); |
||||
} |
// vconsole; |
||||
}, |
// 让我们调用这个方法尝试打开摄像头 |
||||
destroyed(){ |
this.openScan(); |
||||
this.codeReader.reset(); |
}, |
||||
this.codeReader = null; |
methods: { |
||||
}, |
// 开打开打 |
||||
methods: { |
async openScan() { |
||||
async openScan() { // 初始化摄像头 |
const that = this; |
||||
this.codeReader = await new BrowserMultiFormatReader(); |
// 这个就是data里的哪个new出来的玩意,调用里面的方法 |
||||
this.codeReader.getVideoInputDevices().then(videoDevices => { |
that.codeReader |
||||
this.tipMsg = '正在调用摄像头...'; |
.getVideoInputDevices() |
||||
this.tipShow = true; |
.then(videoInputDevices => { |
||||
console.log('get-videoDevices', videoDevices); |
// 记录一下扫描到的摄像头数量,这个videoInputDevices是个数组,里面有扫描到的摄像头数据 |
||||
|
this.videoLength = videoInputDevices.length; |
||||
// 默认获取摄像头列表里的最后一个设备id,通过几部测试机发现一般前置摄像头位于列表里的前面几位,所以一般获取最后一个的是后置摄像头 |
console.log(JSON.stringify(videoInputDevices)); |
||||
let firstDeviceId = videoDevices[videoDevices.length - 1].deviceId; |
console.log(videoInputDevices.length); |
||||
// 一般获取了手机的摄像头列表里不止一个,有的手机摄像头高级多层,会有变焦摄像头等情况,需要做处理 |
that.num = videoInputDevices.length |
||||
if (videoDevices.length > 1) { |
// 这步我们来决定一下调用第几个摄像头,看到这个num没,这就是data里的 |
||||
// 一般通过判断摄像头列表项里的 label 字段,'camera2 0, facing back' 字符串含有 'back' 和 '0',大部分机型是这样,如果有些机型没有,那就还是默认获取最后一个 |
const firstDeviceId = videoInputDevices[this.videoLength -1].deviceId; |
||||
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 : |
that.decodeFromInputVideoFunc( |
||||
videoDevices[videoDevices.length - 1].deviceId; |
firstDeviceId, |
||||
} |
videoInputDevices.length |
||||
console.log('get-firstDeviceId', firstDeviceId); |
); |
||||
|
}) |
||||
this.decodeFromInputVideoFunc(firstDeviceId); |
// 失败回调,为什么这里的失败回调这么写,后面会说的 |
||||
}).catch(err => { |
.catch(err => { |
||||
this.tipShow = false; |
this.num = 1; |
||||
|
that.openScan(); |
||||
console.error(err); |
console.error(err); |
||||
}); |
}); |
||||
}, |
}, |
||||
decodeFromInputVideoFunc(firstDeviceId) { // 使用摄像头扫描 |
//这就是在openScan里调的另一个方法,传入想调用的摄像头id和摄像头数量 |
||||
this.codeReader.reset(); // 重置 |
decodeFromInputVideoFunc(firstDeviceId, length) { |
||||
this.codeReader.decodeFromInputVideoDeviceContinuously(firstDeviceId, 'video', (result, err) => { |
const that = this; |
||||
this.tipMsg = '正在尝试识别...'; |
that.codeReader.reset(); // 重置 |
||||
|
that.textContent = null; // 重置 |
||||
|
// 看不懂不重要,打印出来自己琢磨琢磨 |
||||
|
that.codeReader.decodeFromInputVideoDeviceContinuously( |
||||
|
firstDeviceId, |
||||
|
"video", |
||||
|
(result, err) => { |
||||
|
that.textContent = null; |
||||
|
// 扫描成功 这个result就是扫描结果,长啥样自己打印出来看看 |
||||
if (result) { |
if (result) { |
||||
console.log('扫码结果', result); |
that.textContent = result; |
||||
this.scanText = result.text; |
// 这里写你要对扫描结果做什么,我这里扫描出来的是个网址,写的页面跳转 |
||||
if (this.scanText) { |
if (that.textContent) { |
||||
this.tipShow = false; |
setTimeout(() => { |
||||
Dialog.confirm({ // 获取到扫码结果进行弹窗提示,这部分接下去的代码根据需要,读者自行编写了 |
// 跳转页面至登录页面 |
||||
title: '扫码结果', |
router.push({ |
||||
message: this.scanText, |
path: "/sign", |
||||
}).then(() => { // 点击确认 |
query: { |
||||
|
enterpriseNumber: that.textContent, |
||||
}).catch(() => { // 点击取消 |
} |
||||
|
}); |
||||
}); |
// 记得重置,不然在微信里用会有问题 |
||||
|
that.textContent = null; |
||||
|
that.codeReader && that.codeReader.reset(); |
||||
|
}, 100); |
||||
} |
} |
||||
} |
} |
||||
}); |
// 扫描失败,我这里是直接找下一个摄像头,其实可以不写 |
||||
}, |
if (err && !err) { |
||||
clickIndexLeft(){ // 返回上一页 |
this.num++; |
||||
// this.$destroy(); |
setTimeout(() => { |
||||
this.$router.go(-1); |
that.tipShow = false; |
||||
// window.location.href = document.referrer; |
}, 2000); |
||||
|
if (this.num <= length) { |
||||
|
that.openScan(); |
||||
|
} |
||||
|
console.error(err); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
}, |
||||
|
// 点击切换前后摄像头 |
||||
|
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> |
</script> |
||||
|
|
||||
<style lang="scss"> |
<style lang="scss"> |
||||
.scan-index-bar{ |
.video { |
||||
background-image: linear-gradient( -45deg, #42a5ff ,#59cfff); |
width: 100vw; |
||||
.van-nav-bar__title, .van-nav-bar__arrow, .van-nav-bar__text{ |
height: 100vh; |
||||
color: #fff !important; |
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; |
||||
} |
} |
||||
.scan-page{ |
.tip { |
||||
min-height: 100vh; |
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; |
||||
|
} |
||||
|
|
||||
|
.bgc-f4f4f4 { |
||||
background-color: #363636; |
background-color: #363636; |
||||
overflow-y: hidden; |
} |
||||
.scan-video{ |
|
||||
height: 85vh; |
.page { |
||||
} |
position: relative; |
||||
.scan-tip{ |
overflow-y: auto; |
||||
width: 100vw; |
position: relative; |
||||
text-align: center; |
height: 100vh; |
||||
color: white; |
} |
||||
font-size: 5vw; |
.change { |
||||
} |
z-index: 100; |
||||
|
position: fixed; |
||||
|
bottom: 40px; |
||||
|
left: 50%; |
||||
|
transform: translateX(-50%); |
||||
|
color: #fff; |
||||
|
text-align: center; |
||||
|
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> |
</style> |
||||
Loading…
Reference in new issue