Skip to content

Commit 7431c0f

Browse files
committed
add node-qrcode
1 parent 087477c commit 7431c0f

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"classnames": "^2.2.5",
5959
"immutable": "^3.8.1",
6060
"prop-types": "^15.5.10",
61+
"qrcode": "^1.2.0",
6162
"react": "^15.3.0",
6263
"react-dom": "^15.3.0",
6364
"react-redux": "^4.4.5",

src/components/guide/index.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import React from 'react';
2+
import QRCode from 'qrcode';
23
import style from './index.less';
34
import { transform, i18n, lan } from '../../unit/const';
45
import { isMobile } from '../../unit';
56

7+
68
export default class Guide extends React.Component {
79
constructor() {
810
super();
911
this.state = {
1012
isMobile: isMobile(),
13+
QRCode: '',
1114
};
1215
}
13-
shouldComponentUpdate() {
14-
return false;
16+
componentWillMount() {
17+
if (this.state.isMobile) {
18+
return;
19+
}
20+
QRCode.toDataURL(location.href, { margin: 1 })
21+
.then(dataUrl => this.setState({ QRCode: dataUrl }));
22+
}
23+
shouldComponentUpdate(state) {
24+
if (state.QRCode === this.state.QRCode) {
25+
return false;
26+
}
27+
return true;
1528
}
1629
render() {
1730
if (this.state.isMobile) {
@@ -57,13 +70,15 @@ export default class Guide extends React.Component {
5770
</p>
5871
<div className={style.space}>SPACE</div>
5972
</div>
60-
<div className={`${style.guide} ${style.qr}`}>
61-
<img
62-
src={`//game.weixin.qq.com/cgi-bin/comm/qrcode?s=10&m=1&d=${location.href}`}
63-
alt={i18n.QRCode[lan]}
64-
title={i18n.QRNotice[lan]}
65-
/>
66-
</div>
73+
{ this.state.QRCode !== '' ? (
74+
<div className={`${style.guide} ${style.qr}`}>
75+
<img
76+
src={this.state.QRCode}
77+
alt={i18n.QRCode[lan]}
78+
/>
79+
<span>{ i18n.QRNotice[lan] }</span>
80+
</div>
81+
) : null }
6782
</div>
6883
);
6984
}

src/components/guide/index.less

+12-4
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,23 @@
4141
&.qr{
4242
left: auto;
4343
top: 5%;
44-
width: 190px;
44+
width: 150px;
4545
height:190px;
4646
opacity: .45;
47-
padding:0 0 40px 40px;
4847
text-align: right;
48+
cursor: none;
49+
span{
50+
display: none;
51+
text-align: center;
52+
line-height: 40px;
53+
}
4954
&:hover{
5055
img{
51-
width: 100%;
52-
height: 100%;
56+
width: 150px;
57+
height: 150px;
58+
}
59+
span{
60+
display: block;
5361
}
5462
}
5563
img{

0 commit comments

Comments
 (0)