This commit is contained in:
Iruka 2024-09-26 18:52:14 +08:00
parent ee6dc2b3cf
commit 363cb57b7d
23 changed files with 3615 additions and 151 deletions

20
App.vue
View File

@ -1,11 +1,13 @@
<script>
import indexUtil from "@/utils/indexUtil.js"
import dc from "@/utils/deviceUtil/dc.js"
import mqttUtil from "@/utils/mqttUtil.js"
export default {
data() {
return {
indexData: new indexUtil(), //
indexData: new indexUtil(this.deviceChange), //
dc: new dc(),
mqtt: null,
mqttObj: {
topics: []
@ -36,6 +38,22 @@
console.log('App Hide')
},
methods: {
deviceChange(e) {
console.error("deviceChange", e);
if (e == this.indexData.eventType.land) {
console.error("地块更新通知")
// this.indexData.getNewDeviceList();
}
if (e == this.indexData.eventType.device) {
console.error("设备更新通知")
console.error("dexice:", this.indexData.device)
this.dc.setStations(this.indexData.device.stations);
this.dc.setFlapValves(this.indexData.device.flapValves);
this.dc.setValves(this.indexData.selectItem.id, this.indexData.device.waterOutlets);
console.error("this.dc:",this.dc)
}
},
setTime: function() {
console.error(this.globalData.num);
// setTimeout(() => {

View File

@ -14,4 +14,13 @@ export function getManagerGroundList(userID) {
url: "/landManager/select/" + userID,
method: "get"
})
}
//查询设备列表
export function getDeviceList(data) {
return request({
url: "/device/control/app/listNew2",
method: "get",
data: data
})
}

View File

@ -89,7 +89,8 @@
if (item.id != oldItem.id) {
this.indexData.setStorage(2, item);
this.$emit("select", item);
uni.$emit("notify-updates-land");
this.indexData.onEventHandler(this.indexData.eventType.land);
uni.$emit("notify-update-land");
}
this.close();
},

View File

@ -4,7 +4,7 @@
<block v-slot:left>
<view @click="openLand">地块</view>
</block>
<view>田间</view>
<view>{{ indexData.selectItem ? indexData.selectItem.name:"田间" }}</view>
<block v-slot:right>
<view class="fixed">
<view align="right" class="icon iconfont icon-liebiao" @click="toList"></view>
@ -108,62 +108,32 @@
</view>
</template>
<view class="u-collapse-content">
<u-row>
<u-row v-for="item in dc.stations">
<u-col span="3">
<view class="fixed">
<text class="font-red"></text>
<view>E0000104</view>
<text :class="[item.online ? 'font-green':'font-red']"></text>
<view>{{ item.deviceCode }}</view>
</view>
</u-col>
<u-col span="4" style="align-items: center;">
<view class="fixed">
<view class="signal">
<view class="bar"></view>
<view class="bar"></view>
<view class="bar"></view>
<view class="bar"></view>
<view class="bar"></view>
<!-- <view class="signal" v-if="item.signalValue > 110"> -->
<view class="signal" v-if="item.signalValue > 0">
<view v-for="(_,i) in 4"
:class="['bar',item.signalValue > (8 * i) ? 'green':'']"></view>
<view :class="['bar',item.signalValue > 30 ? 'green':'']"></view>
</view>
<view class="signal" v-else>
<view class="bar" v-for="i in 5"></view>
<view class="bar-no">
<u-icon name="close"></u-icon>
</view>
</view>
<text>(12)</text>
<text>({{ item.signalValue }})</text>
<view class="battery-container">
<text>{{ 10 }}</text>
<view class="battery-level" :style="[`width:${10}%`]" />
</view>
</view>
</u-col>
<u-col span="5">
<view class="fixed">
<u-button type="success" size="mini" text="手持基站"></u-button>
<u-button type="success" size="mini" text="刷新" icon="reload"></u-button>
</view>
</u-col>
</u-row>
<u-row>
<u-col span="3">
<view class="fixed">
<text class="font-green"></text>
<view>E0000104</view>
</view>
</u-col>
<u-col span="4" style="align-items: center;">
<view class="fixed">
<view class="signal">
<view class="bar green"></view>
<view class="bar green"></view>
<view class="bar green"></view>
<view class="bar green"></view>
<view class="bar"></view>
<view class="bar-no" style="display: none;">
<u-icon name="close"></u-icon>
</view>
</view>
<text>(12)</text>
<view class="battery-container">
<text>{{ 60 }}</text>
<view class="battery-level" :style="[`width:${60}%`]" />
<text>{{ item.currentBatteryCapacity }} </text>
<view class="battery-level"
:style="[`width:${item.currentBatteryCapacity}%`]" />
</view>
</view>
</u-col>
@ -176,28 +146,28 @@
</u-row>
</view>
</u-collapse-item>
</u-collapse>
</view>
<!-- 阀门列表 -->
<view class="card">
<u-collapse accordion>
<u-collapse-item>
<u-collapse-item v-for="item in dc.valves">
<template #title>
<view class="sf-title fixed">
<view class="iconfont icon-diefa icon"></view>
<view class="text">A1</view>
<view class="text">{{ item.rowKey }}</view>
<view style="margin:0 10px;">出水口数量</view>
<u-badge numberType="overflow" type="info" max="999" value="155"></u-badge>
<u-badge numberType="overflow" type="info" max="999"
:value="item.children.length || 0" />
</view>
</template>
<view class="u-collapse-content">
<!-- 蝶阀 -->
<u-row>
<u-row v-if="item.deviceId">
<u-col span="4">
<view class="fixed">
<view>A1</view>
<text class="font-green">在线</text>
<text class="font-green"></text>
<view>{{ item.rowKey }}</view>
</view>
</u-col>
<u-col span="5">
@ -213,86 +183,141 @@
</u-col>
</u-row>
<!-- 阀门 -->
<view class="card-grey">
<view class="card-title">
<u-row>
<u-col span="2">
<view><text class="font-green"></text>1-1</view>
</u-col>
<u-col span="5">
<view class="fixed">
<view class="battery-container">
<text>60</text>
<view class="battery-level battery-level-60">
<view v-for="item2 in item.children">
<view v-if="item2.deviceId" class="card-grey">
<view class="card-title">
<u-row>
<u-col span="2">
<view><text class="font-green"></text>{{ item2.rowKey }}</view>
</u-col>
<u-col span="5">
<view class="fixed">
<view class="battery-container">
<text>{{ item2.device.custom.battery.value }}</text>
<view class="battery-level"
:style="[`width:${item2.device.custom.battery.value}%`]" />
</view>
<view>
<view class="iconfont icon-wendu icon" />
{{ item2.device.custom.t }}
</view>
</view>
<view>
<view class="iconfont icon-wendu icon"></view>26.2
</u-col>
<u-col span="5" style="align-items: flex-end;">
<view class="fixed">
<u-button type="success" size="mini" text="刷新"
icon="reload"></u-button>
</view>
</view>
</u-col>
<u-col span="5" style="align-items: flex-end;">
<view class="fixed">
<u-button type="success" size="mini" text="刷新"
icon="reload"></u-button>
</view>
</u-col>
</u-row>
</view>
<view class="control">
<u-row>
<u-col span="3" style=" align-items: flex-end;" @click="angleSliderShow">
<view class="buttons">
<view class="btn fixed active">
<text></text>
<text>0.00</text>
<view class="iconfont icon-suoding icon"></view>
</view>
</view>
<u-line-progress height="8" :showText="false" :percentage="60"
activeColor="#74ffd4" inactiveColor="#c7c7c7"
style="width: 75px;margin-top: 5px;">
</u-line-progress>
</u-col>
<u-col span="6">
<view class="valve">
<view>
<view class="btn fixed">
<text>全开</text>
</view>
</view>
<view class="btn-img">
<view class="text">
<view class="left">-99.63</view>
<view class="top">-99.63</view>
<view class="middle">离线</view>
<view class="right">-99.63</view>
<view class="bottom">-99.63</view>
</view>
<image src="../static/images/valves/valve3-all.gif"
mode="widthFix">
</image>
</view>
<view>
<view class="btn fixed">
<text>全关</text>
</view>
</view>
</view>
</u-col>
<u-col span="3">
<view class="buttons">
<view class="btn fixed">
<text></text>
<text>0.00</text>
<view class="iconfont icon-suoding icon"></view>
</view>
</view>
</u-col>
</u-row>
<view class="font-red">
<view class="iconfont icon-guzhang icon"></view>角度4故障
</u-col>
</u-row>
</view>
<view class="control">
<u-row
v-if="item2.device.deviceTypeId == 2 || item2.device.deviceTypeId == 3">
<u-col span="3" style=" align-items: flex-end;"
@click="angleSliderShow">
<view class="buttons">
<view class="btn fixed active">
<text></text>
<text>(999)</text>
<!-- <view class="iconfont icon-suoding icon"></view> -->
</view>
</view>
<u-line-progress height="8" :showText="false" :percentage="60"
activeColor="#74ffd4" inactiveColor="#c7c7c7"
style="width: 75px;margin-top: 5px;">
</u-line-progress>
</u-col>
<u-col span="6">
<view class="valve">
<view>
<view class="btn fixed">
<text>全开</text>
</view>
</view>
<view class="btn-img">
<view class="text">
<view class="left">{{ item2.device.custom.p1 }}</view>
<view class="top"></view>
<view class="middle"
v-show="!item2.device.custom.online">离线</view>
<view class="right">{{ item2.device.custom.p2 }}</view>
<view class="bottom"></view>
</view>
<image :src="item2.device.custom.showImg" mode="widthFix" />
</view>
<view>
<view class="btn fixed">
<text>全关</text>
</view>
</view>
</view>
</u-col>
<u-col span="3">
<view class="buttons">
<view class="btn fixed">
<text></text>
<text>(超时)</text>
<!-- <view class="iconfont icon-suoding icon"></view> -->
</view>
</view>
</u-col>
</u-row>
<u-row v-if="item2.device.deviceTypeId == 13">
<u-col span="3" style=" align-items: flex-end;">
<view class="buttons">
<view class="btn fixed active">
<text></text>
<text>0.00</text>
<view class="iconfont icon-suoding icon"></view>
</view>
</view>
</u-col>
<u-col span="6">
<view class="valve">
<view>
<view class="btn fixed">
<text></text>
</view>
</view>
<view class="btn-img">
<view class="text5">
<view class="left">{{ item2.device.custom.p[0] }}</view>
<view class="top">{{ item2.device.custom.p[1] }}</view>
<view class="middle"
v-show="!item2.device.custom.online">离线</view>
<view class="right">{{ item2.device.custom.p[2] }}
</view>
<view class="bottom">{{ item2.device.custom.p[3] }}
</view>
</view>
<image :src="item2.device.custom.showImg" mode="widthFix" />
</view>
<view>
<view class="btn fixed">
<text></text>
</view>
</view>
</view>
</u-col>
<u-col span="3">
<view class="buttons">
<view class="btn fixed">
<text></text>
<text>0.00</text>
<view class="iconfont icon-suoding icon"></view>
</view>
</view>
</u-col>
</u-row>
<view class="font-red">
<view class="iconfont icon-guzhang icon"></view>角度4故障
</view>
</view>
</view>
<view v-else class="card-grey">
{{ item2.rowKey }}
</view>
</view>
<view class="card-grey">
@ -372,6 +397,7 @@
</view>
</view>
</view>
</u-collapse-item>
</u-collapse>
</view>
@ -394,20 +420,22 @@
export default {
data() {
return {
isSticky: false,
show: false,
landList: [1, 2, 3],
isSticky: false, //
value: false,
sliderValue: 1,
landDataChange: true,
indexData: getApp().indexData,
dc: getApp().dc,
// show: false,
}
},
onLoad() {
console.error("onLoad")
// uni.$emit("mqtt-link");
uni.$off("notify-updates-land");
uni.$on("notify-updates-land", () => {
console.error("更新数据")
this.landDataChange = true;
uni.$off("notify-update-land");
uni.$on("notify-update-land", () => {
console.error("index监听地块更新")
// this.landDataChange = true;
getApp().indexData.getNewDeviceList();
});
},
onShow() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -10,5 +10,6 @@ const constant = {
rememberPassword: "rememberPassword",
lands: "custom_lands",
landItem: "custom_landItem",
device: "custom_device",
}
export default constant

1260
utils/deviceUtil/dc.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,105 @@
import { getYMDHMS } from "@/utils/deviceUtil/js/common.js"
// 服务商
function facilitator(variate) {
if (variate) {
if (variate.value === "1") {
return "移动"
} else if (variate.value === "2") {
return "电信"
} else if (variate.value === "3") {
return "联通"
}
} else {
return "未知"
}
}
// 鼠标划过要显示的文字
function handleHoverShowText(object, code) {
if (object && object.items) {
let { cs, ns, ls } = object.items
let { b, bb, cc, g, l, mcu, ps, t } = object.items.adcProperty
return [
// ["基站编码:", code],
["充电状态:", cs.value],
["433环境噪声", ls.value],
["4G信号强度(%)", ns.value],
["电池ADC(V)", b],
["电池ADC(%)", Number(bb) > 100 ? 100 : bb],
["433ADC(V)", l],
["MCUADC(V) ", mcu],
["4G供电ADC(V)", g],
["MCU温度ADC(℃)", t],
["充电电流ADC(mA)", cc],
["充电电压ADC(V)", ps],
["数据上报时间:", getYMDHMS(object.time)]
]
} else {
return false
}
}
// 处理单条数据
export function alone(obj, state) {
let { status, deviceName, iotId, privateSeal, deviceTypeId, rolaFrequency } = obj
let { ns, to, cs, adcProperty } = obj.items
return {
online: status !== "" ? status === "online" : state,
signalValue: ns ? Number(ns.value) : 0,
facilitator: facilitator(to),
deviceCode: deviceName,
chargedState: cs ? cs.value === "1" : false,
currentBatteryCapacity: adcProperty ? (parseInt(adcProperty.bb) > 100 ? 100 : parseInt(adcProperty.bb)) : 0,
iotId: iotId,
privateSeal,
deviceTypeId,
rolaFrequency,
text: handleHoverShowText(obj, deviceName)
}
}
export function presentStationData(arr) {
let newArray = []
for (let i = 0; i < arr.length; i++) {
let { status, deviceCode, privateSeal, deviceTypeId, rolaFrequency,deviceVer,softVer,id } = arr[i]
if (arr[i].data && arr[i].data.items) {
let { ns, to, cs, adcProperty } = arr[i].data.items
newArray.push({
online: status === "online",
signalValue: ns ? Number(ns.value) : 0,
facilitator: facilitator(to),
deviceCode: deviceCode,
chargedState: cs ? cs.value === "1" : false,
currentBatteryCapacity: adcProperty ? (parseInt(adcProperty.bb) > 100 ? 100 : parseInt(adcProperty.bb)) : 0,
iotId: arr[i].iotId,
privateSeal,
deviceTypeId,
rolaFrequency,
deviceVer,
softVer,
id,
text: handleHoverShowText(arr[i].data, deviceCode)
})
} else {
newArray.push({
online: status === "online",
signalValue: 0,
facilitator: "未知",
deviceCode: deviceCode,
chargedState: false,
currentBatteryCapacity: 0,
iotId: arr[i].iotId,
privateSeal,
deviceTypeId,
rolaFrequency,
deviceVer,
softVer,
id,
text: handleHoverShowText(arr[i].data, deviceCode)
})
}
}
return newArray
}

View File

@ -0,0 +1,138 @@
import store from "@/store"
// 是否拥有管理员角色权限
export function hasRole() {
const roleFlag = ["admin", "sysAdmin"] // 管理员的角色字符
const roles = store.getters && store.getters.roles
console.log(roles)
const isHasRole = roles.some(role => {
return roleFlag.includes(role)
})
return isHasRole
}
// 将报警类型转换为汉字
export function convertToKanji(row) {
if (row.data && row.data.items && row.data.items.wt) {
let {
wt
} = row.data.items
wt = Number(wt.value)
if (wt === 0) {
return "无"
} else if (wt === 1) {
return "电机堵转"
} else if (wt === 2) {
return "角度故障"
} else if (wt === 3) {
return "低电量禁止控制"
} else if (wt === 4) {
return "电机初始化未完成"
} else if (wt === 5) {
return "压力1故障"
} else if (wt === 6) {
return "压力2故障"
} else {
return wt.value ? wt.value + "(未知错误)" : "(未知错误)"
}
} else {
return "/"
}
}
// 电量、温度、压力一、压力二
export function showValueFn(row, type) {
if (row.data && row.data.items && row.data.items.adcProperty) {
let {
bb,
t,
pp1,
pp2
} = row.data.items.adcProperty
if (type === 1) {
return parseInt(bb) > 100 ? 100 : parseInt(bb)
}
if (type === 2) {
return t
}
if (type === 3) {
return pp1
}
if (type === 4) {
return pp2
}
} else {
return ""
}
}
export function getYMDHMS(timestamp) {
let date = new Date(parseInt(timestamp))
let Year = date.getFullYear()
let Moth = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1
let Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
let Hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
let Minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
let Sechond = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
let GMT = Year + "-" + Moth + "-" + Day + " " + Hour + ":" + Minute + ":" + Sechond
return GMT
}
const warningTypeText = {
"valve": [
"电机堵转",
"角度故障",
"低电量禁止控制",
"电机初始化未完成",
"压力1故障",
"压力2故障",
],
"flapValve": [
"电机堵转",
"低电量禁止控制",
"压力故障"
]
};
export function getWarningTypeText(row) {
let wtText = "";
let controllable = true;
if (row.data && row.data.items && row.data.items.wt) {
let {
wt
} = row.data.items;
let wtArray = Number(wt.value).toString(2).split('').map(Number);
wtArray.reverse();
let wtTextArr = [];
if (row.deviceValve) {
wtTextArr = warningTypeText.valve;
if (wtArray.length > 2 && wtArray[2] === 1) {
controllable = false;
}
} else if (row.deviceFlapValve) {
wtTextArr = warningTypeText.flapValve;
if (wtArray.length > 1 && wtArray[1] === 1) {
controllable = false;
}
}
for (var i = 0; i < wtArray.length; i++) {
if (wtArray[i] === 1) {
if (wtTextArr.length > i) {
if (wtText == "") {
wtText = wtTextArr[i];
} else {
wtText += "," + wtTextArr[i];
}
} else {
wtText += "未知故障";
break;
}
}
};
}
return {
controllable: controllable,
text: wtText || "/"
};
}

View File

@ -0,0 +1,95 @@
// // 温度图片
// import temperatureIcon from "@/static/images/index/temperature.png"
// // 红点图片
// import redDotIcon from "@/static/images/red-point.png"
// // 绿点图片
// import greenDotIcon from "@/static/images/green-point.png"
// // 灰色电池图片
// import grayBatteryIcon from "@/static/images/index/dianchigray.png"
// // 绿色电池图片
// import greenBatteryIcon from "@/static/images/index/dianchigreen.png"
// // 向上白色箭头
// import upWhiteArrowIcon from "@/static/images/index/upwhitearrow.png"
// // 向上黑色箭头
// import upBlackArrowIcon from "@/static/images/index/upblackarrow.png"
// // 向下黑色箭头
// import downBlackArrowIcon from "@/static/images/index/downblackarrow.png"
// // 向下白色箭头
// import downWhiteArrowIcon from "@/static/images/index/downwhitearrow.png"
// // 警告标志
// import warningIcon from "@/static/images/index/warning.png"
// // 阀门未激活图片
// import valveInactiveIcon from "@/static/images/index/valves/valveinactive.gif"
// // L型全关图片
// import lTypeAllClosedIcon from "@/static/images/index/valves/ltypeallclosed.gif"
// // T型全关图片
// import tTypeAllClosedIcon from "@/static/images/index/valves/ttypeallclosed.gif"
// // L型一开
// import lTypeOneOpenIcon from "@/static/images/index/valves/ltypeoneopen.gif"
// // T型一开
// import tTypeOneOpenIcon from "@/static/images/index/valves/ttypeoneopen.gif"
// // L型二开
// import lTypeTwoOpenIcon from "@/static/images/index/valves/ltypetwoopen.gif"
// // T型二开
// import tTypeTwoOpenIcon from "@/static/images/index/valves/ttypetwoopen.gif"
// // 全开
// import allOpenIcon from "@/static/images/index/valves/allopen.gif"
// // 全开
// import loaddingIcon from "@/static/images/index/valves/loaddingIcon.gif"
// // 五通阀默认图标
// import fiveDefault from "@/static/images/index/fiveValves/default.png"
// export {
// temperatureIcon,
// redDotIcon,
// greenDotIcon,
// grayBatteryIcon,
// greenBatteryIcon,
// upWhiteArrowIcon,
// upBlackArrowIcon,
// downBlackArrowIcon,
// downWhiteArrowIcon,
// warningIcon,
// valveInactiveIcon,
// lTypeAllClosedIcon,
// tTypeAllClosedIcon,
// lTypeOneOpenIcon,
// tTypeOneOpenIcon,
// lTypeTwoOpenIcon,
// tTypeTwoOpenIcon,
// allOpenIcon,
// loaddingIcon,
// fiveDefault
// }
//3通阀
import valve3 from "@/static/images/valves/3/valve3.png"
import valve3_1 from "@/static/images/valves/3/valve3_1.gif"
import valve3_2 from "@/static/images/valves/3/valve3_2.gif"
import valve3_all from "@/static/images/valves/3/valve3_all.gif"
import valve3_run from "@/static/images/valves/3/valve3_run.gif"
//5通阀
import valve5 from "@/static/images/valves/5/valve5.png"
import valve5_1 from "@/static/images/valves/5/valve5_1.gif"
import valve5_2 from "@/static/images/valves/5/valve5_2.gif"
import valve5_3 from "@/static/images/valves/5/valve5_3.gif"
import valve5_4 from "@/static/images/valves/5/valve5_4.gif"
import valve5_all from "@/static/images/valves/5/valve5_all.gif"
import valve5_run from "@/static/images/valves/5/valve5_run.gif"
export {
valve3,
valve3_1,
valve3_2,
valve3_all,
valve3_run,
valve5,
valve5_1,
valve5_2,
valve5_3,
valve5_4,
valve5_all,
valve5_run
}

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ import * as commonUtils from "@/utils/common.js"
import {
deptTreeSelectByRole,
getManagerGroundList,
getDeviceList
} from "@/api/index.js"
class indexUtil {
@ -13,37 +14,56 @@ class indexUtil {
static showIndex = null; //默认显示的面板索引
static selectItem = null; //选中的数据
static isDataChange = false; //数据是否改变
static deviceData = null; //设备数据
//接收创建来的数据
constructor() {
constructor(eventHandler) {
this.isFirst = true;
this.userId = null;
this.list = [];
this.showIndex = null;
this.selectItem = null;
this.eventHandler = eventHandler;
}
// 获取列表
getList(userId) {
uni.showLoading();
this.userId = userId;
//如果是第一次获取,则先取缓存,然后异步更新数据
if (this.isFirst) {
//地块列表缓存
const lands = uni.getStorageSync(constant.lands);
if (lands && lands.userId == userId) {
this.list = lands.data;
}
//选中地块缓存
this.selectItem = uni.getStorageSync(constant.landItem) || null;
//默认显示索引
this.showIndex = this.findLandIndex(this.list, this.selectItem);
//设备列表
if (this.selectItem) {
const device = uni.getStorageSync(constant.device) || null;
if (device && device.landId == this.selectItem.id) {
this.device = device;
} else {
this.device = null;
}
} else {
this.device = null;
}
}
uni.hideLoading();
if (this.isFirst) {
this.isFirst = false;
this.getNewList(userId);
this.getNewLandList(userId);
this.getNewDeviceList(userId);
}
}
// 获取最新数据
async getNewList(userId) {
// 获取最新地块数据
async getNewLandList(userId) {
this.userId = userId;
// 如果是第一次获取,则重新查询一遍数据,更新旧数据
let company = await deptTreeSelectByRole();
@ -58,7 +78,7 @@ class indexUtil {
let land = await getManagerGroundList(userId);
// console.error("land:", land);
if (land.data.length) {
this.handleData(companys, land.data);
this.handleLandData(companys, land.data);
} else {
commonUtils.toast("无数据");
this.list = null;
@ -81,8 +101,8 @@ class indexUtil {
this.setStorage(2, this.selectItem);
}
// 组织数据
handleData(companys, lands) {
// 组织地块数据
handleLandData(companys, lands) {
let id = null;
let selectItem = null;
const landItem = uni.getStorageSync(constant.landItem);
@ -106,8 +126,7 @@ class indexUtil {
controlFlag: item.controlFlag, //设备是否可控0是 1否
enableFlapValve: item.enableFlapValve == 0, //启用蝶阀
landManualOperation: item.landManualOperation == 0, //启用批量控制
mapContent: null,
isSelect: false
mapContent: null
}
// 获取地图信息
if (item.landMap != null) {
@ -115,7 +134,6 @@ class indexUtil {
}
// 判断是否当前选中的数据
if (param.id == id) {
param.isSelect = true;
selectItem = param;
}
// 判断公司是否已经分组,如果未分组,则添加分组
@ -130,7 +148,6 @@ class indexUtil {
let index = 0;
while (!selectItem) {
if (companys[index].children.length) {
companys[index].children[0].isSelect = true;
selectItem = companys[index].children[0];
}
}
@ -153,6 +170,41 @@ class indexUtil {
return showIndex;
}
//获取最新设备数据
async getNewDeviceList() {
// 如果是第一次获取,则重新查询一遍数据,更新旧数据
// let device = await getDeviceList();
// console.error("device:", device)
let query = {
landId: this.selectItem.id,
deviceCode: ""
}
getDeviceList(query).then(res => {
// console.error("device:", res);
let device = {
stations: [],
flapValves: [],
waterOutlets: [],
}
if (res.data) {
if (res.data.devices.length) {
device.stations = res.data.devices.filter(item => item.deviceTypeId === 1);
device.flapValves = res.data.devices.filter(item => item.deviceTypeId === 12);
}
if (res.data.waterOutletGroups.length) {
device.waterOutlets = res.data.waterOutletGroups;
}
} else {
device = null;
}
console.error("device:", device)
this.device = device;
this.onEventHandler(this.eventType.device);
}).catch(error => {
commonUtils.toast(error);
})
}
// 缓存数据
setStorage(type, data) {
if (type == 1) {
@ -163,5 +215,14 @@ class indexUtil {
commonUtils.toast("数据持久化异常");
}
}
/****************************** 消息回调 ******************************/
eventType = {
land: "land",
device: "device",
}
onEventHandler(type) {
this.eventHandler(type);
}
}
export default indexUtil