forked from yinxin630/fiora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
107 lines (102 loc) · 3.25 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React, { Component } from 'react';
import { hot } from 'react-hot-loader';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import 'normalize.css';
import action from '@/state/action';
import Dialog from '@/components/Dialog';
import Main from './modules/main/Main';
import Login from './modules/main/login/Login';
import './App.less';
// App can't be stateless component
class App extends Component {
static propTypes = {
showLoginDialog: PropTypes.bool,
backgroundImage: PropTypes.string,
}
static getWidth() {
let width = 0.6;
if (window.innerWidth < 1000) {
width = 0.9;
} else if (window.innerWidth < 1300) {
width = 0.8;
} else if (window.innerWidth < 1600) {
width = 0.7;
}
return width;
}
constructor(props) {
super(props);
this.state = {
width: App.getWidth(),
height: 0.85,
resize: 0,
backgroundWidth: window.innerWidth,
backgroundHeight: window.innerHeight,
};
}
componentDidMount() {
const img = new Image();
img.onload = () => {
this.setState({
backgroundWidth: Math.max(img.width, window.innerWidth),
backgroundHeight: Math.max(img.height, window.innerHeight),
});
};
img.src = this.props.backgroundImage;
window.onresize = () => {
// 触发rerender
this.setState({
resize: this.state.resize + 1,
width: App.getWidth(),
});
};
}
get style() {
const { backgroundWidth, backgroundHeight } = this.state;
return {
backgroundImage: `url(${this.props.backgroundImage})`,
backgroundSize: `${backgroundWidth}px ${backgroundHeight}px`,
backgroundRepeat: 'no-repeat',
};
}
get blurStyle() {
const { width, height } = this.state;
const { innerWidth, innerHeight } = window;
return Object.assign(
{
backgroundPosition: `${-(1 - width) * innerWidth / 2}px ${-(1 - height) * innerHeight / 2}px`,
},
this.childStyle,
this.style,
);
}
get childStyle() {
const { width, height } = this.state;
return {
width: `${width * 100}%`,
height: `${height * 100}%`,
position: 'absolute',
left: `${(1 - width) / 2 * 100}%`,
top: `${(1 - height) / 2 * 100}%`,
};
}
render() {
const { showLoginDialog } = this.props;
return (
<div className="app" style={this.style}>
<div className="blur" style={this.blurStyle} />
<div className="child" style={this.childStyle}>
<Main />
</div>
<Dialog visible={showLoginDialog} closable={false} onClose={action.closeLoginDialog}>
<Login />
</Dialog>
</div>
);
}
}
export default connect(state => ({
showLoginDialog: state.getIn(['ui', 'showLoginDialog']),
backgroundImage: state.getIn(['ui', 'backgroundImage']),
}))(hot(module)(App));