From 405c4f74bc75f8c2e62d2165a35c0b4f178110ae Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Wed, 22 Jul 2026 15:57:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(weather):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=A4=A9=E6=B0=94=E6=8E=A5=E5=8F=A3=E8=AF=B7=E6=B1=82=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=B9=B6=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8props?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IndexInfo/RightPanel/WorkPanel/index.js | 2 +- .../Content/branchOffice/IndexLeft/index.js | 10 +++++--- .../Content/branchOffice/QiXiang/index.js | 10 +++++--- .../components/CenterPanel/index.js | 10 +++++--- src/utils/weather.js | 25 ------------------- 5 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/pages/Container/Map/components/Content/IndexInfo/RightPanel/WorkPanel/index.js b/src/pages/Container/Map/components/Content/IndexInfo/RightPanel/WorkPanel/index.js index 8221853..66dc547 100644 --- a/src/pages/Container/Map/components/Content/IndexInfo/RightPanel/WorkPanel/index.js +++ b/src/pages/Container/Map/components/Content/IndexInfo/RightPanel/WorkPanel/index.js @@ -52,7 +52,7 @@ function WorkPanel(props) { }, []); return ( - +
{list.map(item => (
diff --git a/src/pages/Container/Map/components/Content/branchOffice/IndexLeft/index.js b/src/pages/Container/Map/components/Content/branchOffice/IndexLeft/index.js index 4939f6a..c0edc65 100644 --- a/src/pages/Container/Map/components/Content/branchOffice/IndexLeft/index.js +++ b/src/pages/Container/Map/components/Content/branchOffice/IndexLeft/index.js @@ -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); diff --git a/src/pages/Container/Map/components/Content/branchOffice/QiXiang/index.js b/src/pages/Container/Map/components/Content/branchOffice/QiXiang/index.js index f567355..c7bd917 100644 --- a/src/pages/Container/Map/components/Content/branchOffice/QiXiang/index.js +++ b/src/pages/Container/Map/components/Content/branchOffice/QiXiang/index.js @@ -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); diff --git a/src/pages/Container/White/BranchOffice/components/CenterPanel/index.js b/src/pages/Container/White/BranchOffice/components/CenterPanel/index.js index 1e09941..7a4733c 100644 --- a/src/pages/Container/White/BranchOffice/components/CenterPanel/index.js +++ b/src/pages/Container/White/BranchOffice/components/CenterPanel/index.js @@ -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); diff --git a/src/utils/weather.js b/src/utils/weather.js index d14483d..033866f 100644 --- a/src/utils/weather.js +++ b/src/utils/weather.js @@ -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} 百度天气接口 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,