From 0e86a3fc620497b8e5b9de829ddced62bfdf19af Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期一, 21 四月 2025 16:15:46 +0800
Subject: [PATCH] gx
---
src/views/deviceWindoes2.vue | 35 +++++++++++++++++------------------
1 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/src/views/deviceWindoes2.vue b/src/views/deviceWindoes2.vue
index 73455ef..b02ec5c 100644
--- a/src/views/deviceWindoes2.vue
+++ b/src/views/deviceWindoes2.vue
@@ -787,6 +787,7 @@
</template>
<script lang="ts" setup>
+ import { BrowserMultiFormatReader, NotFoundException, ChecksumException, FormatException } from '@zxing/library';
import TQS88 from "../img/TQS88.png";
import shezhi from '../img/shezhi.png'
import xinlv from '../img/xinlv.png'
@@ -798,7 +799,6 @@
import cljd from '../img/cljd.png'
import tizhong from '../img/tizhong.png'
import {EventSourcePolyfill} from 'event-source-polyfill';
- import jsQR from 'jsqr';
import { computed, getCurrentInstance, onBeforeMount, onMounted, ref, watch, watchEffect } from "vue";
import { Local } from '../utils/storage';
import * as echarts from "echarts";
@@ -1186,31 +1186,30 @@
ElMessage.warning('请先输入设备编号')
}
}
- const onFileChange=(event: Event) =>{
+ const onFileChange=async(event: Event)=> {
const inputElement = event.target as HTMLInputElement;
if (!inputElement.files || inputElement.files.length === 0) return;
const file = inputElement.files[0];
const reader = new FileReader();
- reader.onload = function(e) {
+ reader.onload = async (e) => {
if (e.target && typeof e.target.result === 'string') {
- const img = document.createElement('img');
- img.src = e.target.result;
- img.onload = function() {
- const canvas = document.createElement('canvas');
- canvas.width = img.width;
- canvas.height = img.height;
- const ctx = canvas.getContext('2d');
- if (ctx) {
- ctx.drawImage(img, 0, 0);
- const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
- const code = jsQR(imageData.data, imageData.width, imageData.height);
- if (code) {
- codeResult.value = code.data;
- }
+ try {
+ const codeReader = new BrowserMultiFormatReader();
+ const result = await codeReader.decodeFromImage(undefined, e.target.result);
+ codeResult.value = result.text;
+ } catch (err) {
+ if (err instanceof NotFoundException) {
+ console.error("未找到二维码");
+ } else if (err instanceof ChecksumException) {
+ console.error("校验错误");
+ } else if (err instanceof FormatException) {
+ console.error("格式错误");
+ } else {
+ console.error(err);
}
- };
+ }
}
};
--
Gitblit v1.8.0