Explorar o código

设备显示,报警历史,开锁历史查询

all %!s(int64=4) %!d(string=hai) anos
pai
achega
2ddcfd6c54

+ 49 - 0
frontend_lock/src/api/channels.ts

@@ -0,0 +1,49 @@
+import request from './request'
+
+
+/**
+ * 获取设备
+ * @param data 
+ */
+export function getchannels(params) {
+  return request({
+    url: 'channels/list',
+    method: 'get',
+    data: params
+  })
+}
+
+/**
+ * 获取最新数据
+ * @param data 
+ */
+export function datavalue(params) {
+  return request({
+    url: 'channels/datavalue/' + params,
+    method: 'get',
+  })
+}
+
+/**
+ * 获取全部智能锁的历史数据
+ * @param data 
+ */
+export function getrecordhistory(params) {
+  return request({
+    url: 'channels/getrecordhistory',
+    method: 'get',
+    data: params
+  })
+}
+
+/**
+ * 获取设备的报警信息
+ * @param data 
+ */
+export function triggerinforlist(params) {
+  return request({
+    url: 'channels/triggerinforlist',
+    method: 'get',
+    data: params
+  })
+}

+ 3 - 5
frontend_lock/src/api/login.ts

@@ -12,13 +12,11 @@ import request from './request'
  * 登录
  * @param data 
  */
