Commit b122d3d9 authored by 杨思琦's avatar 杨思琦

fix: 站点修改

parent 502148b5
Pipeline #86084 passed with stages
...@@ -180,9 +180,11 @@ const Stations = props => { ...@@ -180,9 +180,11 @@ const Stations = props => {
const renderSite = ({ data, config, loading, setLoading, action, actionRef, setMenuLoading }) => { const renderSite = ({ data, config, loading, setLoading, action, actionRef, setMenuLoading }) => {
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [stationName, setStationName] = useState('');
useEffect(() => { useEffect(() => {
window.share.event.on('changeSiteVisible', res => { window.share.event.on('changeSiteVisible', (res) => {
setVisible(res); setStationName(res.currentStationName);
setVisible(res.visible);
}); });
return () => { return () => {
window.share.event.removeAllListeners('changeSiteVisible'); window.share.event.removeAllListeners('changeSiteVisible');
...@@ -226,7 +228,7 @@ const renderSite = ({ data, config, loading, setLoading, action, actionRef, setM ...@@ -226,7 +228,7 @@ const renderSite = ({ data, config, loading, setLoading, action, actionRef, setM
{Array.isArray(data.stations) ? ( {Array.isArray(data.stations) ? (
<div className={layoutStyles.toggleSite}> <div className={layoutStyles.toggleSite}>
<img src={require('../assets/basic/site.png')} className={layoutStyles.site} alt="" /> <img src={require('../assets/basic/site.png')} className={layoutStyles.site} alt="" />
<span className={layoutStyles.name}>{data.currentStationName}</span> <span className={layoutStyles.name}>{stationName === '' ? data.currentStationName : stationName}</span>
<ArrowIcon <ArrowIcon
className={layoutStyles.arrow} className={layoutStyles.arrow}
// fillColor="#fff" // fillColor="#fff"
...@@ -403,7 +405,7 @@ const Layout = props => { ...@@ -403,7 +405,7 @@ const Layout = props => {
GetIntegrationConfig(); GetIntegrationConfig();
} }
window.share.event.on('updateSite', res => { window.share.event.on('updateSite', res => {
setCityData({...cityData, ...res}); setCityData(res);
}); });
const handleToggleIndustry = event => { const handleToggleIndustry = event => {
......
...@@ -288,7 +288,7 @@ class Site { ...@@ -288,7 +288,7 @@ class Site {
return arr; return arr;
} }
writeCookie(token, site, onChangeVisible, actionRef, accessToken) { writeCookie(token, site, onChangeVisible, actionRef, accessToken, item) {
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();
...@@ -348,7 +348,7 @@ class Site { ...@@ -348,7 +348,7 @@ class Site {
self.props.history && self.props.history.push(url); self.props.history && self.props.history.push(url);
self.props && self.props.updateCollapsed && self.props.updateCollapsed(false); self.props && self.props.updateCollapsed && self.props.updateCollapsed(false);
window.share.event.emit('triggerMicro', this.props.global); window.share.event.emit('triggerMicro', this.props.global);
onChangeVisible ? onChangeVisible(false) : window.share.event.emit('changeSiteVisible', false); window.share.event.emit('changeSiteVisible', { currentStationName: item.groupName, visible: false });
}); });
login.init(); login.init();
} }
...@@ -359,15 +359,14 @@ class Site { ...@@ -359,15 +359,14 @@ class Site {
const { token } = this.globalConfig.userInfo; const { token } = this.globalConfig.userInfo;
this.setLoading(true); this.setLoading(true);
if (token) { if (token) {
window.share.event.emit('updateSite', { ...item, currentStationName: item.groupName }); this.beforeChangeCheck(token, site, onChangeVisible, actionRef, item);
this.beforeChangeCheck(token, site, onChangeVisible, actionRef);
} else { } else {
this.setLoading(false); this.setLoading(false);
message.warning('切换企业失败'); message.warning('切换企业失败');
} }
} }
beforeChangeCheck(token, site, onChangeVisible, actionRef) { beforeChangeCheck(token, site, onChangeVisible, actionRef, item) {
const userParam = { const userParam = {
token, token,
subOID: 'subOID', subOID: 'subOID',
...@@ -405,17 +404,17 @@ class Site { ...@@ -405,17 +404,17 @@ class Site {
const accessToken = tokenRes.data?.access_token ?? null; const accessToken = tokenRes.data?.access_token ?? null;
config.access_token = accessToken; config.access_token = accessToken;
localStorage.setItem('access_token', accessToken); localStorage.setItem('access_token', accessToken);
this.writeCookie(token, site, onChangeVisible, actionRef, accessToken); this.writeCookie(token, site, onChangeVisible, actionRef, accessToken, item);
}) })
.catch(err => { .catch(err => {
this.setLoading(false); this.setLoading(false);
config.access_token = null; config.access_token = null;
this.writeCookie(token, site, onChangeVisible, actionRef, null); this.writeCookie(token, site, onChangeVisible, actionRef, null, item);
}); });
} else { } else {
config.access_token = null; config.access_token = null;
localStorage.setItem('access_token', null); localStorage.setItem('access_token', null);
this.writeCookie(token, site, onChangeVisible, actionRef, null); this.writeCookie(token, site, onChangeVisible, actionRef, null, item);
} }
}) })
.catch(err => { .catch(err => {
......
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