App.js
2.85 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
import React, { useEffect, useState } from 'react'
import RouterView from './router'
import ErrorBoundaries from 'xbd-error-boundaries'
import zhCN from 'antd/lib/locale/zh_CN'
import moment from 'moment'
import store from './store'
import http from './libs/fetch'
import { APP } from './config'
import { Provider } from 'react-redux'
import { ConfigProvider, Modal, notification } from 'antd'
import { getbaseConfig } from '@/api/config'
import 'moment/locale/zh-cn'
moment.locale('zh')
function App() {
const [appCode, setAppCode] = useState('')
useEffect(() => {
// 成功回调
const onSucess = (res) => {
store.dispatch.baseConfig.setState(res)
http.setHeader('operationChannel', res.operationChannel)
setAppCode(res.app_code)
window.localStorage.setItem('baseConfig', JSON.stringify(res))
document.title = res.platformName
let link = document.createElement('link')
link.type = 'image/x-icon'
link.rel = 'shortcut icon'
link.href = res.logoIcon
document.getElementsByTagName('head')[0].appendChild(link)
}
// 失败回调
const onError = (res) => {
if (res === undefined) {
Modal.error({
title: '启动错误',
content: '获取关键数据失败,请联系客服'
})
}
else {
console.error(res)
const CacheConfig = window.localStorage.getItem('baseConfig')
if (!CacheConfig)
onError()
else {
notification.open({
message: '获取最新系统配置失败',
description: '网络情况较差!加载最新系统核心配置失败,可能部分系统功能不能正确启用。请刷新页面或联系客服',
duration: 0
})
onSucess(JSON.parse(CacheConfig))
}
}
}
getbaseConfig()
.then(res => !res.id === undefined ? onError() : onSucess(res))
.catch(onError)
}, [])
if (process.env.NODE_ENV === 'development') {
return (
<Provider store={store}>
<ConfigProvider locale={zhCN}>
<RouterView></RouterView>
</ConfigProvider>
</Provider>
)
}
else {
return (
<ErrorBoundaries app_code={appCode} url={`${APP.GET_PALTFORM_CONFIG_URL}api/log`} >
<Provider store={store}>
<ConfigProvider locale={zhCN}>
<RouterView></RouterView>
</ConfigProvider>
</Provider>
</ErrorBoundaries>
)
}
}
export default App