Commit 32cd9c1c authored by 张瑶's avatar 张瑶

云平台网关取子站配置

parent 25c2adde
import { Modal, notification } from 'antd';
import { notification } from 'antd';
import { instanceRequest, service, event } from '@wisdom-utils/utils';
import AppService from './service/base';
import notificationService from './service/notification';
import CloudService from './service/cloud';
const { warning } = Modal;
// eslint-disable-next-line no-return-await
instanceRequest.reportCodeError = true;
instanceRequest.transformRequestURL = function(url) {
// url = url.replace(/\/GateWay/, '')
const excludeURL = [
'/PandaCore/GCK/Basis/GateWayConfig',
'/CityInterface/rest/services.svc/GetConfig',
......@@ -20,28 +17,9 @@ instanceRequest.transformRequestURL = function(url) {
if (excludeURL.includes(url)) {
return url.replace(/PandaCore\/GateWay\//, '');
}
// if (
// window.globalConfig &&
// window.globalConfig.hasGateWay &&
// /^\/(cityinterface|CityInterface|Cityinterface|CityServer|PandaInformatization)/.test(
// url,
// )
// ) {
// return /\/CityInterface\/rest\/services.svc\/GetConfig/.test(url)
// ? url
// ? /^\/GateWay/.test(url)
// ? url
// : `/GateWay${url}`
// : `/GateWay${url}`
// : `/GateWay${url}`;
// }
// if(window.globalConfig && window.globalConfig.hasGateWay) {
// return url && /^\/GateWay/.test(url) ? url : `/GateWay${url}`
// }
return url;
};
const codeMessage = {
200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。',
......@@ -60,7 +38,6 @@ const codeMessage = {
504: '网关超时。',
};
const instance = null;
instanceRequest.setErrorHandler(error => {
const { response } = error;
if (response && response.status) {
......@@ -69,11 +46,7 @@ instanceRequest.setErrorHandler(error => {
if (status === 401) {
event.emit('event:logout');
} else {
// notification.error({
// message: `请求错误 ${status}: ${config.url}`,
// description: errorText,
// });
console.log(errorText);
console.error(errorText);
}
} else if (!response) {
notification.error({
......
......@@ -25,7 +25,6 @@ import SecurityLayout from './SecurityLayout';
import Site from './Site';
const { params } = helpers;
const { getParamsV1 } = params;
// const ArcgisMap = React.lazy(() => import('../pages/map/arcgis'));
// const AMap = React.lazy(() => import('../pages/map/amap'));
......@@ -244,7 +243,9 @@ const transformFloatMenu = (routes, homepage) => {
};
const Layout = props => {
const currentProduct = `__global__recent_productIndex__micro_${window.location.hostname}_${params.getParams('client') ||
const currentProduct = `__global__recent_productIndex__micro_${window.location.hostname}_${params.getParams(
'client',
) ||
sessionStorage.getItem('client') ||
'city'}`;
const menuState = sessionStorage.getItem('menuState') || 'open';
......
......@@ -297,7 +297,7 @@ class Site {
return arr;
}
writeCookie(token, site, onChangeVisible, actionRef) {
writeCookie(token, site, onChangeVisible, actionRef, accessToken) {
const date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
// date = date.toGMTString();
......@@ -306,6 +306,8 @@ class Site {
path: '/',
});
localStorage.setItem('access_token', accessToken);
const encodeSite = encode(encodeURIComponent(site));
Cookies.set('site', encodeSite, {
expires: date,
......@@ -375,25 +377,55 @@ class Site {
}
beforeChangeCheck(token, site, onChangeVisible, actionRef) {
// eslint-disable-next-line no-undef
appService
.getUserInfo({
const userParam = {
token,
subOID: 'subOID',
site,
ignoreSite: true,
};
const gateWayParam = {
_site: site,
};
Promise.all([appService.getUserInfo(userParam), appService.getWateWayConfig(gateWayParam)])
.then(results => {
const res = results[0];
const gatewayRes = results[1];
if (res.code !== 0) {
this.setLoading(false);
message.error('获取用户信息失败');
}
const config = window?.globalConfig;
config.uiwidgets = [];
config.widgets = [];
config.allWidgets = [];
config.userInfo = window?.globalConfig?.transformUserInfo?.(res.data) ?? res.data;
window.globalConfig = config;
// 重置网关配置
// eslint-disable-next-line prettier/prettier, no-undef
const hasGateWay = !gatewayRes || !gatewayRes.data ? false : _.isString(gatewayRes.data) ? JSON.parse(gatewayRes.data) : (typeof gatewayRes.data === 'boolean' ? gatewayRes.data : false);
if (hasGateWay) {
appService
.authorizationToken({
loginName: config.userInfo?.loginName || '',
type: 'WorkNo',
})
.then(res => {
if (res && res.code === 0) {
this.writeCookie(token, site, onChangeVisible, actionRef);
} else {
message.warning('企业切换失败,请联系管理员排查问题!');
.then(tokenRes => {
const accessToken = tokenRes.data?.access_token ?? null;
localStorage.setItem('access_token', accessToken);
this.writeCookie(token, site, onChangeVisible, actionRef, accessToken);
})
.catch(err => {
this.setLoading(false);
this.writeCookie(token, site, onChangeVisible, actionRef, null);
});
} else {
localStorage.setItem('access_token', null);
this.writeCookie(token, site, onChangeVisible, actionRef, null);
}
})
.catch(e => {
message.warning('企业切换失败,请联系管理员排查问题!');
.catch(err => {
this.setLoading(false);
message.warning('企业切换失败,请联系管理员排查问题!');
});
}
......
import React from 'react';
import classnames from 'classnames';
import styles from './index.less';
import cover from './images/default.png';
import { chunk } from 'lodash-es';
import cover from './images/default.png';
import styles from './index.less';
const assetPath = `${window.location.origin}/PandaWorkFlow/WorkFlow/AccountManage/DownloadFiles`;
const Card = ({onCardClick, ...props}) => {
const Card = ({ onCardClick, ...props }) => {
const { config } = props;
if(config['副标题'].indexOf('\\n') === -1){
config['副标题'] = config['副标题'] + '\\n';
if (config['副标题'].indexOf('\\n') === -1) {
config['副标题'] += '\\n';
}
if(config['系统特点'].indexOf(',') === -1){
config['系统特点'] = config['系统特点'] + ',';
if (config['系统特点'].indexOf(',') === -1) {
config['系统特点'] += ',';
}
return (
<div className={styles.card} onClick={e => onCardClick(e, props)}>
<div className={classnames(styles['card-title'], styles['nowrap-text'])}>
{config && config['标题']}
</div>
<div
key={config && config['标题'] ? config['标题'] : Math.random()}
className={styles.card}
onClick={e => onCardClick(config, props)}
>
<div className={classnames(styles['card-title'], styles['nowrap-text'])}>{config && config['标题']}</div>
<div className={classnames(styles['card-content'])}>
<div className={classnames(styles['card-img'])}>
<img src={config && config['封面图'] ? `${assetPath}?filePath=${config['封面图']}` : cover} />
<img src={config && config['封面图'] ? `${assetPath}?filePath=${config['封面图']}` : cover} alt="" />
{
config && config['系统描述'] ? (
<div className={styles.back}>
{config && config['系统描述']}
</div>
) : null
}
{config && config['系统描述'] ? <div className={styles.back}>{config && config['系统描述']}</div> : null}
</div>
<div className={classnames(styles['card-info'])}>
<div className={classnames(styles['card-desc'])}>
{
config && config['副标题'] && config && config['副标题'].split("\\n").map((item, index) => {
return <div key={index}>{item}</div>
})
}
{config &&
config['副标题'] &&
config['副标题'].split('\\n').map((item, index) => <div key={index}>{item}</div>)}
</div>
<div className={classnames(styles['card-tags'])}>
<div className={classnames(styles['card-list'])}>
{
config && config['系统特点'] && chunk(config['系统特点'].split(',') , 2).map((item, index) => {
return <div key={index} className={classnames(styles['card-list-content'])}>
{
item.map((child, key) => {
return <div className={classnames(styles['card-tag'])}
{config['系统特点'] &&
chunk(config['系统特点'].split(','), 2).map((item, index) => (
<div key={index} className={classnames(styles['card-list-content'])}>
{item.map(child => (
<div
className={classnames(styles['card-tag'])}
style={{
height: config['系统特点'].split(',').length <= 6 ? 44 : 40,
lineHeight: config['系统特点'].split(',').length <= 6 ? '44px' : '40px',
marginTop: config['系统特点'].split(',').length <= 8 ? 10 : 0
}} key={key + index}>
marginTop: config['系统特点'].split(',').length <= 8 ? 10 : 0,
}}
key={child}
>
<i className={classnames(styles['card-tag-icon'])} />
{child}
</div>
})
}
))}
</div>
})
}
))}
</div>
</div>
</div>
</div>
......
import React from 'react';
import styles from './index.less';
import Card from './Card';
import classnames from 'classnames';
const Panel = ({ products = [], onCardClick, pageIndex, pageSize }) => {
return (
<div className={classnames(styles.panel)} num={pageIndex == 0 ? products.length : pageSize}>
{ products.map((item, index) => <Card key={index} {...item} onCardClick={onCardClick}/>)}
import Card from './Card';
import styles from './index.less';
const Panel = ({ products = [], onCardClick, pageIndex, pageSize }) => (
<div className={classnames(styles.panel)} num={pageIndex === 0 ? products.length : pageSize}>
{products.map((item, index) => (
<Card key={index} {...item} onCardClick={onCardClick} />
))}
</div>
);
};
);
export default Panel;
......@@ -6,18 +6,16 @@ import { chunk } from 'lodash';
import classnames from 'classnames';
import defaultSetting from '@wisdom-utils/components/lib/AppLayout/layouts/defaultSettings';
import SecurityLayout from '@/layouts/SecurityLayout';
import styles from './index.less';
import Panel from './Panel';
import { appService, cloudService } from '@/api'
import moment from 'moment';
import { appService, cloudService } from '@/api';
import { actionCreators } from '@/containers/App/store';
import { defaultApp } from '@/micro';
import LoginAction from '../../../user/login/login';
import Cookies from 'js-cookie';
import { decode, encode } from 'js-base64';
import moment from 'moment';
import { encode } from 'js-base64';
import icon from './images/退出.png';
import Panel from './Panel';
import LoginAction from '../../../user/login/login';
import styles from './index.less';
/**
* 熊猫新产品引导页
......@@ -28,62 +26,73 @@ const pageSize = 6;
const NewProducts = props => {
const [products, setProducts] = useState([]);
const [loading, setLoading] = useState(false);
const [time, setTime] = useState(moment().format('YYYY-MM-DD HH:mm:ss'))
const [time, setTime] = useState(moment().format('YYYY-MM-DD HH:mm:ss'));
const ref = useRef();
// 计时器
useEffect(() => {
setInterval(() => {
setTime(moment().format('YYYY-MM-DD HH:mm:ss'))
}, 1000)
}, [time])
setTime(moment().format('YYYY-MM-DD HH:mm:ss'));
}, 1000);
}, [time]);
// 获取卡片数据
useEffect(() => {
setLoading(true);
cloudService.getAccountPageList({
cloudService
.getAccountPageList({
pageIndex: 1,
pageSize: 100,
sortFields: '排序',
direction: 'desc',
accountName: '演示_熊猫新产品',
// info: searchInfo,
// queryWhere:
// " and (登录时间 >= '" + stime + "' and 登录时间 <= '" + etime + "')",
ignoreSite: true,
}).then(res => {
})
.then(res => {
setLoading(false);
const configData = JSON.parse(res.data.jsonData || '[]');
const configMap = configData.reduce((pre, item, index) => {
if(item.site && item['是否显示'] === '是') {
if (item.site && item['是否显示'] === '是') {
pre[item.site] = item;
}
return pre;
}, {});
const Groups = props.global?.userInfo?.Groups ?? [];
const data = Groups
.filter(item => item.industry === '熊猫新产品' && configMap[item.site])
.map(item => ({ ...item, config: configMap[item.site] }));
data.sort((a,b) => Number(a.config['排序']) - Number(b.config['排序']));
const data = Groups.filter(item => item.industry === '熊猫新产品' && configMap[item.site]).map(item => ({
...item,
config: configMap[item.site],
}));
data.sort((a, b) => Number(a.config['排序']) - Number(b.config['排序']));
setProducts(chunk(data, pageSize));
}).catch(err => {
setLoading(false);
notification.error({ message: '提示', duration: 3, description: '获取产品信息错误' })
})
}, []);
.catch(err => {
setLoading(false);
notification.error({ message: '提示', duration: 3, description: '获取产品信息错误' });
});
}, [props.global.userInfo.Groups]);
const updateConfig = config => {
props.updateConfig && props.updateConfig(config);
const loginAction = new LoginAction({ ...props, global: config });
loginAction && loginAction.getUserInfoAndConfig('', true, '熊猫新产品');
};
// 卡片点击事件
const handleClick = (e, data) => {
const handleClick = (data, datas) => {
setLoading(true);
appService
.getUserInfo({
const userParam = {
token: props.global.token,
subOID: 'subOID',
site: data.site,
ignoreSite: true,
})
.then(res => {
};
const gateWayParam = {
_site: data.site,
};
Promise.all([appService.getUserInfo(userParam), appService.getWateWayConfig(gateWayParam)])
.then(results => {
const res = results[0];
const gatewayRes = results[1];
if (res.code !== 0) {
setLoading(false);
message.error('获取用户信息失败');
......@@ -94,28 +103,50 @@ const NewProducts = props => {
config.widgets = [];
config.allWidgets = [];
config.userInfo = window?.globalConfig?.transformUserInfo?.(res.data) ?? res.data;
props.updateConfig && props.updateConfig(config);
// 默认有个上次记住的登入企业,存在印象。这里把cookie和localStorage中的都重新设置一下
const date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
const encodeSite = encode(encodeURIComponent(data.site));
localStorage.setItem('loginSite', JSON.stringify({[config.token]: data.site}))
localStorage.setItem('loginSite', JSON.stringify({ [config.token]: data.site }));
Cookies.set('site', encodeSite, {
expires: date,
path: '/',
});
const loginAction = new LoginAction({...props, global: config});
// props.instance && props.instance.updateConfig(config);
loginAction && loginAction.getUserInfoAndConfig('', true, '熊猫新产品');
}).catch(err => {
props.updateConfig && props.updateConfig(config);
// 重置网关配置
// eslint-disable-next-line prettier/prettier, no-undef
const hasGateWay = !gatewayRes || !gatewayRes.data ? false : _.isString(gatewayRes.data) ? JSON.parse(gatewayRes.data) : (typeof gatewayRes.data === 'boolean' ? gatewayRes.data : false);
config.hasGateWay = hasGateWay;
config.apiGatewayDomain = `${window.location.origin}${hasGateWay ? '/PandaCore/GateWay' : ''}`;
if (hasGateWay) {
appService
.authorizationToken({
loginName: config.userInfo?.loginName || '',
type: 'WorkNo',
})
.then(tokenRes => {
if (res.code === 0) {
config.access_token = tokenRes.data?.access_token ?? '';
localStorage.setItem('access_token', config.access_token);
}
updateConfig(config);
})
.catch(err => {
updateConfig(config);
});
} else {
config.access_token = null;
localStorage.setItem('access_token', config.access_token);
updateConfig(config);
}
})
.catch(err => {
setLoading(false);
message.error('获取用户信息失败');
});
};
// toggleIndustry 事件
useEffect(() => {
// 借用引导页的触发逻辑进入系统
......@@ -123,27 +154,23 @@ const NewProducts = props => {
setLoading(false);
props.history.push(`/?client=${props.global.client}`);
defaultApp();
// window.share.event.emit('triggerMicro', props.global);
props.updateCurrentIndex(0);
};
window.share.event.on('toggleIndustry', handleToggleIndustry);
return () => {
window.share.event.removeListener('toggleIndustry', handleToggleIndustry);
};
}, [window.share.event, props]);
}, [props]);
useDocumentTitle(
{ title: defaultSetting.title, id: '', pageName: '新产品介绍' },
props.global.title || defaultSetting.title,
);
// 卡片左右切换
const onPrev = e => ref.current && ref.current.prev();
const onNext = e => ref.current && ref.current.next();
return (
<SecurityLayout>
<div className={styles.newproducts}>
......@@ -152,25 +179,36 @@ const NewProducts = props => {
<div className={styles.pageTitle}>熊猫智慧水务新产品</div>
<div className={classnames(styles['page-time'])}>
<span>{time}</span>
<img src={icon} onClick={() => {
<img
src={icon}
onClick={() => {
window.history.go(-1);
// window.history.pushState('', null, `/industry`);
// props.history.push(`/industry`);
}} className={classnames(styles.pageIcon)} alt='退出' />
}}
className={classnames(styles.pageIcon)}
alt="退出"
/>
</div>
<div className={styles.container}>
<Carousel ref={ref}>
{ products.map((item, index) => <Panel key={index} products={item} pageIndex={index} pageSize={pageSize} onCardClick={handleClick}/>) }
{products.map((item, index) => (
<Panel key={index} products={item} pageIndex={index} pageSize={pageSize} onCardClick={handleClick} />
))}
</Carousel>
{
products && products.length > 1 && (
{products && products.length > 1 && (
<>
<div className={classnames(styles['cus-arrow'], styles['cus-arrow-prev'])} title="上一页" onClick={onPrev} />
<div className={classnames(styles['cus-arrow'], styles['cus-arrow-next'])} title="下一页" onClick={onNext} />
<div
className={classnames(styles['cus-arrow'], styles['cus-arrow-prev'])}
title="上一页"
onClick={onPrev}
/>
<div
className={classnames(styles['cus-arrow'], styles['cus-arrow-next'])}
title="下一页"
onClick={onNext}
/>
</>
)
}
)}
</div>
</div>
</Spin>
......@@ -178,10 +216,12 @@ const NewProducts = props => {
</SecurityLayout>
);
};
const mapStateToProps = (state) => ({
const mapStateToProps = state => ({
global: state.getIn(['global', 'globalConfig']),
});
const mapDispatchToProps = (dispatch) => ({
const mapDispatchToProps = dispatch => ({
updateConfig(config) {
dispatch(actionCreators.getConfig(config));
},
......@@ -189,4 +229,8 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(actionCreators.updateCurrentIndex(index));
},
});
export default connect(mapStateToProps, mapDispatchToProps)(NewProducts);
export default connect(
mapStateToProps,
mapDispatchToProps,
)(NewProducts);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment