Commit cd5f6e04 authored by 单奇雲's avatar 单奇雲

天气查询

parent 0267a1ae
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -7,7 +7,7 @@ const AmosConfig = endConf.AmosConfig; ...@@ -7,7 +7,7 @@ const AmosConfig = endConf.AmosConfig;
const securityBaseWsURI = AmosConfig.wsURI.securityBaseURI; const securityBaseWsURI = AmosConfig.wsURI.securityBaseURI;
// 三维视图 // 三维视图
//const view3dURI = AmosConfig.httpURI.view3dURI; //const view3dURI = AmosConfig.httpURI.view3dURI;
const view3dURI = AmosConfig.httpURI.baseURI; const view3dURI = AmosConfig.httpURI.view3dURI;
export const baseURI = AmosConfig.httpURI.baseURI; export const baseURI = AmosConfig.httpURI.baseURI;
//const patrolURI = AmosConfig.httpURI.patrolURI; //const patrolURI = AmosConfig.httpURI.patrolURI;
const patrolURI = AmosConfig.httpURI.baseURI; const patrolURI = AmosConfig.httpURI.baseURI;
...@@ -85,6 +85,7 @@ export const FscSerUrl = { ...@@ -85,6 +85,7 @@ export const FscSerUrl = {
statisticsCheckUrl: completePrefix(patrolURI, 'api/view3d/statistics/check'),//今日巡检统计接口 statisticsCheckUrl: completePrefix(patrolURI, 'api/view3d/statistics/check'),//今日巡检统计接口
statisticsDutyUrl: completePrefix(patrolURI, 'api/view3d/statistics/duty'), //今日值班统计 statisticsDutyUrl: completePrefix(patrolURI, 'api/view3d/statistics/duty'), //今日值班统计
onlineDayUrl: completePrefix(patrolURI, 'api/view3d/online/date'), //消防安全执行天数 onlineDayUrl: completePrefix(patrolURI, 'api/view3d/online/date'), //消防安全执行天数
cityWeatherUrl: completePrefix(patrolURI, '/api/weather/{cityCode}'), //天气查询
//******************************************************************************* //*******************************************************************************
......
import { singleFetch } from './../utils/request'; import formatUrl from 'amos-processor/lib/utils/urlFormat';
import { singleFetch, commonGet } from './../utils/request';
import { FscSerUrl } from './../consts/urlConsts';
/** /**
* 获取在线天气 * 获取在线天气
* @param {string} cityKey * @param {string} cityKey
*/ */
export const getOnlineWeather = (cityKey) => { export const getOnlineWeather = (cityCode) => {
const url = `http://wthrcdn.etouch.cn/weather_mini?city=${cityKey}`; // const url = `http://wthrcdn.etouch.cn/weather_mini?city=${cityKey}`;
return singleFetch(url); return commonGet(formatUrl(FscSerUrl.cityWeatherUrl, { cityCode }));
};
export const getWeatherCityCode = () => {
return singleFetch('/src/_mock/weatherCity.json');
}; };
export const conmmonGetService =(url) =>{ export const conmmonGetService = (url) =>{
return singleFetch(url); return singleFetch(url);
} };
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { getOnlineWeather } from './../../../services/commonServices'; import { message } from 'amos-framework';
import { getOnlineWeather,getWeatherCityCode } from './../../../services/commonServices';
class Weather extends Component { class Weather extends Component {
...@@ -22,9 +23,14 @@ class Weather extends Component { ...@@ -22,9 +23,14 @@ class Weather extends Component {
} }
getWeatherInfo = () => { getWeatherInfo = () => {
const { address } = this.props; let { address } = this.props;
getOnlineWeather(address).then((res) => { getWeatherCityCode().then(citys => {
this.parseData(res.data); const curCity = citys.find( e => e.city_name.indexOf(address) > -1 );
getOnlineWeather(curCity.city_code).then((res) => {
this.parseData(res.data);
},error => {
message.danger(`天气(${address})查询失败!`);
});
}); });
} }
...@@ -32,10 +38,10 @@ class Weather extends Component { ...@@ -32,10 +38,10 @@ class Weather extends Component {
const { forecast = [] } = data; const { forecast = [] } = data;
const current = forecast[0]; const current = forecast[0];
if (current){ if (current){
const fengli = current.fengli.replace('<![CDATA\[', '').replace(']]>', ''); // const fengli = current.fengli.replace('<![CDATA\[', '').replace(']]>', '');
const high = current.high.replace('高温', '').trim(); const high = current.high.replace('高温', '').trim();
const low = current.low.replace('低温', '').trim(); const low = current.low.replace('低温', '').trim();
const weatherInfo = `${current.type} ${low}~${high} ${current.fengxiang} ${fengli}`; const weatherInfo = `${current.type} ${low}~${high} ${current.fx} ${current.fl}`;
this.setState({ this.setState({
weatherInfo weatherInfo
}); });
......
...@@ -162,7 +162,9 @@ class RegionSelect extends Component { ...@@ -162,7 +162,9 @@ class RegionSelect extends Component {
let { departments = [], roles = [] } = this.state; let { departments = [], roles = [] } = this.state;
if (key === 'company') { if (key === 'company') {
reginParams.company = companys.find(item => item.sequenceNbr === value); let company = companys.find(item => item.sequenceNbr === value);
reginParams.company = company;
reginParams.address = company.address;
departments = companyDepartments[value]; departments = companyDepartments[value];
roles = orgRoles[value]; roles = orgRoles[value];
} }
......
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