diff --git a/src/basePage/iot/index.tsx b/src/basePage/iot/index.tsx index f2b5718..bc20f5f 100644 --- a/src/basePage/iot/index.tsx +++ b/src/basePage/iot/index.tsx @@ -1,4 +1,4 @@ -import { Image, View } from "@tarojs/components" +import { Image, Text, View } from "@tarojs/components" import { useEffect, useState } from "react" import onlineIcon from '../../assets/images/icons/online.png' import offlineIcon from '../../assets/images/icons/offline.png' @@ -7,6 +7,7 @@ import img from '../../assets/images/img.png' import Taro from "@tarojs/taro" import TabWrapper from "../../components/customized/tabWrapper" import { request } from "../../config/axios" +import { ScrollView } from "@tarojs/components" const getDeviceList = (data) => { return request({ @@ -16,6 +17,23 @@ const getDeviceList = (data) => { }) } +const UrlMap = { + '气象监测': '/iotManager/weatherStation/index?id=1', + '土壤监测': '/iotManager/soilMoisture/index?id=1', + '虫情监测': '', + '环境检测': '', + '其他摄像头': '', + '棚内环境监测': '/iotManager/envMonitor/index?id=1', + '设备监控': '/iotManager/deviceMonitor/index?id=1' +} + +const getDeviceInfoCard = () => { + return request({ + url: '/agriculture/big-screen/deviceInfoCard', + method: 'GET' + }) +} + const getBaseInfo = (data) => { return request({ url: '/agriculture/big-screen/getParkBaseInfo', @@ -30,6 +48,46 @@ const Iot = () => { title: '全部' }]) + const refreshFunc = ():Promise => { + return new Promise((resolve, reject) => { + if (selectedMenuId === 'all') { + getDeviceInfoCard().then(({ data }) => { + if (Array.isArray(data.category)) { + setDataList(data.category.map((item, index) => ({ + id: index, + title: item.categoryName, + value: item.total, + online: item.online, + offline: item.offline, + error: item.fault, + img: item.imgId, + url: UrlMap[item.categoryName] + }))) + } + resolve() + }).catch(() => { resolve() }) + return + } + if (!selectedMenuId) return; + getDeviceList({ parkId: selectedMenuId }).then(({ data }) => { + setDataList(data.map((item, index) => ({ + id: index, + title: item.categoryName, + value: item.total, + online: item.online, + offline: item.offline, + error: item.fault, + img: item.imgId, + url: UrlMap[item.categoryName] + }))) + resolve() + }).catch(() => { resolve() }) + }) + } + useEffect(() => { + refreshFunc() + }, [selectedMenuId]) + const getTopMenuList = async () => { const { data } = await getBaseInfo({ parentId: '0' }) if (Array.isArray(data)) setTopMenus([{ @@ -43,102 +101,91 @@ const Iot = () => { useEffect(() => { getTopMenuList() - getDeviceList({ - parkId: 1 - }).then(res => { - console.log('getDeviceList', res); + getDeviceInfoCard().then(({ data }) => { + if (Array.isArray(data.category)) { + setDataList(data.category.map((item, index) => ({ + id: index, + title: item.categoryName, + value: item.total, + online: item.online, + offline: item.offline, + error: item.fault, + img: item.imgId, + url: UrlMap[item.categoryName] + }))) + } }) }, []) - const dataList = [ - { - id: '1', - title: '气象站', - value: 3, - online: 3, - offline: 0, - error: 0, - url: '/iotManager/weatherStation/index?id=1' - }, - { - id: '2', - title: '土壤墒情', - value: 4, - online: 3, - offline: 1, - error: 0, - url: '/iotManager/soilMoisture/index?id=1' - }, - { - id: '3', - title: '棚内环境监测', - value: 3, - online: 3, - offline: 0, - error: 0, - url: '/iotManager/envMonitor/index?id=1' - }, - { - id: '4', - title: '设备监控', - value: 3, - online: 3, - offline: 0, - error: 0, - url: '/iotManager/deviceMonitor/index?id=1' - }, - { - id: '5', - title: '气象站', - value: 3, - online: 3, - offline: 0, - error: 0, - url: '/iotManager/envMonitor/index?id=1' - }, - ] + const [dataList, setDataList] = useState>([]) + + const [refreshTrigger, setRefreshTrigger] = useState(false) return ( - - { - dataList.map(item => { - return ( - { - Taro.navigateTo({ url: item.url }) - }} - > - - - - - { item.title } - - - - 在线 - 3 + + { + console.log('触发下拉刷新'); + setRefreshTrigger(true) + refreshFunc().then(() => setRefreshTrigger(false)) + }} + > + { + dataList.map(item => { + return ( + { + console.log('跳转到-> ', item.url); + + Taro.navigateTo({ url: item.url }) + }} + > + + + + + + { item.title } + { item.value } - - - 离线 - 3 - - - - 故障 - 3 + + + + 在线 + {item.online} + + + + 离线 + {item.offline} + + + + 故障 + {item.error} + - - ) - }) - } + ) + }) + } + + + {/* + + */} ) diff --git a/src/components/customized/tabWrapper/index.tsx b/src/components/customized/tabWrapper/index.tsx index b1d17cf..ed77e89 100644 --- a/src/components/customized/tabWrapper/index.tsx +++ b/src/components/customized/tabWrapper/index.tsx @@ -9,22 +9,24 @@ import Taro from "@tarojs/taro" */ const TabWrapper = ({ options, selectedId = '', callback }) => { return ( - - { - options.map((item:any) => { - return ( - { - Taro.vibrateShort({ type: 'light' }) - callback(item.id) - }} - >{ item.title } - ) - }) - } + + + { + options.map((item:any) => { + return ( + { + Taro.vibrateShort({ type: 'light' }) + callback(item.id) + }} + >{ item.title } + ) + }) + } + ) } diff --git a/src/iotManager/apis/index.ts b/src/iotManager/apis/index.ts new file mode 100644 index 0000000..35bbc88 --- /dev/null +++ b/src/iotManager/apis/index.ts @@ -0,0 +1,19 @@ +import { request } from "src/config/axios" + +// 获取实时数据 deviceType -> 设备类型 belongPark -> 园区ID belongPlot -> 地块ID +export const runTimeData = (data) => { + return request({ + url: '/agriculture/big-screen/environmentData', + method: 'GET', + data + }) +} + +// 数据监测 deviceType -> 设备类型 belongPark -> 园区ID belongPlot -> 地块ID +export const dataMonitor = (data) => { + return request({ + url: '/agriculture/big-screen/environmentView', + method: 'GET', + data + }) +} \ No newline at end of file diff --git a/src/iotManager/soilMoisture/index.tsx b/src/iotManager/soilMoisture/index.tsx index 1badd25..55639f9 100644 --- a/src/iotManager/soilMoisture/index.tsx +++ b/src/iotManager/soilMoisture/index.tsx @@ -9,6 +9,7 @@ import IconLabelValue from "../../components/iot/iconLabelValue"; import SubTitle from "../../components/iot/subTitle"; import BasicStatus from "../../components/iot/basicStatus"; import PageWrapper from "../../components/customized/pageWrapper"; +import TabWrapper from "../../components/customized/tabWrapper"; const GridContainer = ({ children }) => { return ( @@ -98,21 +99,8 @@ const SoilMoisture = () => { return ( + - - { - deviceList.map(item => { - return ( - setCurDeviceId(item.id)} - >{ item.title } - ) - }) - } - diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 76f93f7..264691e 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -27,12 +27,9 @@ const getTenantId = (data) => { const autoLoginCheck = async () => { const expireTime = Taro.getStorageSync('expiresTime') const nowTime = new Date().valueOf() - console.log('expireTime', expireTime); - console.log('nowTime', nowTime); - console.log('expireTime', expireTime - nowTime); if (expireTime) { - if ((nowTime - expireTime) > 1000 * 60 * 15) { + if ((expireTime - nowTime) > 1000 * 60 * 15) { // 过期时间大于15分钟 Taro.redirectTo({ url: '/basePage/index/index' }) } else {