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 { instanceRequest, service, event } from '@wisdom-utils/utils';
import AppService from './service/base'; import AppService from './service/base';
import notificationService from './service/notification'; import notificationService from './service/notification';
import CloudService from './service/cloud'; import CloudService from './service/cloud';
const { warning } = Modal;
// eslint-disable-next-line no-return-await
instanceRequest.reportCodeError = true; instanceRequest.reportCodeError = true;
instanceRequest.transformRequestURL = function(url) { instanceRequest.transformRequestURL = function(url) {
// url = url.replace(/\/GateWay/, '')
const excludeURL = [ const excludeURL = [
'/PandaCore/GCK/Basis/GateWayConfig', '/PandaCore/GCK/Basis/GateWayConfig',
'/CityInterface/rest/services.svc/GetConfig', '/CityInterface/rest/services.svc/GetConfig',
...@@ -20,28 +17,9 @@ instanceRequest.transformRequestURL = function(url) { ...@@ -20,28 +17,9 @@ instanceRequest.transformRequestURL = function(url) {
if (excludeURL.includes(url)) { if (excludeURL.includes(url)) {
return url.replace(/PandaCore\/GateWay\//, ''); 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; return url;
}; };
const codeMessage = { const codeMessage = {
200: '服务器成功返回请求的数据。', 200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。', 201: '新建或修改数据成功。',
...@@ -60,7 +38,6 @@ const codeMessage = { ...@@ -60,7 +38,6 @@ const codeMessage = {
504: '网关超时。', 504: '网关超时。',
}; };
const instance = null;
instanceRequest.setErrorHandler(error => { instanceRequest.setErrorHandler(error => {
const { response } = error; const { response } = error;
if (response && response.status) { if (response && response.status) {
...@@ -69,11 +46,7 @@ instanceRequest.setErrorHandler(error => { ...@@ -69,11 +46,7 @@ instanceRequest.setErrorHandler(error => {
if (status === 401) { if (status === 401) {
event.emit('event:logout'); event.emit('event:logout');
} else { } else {
// notification.error({ console.error(errorText);
// message: `请求错误 ${status}: ${config.url}`,
// description: errorText,
// });
console.log(errorText);
} }
} else if (!response) { } else if (!response) {
notification.error({ notification.error({
......
...@@ -25,7 +25,6 @@ import SecurityLayout from './SecurityLayout'; ...@@ -25,7 +25,6 @@ import SecurityLayout from './SecurityLayout';
import Site from './Site'; import Site from './Site';
const { params } = helpers; const { params } = helpers;
const { getParamsV1 } = params;
// const ArcgisMap = React.lazy(() => import('../pages/map/arcgis')); // const ArcgisMap = React.lazy(() => import('../pages/map/arcgis'));
// const AMap = React.lazy(() => import('../pages/map/amap')); // const AMap = React.lazy(() => import('../pages/map/amap'));
...@@ -244,7 +243,9 @@ const transformFloatMenu = (routes, homepage) => { ...@@ -244,7 +243,9 @@ const transformFloatMenu = (routes, homepage) => {
}; };
const Layout = props => { 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') || sessionStorage.getItem('client') ||
'city'}`; 'city'}`;
const menuState = sessionStorage.getItem('menuState') || 'open'; const menuState = sessionStorage.getItem('menuState') || 'open';
......
...@@ -297,7 +297,7 @@ class Site { ...@@ -297,7 +297,7 @@ class Site {
return arr; return arr;
} }
writeCookie(token, site, onChangeVisible, actionRef) { writeCookie(token, site, onChangeVisible, actionRef, accessToken) {
const date = new Date(); const date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000); date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
// date = date.toGMTString(); // date = date.toGMTString();
...@@ -306,6 +306,8 @@ class Site { ...@@ -306,6 +306,8 @@ class Site {
path: '/', path: '/',
}); });
localStorage.setItem('access_token', accessToken);
const encodeSite = encode(encodeURIComponent(site)); const encodeSite = encode(encodeURIComponent(site));
Cookies.set('site', encodeSite, { Cookies.set('site', encodeSite, {
expires: date, expires: date,
...@@ -375,25 +377,55 @@ class Site { ...@@ -375,25 +377,55 @@ class Site {
} }
beforeChangeCheck(token, site, onChangeVisible, actionRef) { beforeChangeCheck(token, site, onChangeVisible, actionRef) {
// eslint-disable-next-line no-undef const userParam = {
appService
.getUserInfo({
token, token,
subOID: 'subOID', subOID: 'subOID',
site, site,
ignoreSite: true, 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 => { .then(tokenRes => {
if (res && res.code === 0) { const accessToken = tokenRes.data?.access_token ?? null;
this.writeCookie(token, site, onChangeVisible, actionRef); localStorage.setItem('access_token', accessToken);
} else { this.writeCookie(token, site, onChangeVisible, actionRef, accessToken);
message.warning('企业切换失败,请联系管理员排查问题!'); })
.catch(err => {
this.setLoading(false); 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 => { .catch(err => {
message.warning('企业切换失败,请联系管理员排查问题!');
this.setLoading(false); this.setLoading(false);
message.warning('企业切换失败,请联系管理员排查问题!');
}); });
} }
......
import React from 'react'; import React from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import styles from './index.less';
import cover from './images/default.png';
import { chunk } from 'lodash-es'; 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 assetPath = `${window.location.origin}/PandaWorkFlow/WorkFlow/AccountManage/DownloadFiles`;
const Card = ({onCardClick, ...props}) => { const Card = ({ onCardClick, ...props }) => {
const { config } = props; const { config } = props;
if(config['副标题'].indexOf('\\n') === -1){ if (config['副标题'].indexOf('\\n') === -1) {
config['副标题'] = config['副标题'] + '\\n'; config['副标题'] += '\\n';
} }
if(config['系统特点'].indexOf(',') === -1){ if (config['系统特点'].indexOf(',') === -1) {
config['系统特点'] = config['系统特点'] + ','; config['系统特点'] += ',';
} }
return ( return (
<div className={styles.card} onClick={e => onCardClick(e, props)}> <div
<div className={classnames(styles['card-title'], styles['nowrap-text'])}> key={config && config['标题'] ? config['标题'] : Math.random()}
{config && config['标题']} className={styles.card}
</div> 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-content'])}>
<div className={classnames(styles['card-img'])}> <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>
<div className={classnames(styles['card-info'])}> <div className={classnames(styles['card-info'])}>
<div className={classnames(styles['card-desc'])}> <div className={classnames(styles['card-desc'])}>
{ {config &&
config && config['副标题'] && config && config['副标题'].split("\\n").map((item, index) => { config['副标题'] &&
return <div key={index}>{item}</div> config['副标题'].split('\\n').map((item, index) => <div key={index}>{item}</div>)}
})
}
</div> </div>
<div className={classnames(styles['card-tags'])}> <div className={classnames(styles['card-tags'])}>
<div className={classnames(styles['card-list'])}> <div className={classnames(styles['card-list'])}>
{ {config['系统特点'] &&
config && config['系统特点'] && chunk(config['系统特点'].split(',') , 2).map((item, index) => { chunk(config['系统特点'].split(','), 2).map((item, index) => (
return <div key={index} className={classnames(styles['card-list-content'])}> <div key={index} className={classnames(styles['card-list-content'])}>
{ {item.map(child => (
item.map((child, key) => { <div
return <div className={classnames(styles['card-tag'])} className={classnames(styles['card-tag'])}
style={{ style={{
height: config['系统特点'].split(',').length <= 6 ? 44 : 40, height: config['系统特点'].split(',').length <= 6 ? 44 : 40,
lineHeight: config['系统特点'].split(',').length <= 6 ? '44px' : '40px', lineHeight: config['系统特点'].split(',').length <= 6 ? '44px' : '40px',
marginTop: config['系统特点'].split(',').length <= 8 ? 10 : 0 marginTop: config['系统特点'].split(',').length <= 8 ? 10 : 0,
}} key={key + index}> }}
key={child}
>
<i className={classnames(styles['card-tag-icon'])} /> <i className={classnames(styles['card-tag-icon'])} />
{child} {child}
</div> </div>
}) ))}
}
</div> </div>
}) ))}
}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
......
import React from 'react'; import React from 'react';
import styles from './index.less';
import Card from './Card';
import classnames from 'classnames'; import classnames from 'classnames';
const Panel = ({ products = [], onCardClick, pageIndex, pageSize }) => { import Card from './Card';
return ( import styles from './index.less';
<div className={classnames(styles.panel)} num={pageIndex == 0 ? products.length : pageSize}>
{ products.map((item, index) => <Card key={index} {...item} onCardClick={onCardClick}/>)} 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> </div>
); );
};
export default Panel; export default Panel;
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