index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { useEffect, memo, useMemo } from 'react'
  21. import Helmet from 'react-helmet'
  22. import { useDispatch, useSelector } from 'react-redux'
  23. import { AppActions } from './actions'
  24. import { querystring } from '../../util'
  25. import {
  26. Route,
  27. HashRouter as Router,
  28. Switch,
  29. useHistory
  30. } from 'react-router-dom'
  31. import injectReducer, { useInjectReducer } from 'utils/injectReducer'
  32. import injectSaga, { useInjectSaga } from 'utils/injectSaga'
  33. import reducer from './reducer'
  34. import saga from './sagas'
  35. import { Tmode } from 'app/components/SharePanel/types'
  36. import { makeSelectShareType } from './selectors'
  37. import { Display } from 'share/containers/Display/Loadable'
  38. import { Dashboard } from 'share/containers/Dashboard/Loadable'
  39. import { NotFound } from 'containers/NotFoundPage/Loadable'
  40. import { setToken } from 'app/utils/request'
  41. import Interceptor from './Interceptor'
  42. export const App: React.FC = () => {
  43. useInjectReducer({ key: 'global', reducer })
  44. useInjectSaga({ key: 'global', saga })
  45. const shareType: Tmode = useSelector(makeSelectShareType())
  46. const { shareToken } = useMemo(
  47. () => querystring(window.location.search.substr(1)),
  48. [window.location.search]
  49. )
  50. const history = useHistory()
  51. const currentPathname = history.location.pathname + history.location.search
  52. const dispatch = useDispatch()
  53. useEffect(() => {
  54. dispatch(AppActions.interceptor(shareToken))
  55. dispatch(AppActions.getServerConfigurations())
  56. }, [])
  57. useEffect(() => {
  58. const pathname = sessionStorage.getItem('pathname')
  59. if (pathname && pathname !== currentPathname) {
  60. history.push(pathname)
  61. sessionStorage.removeItem('pathname')
  62. }
  63. const token = localStorage.getItem('TOKEN')
  64. if (token) {
  65. setToken(token)
  66. }
  67. }, [])
  68. useEffect(() => {
  69. if (shareType === 'NORMAL') {
  70. dispatch(AppActions.getPermissions(shareToken))
  71. }
  72. }, [shareType])
  73. return (
  74. <div>
  75. <Helmet
  76. titleTemplate="%s - 聚合平台"
  77. defaultTitle="聚合平台-数据分享"
  78. meta={[
  79. {
  80. name: 'description',
  81. content: '聚合平台-数据分享'
  82. }
  83. ]}
  84. />
  85. <Interceptor>
  86. <Router>
  87. <Switch>
  88. <Route exact path="/share/display" component={Display} />
  89. <Route exact path="/share/dashboard" component={Dashboard} />
  90. <Route path="*" component={NotFound} />
  91. </Switch>
  92. </Router>
  93. </Interceptor>
  94. </div>
  95. )
  96. }
  97. export default App