index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-02-19 11:59:48
  4. * @LastEditTime: 2021-03-12 14:50:23
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \intelligentLock\src\pages\index\index.vue
  8. -->
  9. <template>
  10. <view class="page">
  11. <!-- <view>
  12. <AtNavBar :onClickLeftIcon="handleClick.bind(this, '返回')"
  13. title="首页"
  14. leftIconType="chevron-left"
  15. color='#646464' />
  16. </view> -->
  17. <view class="detail">
  18. <view class="detailTop">
  19. <view class="hospitalName">山东省立医院</view>
  20. <view class="line"></view>
  21. </view>
  22. <view class="deviceBox">
  23. <view class="deviceBoxItem"> <text class="deviceText">{{all}}</text></view>
  24. <view class="deviceBoxItem"><text class="deviceText">{{online}}</text></view>
  25. <view class="deviceBoxItem"><text class="deviceText">{{ofline}}</text></view>
  26. </view>
  27. </view>
  28. <!-- 设备 -->
  29. <view class="device">
  30. <view class="panel">
  31. <view class="panel__content">
  32. <AtTabs :current="currentTab"
  33. :tabList="tabList"
  34. :onClick="handleClick.bind(this, 'currentTab')"
  35. class="deviceTab">
  36. <AtTabsPane :current="currentTab"
  37. :index="0">
  38. <view class="tab-content deviceList">
  39. <view class="deviceItem"
  40. v-for="(item,index) in deviceList"
  41. :key="index">
  42. <AtCard class="deviceItemCard"
  43. :title="item.title"
  44. :onClick="deviceItemClick">
  45. <view :class="[item.DState == 1 ? 'onOffLine':
  46. 'offLine']">{{item.DState == 1?"在线" : "离线"}}</view>
  47. <view class="humiture">
  48. <!-- 温度 -->
  49. <view v-if="displayTemp(item.DataItem)"
  50. class="humitureItem temperature">{{item.Temp}}℃</view>
  51. <!-- 湿度 -->
  52. <view v-if="displayHum(item.DataItem)"
  53. class="humitureItem">{{item.Hum}}%</view>
  54. <!-- 智能锁 -->
  55. <view v-if="displayDoor(item.DataItem)"
  56. class="humitureItem imgBox">
  57. <image class="img"
  58. :src="slockPng" />
  59. </view>
  60. </view>
  61. <!-- 时间 -->
  62. <view class="time">
  63. {{item.Time}}
  64. </view>
  65. </AtCard>
  66. </view>
  67. </view>
  68. </AtTabsPane>
  69. <AtTabsPane :current="currentTab"
  70. :index="1">
  71. <view class="tab-content deviceList"
  72. style="margin-left:7px">
  73. <view class="deviceItem"
  74. v-for="(item,index) in deviceList"
  75. v-show="item.DState == 1"
  76. :key="index">
  77. <AtCard class="deviceItemCard"
  78. :title="item.title"
  79. :onClick="deviceItemClick">
  80. <view :class="[item.DState == 1 ? 'onOffLine':
  81. 'offLine']">{{item.DState == 1?"在线" : "离线"}}</view>
  82. <!-- <view class="deviceName"></view> -->
  83. <!-- 温湿度 -->
  84. <view class="humiture">
  85. <view v-if="displayTemp(item.DataItem)"
  86. class="humitureItem temperature">{{item.Temp}}℃</view>
  87. <view v-if="displayHum(item.DataItem)"
  88. class="humitureItem">{{item.Hum}}%</view>
  89. <view v-if="displayDoor(item.DataItem)"
  90. class="humitureItem imgBox">
  91. <image class="img"
  92. :src="slockPng" />
  93. </view>
  94. </view>
  95. <!-- 时间 -->
  96. <view class="time">
  97. {{item.Time}}
  98. </view>
  99. </AtCard>
  100. </view>
  101. </view>
  102. </AtTabsPane>
  103. <AtTabsPane :current="currentTab"
  104. :index="2">
  105. <view class="tab-content deviceList"
  106. style="margin-left:15px">
  107. <view class="deviceItem"
  108. v-for="(item,index) in deviceList"
  109. v-show="item.DState == 2"
  110. :key="index">
  111. <AtCard class="deviceItemCard"
  112. :title="item.title"
  113. :onClick="deviceItemClick">
  114. <view :class="[item.DState == 1 ? 'onOffLine':
  115. 'offLine']">{{item.DState == 1?"在线" : "离线"}}</view>
  116. <!-- <view class="deviceName"></view> -->
  117. <!-- 温湿度 -->
  118. <view class="humiture">
  119. <view v-if="displayTemp(item.DataItem)"
  120. class="humitureItem temperature">{{item.Temp}}℃</view>
  121. <view v-if="displayHum(item.DataItem)"
  122. class="humitureItem">{{item.Hum}}%</view>
  123. <view v-if="displayDoor(item.DataItem)"
  124. class="humitureItem imgBox">
  125. <image class="img"
  126. :src="slockPng" />
  127. </view>
  128. </view>
  129. <!-- 时间 -->
  130. <view class="time">
  131. {{item.Time}}
  132. </view>
  133. </AtCard>
  134. </view>
  135. </view>
  136. </AtTabsPane>
  137. </AtTabs>
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. </template>
  143. <script>
  144. import './index.scss'
  145. import slockPng from '../../assets/images/index/slock.png'
  146. import { getchannels, datavalue } from "../../api/channels";
  147. import { getOpenId } from '../../utils/cache'
  148. export default {
  149. data () {
  150. return {
  151. slockPng,
  152. msg: '首页',
  153. openid: '', //微信码
  154. currentPage: 1, // 分页
  155. size: 1000, // 分页
  156. currentItemCount: 0, // 分页
  157. currentTab: 0,
  158. tabList: [
  159. { title: '全部' },
  160. { title: '在线' },
  161. { title: '离线' }
  162. ],
  163. deviceList: [],
  164. all: 0, //全部设备数量
  165. online: 0, //在线备数量
  166. ofline: 0 //离线备数量
  167. }
  168. },
  169. created () {
  170. this.openid = getOpenId()
  171. this.getChannels()
  172. },
  173. onShow () { },
  174. onHide () { },
  175. methods: {
  176. handleClick (stateName, value) {
  177. this[stateName] = value
  178. },
  179. //获取所有设备
  180. getChannels () {
  181. const params = { _currentPage: this.currentPage, _size: this.size, openid: this.openid }
  182. getchannels(params)
  183. .then(res => {
  184. this.deviceList = res.items
  185. //全部设备数量
  186. this.all = this.deviceList.length
  187. this.loaddataall()
  188. }).catch(() => { })
  189. },
  190. //获取所有传感器信息
  191. loaddataall () {
  192. for (let i = 0; i < this.deviceList.length; i++) {
  193. this.loaddata(this.deviceList[i], i)
  194. }
  195. console.log('----_this.deviceListoffLine-----', _this.deviceListoffLine)
  196. },
  197. //赋传感器数据
  198. loaddata (code, k) {
  199. let _this = this
  200. datavalue(code.Serial)
  201. .then(res => {
  202. //在线设备统计
  203. if (res.DState == 1) {
  204. this.online = this.online + 1
  205. }
  206. //离线设备统计
  207. if (res.DState == 2) {
  208. this.ofline = this.ofline + 1
  209. }
  210. _this.deviceList[k].Temp = res.Temp
  211. _this.deviceList[k].Hum = res.Hum
  212. _this.deviceList[k].Vol = res.Vol
  213. _this.deviceList[k].Rssi = res.Rssi
  214. _this.deviceList[k].Time = res.Time
  215. _this.deviceList[k].O2 = res.O2
  216. _this.deviceList[k].Co2 = res.Co2
  217. _this.deviceList[k].Power = res.Power
  218. _this.deviceList[k].Supply = res.Supply
  219. _this.deviceList[k].DState = res.DState
  220. _this.deviceList[k].Signal = res.Signal
  221. _this.deviceList[k].Doorlock = res.Doorlock
  222. })
  223. },
  224. deviceItemClick () {
  225. console.log("设备详情点击---item",)
  226. this.$taro.navigateTo({
  227. url: '/pages/deviceDetail/index'
  228. })
  229. },
  230. displayTemp (val) {
  231. val = val + '';
  232. return val === '0' || val === '6' || val === '7' || val === '9' || val === '10'
  233. },
  234. displayHum (val) {
  235. val = val + '';
  236. return val === '0' || val === '7' || val === '9'
  237. },
  238. displayCO2 (val) {
  239. val = val + '';
  240. return val === '9' || val === '26'
  241. },
  242. displayO2 (val) {
  243. val = val + '';
  244. return val === '7' || val === '17'
  245. },
  246. displayPower (val) {
  247. val = val + '';
  248. return val === '13'
  249. },
  250. displayDoor (val) {
  251. val = val + '';
  252. return val === '31'
  253. },
  254. }
  255. }
  256. </script>