From 0fb64ea0609ba0badeda91bd28084096b2a32448 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Fri, 1 May 2020 16:30:37 +0800 Subject: [PATCH] Basic QR Code generator --- src/components/QrItem.js | 36 ++++++++++++ src/components/QrRendererBase.js | 36 ++++++++++++ src/components/QrRendererRound.js | 36 ++++++++++++ src/components/Qrcode.js | 95 +++++++++++++++++++------------ 4 files changed, 167 insertions(+), 36 deletions(-) create mode 100644 src/components/QrItem.js create mode 100644 src/components/QrRendererBase.js create mode 100644 src/components/QrRendererRound.js diff --git a/src/components/QrItem.js b/src/components/QrItem.js new file mode 100644 index 0000000..2bcf439 --- /dev/null +++ b/src/components/QrItem.js @@ -0,0 +1,36 @@ +import React from "react"; +import './Qrcode.css' + +function calViewBox(props) { + if (!props.qrcode) return '0 0 0 0'; + + const nCount = props.qrcode.getModuleCount(); + return '0 0 ' + String(nCount) + ' ' + String(nCount); +} + +class QrItem extends React.Component { + + constructor(props) { + super(props); + this.state = { + value: props.value + } + } + + render() { + return ( +
+
+ + {this.props.renderer} + +
+
+ {this.state.value} +
+
+ ); + } +} + +export default QrItem; diff --git a/src/components/QrRendererBase.js b/src/components/QrRendererBase.js new file mode 100644 index 0000000..40b9fa9 --- /dev/null +++ b/src/components/QrRendererBase.js @@ -0,0 +1,36 @@ +import React from "react"; +import './Qrcode.css' + +function listPoint(props) { + if (!props.qrcode) return [] + + const qrcode = props.qrcode; + const nCount = qrcode.getModuleCount(); + const pointList = new Array(nCount); + let id = 0; + for (let row = 0; row < nCount; row++) { + for (let col = 0; col < nCount; col++) { + if (qrcode.isDark(row, col)) + pointList.push() + } + } + return pointList; +} + +class QrRendererBase extends React.Component { + + constructor(props) { + super(props); + } + + render() { + return ( + + + {listPoint(this.props)} + + ); + } +} + +export default QrRendererBase diff --git a/src/components/QrRendererRound.js b/src/components/QrRendererRound.js new file mode 100644 index 0000000..4c90004 --- /dev/null +++ b/src/components/QrRendererRound.js @@ -0,0 +1,36 @@ +import React from "react"; +import './Qrcode.css' + +function listPoint(props) { + if (!props.qrcode) return [] + + const qrcode = props.qrcode; + const nCount = qrcode.getModuleCount(); + const pointList = new Array(nCount); + let id = 0; + for (let row = 0; row < nCount; row++) { + for (let col = 0; col < nCount; col++) { + if (qrcode.isDark(row, col)) + pointList.push() + } + } + return pointList; +} + +class QrRendererRound extends React.Component { + + constructor(props) { + super(props); + } + + render() { + return ( + + + {listPoint(this.props)} + + ); + } +} + +export default QrRendererRound diff --git a/src/components/Qrcode.js b/src/components/Qrcode.js index d7fadbf..1b7c288 100644 --- a/src/components/Qrcode.js +++ b/src/components/Qrcode.js @@ -1,51 +1,74 @@ import React from "react"; +import QrItem from './QrItem' +import {getQrcodeData} from "../utils/qrcodeHandler"; import './Qrcode.css' -function QrItem(props) { - return ( -
-
+import QrRendererBase from './QrRendererBase' +import QrRendererRound from './QrRendererRound' -
-
- {props.value} -
-
+function QrBoxList(props) { + return ( + + } /> + } /> + + + + + + + ); } -function Qrs(props) { - const numbers = props.numbers; - const listItems = numbers.map((number) => - +class Qrcode extends React.Component { - ); - return ( -
-
-

qrbtf.com

- -
-
-
- Styles + constructor(props) { + super(props); + this.handleChange = this.handleChange.bind(this) + this.handleCreate = this.handleCreate.bind(this) + this.state = { + text: '', + options: {text: ''}, + qrcode: null + }; + } + + handleChange(e) { + this.setState({text: e.target.value}) + } + + handleCreate(e) { + const text = this.state.text + this.setState({options: {text: text}, qrcode: getQrcodeData({text: text})}); + } + + render() { + return ( +
+
+

qrbtf.com

+ {if(e.key == 'Enter') this.handleCreate(e)}} + />
-
-
- {listItems} +
+
+ Styles +
+
+
+ +
-
- - ); -} - -const numbers = ['C1', 'C2', 'S1', 'D1', 'D2', 'D3', 'D4', 'A1', 'A2', 'A3', 'A4']; -const Qrcode = (props) => { - return ( - - ); + ); + } } export default Qrcode;