Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
basic-uniapp-v3
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-uniapp-v3
Commits
13efb5af
提交
13efb5af
authored
4月 22, 2026
作者:
吴佳伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 农场页面天气工具
上级
dfadc655
全部展开
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
83 行增加
和
20 行删除
+83
-20
weather.ts
src/api/model/weather.ts
+23
-1
echarts.module.js
src/components/Echarts/src/echarts.module.js
+13
-5
hook.ts
src/components/Echarts/src/hook.ts
+2
-2
index.vue
src/components/Echarts/src/index.vue
+6
-1
WeatherChartPopup.vue
src/pages/nongchang/detail/components/WeatherChartPopup.vue
+0
-0
index.vue
src/pages/nongchang/detail/index.vue
+39
-11
没有找到文件。
src/api/model/weather.ts
浏览文件 @
13efb5af
import
{
weatherHttp
}
from
'/@/utils/http/axios'
import
{
otherHttp
,
weatherHttp
}
from
'/@/utils/http/axios'
const
API_KEY
=
'4fb5c9e814994516b6522419651f2e9e'
const
API_KEY
=
'4fb5c9e814994516b6522419651f2e9e'
...
@@ -22,3 +22,25 @@ export function alarm(location: string) {
...
@@ -22,3 +22,25 @@ export function alarm(location: string) {
url
:
`/weatheralert/v1/current/
${
location
.
replace
(
','
,
'/'
)}
?key=
${
API_KEY
}
`
,
url
:
`/weatheralert/v1/current/
${
location
.
replace
(
','
,
'/'
)}
?key=
${
API_KEY
}
`
,
})
})
}
}
// 格点天气预报-日值(降雨、大风用)
export
function
gridForecastDaily
(
location
:
string
,
day
=
3
)
{
return
weatherHttp
.
get
({
url
:
`/v7/weather/
${
day
}
d?key=
${
API_KEY
}
&location=
${
location
}
`
,
})
}
// 格点天气预报-小时值(温度用)
export
function
gridForecastHourly
(
location
:
string
)
{
return
weatherHttp
.
get
({
url
:
`/v7/weather/24h?key=
${
API_KEY
}
&location=
${
location
}
`
,
})
}
// 强对流预报(自建接口)
export
function
severeForecast
(
lon
:
string
,
lat
:
string
)
{
return
otherHttp
.
get
({
url
:
'/weather/forecast'
,
params
:
{
lon
,
lat
},
},
{
isTransformResponse
:
false
})
}
src/components/Echarts/src/echarts.module.js
浏览文件 @
13efb5af
...
@@ -13,17 +13,17 @@ export default {
...
@@ -13,17 +13,17 @@ export default {
},
},
methods
:
{
methods
:
{
loadLibs
:
loadEchartsLibs
,
loadLibs
:
loadEchartsLibs
,
init
()
{
init
(
notMerge
)
{
// 如果已经初始化过了,就直接更新配置项
// 如果已经初始化过了,就直接更新配置项
if
(
this
.
chart
&&
this
.
chart
.
setOption
)
{
if
(
this
.
chart
&&
this
.
chart
.
setOption
)
{
this
.
chart
.
setOption
(
this
.
option
)
this
.
chart
.
setOption
(
this
.
option
,
{
notMerge
:
notMerge
||
false
}
)
return
return
}
}
// 初始化组件
// 初始化组件
const
chart
=
window
.
echarts
.
init
(
document
.
getElementById
(
this
.
option
.
id
))
const
chart
=
window
.
echarts
.
init
(
document
.
getElementById
(
this
.
option
.
id
))
// 设置图表配置项
// 设置图表配置项
chart
.
setOption
(
this
.
option
)
chart
.
setOption
(
this
.
option
,
{
notMerge
:
notMerge
||
false
}
)
this
.
chart
=
chart
this
.
chart
=
chart
},
},
changeOption
(
option
)
{
changeOption
(
option
)
{
...
@@ -45,12 +45,20 @@ export default {
...
@@ -45,12 +45,20 @@ export default {
}
}
}
}
const
notMerge
=
option
.
__notMerge
// 清除内部标记
delete
option
.
__notMerge
if
(
notMerge
)
{
this
.
option
=
option
}
else
{
this
.
option
=
merge
(
this
.
option
,
option
)
this
.
option
=
merge
(
this
.
option
,
option
)
}
if
(
typeof
window
.
echarts
===
'object'
&&
typeof
window
.
echarts
.
init
===
'function'
)
{
if
(
typeof
window
.
echarts
===
'object'
&&
typeof
window
.
echarts
.
init
===
'function'
)
{
this
.
init
()
this
.
init
(
notMerge
)
}
else
{
}
else
{
this
.
loadLibs
().
then
(()
=>
{
this
.
loadLibs
().
then
(()
=>
{
this
.
init
()
this
.
init
(
notMerge
)
})
})
}
}
},
},
...
...
src/components/Echarts/src/hook.ts
浏览文件 @
13efb5af
...
@@ -44,10 +44,10 @@ export function useEcharts<T extends EchartsInstance, P extends EChartsOption>(
...
@@ -44,10 +44,10 @@ export function useEcharts<T extends EchartsInstance, P extends EChartsOption>(
return
[
return
[
register
,
register
,
{
{
setOption
:
(
option
:
Partial
<
P
>
):
Promise
<
void
>
=>
{
setOption
:
(
option
:
Partial
<
P
>
,
opts
?:
{
notMerge
?:
boolean
;
lazyUpdate
?:
boolean
}
):
Promise
<
void
>
=>
{
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
((
resolve
)
=>
{
tryOnMounted
(()
=>
{
tryOnMounted
(()
=>
{
getInstance
()?.
setOption
(
option
)
getInstance
()?.
setOption
(
option
,
opts
)
resolve
()
resolve
()
})
})
})
})
...
...
src/components/Echarts/src/index.vue
浏览文件 @
13efb5af
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
this
.
$emit
(
'register'
,
this
)
this
.
$emit
(
'register'
,
this
)
},
},
methods
:
{
methods
:
{
setOption
(
option
)
{
setOption
(
option
,
opts
)
{
// 处理tooltip formatter函数序列化
// 处理tooltip formatter函数序列化
if
(
option
.
tooltip
&&
typeof
option
.
tooltip
.
formatter
===
'function'
)
{
if
(
option
.
tooltip
&&
typeof
option
.
tooltip
.
formatter
===
'function'
)
{
// 将函数转换为字符串,在视图层重新构建
// 将函数转换为字符串,在视图层重新构建
...
@@ -25,6 +25,11 @@
...
@@ -25,6 +25,11 @@
id
:
this
.
id
,
id
:
this
.
id
,
...
option
,
...
option
,
}
}
// 保存 opts 供 renderjs 层使用
if
(
opts
?.
notMerge
!==
undefined
)
{
this
.
option
.
__notMerge
=
opts
.
notMerge
}
},
},
},
},
}
}
...
...
src/pages/nongchang/detail/components/WeatherChartPopup.vue
0 → 100644
浏览文件 @
13efb5af
差异被折叠。
点击展开。
src/pages/nongchang/detail/index.vue
浏览文件 @
13efb5af
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
import
{
ToolBoxWidget
,
useToolBoxWidget
}
from
'@/components/Map/Widgets/ToolBox'
import
{
ToolBoxWidget
,
useToolBoxWidget
}
from
'@/components/Map/Widgets/ToolBox'
import
*
as
NongchangAPI
from
'@/api/model/nongchang'
import
*
as
NongchangAPI
from
'@/api/model/nongchang'
import
*
as
farmbaseApi
from
'@/api/model/farmbase'
import
*
as
farmbaseApi
from
'@/api/model/farmbase'
import
WeatherChartPopup
from
'./components/WeatherChartPopup.vue'
// 页面参数
// 页面参数
const
page
=
reactive
<
Page
>
({
const
page
=
reactive
<
Page
>
({
...
@@ -64,7 +65,11 @@
...
@@ -64,7 +65,11 @@
farmbaseInfo
:
{},
farmbaseInfo
:
{},
farmbaseInfoList
:
[],
farmbaseInfoList
:
[],
deviceTypeCount
:
[],
deviceTypeCount
:
[],
activeWeatherType
:
''
as
''
|
'rain'
|
'temp'
|
'wind'
|
'severe'
,
})
})
// 当前基地中心经纬度(用于天气接口请求)
const
baseCenterLonLat
=
ref
<
[
number
,
number
]
|
null
>
(
null
)
onLoad
(()
=>
{
onLoad
(()
=>
{
const
today
=
dayjs
()
const
today
=
dayjs
()
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
...
@@ -113,6 +118,8 @@
...
@@ -113,6 +118,8 @@
if
(
c
[
1
]
>
maxLat
)
maxLat
=
c
[
1
]
if
(
c
[
1
]
>
maxLat
)
maxLat
=
c
[
1
]
}
}
const
center
:
[
number
,
number
]
=
[(
minLon
+
maxLon
)
/
2
,
(
minLat
+
maxLat
)
/
2
]
const
center
:
[
number
,
number
]
=
[(
minLon
+
maxLon
)
/
2
,
(
minLat
+
maxLat
)
/
2
]
// 存储基地中心经纬度,供天气接口使用
baseCenterLonLat
.
value
=
center
// 使用 flyTo 而非 fitBounds,避免 maxBounds 约束干扰
// 使用 flyTo 而非 fitBounds,避免 maxBounds 约束干扰
map
.
flyTo
({
map
.
flyTo
({
center
,
center
,
...
@@ -121,8 +128,10 @@
...
@@ -121,8 +128,10 @@
})
})
}
}
}
else
if
(
res
.
longitude
&&
res
.
latitude
)
{
}
else
if
(
res
.
longitude
&&
res
.
latitude
)
{
const
center
:
[
number
,
number
]
=
[
Number
(
res
.
longitude
),
Number
(
res
.
latitude
)]
baseCenterLonLat
.
value
=
center
map
.
flyTo
({
map
.
flyTo
({
center
:
[
Number
(
res
.
longitude
),
Number
(
res
.
latitude
)]
,
center
,
zoom
:
15
,
zoom
:
15
,
duration
:
1000
,
duration
:
1000
,
})
})
...
@@ -347,15 +356,19 @@
...
@@ -347,15 +356,19 @@
if
(
c
[
1
]
<
minLat
)
minLat
=
c
[
1
]
if
(
c
[
1
]
<
minLat
)
minLat
=
c
[
1
]
if
(
c
[
1
]
>
maxLat
)
maxLat
=
c
[
1
]
if
(
c
[
1
]
>
maxLat
)
maxLat
=
c
[
1
]
}
}
const
center
:
[
number
,
number
]
=
[(
minLon
+
maxLon
)
/
2
,
(
minLat
+
maxLat
)
/
2
]
baseCenterLonLat
.
value
=
center
map
.
flyTo
({
map
.
flyTo
({
center
:
[(
minLon
+
maxLon
)
/
2
,
(
minLat
+
maxLat
)
/
2
]
,
center
,
zoom
:
15
,
zoom
:
15
,
duration
:
0
,
duration
:
0
,
})
})
}
}
}
else
if
(
firstBase
.
longitude
&&
firstBase
.
latitude
)
{
}
else
if
(
firstBase
.
longitude
&&
firstBase
.
latitude
)
{
const
center
:
[
number
,
number
]
=
[
Number
(
firstBase
.
longitude
),
Number
(
firstBase
.
latitude
)]
baseCenterLonLat
.
value
=
center
map
.
flyTo
({
map
.
flyTo
({
center
:
[
Number
(
firstBase
.
longitude
),
Number
(
firstBase
.
latitude
)]
,
center
,
zoom
:
15
,
zoom
:
15
,
duration
:
0
,
duration
:
0
,
})
})
...
@@ -454,33 +467,33 @@
...
@@ -454,33 +467,33 @@
{
{
name
:
'降雨'
,
name
:
'降雨'
,
icon
:
'/static/images/codefun/rain.png'
,
icon
:
'/static/images/codefun/rain.png'
,
type
:
'
button'
,
type
:
'
toggle'
as
const
,
handle
:
()
=>
{
handle
:
()
=>
{
Message
.
toast
(
'暂无降雨数据
'
)
onWeatherClick
(
'rain
'
)
},
},
},
},
{
{
name
:
'温度'
,
name
:
'温度'
,
icon
:
'/static/images/codefun/temp.png'
,
icon
:
'/static/images/codefun/temp.png'
,
type
:
'
button'
,
type
:
'
toggle'
as
const
,
handle
:
()
=>
{
handle
:
()
=>
{
Message
.
toast
(
'暂无温度数据
'
)
onWeatherClick
(
'temp
'
)
},
},
},
},
{
{
name
:
'强对流'
,
name
:
'强对流'
,
icon
:
'/static/images/codefun/severe.png'
,
icon
:
'/static/images/codefun/severe.png'
,
type
:
'
button'
,
type
:
'
toggle'
as
const
,
handle
:
()
=>
{
handle
:
()
=>
{
Message
.
toast
(
'暂无强对流数据
'
)
onWeatherClick
(
'severe
'
)
},
},
},
},
{
{
name
:
'大风'
,
name
:
'大风'
,
icon
:
'/static/images/codefun/wind.png'
,
icon
:
'/static/images/codefun/wind.png'
,
type
:
'
button'
,
type
:
'
toggle'
as
const
,
handle
:
()
=>
{
handle
:
()
=>
{
Message
.
toast
(
'暂无大风数据
'
)
onWeatherClick
(
'wind
'
)
},
},
},
},
{
{
...
@@ -522,6 +535,14 @@
...
@@ -522,6 +535,14 @@
},
},
})
})
}
}
// 天气按钮点击处理
function
onWeatherClick
(
type
:
'rain'
|
'temp'
|
'wind'
|
'severe'
)
{
if
(
model
.
activeWeatherType
===
type
)
{
model
.
activeWeatherType
=
''
}
else
{
model
.
activeWeatherType
=
type
}
}
// 保留原有的导航栏按钮点击回调(如果有需要的话)
// 保留原有的导航栏按钮点击回调(如果有需要的话)
onNavigationBarButtonTap
((
e
)
=>
{
onNavigationBarButtonTap
((
e
)
=>
{
if
(
e
.
index
===
0
)
{
if
(
e
.
index
===
0
)
{
...
@@ -736,6 +757,13 @@
...
@@ -736,6 +757,13 @@
@
submit-success=
"getDeviceTypeCount"
@
submit-success=
"getDeviceTypeCount"
@
close=
"showDialog = false"
@
close=
"showDialog = false"
/>
/>
<WeatherChartPopup
:visible=
"model.activeWeatherType !== ''"
:type=
"model.activeWeatherType"
:lon=
"baseCenterLonLat?.[0] ?? ''"
:lat=
"baseCenterLonLat?.[1] ?? ''"
@
close=
"model.activeWeatherType = ''"
/>
</view>
</view>
</
template
>
</
template
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论