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
/*
* @Title:
* @Author: hongmye
* @Date: 2023-01-10 11:18:55
*/
import React, { useEffect, useMemo, useState } from 'react';
import { Empty, Spin, notification } from 'antd';
import SecurityLayout from '@/layouts/SecurityLayout';
import { appService } from '@/api';
import Cookies from 'js-cookie';
import _ from 'lodash';
import { useHistory, useAliveController } from '@wisdom-utils/runtime';
import { connect } from 'react-redux';
import { actionCreators } from '@/containers/App/store';
import { SERVICE_INTERFACE_SUCCESS_CODE } from '@/constants';
import PandaBootPage from './panda';
import IntegrationPage from './integration';
import Demonstration from './demonstration';
const systemItemName = '引导页模板'; // 系统配置项名称
const BootPageTemplate = {
default: PandaBootPage,
integration: IntegrationPage,
demonstration: Demonstration,
};
const BootPage = props => {
const [info, setInfo] = useState({
first: true,
loading: true,
error: false,
});
const { clear } = useAliveController();
const history = useHistory();
const [template, setTemplate] = useState('default');
const [pattern, setPattern] = useState(true); // 是否进入演示模式
const RenderComponent = useMemo(() => {
if (window?.globalConfig?.isIntegration >= 1) {
// 集成登录
return BootPageTemplate.integration;
}
if (pattern && template !== 'integration') {
return BootPageTemplate.demonstration;
}
// 云平台
return BootPageTemplate[template] || BootPageTemplate.default;
}, [template, pattern]);
useEffect(() => {
const tk = Cookies.get('token') || props.global.token;
const isLogin = tk !== null && tk !== 'undefined' && tk !== void 0;
let client = props?.global?.client || sessionStorage.getItem('client') || null;
client = client !== 'undefined' && !_.isNull(client) && !_.isUndefined(client) ? client : 'city';
const generateType = props.global && props.global.hasOwnProperty('get') ? props.global.get('generateType') : null;
if (!isLogin) {
history.push(`/user/login?client=${client}${generateType || ''}`, { reload: true });
clear();
props.logout();
}
}, [clear, history, props]);
useEffect(() => {
if (window?.globalConfig?.isIntegration >= 1) {
setInfo({ first: false, loading: false, error: false });
return false;
}
appService
.sysConfiguration({
moduleName: systemItemName,
ignoreSite: true,
})
.then(res => {
const { code, data } = res;
if (code !== SERVICE_INTERFACE_SUCCESS_CODE) {
notification.error({ message: '提示', duration: 3, description: '系统引导页配置错误' });
setInfo({ first: false, loading: false, error: true });
return;
}
// if (data === null) notification.info({ message: '提示', duration: 3, description: '未配置系统引导页' });
setTemplate(data);
setInfo({ first: false, loading: false, error: false });
})
.catch(err => {
notification.error({ message: '提示', duration: 3, description: '系统引导页配置错误' });
setInfo({ first: false, loading: false, error: true });
});
}, []);
return (
<SecurityLayout>
{info.loading ? <Spin /> : info.error ? <Empty /> : <RenderComponent setPattern={setPattern} {...props} />}
</SecurityLayout>
);
};
const mapStateToProps = state => ({
global: state.getIn(['global', 'globalConfig']),
instance: state.getIn(['global', 'instance']),
});
const mapDispatchToProps = dispatch => ({
logout() {
dispatch(actionCreators.logout());
},
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(BootPage);