diff --git a/src/components/QrRendererBase.js b/src/components/QrRendererBase.js index e5ee63f..0b3ba49 100644 --- a/src/components/QrRendererBase.js +++ b/src/components/QrRendererBase.js @@ -1,7 +1,7 @@ import React from "react"; import './Qrcode.css' import {getTypeTable, QRPointType} from "../utils/qrcodeHandler"; -import {rand} from "../utils/util"; +import {defaultRenderer, rand} from "../utils/util"; function listPoint(props) { if (!props.qrcode) return [] @@ -16,7 +16,6 @@ function listPoint(props) { let opacity = props.params[2] / 100; let posType = props.params[3]; let id = 0; - console.log(posType) const vw = [3, -3]; const vh = [3, -3]; @@ -71,13 +70,6 @@ function listPoint(props) { return pointList; } -function calViewBox(props) { - if (!props.qrcode) return '0 0 0 0'; - - const nCount = props.qrcode.getModuleCount(); - return String(-nCount / 5) + ' ' + String(-nCount / 5) + ' ' + String(nCount + nCount / 5 * 2) + ' ' + String(nCount + nCount / 5 * 2); -} - class QrRendererBase extends React.Component { constructor(props) { super(props); @@ -115,12 +107,7 @@ class QrRendererBase extends React.Component { } render() { - return ( - - {listPoint(this.props)} - - ); + return defaultRenderer(this.props.qrcode, listPoint(this.props)); } } diff --git a/src/components/QrRendererBlank.js b/src/components/QrRendererBlank.js index c4d11ba..39b787d 100644 --- a/src/components/QrRendererBlank.js +++ b/src/components/QrRendererBlank.js @@ -1,13 +1,10 @@ import React from "react"; import './Qrcode.css' +import {defaultRenderer} from "../utils/util"; class QrRendererBlank extends React.Component { render() { - return ( - - - ); + return defaultRenderer(this.props.qrcode); } } diff --git a/src/components/QrRendererRandRect.js b/src/components/QrRendererRandRect.js index d17377c..5913c87 100644 --- a/src/components/QrRendererRandRect.js +++ b/src/components/QrRendererRandRect.js @@ -1,6 +1,6 @@ import React from "react"; import './Qrcode.css' -import {rand, randRGB} from "../utils/util"; +import {defaultRenderer, rand, randRGB} from "../utils/util"; function listPoint(props) { if (!props.qrcode) return [] @@ -38,21 +38,9 @@ function listPoint(props) { return pointList; } -function calViewBox(props) { - if (!props.qrcode) return '0 0 0 0'; - - const nCount = props.qrcode.getModuleCount(); - return String(-nCount / 5) + ' ' + String(-nCount / 5) + ' ' + String(nCount + nCount / 5 * 2) + ' ' + String(nCount + nCount / 5 * 2); -} - class QrRendererRandRect extends React.Component { render() { - return ( - - {listPoint(this.props)} - - ); + return defaultRenderer(this.props.qrcode, listPoint(this.props)); } } diff --git a/src/components/QrRendererRandRound.js b/src/components/QrRendererRandRound.js index 3e13998..d353162 100644 --- a/src/components/QrRendererRandRound.js +++ b/src/components/QrRendererRandRound.js @@ -1,7 +1,7 @@ import React from "react"; import './Qrcode.css' import {getTypeTable, QRPointType} from "../utils/qrcodeHandler"; -import {rand} from "../utils/util"; +import {rand, defaultRenderer} from "../utils/util"; function listPoint(props) { if (!props.qrcode) return [] @@ -16,7 +16,6 @@ function listPoint(props) { let opacity = props.params[2] / 100; let posType = props.params[3]; let id = 0; - console.log(posType) const vw = [3, -3]; const vh = [3, -3]; @@ -71,13 +70,6 @@ function listPoint(props) { return pointList; } -function calViewBox(props) { - if (!props.qrcode) return '0 0 0 0'; - - const nCount = props.qrcode.getModuleCount(); - return String(-nCount / 5) + ' ' + String(-nCount / 5) + ' ' + String(nCount + nCount / 5 * 2) + ' ' + String(nCount + nCount / 5 * 2); -} - class QrRendererRandRound extends React.Component { constructor(props) { super(props); @@ -115,12 +107,7 @@ class QrRendererRandRound extends React.Component { } render() { - return ( - - {listPoint(this.props)} - - ); + return defaultRenderer(this.props.qrcode, listPoint(this.props)); } } diff --git a/src/components/QrRendererRound.js b/src/components/QrRendererRound.js index 164498d..a5555cb 100644 --- a/src/components/QrRendererRound.js +++ b/src/components/QrRendererRound.js @@ -1,7 +1,7 @@ import React from "react"; import './Qrcode.css' import {getTypeTable, QRPointType} from "../utils/qrcodeHandler"; -import {rand} from "../utils/util"; +import {defaultRenderer, rand} from "../utils/util"; function listPoint(props) { if (!props.qrcode) return [] @@ -16,7 +16,6 @@ function listPoint(props) { let opacity = props.params[2] / 100; let posType = props.params[3]; let id = 0; - console.log(posType) const vw = [3, -3]; const vh = [3, -3]; @@ -71,13 +70,6 @@ function listPoint(props) { return pointList; } -function calViewBox(props) { - if (!props.qrcode) return '0 0 0 0'; - - const nCount = props.qrcode.getModuleCount(); - return String(-nCount / 5) + ' ' + String(-nCount / 5) + ' ' + String(nCount + nCount / 5 * 2) + ' ' + String(nCount + nCount / 5 * 2); -} - class QrRendererRound extends React.Component { constructor(props) { super(props); @@ -115,12 +107,7 @@ class QrRendererRound extends React.Component { } render() { - return ( - - {listPoint(this.props)} - - ); + return defaultRenderer(this.props.qrcode, listPoint(this.props)); } } diff --git a/src/components/Qrcode.js b/src/components/Qrcode.js index b99d0a6..9de6e17 100644 --- a/src/components/Qrcode.js +++ b/src/components/Qrcode.js @@ -21,9 +21,6 @@ const logoStyle = { backgroundPosition: 'left' }; -const date = new Date(); -const currentYear = date.getFullYear(); - const styleList = [ {value: "A1", renderer: QrRendererBase}, {value: "A2", renderer: QrRendererRound}, @@ -35,6 +32,8 @@ const styleList = [ {value: "D2", renderer: QrRendererBlank}, ]; +const currentYear = new Date().getFullYear(); + class Qrcode extends React.Component { paramInfoBuffer; paramValueBuffer; @@ -56,8 +55,8 @@ class Qrcode extends React.Component { paramInfo: [], paramValue: [] }; - this.paramInfoBuffer = new Array(10).fill(new Array(10)); - this.paramValueBuffer = new Array(10).fill(new Array(10)); + this.paramInfoBuffer = new Array(16).fill(new Array(16)); + this.paramValueBuffer = new Array(16).fill(new Array(16)); } componentDidMount() { @@ -123,6 +122,7 @@ class Qrcode extends React.Component { return ( + {points} + + ); +} + export function isWeiXin(){ const ua = window.navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i) == 'micromessenger'){