国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

H5實(shí)現(xiàn)掃碼讀取二維碼條形碼功能(二維碼+條形碼)

這篇具有很好參考價(jià)值的文章主要介紹了H5實(shí)現(xiàn)掃碼讀取二維碼條形碼功能(二維碼+條形碼)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

本文主要介紹二維碼實(shí)現(xiàn)的原理

1、使用插件

npm install @zxing/library

2、主要用到 BrowserMultiFormatReader 這個(gè)構(gòu)造函數(shù),用于打開(kāi)攝像頭

import { BrowserMultiFormatReader } from "@zxing/library";
  1. 視圖
<template>
  <div class="pageScan">
    <!-- <van-uploader :after-read="afterRead">
      <div class="item">相冊(cè)</div>
    </van-uploader> -->
    <span class="fileinput-button">
      <span>相冊(cè)</span>
      <input type="file" @change="fileChange" id="avatar" accept="image/*" />
    </span>
    <video ref="video" id="video" class="scanVideo" autoplay></video>
    <div class="scanner">
      <div class="box">
        <div class="line"></div>
        <div class="angle"></div>
      </div>
    </div>
  </div>
</template>
  1. 核心代碼(以vue3寫(xiě)法舉例)
<script setup>
import { defineComponent, reactive, onUnmounted, ref } from "vue";
import { useRouter } from "vue-router";
import { BrowserMultiFormatReader } from "@zxing/library";
import QrCode from "qrcode-decoder";
const form = reactive({
  loadingShow: false,
  scanText: "",
  vin: null,
  tipMsg: "嘗試識(shí)別中...",
  tipShow: false,
});
const result = ref("");
const router = useRouter();

const codeReader = new BrowserMultiFormatReader();
const afterRead = (file) => {
  getUrl(file.file);
};
const fileChange = () => {
  // 獲取dom 對(duì)象
  let file = document.getElementById("avatar");
  let resultFile = file?.files[0];
  console.log("resultFile", resultFile);
  getUrl(resultFile);
  // let reader = new FileReader();
  // reader.readAsText(resultFile, "UTF-8");
  // console.log("reader", reader);
};
const getUrl = (file) => {
  let qr = new QrCode();
  let url = getObjectURL(file);
  qr.decodeFromImage(url).then((res) => {
    //打印結(jié)果為 解析出來(lái)的 二維碼地址
    // alert(`res.data ${res.data}`);
    if (res.data) {
      router.push({
        path: "/TransferAccout",
        query: { codeResult: res.data },
      });
    }
    // alert(`res.data====${res.data}`, res.data);
  });
};
const getObjectURL = (file) => {
  let url = null;
  if (window.createObjectURL !== undefined) {
    // basic
    url = window.createObjectURL(file);
  } else if (window.URL !== undefined) {
    // mozilla(firefox)
    url = window.URL.createObjectURL(file);
  } else if (window.webkitURL !== undefined) {
    // webkit or chrome
    url = window.webkitURL.createObjectURL(file);
  }
  return url;
};
const openScan = async () => {
  codeReader
    .getVideoInputDevices()
    .then((videoInputDevices) => {
      form.tipShow = true;
      form.tipMsg = "正在調(diào)用攝像頭...";
      // console.log("videoInputDevices", videoInputDevices);
      // 默認(rèn)獲取第一個(gè)攝像頭設(shè)備id
      let firstDeviceId = videoInputDevices[0].deviceId;
      // 獲取第一個(gè)攝像頭設(shè)備的名稱(chēng)
      const videoInputDeviceslablestr = JSON.stringify(
        videoInputDevices[0].label
      );
      if (videoInputDevices.length > 1) {
        // 判斷是否后置攝像頭
        if (videoInputDeviceslablestr.indexOf("back") > -1) {
          firstDeviceId = videoInputDevices[0].deviceId;
        } else {
          firstDeviceId = videoInputDevices[1].deviceId;
        }
      }
      decodeFromInputVideoFunc(firstDeviceId);
    })
    .catch((err) => {
      form.tipShow = false;
      // console.log(`失敗出錯(cuò): ${err}`);
    });
};
openScan();

