[Re-render rules]
This commit is contained in:
parent
7b812f3469
commit
693ac27ae6
|
@ -16,12 +16,16 @@ class QrItem extends React.Component {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.forceUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
handleClick(e) {
|
handleClick(e) {
|
||||||
this.props.onSelected(this.props.index);
|
this.props.onSelected(this.props.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps, nextState, nextContext) {
|
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() {
|
render() {
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import {srand, rand} from "../utils/util";
|
||||||
import './Qrcode.css'
|
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) {
|
function listPoint(props) {
|
||||||
if (!props.qrcode) return []
|
if (!props.qrcode) return []
|
||||||
|
|
||||||
|
@ -20,7 +14,7 @@ function listPoint(props) {
|
||||||
for (let i = 0; i < nCount; i++) { //一维长度为5
|
for (let i = 0; i < nCount; i++) { //一维长度为5
|
||||||
sizeTable[i] = new Array(i); //在声明二维
|
sizeTable[i] = new Array(i); //在声明二维
|
||||||
for (let j = 0; j < nCount; j++) { //二维长度为5
|
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();
|
var nearPoint = new Array();
|
||||||
|
|
|
@ -127,6 +127,7 @@ class Qrcode extends React.Component {
|
||||||
renderer={React.createElement(style.renderer, {
|
renderer={React.createElement(style.renderer, {
|
||||||
qrcode: this.state.qrcode,
|
qrcode: this.state.qrcode,
|
||||||
})}
|
})}
|
||||||
|
text={this.state.text}
|
||||||
selected={index == this.state.selectedIndex}
|
selected={index == this.state.selectedIndex}
|
||||||
onSelected={this.handleSelected}
|
onSelected={this.handleSelected}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue