From 58535095e5a18c64954e4205c268c64cc7072f8e Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Mon, 4 May 2020 22:52:27 +0800 Subject: [PATCH] [Params adjustment] --- src/components/QrItem.js | 4 ++++ src/components/QrRendererBase.js | 34 +++++++++++++------------- src/components/QrRendererRound.js | 40 ++++++++++++++++--------------- src/components/Qrcode.js | 18 +++++++++----- 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/components/QrItem.js b/src/components/QrItem.js index 60889e2..4f1c8c4 100644 --- a/src/components/QrItem.js +++ b/src/components/QrItem.js @@ -13,6 +13,10 @@ class QrItem extends React.Component { this.handleClick = this.handleClick.bind(this); } + componentDidMount() { + this.forceUpdate() + } + handleClick(e) { this.props.onSelected(this.props.index); } diff --git a/src/components/QrRendererBase.js b/src/components/QrRendererBase.js index e313684..76933ba 100644 --- a/src/components/QrRendererBase.js +++ b/src/components/QrRendererBase.js @@ -7,7 +7,7 @@ function listPoint(props) { const qrcode = props.qrcode; const nCount = qrcode.getModuleCount(); const pointList = new Array(nCount); - const params = props.getParamValue(); + const params = props.params; let id = 0; for (let row = 0; row < nCount; row++) { @@ -33,21 +33,23 @@ function calViewBox(props) { class QrRendererBase extends React.Component { constructor(props) { super(props); - this.props.setParamInfo([ - { - key: '大小', - default: 1 - }, - { - key: '定位点样式', - default: 0, - choices: [ - "矩形", - "圆形" - ] - } - ] - ); + if (this.props.setParamInfo) { + this.props.setParamInfo([ + { + key: '大小', + default: 1 + }, + { + key: '定位点样式', + default: 0, + choices: [ + "矩形", + "圆形" + ] + } + ] + ); + } } render() { diff --git a/src/components/QrRendererRound.js b/src/components/QrRendererRound.js index e4cd364..cd22d74 100644 --- a/src/components/QrRendererRound.js +++ b/src/components/QrRendererRound.js @@ -50,25 +50,27 @@ function calViewBox(props) { class QrRendererRound extends React.Component { constructor(props) { super(props); - this.props.setParamInfo([ - { - key: '没有choices的文本框1', - default: 1 - }, - { - key: '没有choices的文本框2', - default: 100 - }, - { - key: '有choices的选择框', - default: 0, - choices: [ - "option1", - "option2" - ] - } - ] - ); + if (this.props.setParamInfo) { + this.props.setParamInfo([ + { + key: '没有choices的文本框1', + default: 1 + }, + { + key: '没有choices的文本框2', + default: 100 + }, + { + key: '有choices的选择框', + default: 0, + choices: [ + "option1", + "option2" + ] + } + ] + ); + } } render() { diff --git a/src/components/Qrcode.js b/src/components/Qrcode.js index 7b68477..38b0b5f 100644 --- a/src/components/Qrcode.js +++ b/src/components/Qrcode.js @@ -53,9 +53,14 @@ class Qrcode extends React.Component { } componentDidMount() { - this.setState({paramInfo: this.paramInfoBuffer, paramValue: this.paramValueBuffer}, () => { - this.handleCreate(); - }) + const text = 'https://qrbtf.com/'; + this.setState({ + paramInfo: this.paramInfoBuffer, + paramValue: this.paramValueBuffer, + text: text, + options: {text: text}, + qrcode: getQrcodeData({text: text}) + }); } setParamInfo(index) { @@ -95,13 +100,13 @@ class Qrcode extends React.Component { downloadSvg(e) { const style = styleList[this.state.selectedIndex] - const el = React.createElement(style.renderer, {qrcode: this.state.qrcode}) + 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) { const style = styleList[this.state.selectedIndex] - const el = React.createElement(style.renderer, {qrcode: this.state.qrcode}) + 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) } @@ -152,6 +157,7 @@ class Qrcode extends React.Component { } render() { + console.log(1) return (
@@ -181,7 +187,7 @@ class Qrcode extends React.Component { qrcode={this.state.qrcode} renderer={React.createElement(style.renderer, { qrcode: this.state.qrcode, - getParamValue: this.getParamValue(index), + params: this.state.paramValue[index], setParamInfo: this.setParamInfo(index) })} text={this.state.text}