const decodeFromInputVideoFunc = (firstDeviceId) => {
  codeReader.reset(); // 重置
  form.scanText = "";
  codeReader.decodeFromInputVideoDeviceContinuously(
    firstDeviceId,
    "video",
    (result, err) => {
      form.tipMsg = "正在嘗試識(shí)別...";
      form.scanText = "";
      if (result) {
        console.log("掃描結(jié)果", result);
        result.value = result;
        // alert(`掃描結(jié)果${result.value}`);
        router.push({
          path: "/TransferAccout",
          query: { codeResult: result.value },
        });
        // form.scanText = result.text;
        form.scanText = result.getText();
        // alert(`form.scanText===${form.scanText}`);
        if (form.scanText) {
          form.tipShow = false;
        }
      }
      if (err && !err) {
        form.tipMsg = "識(shí)別失敗";
        setTimeout(() => {
          form.tipShow = false;
        }, 2000);
        // console.error(err);
        // alert("err", err);
      }
    }
  );
};

//銷(xiāo)毀組件
onUnmounted(() => {
  codeReader.reset();
  console.log("銷(xiāo)毀組件");
});
</script>
  1. 二維碼的樣式
// 掃碼組件
.scan-index-bar {
  background-image: linear-gradient(-45deg, #42a5ff, #59cfff);
}
.van-nav-bar__title {
  color: #fff !important;
}
.scanVideo {
  height: 80vh;
}
.scanTip {
  width: 100vw;
  text-align: center;
  margin-bottom: 10vh;
  color: white;
  font-size: 4vw;
}
.pageScan {
  overflow-y: hidden;
  background-color: #363636;
  width: 100vw;
  height: 100vh;
  position: relative;
  // :deep(.van-uploader) {
  //   z-index: 99;
  // }
  .item {
    display: inline-block;
    position: absolute;
    right: 10px;
    color: white;
    top: 10px;
    font-size: 16px;
    z-index: 99;
  }
}

.scanner {
  background-size: 3rem 3rem;
  background-position: -1rem -1rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}
.scanner .box {
  width: 75vw;
  height: 75vw;
  max-height: 75vh;
  max-width: 75vh;
  position: relative;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  overflow: hidden;
  border: 0.1rem solid rgba(0, 255, 51, 0.2);
}
.scanner .line {
  height: calc(100% - 2px);
  width: 100%;
  background: linear-gradient(180deg, rgba(0, 255, 51, 0) 43%, #00ff33 211%);
  border-bottom: 3px solid #00ff33;
  transform: translateY(-100%);
  animation: radar-beam 2s infinite;
  animation-timing-function: cubic-bezier(0.53, 0, 0.43, 0.99);
  animation-delay: 1.4s;
}
.scanner .box:after,
.scanner .box:before,
.scanner .angle:after,
.scanner .angle:before {
  content: "";
  display: block;
  position: absolute;
  width: 3vw;
  height: 3vw;
  border: 0.2rem solid transparent;
}
.scanner .box:after,
.scanner .box:before {
  top: 0;
  border-top-color: #00ff33;
}
.scanner .angle:after,
.scanner .angle:before {
  bottom: 0;
  border-bottom-color: #00ff33;
}
.scanner .box:before,
.scanner .angle:before {
  left: 0;
  border-left-color: #00ff33;
}
.scanner .box:after,
.scanner .angle:after {
  right: 0;
  border-right-color: #00ff33;
}
@keyframes radar-beam {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(0);
  }
}

.result {
  position: fixed;
  top: 20px;
  left: 20px;
  width: 50px;
  height: 50px;
  border-radius: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
}
.fileinput-button {
  position: absolute;
  display: inline-block;
}

.fileinput-button input {
  position: absolute;
  right: 0px;
  top: 0px;
  opacity: 0;
}
.fileinput-button {
  span {
    font-size: 16px;
  }
  position: absolute;
  display: inline-block;
  overflow: hidden;
  z-index: 99;
  color: white;
  right: 8px;
  top: 8px;
  display: flex;
  align-items: center;
}

``文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-514945.html

到了這里,關(guān)于H5實(shí)現(xiàn)掃碼讀取二維碼條形碼功能(二維碼+條形碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀(guān)點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • C#中輕松實(shí)現(xiàn)二維碼和條形碼識(shí)別:OpenCvSharp和ZXing詳細(xì)教程

    C#中輕松實(shí)現(xiàn)二維碼和條形碼識(shí)別:OpenCvSharp和ZXing詳細(xì)教程

    ? 概述: 本教程使用OpenCvSharp和ZXing庫(kù),詳細(xì)介紹了在C#中識(shí)別二維碼和條形碼的步驟。通過(guò)導(dǎo)入必要的命名空間、加載圖像,并使用ZXing庫(kù)進(jìn)行二維碼和條形碼的識(shí)別,提供了清晰的示例代碼。這方便了開(kāi)發(fā)人員在項(xiàng)目中集成二維碼和條形碼識(shí)別功能。 要使用OpenCvSharp來(lái)分別

    2024年03月09日
    瀏覽(33)
  • opencv檢測(cè)二維碼和條形碼

    opencv檢測(cè)二維碼和條形碼

    使用excel可以實(shí)現(xiàn)制作二維碼,但只能實(shí)現(xiàn)做英文和數(shù)字類(lèi)型的,步驟如下: 在任意單元格輸入內(nèi)容 選項(xiàng)卡里找到開(kāi)發(fā)工具—插入—點(diǎn)擊ActiveX控件的最右下角。 彈出的窗口內(nèi),往下滑動(dòng)選擇Microsoft BarCode Control 16.0后,點(diǎn)擊確定。 在任意區(qū)域,摁住鼠標(biāo)左鍵不放,拖動(dòng)鼠標(biāo),

    2024年02月10日
    瀏覽(32)
  • 【MAUI】條形碼,二維碼掃描功能

    本系列文章面向移動(dòng)開(kāi)發(fā)小白,從零開(kāi)始進(jìn)行平臺(tái)相關(guān)功能開(kāi)發(fā),演示如何參考平臺(tái)的官方文檔使用MAUI技術(shù)來(lái)開(kāi)發(fā)相應(yīng)功能。 移動(dòng)端的掃描條形碼、二維碼的功能已經(jīng)隨處可見(jiàn),已經(jīng)很難找到一個(gè)不支持掃描的App了,但是微軟的MAUI竟然沒(méi)有提供,那么我們應(yīng)該如何實(shí)現(xiàn)呢?

    2024年02月04日
    瀏覽(34)
  • java生成、識(shí)別條形碼和二維碼

    java生成、識(shí)別條形碼和二維碼

    使用 zxing 開(kāi)源庫(kù) Zxing主要是Google出品的,用于識(shí)別一維碼和二維碼的第三方庫(kù) 主要類(lèi): BitMatrix 位圖矩陣 MultiFormatWriter 位圖編寫(xiě)器 MatrixToImageWriter 寫(xiě)入圖片 可以生成、識(shí)別條形碼和二維碼 內(nèi)置三種尺寸: enum Size {SMALL, MIDDLE, BIG} 依賴(lài) 將寬度不等的多個(gè)黑條和白條,按照一定

    2024年02月08日
    瀏覽(27)
  • Python Opencv實(shí)踐 - 二維碼和條形碼識(shí)別

    Python Opencv實(shí)踐 - 二維碼和條形碼識(shí)別

    ? ? ? ? 使用pyzbar模塊來(lái)識(shí)別二維碼和條形碼。ZBar是一個(gè)開(kāi)源軟件,用來(lái)從圖像中讀取條形碼,支持多種編碼,比如EAN-13/UPC-A、UPC-E、EAN-8、代碼128、代碼39、交錯(cuò)2/5以及二維碼。 ? ? ? ? pyzbar是python封裝ZBar的模塊,我們用它來(lái)做條形碼和二維碼的識(shí)別。 ? ? ? ? 安裝方法:

    2024年02月04日
    瀏覽(22)
  • opencv實(shí)戰(zhàn)--角度測(cè)量和二維碼條形碼識(shí)別

    opencv實(shí)戰(zhàn)--角度測(cè)量和二維碼條形碼識(shí)別

    首先導(dǎo)入一個(gè)帶有角度的照片 然后下面的代碼注冊(cè)了一個(gè)鼠標(biāo)按下的回調(diào)函數(shù), 還有一個(gè)點(diǎn)的數(shù)列,鼠標(biāo)事件為按下的時(shí)候就記錄點(diǎn),并畫(huà)出點(diǎn),由于點(diǎn)是畫(huà)在圖像上面的,那么就要求了img是需要刷新的所以將他們放在while True里面 當(dāng)有按鍵按下的的時(shí)候就把圖片歸為原來(lái)的

    2024年02月16日
    瀏覽(28)
  • 【C#】最全單據(jù)打印源碼(打印模板、條形碼&二維碼、字體樣式)

    【C#】最全單據(jù)打印源碼(打印模板、條形碼&二維碼、字體樣式)

    【C#】編號(hào)生成器(定義單號(hào)規(guī)則、固定字符、流水號(hào)、業(yè)務(wù)單號(hào)) 本文鏈接:https://blog.csdn.net/youcheng_ge/article/details/129129787 【C#】日期范圍生成器(開(kāi)始日期、結(jié)束日期) 本文鏈接:https://blog.csdn.net/youcheng_ge/article/details/129040663 【C#】組件化開(kāi)發(fā),調(diào)用dll組件方法 本文鏈接

    2024年02月03日
    瀏覽(61)
  • Python - OpenCV識(shí)別條形碼、二維碼(已封裝,拿來(lái)即用)

    Python - OpenCV識(shí)別條形碼、二維碼(已封裝,拿來(lái)即用)

    此代碼可識(shí)別條形碼和二維碼,已封裝好,拿來(lái)即用: 結(jié)果:

    2024年02月12日
    瀏覽(25)
  • openmv和STM32串口通信識(shí)別條形碼、二維碼(HAL庫(kù))

    openmv和STM32串口通信識(shí)別條形碼、二維碼(HAL庫(kù))

    因?yàn)樽约旱漠呍O(shè)用到了條形碼識(shí)別,所以在這里寫(xiě)一篇關(guān)于使用openmv識(shí)別條形碼和二維碼并且與STM32實(shí)現(xiàn)串口通訊,希望能幫到以后用到這一模塊的同學(xué),STM32方面我使用的是STM32F103RCT6,并且使用HAL進(jìn)行編寫(xiě)代碼。 OpenMV端:由圖知UART_RX—P5 ------ UART_TX—P4 2.STM32端:這里我使用

    2023年04月13日
    瀏覽(25)
  • 如何使用h5-scan-qrcode插件實(shí)現(xiàn)一個(gè)h5頁(yè)面掃碼識(shí)別二維碼功能

    如何使用h5-scan-qrcode插件實(shí)現(xiàn)一個(gè)h5頁(yè)面掃碼識(shí)別二維碼功能

    為了適應(yīng)公司代碼全程使用jquery構(gòu)造 如需其他js或者vue 可根據(jù)此代碼去改(因?yàn)楹枚嗟胤綍?huì)用到這個(gè)東西所以我封裝成了一個(gè)js文件) https://dragonir.github.io/h5-scan-qrcode/#/ 這個(gè)是效果 可以提前看一下~ 我做的比這個(gè)效果多一個(gè)拿取本地圖庫(kù)的二維碼掃碼 scancode ---- html文件 如何

    2024年02月06日
    瀏覽(25)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包