diff --git a/src/components/QrItem.js b/src/components/QrItem.js index 0034d5d..f336494 100644 --- a/src/components/QrItem.js +++ b/src/components/QrItem.js @@ -16,12 +16,16 @@ class QrItem extends React.Component { }; } + componentDidMount() { + this.forceUpdate(); + } + handleClick(e) { this.props.onSelected(this.props.index); } shouldComponentUpdate(nextProps, nextState, nextContext) { - return nextProps.selected || this.props.selected + return (nextProps.selected || this.props.selected) && (this.props.text == nextProps.text || this.props.text.length == 0) } render() { diff --git a/src/components/QrRendererRound.js b/src/components/QrRendererRound.js index 872cf66..1f5abff 100644 --- a/src/components/QrRendererRound.js +++ b/src/components/QrRendererRound.js @@ -1,13 +1,7 @@ import React from "react"; +import {srand, rand} from "../utils/util"; import './Qrcode.css' -function RandomNum(Min,Max){ - const Random = Max - Min; - const random = Math.random(); - const num = Min + random * Random; - return num; -} - function listPoint(props) { if (!props.qrcode) return [] @@ -20,7 +14,7 @@ function listPoint(props) { for (let i = 0; i < nCount; i++) { //一维长度为5 sizeTable[i] = new Array(i); //在声明二维 for (let j = 0; j < nCount; j++) { //二维长度为5 - sizeTable[i][j] = RandomNum(0.33,1); + sizeTable[i][j] = rand(0.33,0.8); } } var nearPoint = new Array(); diff --git a/src/components/Qrcode.js b/src/components/Qrcode.js index ad2a12e..e866125 100644 --- a/src/components/Qrcode.js +++ b/src/components/Qrcode.js @@ -127,6 +127,7 @@ class Qrcode extends React.Component { renderer={React.createElement(style.renderer, { qrcode: this.state.qrcode, })} + text={this.state.text} selected={index == this.state.selectedIndex} onSelected={this.handleSelected} /> diff --git a/src/utils/util.js b/src/utils/util.js new file mode 100644 index 0000000..78318bf --- /dev/null +++ b/src/utils/util.js @@ -0,0 +1,10 @@ +let seed = 0; + +export function srand(sd) { + seed = sd; +} + +export function rand(min, max) { + seed = (seed * 9301 + 49297) % 233280; + return min + (seed / 233280.0) * max; +}