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

fix: 站点获取修改

parent 4f07d3f9
Pipeline #78708 passed with stages
......@@ -326,6 +326,7 @@ const Layout = props => {
const [cityData, setCityData] = useState({});
const [siteLoading, setSiteLoading] = useState(false);
const [siteAction, setSiteAction] = useState(() => new Site(props, setSiteLoading));
const [cityLoading, setCityLoading] = useState(false);
const [menuLoading, setMenuLoading] = useState(true);
const [subLoading, setSubLoading] = useState(true);
const [initWebContent, setInitWebContent] = useState(false);
......@@ -387,13 +388,15 @@ const Layout = props => {
props.global.userInfo &&
props.global.userInfo.token !== null &&
props.global.userInfo.loginName &&
Object.keys(cityData).length === 0
Object.keys(cityData).length === 0 &&
!cityLoading
) {
siteAction.getCityStationsForUser().then(res => {
setCityLoading(true);
siteAction.getCityStationsForUser(props.global.userInfo?.Groups).then(res => {
setCityData(res);
});
}
}, [cityData, props.global, props.global.userInfo, siteAction]);
}, [cityData, cityLoading, props.global, props.global.userInfo, siteAction]);
useEffect(() => {
if (window?.globalConfig?.isIntegration >= 1) {
......
......@@ -53,167 +53,149 @@ class Site {
}
}
getCityStationsForUser() {
const { token } = this.globalConfig.userInfo;
getCityStationsForUser(response) {
const self = this;
return new Promise((resolve, reject) => {
// eslint-disable-next-line no-undef
appService
.getAllGroupsInfoForUser({
token,
'request.preventCache': new Date().getTime(),
ignoreSite: true,
})
.then(res => {
if (res && res.code === 0) {
const result = res.data || [];
let city = self.weatherCity;
let arr = [];
self.globalConfig.userInfo.groupType = '';
self.globalConfig.userInfo.Groups = result;
// eslint-disable-next-line no-array-constructor
self.globalConfig.userInfo.Industries = new Array();
if (self.globalConfig.userInfo.Groups && self.globalConfig.userInfo.Groups.length) {
self.globalConfig.userInfo.Groups.forEach(group => {
if (group.industry && self.globalConfig.userInfo.Industries.indexOf(group.industry) < 0)
self.globalConfig.userInfo.Industries.push(group.industry);
});
}
if (
self.globalConfig.userInfo &&
self.globalConfig.userInfo.site &&
self.globalConfig.userInfo.Groups &&
self.globalConfig.userInfo.Groups.length
) {
// eslint-disable-next-line no-underscore-dangle
const _indestryItem = self.globalConfig.userInfo.Groups.find(
// eslint-disable-next-line eqeqeq
item => item.site === self.globalConfig.userInfo.site,
);
if (_indestryItem && _indestryItem.industry) {
self.globalConfig.Industry = _indestryItem.industry;
}
}
if (response) {
const result = response || [];
let city = self.weatherCity;
let arr = [];
self.globalConfig.userInfo.groupType = '';
self.globalConfig.userInfo.Groups = result;
// eslint-disable-next-line no-array-constructor
self.globalConfig.userInfo.Industries = new Array();
if (self.globalConfig.userInfo.Groups && self.globalConfig.userInfo.Groups.length) {
self.globalConfig.userInfo.Groups.forEach(group => {
if (group.industry && self.globalConfig.userInfo.Industries.indexOf(group.industry) < 0)
self.globalConfig.userInfo.Industries.push(group.industry);
});
}
if (
self.globalConfig.userInfo &&
self.globalConfig.userInfo.site &&
self.globalConfig.userInfo.Groups &&
self.globalConfig.userInfo.Groups.length
) {
// eslint-disable-next-line no-underscore-dangle
const _indestryItem = self.globalConfig.userInfo.Groups.find(
// eslint-disable-next-line eqeqeq
item => item.site === self.globalConfig.userInfo.site,
);
if (_indestryItem && _indestryItem.industry) {
self.globalConfig.Industry = _indestryItem.industry;
}
}
let allStation = [];
let projectStation = [];
self.showStations = [];
if (self.globalConfig.Industry) {
allStation = result.filter(item => item.industry === self.globalConfig.Industry);
self.showStations = allStation.filter(item => item.promoteIndex && item.promoteIndex > 0);
projectStation = allStation.filter(item => !item.promoteIndex);
} else {
allStation = result;
}
let allStation = [];
let projectStation = [];
self.showStations = [];
if (self.globalConfig.Industry) {
allStation = result.filter(item => item.industry === self.globalConfig.Industry);
self.showStations = allStation.filter(item => item.promoteIndex && item.promoteIndex > 0);
projectStation = allStation.filter(item => !item.promoteIndex);
} else {
allStation = result;
}
if (allStation.length) {
let allChoice = false;
allStation.forEach(val => {
if (val.promoteIndex === 0) {
allChoice = true;
}
});
if (!allChoice) {
// me.$el.find('#changeCityWays').hide();
// me.$el.find('.LMBcityBox').hide();
// me.$el.find('div.cities').css('min-width', 'initial');
// me.$el.find('.focusStations').addClass('LMBcolumnList');
}
if (allStation.length > 120) {
// $(me.el).find("div.cities div.cityContent").css("height", '335px');
}
// eslint-disable-next-line no-underscore-dangle
let _enterprise = null;
if (self.globalConfig.userInfo.site && self.globalConfig.userInfo.site.length) {
_enterprise = allStation.filter(
enterprise =>
// eslint-disable-next-line eqeqeq
enterprise.site === self.globalConfig.userInfo.site,
);
}
if (_enterprise && _enterprise.length) {
if (_enterprise[0].groupName.indexOf('演示' >= 0)) {
arr[0] = _enterprise[0].groupName;
} else {
arr = _enterprise[0].city.split('/');
}
const tmp = _enterprise[0].city.split('/')[1];
city = tmp.substr(0, tmp.length - 1);
self.globalConfig.userInfo.groupType = _enterprise[0].groupType;
} else {
arr = allStation[0].city.split('/');
const tmp = arr[1];
city = tmp.substr(0, tmp.length - 1);
self.globalConfig.userInfo.groupType = allStation[0].groupType;
}
}
if (allStation.length > 0) {
self.currentStationName = arr[arr.length - 1];
self.citySelector = self.AvailableofRegionName(projectStation);
self.siteCityList = self.buildCitySelectTemple(projectStation);
if (allStation.length) {
let allChoice = false;
allStation.forEach(val => {
if (val.promoteIndex === 0) {
allChoice = true;
}
// 只有演示环境出现友好提示
if (allStation.length === self.showStations.length) {
self.isOnlyDisplay = true;
});
if (!allChoice) {
// me.$el.find('#changeCityWays').hide();
// me.$el.find('.LMBcityBox').hide();
// me.$el.find('div.cities').css('min-width', 'initial');
// me.$el.find('.focusStations').addClass('LMBcolumnList');
}
if (allStation.length > 120) {
// $(me.el).find("div.cities div.cityContent").css("height", '335px');
}
// eslint-disable-next-line no-underscore-dangle
let _enterprise = null;
if (self.globalConfig.userInfo.site && self.globalConfig.userInfo.site.length) {
_enterprise = allStation.filter(
enterprise =>
// eslint-disable-next-line eqeqeq
enterprise.site === self.globalConfig.userInfo.site,
);
}
if (_enterprise && _enterprise.length) {
if (_enterprise[0].groupName.indexOf('演示' >= 0)) {
arr[0] = _enterprise[0].groupName;
} else {
self.citySelector = self.AvailableofRegionName(projectStation);
self.siteCityList = self.buildCitySelectTemple(projectStation);
arr = _enterprise[0].city.split('/');
}
const tmp = _enterprise[0].city.split('/')[1];
city = tmp.substr(0, tmp.length - 1);
self.globalConfig.userInfo.groupType = _enterprise[0].groupType;
} else {
arr = allStation[0].city.split('/');
const tmp = arr[1];
city = tmp.substr(0, tmp.length - 1);
self.globalConfig.userInfo.groupType = allStation[0].groupType;
}
}
if (allStation.length > 0) {
self.currentStationName = arr[arr.length - 1];
self.citySelector = self.AvailableofRegionName(projectStation);
self.siteCityList = self.buildCitySelectTemple(projectStation);
}
// 只有演示环境出现友好提示
if (allStation.length === self.showStations.length) {
self.isOnlyDisplay = true;
} else {
self.citySelector = self.AvailableofRegionName(projectStation);
self.siteCityList = self.buildCitySelectTemple(projectStation);
}
// eslint-disable-next-line no-unused-expressions
self.updateConfig && self.updateConfig(self.globalConfig);
const stations = self.insertYSStation();
if (city) {
// eslint-disable-next-line no-undef
appService
.getWeather({
city,
'request.preventCache': new Date().getTime(),
ignoreSite: true,
})
// eslint-disable-next-line no-shadow
.then(res => {
if (res.say.statusCode === ERR_OK) {
const firtValue = res.getMe[0];
if (firtValue.cityName) {
const text = firtValue.forcastFirst.split(' ')[1];
const imgPath = firtValue.presentPictureFirst.replace('gif', 'svg');
resolve({
stations,
allStation,
weathers: {
icon: `https://panda-water.cn/web4/assets/images/weather2/${imgPath}`,
text: `${text} ${firtValue.temperatureFirst}`,
},
siteCityList: self.siteCityList,
citySelector: self.citySelector,
currentStationName: self.currentStationName,
});
}
} else {
resolve({
stations,
allStation,
siteCityList: self.siteCityList,
citySelector: self.citySelector,
currentStationName: self.currentStationName,
weathers: {},
});
}
})
.catch(error => {
// eslint-disable-next-line no-unused-expressions
self.updateConfig && self.updateConfig(self.globalConfig);
const stations = self.insertYSStation();
if (city) {
// eslint-disable-next-line no-undef
appService
.getWeather({
city,
'request.preventCache': new Date().getTime(),
ignoreSite: true,
})
// eslint-disable-next-line no-shadow
.then(res => {
if (res.say.statusCode === ERR_OK) {
const firtValue = res.getMe[0];
if (firtValue.cityName) {
const text = firtValue.forcastFirst.split(' ')[1];
const imgPath = firtValue.presentPictureFirst.replace('gif', 'svg');
resolve({
stations,
allStation,
currentStationName: self.currentStationName,
weathers: {},
weathers: {
icon: `https://panda-water.cn/web4/assets/images/weather2/${imgPath}`,
text: `${text} ${firtValue.temperatureFirst}`,
},
siteCityList: self.siteCityList,
citySelector: self.citySelector,
currentStationName: self.currentStationName,
});
}
} else {
resolve({
stations,
allStation,
siteCityList: self.siteCityList,
citySelector: self.citySelector,
currentStationName: self.currentStationName,
weathers: {},
});
} else {
}
})
.catch(error => {
resolve({
stations,
allStation,
......@@ -222,9 +204,18 @@ class Site {
siteCityList: self.siteCityList,
citySelector: self.citySelector,
});
}
}
});
});
} else {
resolve({
stations,
allStation,
currentStationName: self.currentStationName,
weathers: {},
siteCityList: self.siteCityList,
citySelector: self.citySelector,
});
}
}
});
}
......
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