-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
198 lines (182 loc) · 6.55 KB
/
Copy pathapp.js
File metadata and controls
198 lines (182 loc) · 6.55 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* global window */
import React from 'react'
import NProgress from 'nprogress'
import PropTypes from 'prop-types'
import pathToRegexp from 'path-to-regexp'
import { connect } from 'dva'
import { Layout, Loader } from 'components'
import { classnames, config } from 'utils'
import { Helmet } from 'react-helmet'
import { withRouter } from 'dva/router'
import { LocaleProvider } from 'antd'
import { Modal, Button} from 'antd'
import enUS from 'antd/lib/locale-provider/en_US'
import '../themes/index.less'
import './app.less'
import Error from './error'
const { prefix, openPages,api } = config
const { walletDownloadAddr } = api
const { Header, Bread, Footer, Sider, styles } = Layout
let lastHref
const App = ({ children, dispatch, app, loading, location }) => {
const { user, siderFold, darkTheme, isNavbar, menuPopoverVisible, navOpenKeys, menu, permissions } = app
let { pathname } = location
pathname = pathname.startsWith('/') ? pathname : `/${pathname}`
const { iconFontJS, iconFontCSS, logo } = config
const current = menu.filter(item => pathToRegexp(item.route || '').exec(pathname))
let hasPermission = current.length ? permissions.visit.includes(current[0].id) : false
const href = window.location.href
if(pathname.indexOf("/slots") != -1 && permissions.visit.includes("10")){
hasPermission = true
}
if (lastHref !== href) {
NProgress.start()
if (!loading.global) {
NProgress.done()
lastHref = href
}
}
const headerProps = {
menu,
user,
location,
siderFold,
isNavbar,
menuPopoverVisible,
navOpenKeys,
switchMenuPopover () {
dispatch({ type: 'app/switchMenuPopver' })
},
logout () {
dispatch({ type: 'app/logout' })
},
switchSider () {
dispatch({ type: 'app/switchSider' })
},
changeOpenKeys (openKeys) {
dispatch({ type: 'app/handleNavOpenKeys', payload: { navOpenKeys: openKeys } })
},
}
const siderProps = {
menu,
location,
siderFold,
darkTheme,
navOpenKeys,
changeTheme () {
dispatch({ type: 'app/switchTheme' })
},
changeOpenKeys (openKeys) {
window.localStorage.setItem(`${prefix}navOpenKeys`, JSON.stringify(openKeys))
dispatch({ type: 'app/handleNavOpenKeys', payload: { navOpenKeys: openKeys } })
},
}
const breadProps = {
menu,
location,
}
if (openPages && openPages.includes(pathname)) {
return (<div>
<Loader fullScreen spinning={loading.effects['app/query']} />
{children}
</div>)
}
function handleDownloadCancel(){
dispatch({
type: 'app/closeDownloadModel',
})
}
function handleModelOk(){
dispatch({
type: 'app/closeWarningModel',
})
}
function handleDownloadOk(){
window.open('http://'+walletDownloadAddr, '_blank');
dispatch({
type: 'app/closeDownloadModel',
})
}
const getFooter = () => {
return(
<div>
<Button type="ghost" size="large" onClick={handleDownloadCancel}>Cancel</Button>
<Button type="primary" size="large" onClick={handleDownloadOk}>Download</Button>
</div>
)
}
const getWarningFooter = () => {
return(
<div>
<Button type="primary" size="large" onClick={handleModelOk}>OK</Button>
</div>
)
}
if(!hasPermission){
dispatch({
type: 'app/redirectToLogin',
})
}
return (
<LocaleProvider locale={enUS}>
<div>
{/*<Loader fullScreen spinning={loading.effects['application/create']} />*/}
<Loader fullScreen spinning={app.showLoading} />
{/* <Loader fullScreen spinning={loading.effects['application/changeStatus']} />
<Loader fullScreen spinning={loading.effects['campaign/create']} />
<Loader fullScreen spinning={loading.effects['campaign/makeNoPending']} />
<Loader fullScreen spinning={loading.effects['campaign/changeStatus' ]} /> */}
<Helmet>
<title>DAD SSP</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href={logo} type="image/x-icon" />
{iconFontJS && <script src={iconFontJS} />}
{iconFontCSS && <link rel="stylesheet" href={iconFontCSS} />}
</Helmet>
<div
className={classnames(styles.layout, { [styles.fold]: isNavbar ? false : siderFold }, { [styles.withnavbar]: isNavbar })}
>
{!isNavbar ? <aside className={classnames(styles.sider, { [styles.light]: !darkTheme })}>
{siderProps.menu.length === 0 ? null : <Sider {...siderProps} />}
</aside> : ''}
<div className={styles.main}>
<Header {...headerProps} />
<Bread {...breadProps} />
<div className={styles.container}>
<div className={styles.content}>
{hasPermission ? children : <Error />}
</div>
</div>
{ /* <Footer /> */ }
</div>
</div>
<Modal
title="Tips"
zIndex={99999999999}
closable={false}
visible={app.showDonwloadModel}
footer = {getFooter()}
>
<p>Please install DAD wallet extension, and log in with DAD wallet, after that please do this operation again.</p>
</Modal>
<Modal
title="Tips"
zIndex={99999999999}
closable={false}
visible={app.showWarningModel}
footer = {getWarningFooter()}
>
<p>{app.warningModelText}</p>
</Modal>
</div>
</LocaleProvider>
)
}
App.propTypes = {
children: PropTypes.element.isRequired,
location: PropTypes.object,
dispatch: PropTypes.func,
app: PropTypes.object,
loading: PropTypes.object
}
export default withRouter(connect(({ app, loading }) => ({ app, loading }))(App))