提交 d51d5b1a 作者: 方治民

chore: 调整农场详情地图页面细节

上级 8b78dc8e
...@@ -83,7 +83,9 @@ ...@@ -83,7 +83,9 @@
} }
if (button.type === 'button') { if (button.type === 'button') {
button.handle?.({ type: 'click', name: button.name }) button.handle?.({ type: 'click', name: button.name, button })
} else if (button.type === 'toggle') {
button.handle?.({ type: 'toggle', name: button.name, button })
} else if (button.type === 'select') { } else if (button.type === 'select') {
// 打开 Select 组件 // 打开 Select 组件
model.selectPopup.title = button.name model.selectPopup.title = button.name
......
...@@ -2,16 +2,19 @@ import type { BasicWidgetInstance, BasicWidgetProps } from '../../utils' ...@@ -2,16 +2,19 @@ import type { BasicWidgetInstance, BasicWidgetProps } from '../../utils'
export interface ToolBoxButtonHandleEvent { export interface ToolBoxButtonHandleEvent {
// 事件类型 // 事件类型
type: 'click' | 'change' type: 'click' | 'change' | 'toggle'
// 事件名称 // 事件名称
name: string name: string
// 事件值 // 事件值
value?: string | string[] | { text: string; value: string } | { text: string; value: string }[] value?: string | string[] | { text: string; value: string } | { text: string; value: string }[]
// 按钮本身
button?: ToolBoxButton
} }
export interface ToolBoxButton { export interface ToolBoxButton {
// 按钮类型 // 按钮类型
type: 'select' | 'button' | 'filter' type: 'select' | 'button' | 'filter' | 'toggle'
// 按钮名称 // 按钮名称
name: string name: string
// 按钮图标 // 按钮图标
......
...@@ -351,7 +351,7 @@ ...@@ -351,7 +351,7 @@
"titleNView": { "titleNView": {
"buttons": [ "buttons": [
{ {
"text": "\ue674 地图模式", "text": "\uE674 地图模式",
"fontSrc": "/static/fonts/tihuan.ttf", "fontSrc": "/static/fonts/tihuan.ttf",
"color": "#fff", "color": "#fff",
"fontSize": "26rpx", "fontSize": "26rpx",
...@@ -567,7 +567,7 @@ ...@@ -567,7 +567,7 @@
{ {
"path": "pages/nongchang/detail/index", "path": "pages/nongchang/detail/index",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "农场",
"enablePullDownRefresh": false, "enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#5DB66F", "navigationBarBackgroundColor": "#5DB66F",
"navigationBarTextStyle": "white", "navigationBarTextStyle": "white",
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
addDefaultSymbolLayer, addDefaultSymbolLayer,
useMapbox, useMapbox,
} from '@/components/Map/Mapbox/hook' } from '@/components/Map/Mapbox/hook'
import type { ToolBoxButtonHandleEvent } from '@/components/Map/Widgets/ToolBox'
import { ToolBoxWidget, useToolBoxWidget } from '@/components/Map/Widgets/ToolBox' import { ToolBoxWidget, useToolBoxWidget } from '@/components/Map/Widgets/ToolBox'
import * as NongchangAPI from '@/api/model/nongchang'
// 页面参数 // 页面参数
const page = reactive<Page>({ const page = reactive<Page>({
...@@ -31,30 +33,58 @@ ...@@ -31,30 +33,58 @@
plots: [], plots: [],
// 设备信息 // 设备信息
devices: [], devices: [],
})
onLoad((options) => {
console.log('页面参数', options)
model.id = options.id
model.name = decodeURIComponent(options.name)
uni.setNavigationBarTitle({ // 天气信息
title: decodeURIComponent(options.name), weather: {
}) live: {
tem: '12°',
phenomena: '',
wind: '',
humidity: '',
},
forecast: [
{
phenomena: '',
date: '',
maxTem: '',
minTem: '',
},
],
},
}) })
// 地图组件 // 地图组件
const center: [number, number] = [111.024108, 29.554847]
const [registerMap, map] = useMapbox({ const [registerMap, map] = useMapbox({
style: { center, zoom: 15 }, style: { zoom: 15 },
onLoaded: (data) => { onLoaded: async (data) => {
console.log('✨✨✨ Map Loaded', data) console.log('✨✨✨ Map Loaded', data)
// 模拟数据 // 查询农场数据
const res = await NongchangAPI.farmsList()
console.log('农场列表', res.records)
// 获取第一个农场信息
const item = res.records?.[0]
model.id = item.id
model.name = item.farmName
model.description = item.description
if (item.longitude && item.latitude) {
model.lonlat = `${item.longitude},${item.latitude}`
} else {
// 模拟位置数据
model.lonlat = '111.024108, 29.554847' model.lonlat = '111.024108, 29.554847'
model.address = '湖南省 张家界市 慈利县 三淹桥村 村委会' Message.toast('未设置农场坐标位置,已使用模拟位置数据')
model.description = '详情信息说明' }
// 设置页面标题
uni.setNavigationBarTitle({
title: item.farmName,
})
// 设置地图中心点
map.flyTo({
center: model.lonlat.split(',').map(Number) as [number, number],
duration: 0,
})
// 渲染地块数据 // 渲染地块数据
model.plots = [ model.plots = [
...@@ -148,8 +178,8 @@ ...@@ -148,8 +178,8 @@
popup: `{{name}}`, popup: `{{name}}`,
}), }),
] ]
addDefaultGeoJSONSource(map, `${page.id}-text`, model.devices) addDefaultGeoJSONSource(map, `${page.id}-symbol`, model.devices)
addDefaultSymbolLayer(map, `${page.id}-text`, { addDefaultSymbolLayer(map, `${page.id}-symbol`, {
layout: { layout: {
'text-field': '', 'text-field': '',
'icon-image': ['get', 'icon'], 'icon-image': ['get', 'icon'],
...@@ -183,9 +213,19 @@ ...@@ -183,9 +213,19 @@
name: '设备', name: '设备',
color: '#75c849', color: '#75c849',
icon: '/static/images/codefun/device.active.png', icon: '/static/images/codefun/device.active.png',
type: 'button', type: 'toggle',
handle: () => { handle: (e: ToolBoxButtonHandleEvent) => {
Message.alert('【设备】功能正在努力开发中...', '') // 切换显示设备数据地图渲染
const active = e.button.icon === '/static/images/codefun/device.active.png'
if (active) {
e.button.color = '#666666'
e.button.icon = '/static/images/codefun/device.png'
map.setLayoutProperty(`${page.id}-symbol`, 'visibility', 'none')
} else {
e.button.color = '#75c849'
e.button.icon = '/static/images/codefun/device.active.png'
map.setLayoutProperty(`${page.id}-symbol`, 'visibility', 'visible')
}
}, },
}, },
], ],
...@@ -196,11 +236,10 @@ ...@@ -196,11 +236,10 @@
buttons: [ buttons: [
{ {
name: '降雨', name: '降雨',
color: '#75c849',
icon: '/static/images/codefun/rain.png', icon: '/static/images/codefun/rain.png',
type: 'button', type: 'button',
handle: () => { handle: () => {
Message.alert('【降雨】功能正在努力开发中...', '') Message.toast('暂无降雨数据')
}, },
}, },
{ {
...@@ -208,7 +247,7 @@ ...@@ -208,7 +247,7 @@
icon: '/static/images/codefun/temp.png', icon: '/static/images/codefun/temp.png',
type: 'button', type: 'button',
handle: () => { handle: () => {
Message.alert('【温度】功能正在努力开发中...', '') Message.toast('暂无温度数据')
}, },
}, },
{ {
...@@ -216,7 +255,7 @@ ...@@ -216,7 +255,7 @@
icon: '/static/images/codefun/severe.png', icon: '/static/images/codefun/severe.png',
type: 'button', type: 'button',
handle: () => { handle: () => {
Message.alert('【强对流】功能正在努力开发中...', '') Message.toast('暂无强对流数据')
}, },
}, },
{ {
...@@ -224,7 +263,7 @@ ...@@ -224,7 +263,7 @@
icon: '/static/images/codefun/wind.png', icon: '/static/images/codefun/wind.png',
type: 'button', type: 'button',
handle: () => { handle: () => {
Message.alert('【大风】功能正在努力开发中...', '') Message.toast('暂无大风数据')
}, },
}, },
{ {
...@@ -232,7 +271,7 @@ ...@@ -232,7 +271,7 @@
icon: '/static/images/codefun/other.png', icon: '/static/images/codefun/other.png',
type: 'button', type: 'button',
handle: () => { handle: () => {
Message.alert('【其他】功能正在努力开发中...', '') Message.alert('敬请期待~', '温馨提醒')
}, },
}, },
], ],
...@@ -265,6 +304,13 @@ ...@@ -265,6 +304,13 @@
<view class="play-wrap hidden"> <view class="play-wrap hidden">
<PlayWidget /> <PlayWidget />
</view> </view>
<!-- 天气信息 -->
<view class="weather-info">
<view>
<view />
</view>
</view>
</view> </view>
</view> </view>
</template> </template>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论