From 1feb9442cb0bd8064b4978782e0adc7efee7c15f Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Wed, 6 May 2020 15:16:59 +0800 Subject: [PATCH] Code arrangement --- src/components/QrItem.js | 7 ++----- src/components/QrRendererBase.js | 3 +-- src/components/QrRendererBlank.js | 3 +-- src/components/QrRendererDSJ.js | 3 +-- src/components/QrRendererRandRect.js | 3 +-- src/components/QrRendererRandRound.js | 3 +-- src/components/QrRendererRound.js | 3 +-- src/components/Qrcode.js | 29 +++++++-------------------- 8 files changed, 15 insertions(+), 39 deletions(-) diff --git a/src/components/QrItem.js b/src/components/QrItem.js index 4f1c8c4..944117a 100644 --- a/src/components/QrItem.js +++ b/src/components/QrItem.js @@ -6,18 +6,17 @@ function calClassName(props) { return 'Qr-item'; } -class QrItem extends React.Component { +export default class QrItem extends React.Component { constructor(props) { super(props); - this.handleClick = this.handleClick.bind(this); } componentDidMount() { this.forceUpdate() } - handleClick(e) { + handleClick = (e) => { this.props.onSelected(this.props.index); } @@ -40,5 +39,3 @@ class QrItem extends React.Component { ); } } - -export default QrItem; diff --git a/src/components/QrRendererBase.js b/src/components/QrRendererBase.js index 0b3ba49..34ab950 100644 --- a/src/components/QrRendererBase.js +++ b/src/components/QrRendererBase.js @@ -70,7 +70,7 @@ function listPoint(props) { return pointList; } -class QrRendererBase extends React.Component { +export default class QrRendererBase extends React.Component { constructor(props) { super(props); if (this.props.setParamInfo) { @@ -111,4 +111,3 @@ class QrRendererBase extends React.Component { } } -export default QrRendererBase diff --git a/src/components/QrRendererBlank.js b/src/components/QrRendererBlank.js index 39b787d..be3c819 100644 --- a/src/components/QrRendererBlank.js +++ b/src/components/QrRendererBlank.js @@ -2,10 +2,9 @@ import React from "react"; import './Qrcode.css' import {defaultRenderer} from "../utils/util"; -class QrRendererBlank extends React.Component { +export default class QrRendererBlank extends React.Component { render() { return defaultRenderer(this.props.qrcode); } } -export default QrRendererBlank diff --git a/src/components/QrRendererDSJ.js b/src/components/QrRendererDSJ.js index 1713420..64b3c40 100644 --- a/src/components/QrRendererDSJ.js +++ b/src/components/QrRendererDSJ.js @@ -158,7 +158,7 @@ function listPoint(props) { return pointList; } -class QrRendererDSJ extends React.Component { +export default class QrRendererDSJ extends React.Component { constructor(props) { super(props); if (this.props.setParamInfo) { @@ -189,4 +189,3 @@ class QrRendererDSJ extends React.Component { } } -export default QrRendererDSJ diff --git a/src/components/QrRendererRandRect.js b/src/components/QrRendererRandRect.js index 5913c87..75dfb1d 100644 --- a/src/components/QrRendererRandRect.js +++ b/src/components/QrRendererRandRect.js @@ -38,10 +38,9 @@ function listPoint(props) { return pointList; } -class QrRendererRandRect extends React.Component { +export default class QrRendererRandRect extends React.Component { render() { return defaultRenderer(this.props.qrcode, listPoint(this.props)); } } -export default QrRendererRandRect diff --git a/src/components/QrRendererRandRound.js b/src/components/QrRendererRandRound.js index d353162..109122f 100644 --- a/src/components/QrRendererRandRound.js +++ b/src/components/QrRendererRandRound.js @@ -70,7 +70,7 @@ function listPoint(props) { return pointList; } -class QrRendererRandRound extends React.Component { +export default class QrRendererRandRound extends React.Component { constructor(props) { super(props); if (this.props.setParamInfo) { @@ -111,4 +111,3 @@ class QrRendererRandRound extends React.Component { } } -export default QrRendererRandRound diff --git a/src/components/QrRendererRound.js b/src/components/QrRendererRound.js index a5555cb..cf1762b 100644 --- a/src/components/QrRendererRound.js +++ b/src/components/QrRendererRound.js @@ -70,7 +70,7 @@ function listPoint(props) { return pointList; } -class QrRendererRound extends React.Component { +export default class QrRendererRound extends React.Component { constructor(props) { super(props); if (this.props.setParamInfo) { @@ -111,4 +111,3 @@ class QrRendererRound extends React.Component { } } -export default QrRendererRound diff --git a/src/components/Qrcode.js b/src/components/Qrcode.js index d0636a0..37b263c 100644 --- a/src/components/Qrcode.js +++ b/src/components/Qrcode.js @@ -40,14 +40,6 @@ class Qrcode extends React.Component { paramValueBuffer; constructor(props) { super(props); - this.handleCreate = this.handleCreate.bind(this) - this.downloadSvg = this.downloadSvg.bind(this) - this.downloadImg = this.downloadImg.bind(this) - this.setParamValue = this.setParamValue.bind(this) - this.getParamValue = this.getParamValue.bind(this) - this.setParamInfo = this.setParamInfo.bind(this) - this.renderAdjustment = this.renderAdjustment.bind(this) - this.renderParamEditor = this.renderParamEditor.bind(this) this.state = { text: '', selectedIndex: 0, @@ -72,7 +64,7 @@ class Qrcode extends React.Component { }); } - setParamInfo(index) { + setParamInfo = (index) => { const _this = this; return function (params) { _this.paramInfoBuffer[index] = params; @@ -82,39 +74,32 @@ class Qrcode extends React.Component { } } - setParamValue(valueIndex, value) { + setParamValue = (valueIndex, value) => { const newValue = this.state.paramValue.slice(); newValue[this.state.selectedIndex][valueIndex] = value; this.setState({paramValue: newValue}); } - getParamValue(index) { - const _this = this; - return function () { - return _this.state.paramValue[index]; - } - } - - handleCreate(e) { + handleCreate = (e) => { let text = this.state.text if (text.length <= 0) text = 'https://qrbtf.com/'; this.setState({text: text, options: {text: text}, qrcode: getQrcodeData({text: text, correctLevel: this.state.correctLevel})}); if (e) e.target.blur(); } - downloadSvg(e) { + downloadSvg = (e) => { const style = styleList[this.state.selectedIndex] const el = React.createElement(style.renderer, {qrcode: this.state.qrcode, params: this.state.paramValue[this.state.selectedIndex]}) saveSvg(style.value, ReactDOMServer.renderToString(el)) } - downloadImg(e) { + downloadImg = (e) => { const style = styleList[this.state.selectedIndex] const el = React.createElement(style.renderer, {qrcode: this.state.qrcode, params: this.state.paramValue[this.state.selectedIndex]}) saveImg(style.value, ReactDOMServer.renderToString(el), 1500, 1500) } - renderParamEditor(info, index) { + renderParamEditor = (info, index) => { if (info.choices) { return (