|
|
@@ -0,0 +1,218 @@
|
|
|
+<template>
|
|
|
+ <div
|
|
|
+ class="scan"
|
|
|
+ v-on:enter="enter"
|
|
|
+ :style="{ background: active ? 'transparent' : '#343434' }"
|
|
|
+ >
|
|
|
+ <div class="btn-close" @click="back">
|
|
|
+ <van-icon name="cross" />
|
|
|
+ </div>
|
|
|
+ <div class="scan-icon">
|
|
|
+ <div class="c1"></div>
|
|
|
+ <div class="c2"></div>
|
|
|
+ <div class="c3"></div>
|
|
|
+ <div class="c4"></div>
|
|
|
+ </div>
|
|
|
+ <div class="btns">
|
|
|
+ <div
|
|
|
+ class="btn flash"
|
|
|
+ @click="flash"
|
|
|
+ v-if="status.canEnableLight === true"
|
|
|
+ >
|
|
|
+ <img src="../assets/flash.png" />
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ class="btn camera"
|
|
|
+ @click="camera"
|
|
|
+ v-if="status.canChangeCamera === true"
|
|
|
+ >
|
|
|
+ <img src="../assets/switch_camera.png" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import axios from "axios";
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ active: false,
|
|
|
+ status: {},
|
|
|
+ light: false,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ mounted() {},
|
|
|
+ activated() {
|
|
|
+ this.start();
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ this.end();
|
|
|
+ },
|
|
|
+ deactivated() {
|
|
|
+ this.end();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ start() {
|
|
|
+ if (window.cordova) {
|
|
|
+ StatusBar.styleBlackOpaque();
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ if (window.cordova) {
|
|
|
+ this.active = true;
|
|
|
+ QRScanner.scan((err, text) => {
|
|
|
+ console.log(text);
|
|
|
+ if (/productDetail\?id\=\d+/.test(text)) {
|
|
|
+ let url = new URL(text);
|
|
|
+ let id = url.searchParams.get("id");
|
|
|
+ this.$toast.loading();
|
|
|
+ axios
|
|
|
+ .get(url.origin + "/collection/get/" + id)
|
|
|
+ .then((res) => {
|
|
|
+ console.log(res);
|
|
|
+ this.$toast.clear();
|
|
|
+ this.$router.replace({
|
|
|
+ name: "Detail1",
|
|
|
+ params: res.data,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.back();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ QRScanner.show((status) => {
|
|
|
+ this.status = status;
|
|
|
+ console.log(status);
|
|
|
+ });
|
|
|
+ QRScanner.resumePreview((status) => {
|
|
|
+ console.log(status);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, 450);
|
|
|
+ },
|
|
|
+ end() {
|
|
|
+ this.active = false;
|
|
|
+ if (window.cordova) {
|
|
|
+ StatusBar.styleDefault();
|
|
|
+ QRScanner.destroy(function (status) {
|
|
|
+ console.log(status);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ back() {
|
|
|
+ this.$router.go(-1);
|
|
|
+ },
|
|
|
+ enter() {
|
|
|
+ console.log("enter");
|
|
|
+ },
|
|
|
+ flash() {
|
|
|
+ if (this.status.lightEnabled) {
|
|
|
+ QRScanner.disableLight((err, status) => {
|
|
|
+ err && console.error(err);
|
|
|
+ console.log(status);
|
|
|
+ this.status = status;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ QRScanner.enableLight((err, status) => {
|
|
|
+ err && console.error(err);
|
|
|
+ console.log(status);
|
|
|
+ this.status = status;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ camera() {
|
|
|
+ if (this.status.currentCamera === 0) {
|
|
|
+ QRScanner.useFrontCamera((err, status) => {
|
|
|
+ err && console.error(err);
|
|
|
+ console.log(status);
|
|
|
+ this.status = status;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ QRScanner.useBackCamera((err, status) => {
|
|
|
+ err && console.error(err);
|
|
|
+ console.log(status);
|
|
|
+ this.status = status;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style lang="less" scoped>
|
|
|
+.scan {
|
|
|
+ transition: translateX 0.45s background 0.15s;
|
|
|
+}
|
|
|
+.btn-close {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ top: env(safe-area-inset-top);
|
|
|
+ color: white;
|
|
|
+ padding: 10px 20px;
|
|
|
+ font-size: 26px;
|
|
|
+}
|
|
|
+.scan-icon {
|
|
|
+ width: 250px;
|
|
|
+ height: 250px;
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ margin: auto;
|
|
|
+ .c1,
|
|
|
+ .c2,
|
|
|
+ .c3,
|
|
|
+ .c4 {
|
|
|
+ position: absolute;
|
|
|
+ width: 50px;
|
|
|
+ height: 50px;
|
|
|
+ }
|
|
|
+ .c1 {
|
|
|
+ left: 0;
|
|
|
+ top: 0;
|
|
|
+ border-left: 8px solid rgba(255, 255, 255, 0.3);
|
|
|
+ border-top: 8px solid rgba(255, 255, 255, 0.3);
|
|
|
+ }
|
|
|
+ .c2 {
|
|
|
+ left: 0;
|
|
|
+ bottom: 0;
|
|
|
+ border-left: 8px solid rgba(255, 255, 255, 0.3);
|
|
|
+ border-bottom: 8px solid rgba(255, 255, 255, 0.3);
|
|
|
+ }
|
|
|
+ .c3 {
|
|
|
+ right: 0;
|
|
|
+ top: 0;
|
|
|
+ border-right: 8px solid rgba(255, 255, 255, 0.3);
|
|
|
+ border-top: 8px solid rgba(255, 255, 255, 0.3);
|
|
|
+ }
|
|
|
+ .c4 {
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ border-right: 8px solid rgba(255, 255, 255, 0.3);
|
|
|
+ border-bottom: 8px solid rgba(255, 255, 255, 0.3);
|
|
|
+ }
|
|
|
+}
|
|
|
+.btns {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ position: absolute;
|
|
|
+ bottom: 100px;
|
|
|
+ left: 0;
|
|
|
+ right: 0;
|
|
|
+ .btn {
|
|
|
+ width: 50px;
|
|
|
+ height: 50px;
|
|
|
+ background: rgba(0, 0, 0, 0.8);
|
|
|
+ border-radius: 50%;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ margin: 0 20px;
|
|
|
+ img {
|
|
|
+ width: 40%;
|
|
|
+ height: 40%;
|
|
|
+ object-fit: contain;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|