| | |
| | | |
| | | </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' |
| | |
| | | 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"; |
| | |
| | | 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); |
| | | } |
| | | }; |
| | | } |
| | | } |
| | | }; |
| | | |