refactor(weather): 移除天气接口请求函数并改为使用props调用
parent
b56fd35bbc
commit
405c4f74bc
|
|
@ -52,7 +52,7 @@ function WorkPanel(props) {
|
|||
}, []);
|
||||
return (
|
||||
<Panel title="重点作业管理统计" className="index-info-right-panel__work">
|
||||
<Spin spinning={props.biStatistics.indexInfoEightWorkLoading}>
|
||||
<Spin spinning={props.biStatistics.indexInfoEightWorkLoading || props.biStatistics.indexInfoKeyProjectLoading}>
|
||||
<div className="index-info-work__list">
|
||||
{list.map(item => (
|
||||
<div className="index-info-work__item" key={item.name}>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import { Connect } from "@cqsjjb/jjb-dva-runtime";
|
||||
import { useMount } from "ahooks";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import SeamlessScroll from "zy-react-library/components/SeamlessScroll";
|
||||
import icon1 from "~/assets/images/public/bigScreen/img10.png";
|
||||
import icon2 from "~/assets/images/public/bigScreen/img11.png";
|
||||
import { NS_BI_STATISTICS } from "~/enumerate/namespace";
|
||||
import Title from "~/pages/Container/Map/components/Content/branchOffice/Title";
|
||||
import { getAlertColor, getWeather, getWeatherIcon } from "~/utils/weather";
|
||||
import { getAlertColor, getWeatherIcon } from "~/utils/weather";
|
||||
import { initEcharts1 } from "./echarts";
|
||||
import "./index.less";
|
||||
|
||||
function IndexLeft() {
|
||||
function IndexLeft(props) {
|
||||
const [weatherData, setWeatherData] = useState({});
|
||||
const [alert, setAlert] = useState([]);
|
||||
const [block1List, setBlock1List] = useState([
|
||||
|
|
@ -46,7 +48,7 @@ function IndexLeft() {
|
|||
const main1Ref = useRef(null);
|
||||
|
||||
const getWeatherData = async () => {
|
||||
const result = await getWeather();
|
||||
const { result = {} } = await props.getWeather();
|
||||
setWeatherData(result.now);
|
||||
setAlert(Array.isArray(result.alerts) ? result.alerts : []);
|
||||
};
|
||||
|
|
@ -215,4 +217,4 @@ function IndexLeft() {
|
|||
);
|
||||
}
|
||||
|
||||
export default IndexLeft;
|
||||
export default Connect([NS_BI_STATISTICS], true)(IndexLeft);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import { Connect } from "@cqsjjb/jjb-dva-runtime";
|
||||
import { useEffect, useState } from "react";
|
||||
import SeamlessScroll from "zy-react-library/components/SeamlessScroll";
|
||||
import icon3 from "~/assets/images/public/bigScreen/ico21.png";
|
||||
import icon1 from "~/assets/images/public/bigScreen/img10.png";
|
||||
import icon2 from "~/assets/images/public/bigScreen/img11.png";
|
||||
import { NS_BI_STATISTICS } from "~/enumerate/namespace";
|
||||
import Title from "~/pages/Container/Map/components/Content/branchOffice/Title";
|
||||
import { getAlertColor, getWeather, getWeatherIcon } from "~/utils/weather";
|
||||
import { getAlertColor, getWeatherIcon } from "~/utils/weather";
|
||||
import "./index.less";
|
||||
|
||||
function QiXiang() {
|
||||
function QiXiang(props) {
|
||||
const [weatherData, setWeatherData] = useState({});
|
||||
const [alert, setAlert] = useState([]);
|
||||
const [block1List, setBlock1List] = useState([
|
||||
|
|
@ -36,7 +38,7 @@ function QiXiang() {
|
|||
]);
|
||||
|
||||
const getWeatherData = async () => {
|
||||
const result = await getWeather();
|
||||
const { result = {} } = await props.getWeather();
|
||||
setWeatherData(result.now);
|
||||
setAlert(Array.isArray(result.alerts) ? result.alerts : []);
|
||||
};
|
||||
|
|
@ -147,4 +149,4 @@ function QiXiang() {
|
|||
);
|
||||
}
|
||||
|
||||
export default QiXiang;
|
||||
export default Connect([NS_BI_STATISTICS], true)(QiXiang);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import { Connect } from "@cqsjjb/jjb-dva-runtime";
|
||||
import { useEventListener, useMount } from "ahooks";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import SeamlessScroll from "zy-react-library/components/SeamlessScroll";
|
||||
import { NS_BI_STATISTICS } from "~/enumerate/namespace";
|
||||
import Title from "~/pages/Container/White/BranchOffice/components/Title";
|
||||
import { getAlertColor, getWeather, getWeatherIcon } from "~/utils/weather";
|
||||
import { getAlertColor, getWeatherIcon } from "~/utils/weather";
|
||||
import { initEcharts1, initEcharts2, initEcharts3, initEcharts4, initEcharts5 } from "./echarts";
|
||||
import "./index.less";
|
||||
|
||||
const block3_2TabsList = ["年度", "季度"];
|
||||
function CenterPanel() {
|
||||
function CenterPanel(props) {
|
||||
const [weatherData, setWeatherData] = useState({});
|
||||
const [alert, setAlert] = useState([]);
|
||||
const [block1_2List, setBlock1_2List] = useState([
|
||||
|
|
@ -42,7 +44,7 @@ function CenterPanel() {
|
|||
const main5Ref = useRef(null);
|
||||
|
||||
const getWeatherData = async () => {
|
||||
const result = await getWeather();
|
||||
const { result = {} } = await props.getWeather();
|
||||
setWeatherData(result.now);
|
||||
setAlert(Array.isArray(result.alerts) ? result.alerts : []);
|
||||
};
|
||||
|
|
@ -291,4 +293,4 @@ function CenterPanel() {
|
|||
);
|
||||
}
|
||||
|
||||
export default CenterPanel;
|
||||
export default Connect([NS_BI_STATISTICS], true)(CenterPanel);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { message } from "antd";
|
||||
import SunIcon from "~/assets/images/public/weather/1.png";
|
||||
import CloudIcon from "~/assets/images/public/weather/2.png";
|
||||
import CloudSunIcon from "~/assets/images/public/weather/3.png";
|
||||
|
|
@ -16,30 +15,6 @@ import HazeIcon from "~/assets/images/public/weather/14.png";
|
|||
import DustIcon from "~/assets/images/public/weather/15.png";
|
||||
import DuststormIcon from "~/assets/images/public/weather/16.png";
|
||||
|
||||
const WEATHER_URL = "https://api.map.baidu.com/weather/v1/?district_id=130300&data_type=all&ak=dIqOi34IlTg5FkNck1vqoBpLhPAj36S1";
|
||||
|
||||
/**
|
||||
* 获取秦皇岛市天气数据。
|
||||
* 统一校验 HTTP 状态和百度接口业务状态,调用方只处理页面展示状态。
|
||||
* @param {{ signal?: AbortSignal }} options 请求配置,可传入 signal 取消请求。
|
||||
* @returns {Promise<object>} 百度天气接口 result 数据。
|
||||
*/
|
||||
export async function getWeather(options = {}) {
|
||||
const response = await fetch(WEATHER_URL, { signal: options.signal });
|
||||
if (!response.ok) {
|
||||
message.error("天气接口请求失败,请检查网络或稍后再试");
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
if (data.status !== 0 || !data.result?.now) {
|
||||
message.error(data.message || "天气接口返回数据异常");
|
||||
return;
|
||||
}
|
||||
|
||||
return data.result;
|
||||
}
|
||||
|
||||
export const weatherIconMap = {
|
||||
晴天: SunIcon,
|
||||
晴: SunIcon,
|
||||
|
|
|
|||
Loading…
Reference in New Issue