-export function login(code) {
+export function login(params) {
     return request({
-        url: '/api/login',
+        url: 'tokens',
         method: 'POST',
-        data:{
-            code
-        } 
+        data: params
     })
 }
 

+ 24 - 25
frontend_lock/src/api/request.ts

@@ -3,30 +3,30 @@ import { getToken, getUserInfo ,remove} from '../utils/cache'
 import {wxLogin} from '../utils/login'
 
 //const baseUrl = `https://yapi.baidu.com/mock/15269`
-const baseUrl = `http://ceshi.psych-yxy.com`
+const baseUrl = `http://localhost:9858/api/`
 
 
 /**
  * 封封微信的的request
  */
 function request(opt) {
-  console.log(getUserInfo().uid)
+  // console.log(getUserInfo().uid)
   return new Promise(function (resolve, reject) {
     let option = Object.assign({
       url: '', data: {}, method: "GET"
     }, opt)
-    console.log('TCL:发起请求',`${option.url}`, { token: getToken(), uid: getUserInfo().uid, ...option.data })
     Taro.request({
       url: `${baseUrl}${option.url}`,
-      data: { token: getToken(), uid: getUserInfo().uid, ...option.data },
+      data: { ...option.data },
       method: option.method,
       header: {
-        'Content-Type': option.contentType || 'application/x-www-form-urlencoded',
+        // 'Content-Type': option.contentType || 'application/x-www-form-urlencoded',
         // 'X-Litemall-Token': getToken()
       },
       success: function (res) {
       console.log('请求成功',res)
-        if (res.statusCode == 200) {
+      resolve(res.data)
+        // if (res.statusCode == 200) {
           // resolve(res.data)
           // if (res.data.errno == 501) {
           //   // 清除登录相关内容
@@ -41,25 +41,24 @@ function request(opt) {
           //     url: '/pages/auth/login/login'
           //   });
           // } else 
-          if (res.data.status_code === '200') {
-            resolve(res.data);
-          } else if (res.data.status_code === '505') {
-            /**
-             * 登录失败就重新登录下然后刷新首页
-             */
-            remove()
-            // wxLogin().then(()=>{
-            Taro.reLaunch({url:'/pages/index/index'})
-            // })
-            Taro.showToast({ icon: 'none', title: res.data.message })
-            reject(res.data.errmsg);
-          } else {
-            Taro.showToast({ icon: 'none', title: res.data.data.error || res.data.message })
-            reject(res.data.errmsg);
-          }
-        } else {
-          reject(res.errMsg);
-        }
+        //   if (res.data.status_code === '200') {
+        //     resolve(res.data);
+        //   } else if (res.data.status_code === '505') {
+        //     /**
+        //      * 登录失败就重新登录下然后刷新首页
+        //      */
+        //     remove()
+        //     // wxLogin().then(()=>{
+        //     Taro.reLaunch({url:'/pages/index/index'})
+        //     // })
+        //     Taro.showToast({ icon: 'none', title: res.data.message })
+        //     reject(res.data.errmsg);
+        //   } else {
+        //     reject(res.data.errmsg);
+        //   }
+        // } else {
+        //   reject(res.errMsg);
+        // }
 
       },
       fail: function (err) {

+ 27 - 3
frontend_lock/src/pages/accountLogin/index.vue

@@ -82,6 +82,9 @@ import loginBg from "../../assets/images/login/loginBg.png"
 import bgfooter from "../../assets/images/login/bgfooter.png"
 import userPng from "../../assets/images/login/account.png"
 import pwdPng from "../../assets/images/login/pwd.png"
+import { login } from "../../api/login";
+import { setOpenId, getOpenId } from '../../utils/cache'
+import { showActionSheet } from '_@tarojs_taro@3.0.26@@tarojs/taro'
 export default {
   name: 'accountLogin',
   mixins: [setStateMixin],
@@ -136,9 +139,30 @@ export default {
         return false
       }
       else {
-        this.$taro.switchTab({
-          url: '/pages/index/index'
-        })
+        const model = {
+          username: this.state.account,
+          password: this.state.password,
+          openid: 'oZ2X-weExJP7jTGlhknsxAnf12r4'
+        }
+        setOpenId(model.openid)
+
+        login(model)
+          .then(res => {
+            this.$taro.switchTab({
+              url: '/pages/index/index'
+            })
+            // _this.PDHeadId = response.info
+            // _this.PDinfo_flag = 'editPDinfo'
+            // _this.getmaterialPDhead() // 查询盘点单主信息
+          }).catch(() => { })
+        // this.$store.dispatch('createToken', event)
+        //   .then(token => {
+        //     this.$router.push('/')
+        //     this.errmessage = ''
+        //   })
+        // this.$taro.switchTab({
+        //   url: '/pages/index/index'
+        // })
       }
     },
     closeToast () {

+ 13 - 0
frontend_lock/src/pages/index/index.scss

@@ -138,6 +138,16 @@
   border-radius: 0 10px 0 10px;
 }
 .offLine{
+  position: absolute;
+  top: 0;
+  right: 0;
+  width: 70px;
+  height: 34px;
+  line-height: 34px;
+  opacity: 1;
+  font-size: 16px;
+  color: #FFFFFF;
+  border-radius: 0 10px 0 10px;
   background: #FF4849;
   border: 1px solid rgba(0, 0, 0, 0);
   box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.04);
@@ -179,6 +189,9 @@
     height: 36px;
   }
 }
+.humitureItem:last-child {
+  border-right: none;
+}
 .temperature{
   padding-left: 0;
 }

+ 163 - 18
frontend_lock/src/pages/index/index.vue

@@ -18,9 +18,9 @@
       <view class="hospitalName">山东省立医院</view>
       <view class="line"></view>
       <view class="deviceBox">
-        <view class="deviceBoxItem">全部设备 <text class="deviceText">15</text></view>
-        <view class="deviceBoxItem">在线设备<text class="deviceText">10</text></view>
-        <view class="deviceBoxItem">离线设备<text class="deviceText">5</text></view>
+        <view class="deviceBoxItem">全部设备 <text class="deviceText">{{all}}</text></view>
+        <view class="deviceBoxItem">在线设备<text class="deviceText">{{online}}</text></view>
+        <view class="deviceBoxItem">离线设备<text class="deviceText">{{ofline}}</text></view>
 
       </view>
     </view>
@@ -39,36 +39,99 @@
                       v-for="(item,index) in deviceList"
                       :key="index">
                   <AtCard class="deviceItemCard"
-                          title="2号冰箱"
+                          :title="item.title"
                           :onClick="deviceItemClick">
-                    <view class="onOffLine">在线</view>
-                    <!-- <view class="deviceName"></view> -->
-                    <!-- 温湿度 -->
+                    <view :class="[item.DState == 1 ? 'onOffLine': 
+                          'offLine']">{{item.DState == 1?"在线" : "离线"}}</view>
+
                     <view class="humiture">
-                      <view class="humitureItem temperature">-86℃</view>
-                      <view class="humitureItem">95%</view>
-                      <view class="humitureItem imgBox">
+                      <!-- 温度 -->
+                      <view v-if="displayTemp(item.DataItem)"
+                            class="humitureItem temperature">{{item.Temp}}℃</view>
+                      <!-- 湿度 -->
+                      <view v-if="displayHum(item.DataItem)"
+                            class="humitureItem">{{item.Hum}}%</view>
+                      <!-- 智能锁 -->
+                      <view v-if="displayDoor(item.DataItem)"
+                            class="humitureItem imgBox">
                         <image class="img"
                                :src="slockPng" />
                       </view>
                     </view>
                     <!-- 时间 -->
                     <view class="time">
-                      2021-02-07 16:00:00
+                      {{item.Time}}
                     </view>
                   </AtCard>
                 </view>
-
               </view>
 
             </AtTabsPane>
             <AtTabsPane :current="currentTab"
                         :index="1">
-              <view class="tab-content">标签页二的内容</view>
+              <view class="tab-content deviceList">
+                <view class="deviceItem"
+                      v-for="(item,index) in deviceList"
+                      v-show="item.DState == 1"
+                      :key="index">
+                  <AtCard class="deviceItemCard"
+                          :title="item.title"
+                          :onClick="deviceItemClick">
+                    <view :class="[item.DState == 1 ? 'onOffLine': 
+                          'offLine']">{{item.DState == 1?"在线" : "离线"}}</view>
+                    <!-- <view class="deviceName"></view> -->
+                    <!-- 温湿度 -->
+                    <view class="humiture">
+                      <view v-if="displayTemp(item.DataItem)"
+                            class="humitureItem temperature">{{item.Temp}}℃</view>
+                      <view v-if="displayHum(item.DataItem)"
+                            class="humitureItem">{{item.Hum}}%</view>
+                      <view v-if="displayDoor(item.DataItem)"
+                            class="humitureItem imgBox">
+                        <image class="img"
+                               :src="slockPng" />
+                      </view>
+                    </view>
+                    <!-- 时间 -->
+                    <view class="time">
+                      {{item.Time}}
+                    </view>
+                  </AtCard>
+                </view>
+              </view>
             </AtTabsPane>
             <AtTabsPane :current="currentTab"
                         :index="2">
-              <view class="tab-content">标签页三的内容</view>
+              <view class="tab-content deviceList">
+                <view class="deviceItem"
+                      v-for="(item,index) in deviceList"
+                      v-show="item.DState == 2"
+                      :key="index">
+                  <AtCard class="deviceItemCard"
+                          :title="item.title"
+                          :onClick="deviceItemClick">
+                    <view :class="[item.DState == 1 ? 'onOffLine': 
+                          'offLine']">{{item.DState == 1?"在线" : "离线"}}</view>
+                    <!-- <view class="deviceName"></view> -->
+                    <!-- 温湿度 -->
+                    <view class="humiture">
+                      <view v-if="displayTemp(item.DataItem)"
+                            class="humitureItem temperature">{{item.Temp}}℃</view>
+                      <view v-if="displayHum(item.DataItem)"
+                            class="humitureItem">{{item.Hum}}%</view>
+                      <view v-if="displayDoor(item.DataItem)"
+                            class="humitureItem imgBox">
+                        <image class="img"
+                               :src="slockPng" />
+                      </view>
+                    </view>
+                    <!-- 时间 -->
+                    <view class="time">
+                      {{item.Time}}
+                    </view>
+                  </AtCard>
+                </view>
+              </view>
             </AtTabsPane>
           </AtTabs>
         </view>
@@ -80,34 +143,116 @@
 <script>
 import './index.scss'
 import slockPng from '../../assets/images/index/slock.png'
+import { getchannels, datavalue } from "../../api/channels";
+import { getOpenId } from '../../utils/cache'
 export default {
   data () {
     return {
       slockPng,
       msg: '首页',
-
+      openid: '',  //微信码
+      currentPage: 1, // 分页
+      size: 1000, // 分页
+      currentItemCount: 0, // 分页
       currentTab: 0,
       tabList: [
         { title: '全部' },
         { title: '在线' },
         { title: '离线' }
       ],
-      deviceList: [1, 2, 3, 4]
+      deviceList: [],
+      all: 0, //全部设备数量
+      online: 0, //在线备数量
+      ofline: 0 //离线备数量
     }
   },
-  created () { },
+  created () {
+    this.openid = getOpenId()
+    this.getChannels()
+  },
   onShow () { },
   onHide () { },
   methods: {
     handleClick (stateName, value) {
       this[stateName] = value
     },
+    //获取所有设备
+    getChannels () {
+      const params = { _currentPage: this.currentPage, _size: this.size, openid: this.openid }
+      getchannels(params)
+        .then(res => {
+          console.log('----res----', res)
+          this.deviceList = res.items
+          //全部设备数量
+          this.all = this.deviceList.length
+          this.loaddataall()
+        }).catch(() => { })
+    },
+    //获取所有传感器信息
+    loaddataall () {
+      for (let i = 0; i < this.deviceList.length; i++) {
+        this.loaddata(this.deviceList[i], i)
+      }
+      console.log('----_this.deviceListoffLine-----', _this.deviceListoffLine)
+    },
+    //赋传感器数据
+    loaddata (code, k) {
+      console.log('----code---', code)
+      let _this = this
+      datavalue(code.Serial)
+        .then(res => {
+          //在线设备统计
+          if (res.DState == 1) {
+            this.online = this.online + 1
+          }
+          //离线设备统计
+          if (res.DState == 2) {
+            this.ofline = this.ofline + 1
+          }
+          _this.deviceList[k].Temp = res.Temp
+          _this.deviceList[k].Hum = res.Hum
+          _this.deviceList[k].Vol = res.Vol
+          _this.deviceList[k].Rssi = res.Rssi
+          _this.deviceList[k].Time = res.Time
+          _this.deviceList[k].O2 = res.O2
+          _this.deviceList[k].Co2 = res.Co2
+          _this.deviceList[k].Power = res.Power
+          _this.deviceList[k].Supply = res.Supply
+          _this.deviceList[k].DState = res.DState
+          _this.deviceList[k].Signal = res.Signal
+          _this.deviceList[k].Doorlock = res.Doorlock
+        })
+    },
     deviceItemClick () {
       console.log("设备详情点击---item",)
       this.$taro.navigateTo({
         url: '/pages/deviceDetail/index'
       })
-    }
+    },
+    displayTemp (val) {
+      val = val + '';
+      return val === '0' || val === '6' || val === '7' || val === '9' || val === '10'
+    },
+    displayHum (val) {
+      val = val + '';
+      return val === '0' || val === '7' || val === '9'
+    },
+    displayCO2 (val) {
+      val = val + '';
+      return val === '9' || val === '26'
+    },
+    displayO2 (val) {
+      val = val + '';
+      return val === '7' || val === '17'
+    },
+    displayPower (val) {
+      val = val + '';
+      return val === '13'
+    },
+    displayDoor (val) {
+      val = val + '';
+      return val === '31'
+    },
   }
 }
 </script>

+ 82 - 9
frontend_lock/src/pages/message/index.vue

@@ -36,19 +36,19 @@
                   <view class="recordItemRight">
                     <!-- 智能锁名称 -->
                     <view class="slock">
-                      <view class="slockName">五号冰箱智能锁</view>
+                      <view class="slockName">{{item.DeviceName}}</view>
                       <view class="slockNum">
                         <image class="numImg"
                                :src="numberPng" />
-                        <view>23646113230</view>
+                        <view>{{item.ChannelCode}}</view>
                       </view>
                     </view>
                     <!-- 打开方式 -->
                     <view class="openMode">智能锁已通过扫码方式打开 </view>
                     <!-- 开锁人,开锁时间 -->
                     <view class="slockPerTime">
-                      <view class="slockPerson">李磊磊</view>
-                      <view class="slockTime">2021-02-07 16:00:00</view>
+                      <view class="slockPerson">{{item.CausePerson}}</view>
+                      <view class="slockTime">{{jstimehandl(item.CreateOn)}}</view>
                     </view>
                   </view>
                 </view>
@@ -56,11 +56,65 @@
             </AtTabsPane>
             <AtTabsPane :current="currentTab"
                         :index="1">
-              <view class="tab-content">标签页二的内容</view>
+              <view class="tab-content recordList">
+                <view class="recordItem"
+                      v-for="(item,index) in recordList"
+                      :key="index">
+                  <view class="recordItemImg">
+                    <image class="slockImg"
+                           :src="slockPng" />
+                  </view>
+                  <view class="recordItemRight">
+                    <!-- 智能锁名称 -->
+                    <view class="slock">
+                      <view class="slockName">{{item.DeviceName}}</view>
+                      <view class="slockNum">
+                        <image class="numImg"
+                               :src="numberPng" />
+                        <view>{{item.ChannelCode}}</view>
+                      </view>
+                    </view>
+                    <!-- 打开方式 -->
+                    <view class="openMode">智能锁已通过扫码方式打开 </view>
+                    <!-- 开锁人,开锁时间 -->
+                    <view class="slockPerTime">
+                      <view class="slockPerson">{{item.CausePerson}}</view>
+                      <view class="slockTime">{{jstimehandl(item.CreateOn)}}</view>
+                    </view>
+                  </view>
+                </view>
+              </view>
             </AtTabsPane>
             <AtTabsPane :current="currentTab"
                         :index="2">
-              <view class="tab-content">标签页三的内容</view>
+              <view class="tab-content recordList">
+                <view class="recordItem"
+                      v-for="(item,index) in recordList"
+                      :key="index">
+                  <view class="recordItemImg">
+                    <image class="slockImg"
+                           :src="slockPng" />
+                  </view>
+                  <view class="recordItemRight">
+                    <!-- 智能锁名称 -->
+                    <view class="slock">
+                      <view class="slockName">{{item.DeviceName}}</view>
+                      <view class="slockNum">
+                        <image class="numImg"
+                               :src="numberPng" />
+                        <view>{{item.ChannelCode}}</view>
+                      </view>
+                    </view>
+                    <!-- 打开方式 -->
+                    <view class="openMode">智能锁已通过扫码方式打开 </view>
+                    <!-- 开锁人,开锁时间 -->
+                    <view class="slockPerTime">
+                      <view class="slockPerson">{{item.CausePerson}}</view>
+                      <view class="slockTime">{{jstimehandl(item.CreateOn)}}</view>
+                    </view>
+                  </view>
+                </view>
+              </view>
             </AtTabsPane>
           </AtTabs>
           <view class="fabBtn">
@@ -82,6 +136,8 @@ import './index.scss'
 import numberPng from "../../assets/images/message/number.png"
 import slockPng from '../../assets/images/message/record.png'
 import mesWarn from "../../assets/images/message/mesWarn.png"
+import { getrecordhistory } from "../../api/channels";
+import { getOpenId } from '../../utils/cache'
 export default {
   data () {
     return {
@@ -95,15 +151,28 @@ export default {
         { title: '近7天' },
         { title: '近1个月' }
       ],
-      recordList: [1, 2, 3, 4]
+      recordList: [],
     }
   },
-  created () { },
+  created () {
+    this.openid = getOpenId()
+    this.getRecordHistory(0)
+  },
   onShow () { },
   onHide () { },
   methods: {
+    //获取所有智能锁设备报警信息
+    getRecordHistory (time) {
+      const params = { openid: this.openid, creaton: time }
+      getrecordhistory(params)
+        .then(res => {
+          this.recordList = res.items
+
+        }).catch(() => { })
+    },
     handleClick (stateName, value) {
       this[stateName] = value
+      this.getRecordHistory(value + '')
     },
     iconClick () {
       this.$taro.navigateTo({
@@ -115,7 +184,11 @@ export default {
       this.$taro.navigateTo({
         url: '/pages/warning/index'
       })
-    }
+    },
+    jstimehandl (val) {
+      val = val.replace('T', ' ')
+      return val.substring(0, 19)
+    },
   }
 }
 </script>

+ 17 - 1
frontend_lock/src/pages/warning/index.vue

@@ -81,6 +81,8 @@ import './index.scss'
 import warnRecord from '../../assets/images/message/warn-record.png'
 import numberPng from "../../assets/images/message/number.png"
 import mesSlock from "../../assets/images/message/mesSlock.png"
+import { triggerinforlist } from "../../api/channels";
+import { getOpenId } from '../../utils/cache'
 mesSlock
 export default {
   name: 'warning',
@@ -89,6 +91,7 @@ export default {
       warnRecord,
       numberPng,
       mesSlock,
+      openid: '',  //微信码
       msg: '消息',
       currentTab: 0,
       tabList: [
@@ -99,10 +102,23 @@ export default {
       warningList: [1, 2, 3, 4]
     }
   },
-  created () { },
+  created () {
+    this.openid = getOpenId()
+    this.triggerInforlist(0)
+    console.log('-------')
+  },
   onShow () { },
   onHide () { },
   methods: {
+    //获取所有设备报警信息
+    triggerInforlist (time) {
+      console.log('---22---', time)
+      const params = { openid: this.openid }
+      triggerinforlist(params)
+        .then(res => {
+          this.warningList = res.items
+        }).catch(() => { })
+    },
     handleClick (stateName, value) {
       this[stateName] = value
     },

+ 12 - 0
frontend_lock/src/utils/cache.ts

@@ -2,6 +2,7 @@ import Taro from "@tarojs/taro";
 
 const TOKEN = "TOKEN";
 const USER_INFO = "USER_INFO";
+const OPEN_ID = "OPEN_ID";
 
 export function getToken(): string {
   return Taro.getStorageSync(TOKEN);
@@ -11,6 +12,7 @@ export function setToken(token: string): void {
   Taro.setStorageSync(TOKEN, token);
 }
 
+
 export function setUserInfo(userInfo: object): void {
   Taro.setStorageSync(USER_INFO, userInfo);
 }
@@ -20,8 +22,18 @@ export function getUserInfo(key?: string): any {
   return key ? userInfo[key] : userInfo;
 }
 
+//openId 微信
+export function setOpenId(openId: object): void {
+  Taro.setStorageSync(OPEN_ID, openId);
+}
+
+export function getOpenId(): string {
+  return Taro.getStorageSync(OPEN_ID);
+}
+
 
 export function remove(){
   Taro.removeStorageSync('TOKEN')
   Taro.removeStorageSync('USER_INFO')
+  Taro.removeStorageSync('OPEN_ID')
 }