zhaobao 2 лет назад
Родитель
Сommit
c90cce5073

+ 2 - 3
src/App.vue

@@ -7,17 +7,16 @@
 
 <script>
 import {getQueryObject} from '@/utils'
-import { setToken ,getToken} from '@/utils/auth'
+import { setToken } from '@/utils/auth'
 import appHeader from '@/components/Header.vue'
 export default {
   components:{
     appHeader
-  }
+  },
 }
 if(getQueryObject().token){
   setToken(getQueryObject().token)
 }
-
 </script>
 <style lang="scss" scoped>
 #app-main{

+ 20 - 1
src/components/Header.vue

@@ -9,6 +9,7 @@
 import {parseTime} from '@/utils'
 import { mapState } from 'pinia'
 import { useStore } from '@/store/modules/user'
+import {getUserProfile} from '@/api/system'
 export default {
     name:'AppHeader',
     data(){
@@ -30,10 +31,28 @@ export default {
             this.timer=setInterval(()=>{
                 this.getnow()
             },1000)
+            this.saveUserInfo()
         },
         getnow(){
             this.time = parseTime(new Date(),'{y}.{m}.{d} {h}:{i}:{s}')
-        }
+        },
+        saveUserInfo(){
+            const store=useStore()
+            if(localStorage.getItem('user')){
+                let user=localStorage.getItem('user');
+                user=JSON.parse(user)
+                store.$patch({
+                    user
+                })
+            }else{
+                getUserProfile().then((res)=>{     
+                    store.$patch({
+                        user:res.data
+                    })                               
+                    localStorage.setItem('user',JSON.stringify(res.data))
+                })
+            }
+        },
     },
     destroyed() {
         if(this.timer){

+ 2 - 4
src/config/index.js

@@ -4,10 +4,8 @@ module.exports = {
     * 服务API地址
     */
     serverUrl: 'http://113.141.93.143:1688', // 正式环境
-    // devServerUrl: 'http://113.141.93.143:1688', // 开发环境
-    devServerUrl: 'http://192.168.3.5:1688/', // 开发环境 qu
-    // devServerUrl: 'http://192.168.3.201:8080/', // 开发环境  test
-    // mqttUrl: 'ws://1.15.92.205:8083/mqtt', // 水泥厂mqtt地址
+    devServerUrl: 'http://113.141.93.143:1688', // 开发环境
+    // devServerUrl: 'http://192.168.3.5:1688/', // 开发环境 qu
     mqttUrl: 'ws://113.141.93.143:8894/mqtt', // mqtt地址
     /**
     * websocket 地址

+ 13 - 19
src/mixins/mqtt.js

@@ -2,6 +2,8 @@
 import config  from '@/config'
 // import { getToken } from '@/utils'
 import * as mqtt from "mqtt/dist/mqtt.min"; 
+import { mapState } from 'pinia'
+import { useStore } from '@/store/modules/user'
 export default {
   destroyed() {
     if (this.client.connected) {
@@ -14,6 +16,11 @@ export default {
       }
     }
   },
+  computed: {
+      ...mapState(useStore,{
+          "user":'user'
+      })
+  },
   methods: {
     initMqtt(
       params={
@@ -22,35 +29,22 @@ export default {
     ) {
       try{
         const self = this
-        
         const options = {
           clean: true,
           connectTimeout: 4000,
           clientId: new Date().getTime(),
           username: 'admin',
           password: 'houyaf1!'
-        }   
+        }  
+        const ocId=this.user.ocId
+        const  subscribeList=[`topic/goaf/waring/person/${ocId}`,`topic/goaf/waring/sensor/${ocId}`,`topic/goaf/fill/scale/${ocId}`]
         const client = mqtt.connect(config.mqttUrl, options)
         client.on('connect', function() {
-          client.subscribe('topic/goaf/waring/person', function(err) {
-            if (!err) {
-              client.publish('topic/1', 'topic/goaf/waring/person 订阅成功')
-            }else{
-              client.publish('topic/1', `topic/goaf/waring/person  订阅成功 ${err}`)
-            }
-          })
-          client.subscribe('topic/goaf/waring/sensor', function(err) {
-            if (!err) {
-              client.publish('topic/1', 'topic/goaf/waring/sensor  订阅成功')
-            }else{
-              client.publish('topic/1', `topic/goaf/waring/sensor  订阅成功 ${err}`)
-            }
-          })
-          client.subscribe('topic/goaf/fill/scale', function(err) {
+          client.subscribe(subscribeList, function(err) {
             if (!err) {
-              client.publish('topic/1', 'topic/goaf/fill/scale  订阅成功')
+              client.publish('topic/1', ' 订阅成功')
             }else{
-              client.publish('topic/1', `topic/goaf/fill/scale  订阅成功 ${err}`)
+              client.publish('topic/1', `订阅成功 ${err}`)
             }
           })
         })

+ 1 - 1
src/views/home/components/SensorWarningStatistics.vue

@@ -81,7 +81,7 @@ export default {
             let rectify_rate=total>0?(data.goafHdangerStatusCompleteNum/total):0
             this.data=data
             this.total=total
-            this.rectify_rate=(rectify_rate*100).toFixed(1)
+            this.rectify_rate=parseFloat((rectify_rate*100).toFixed(1))
         },
         linkTo(){
             this.$router.push({

+ 1 - 1
src/views/home/components/WarningStatistics.vue

@@ -81,7 +81,7 @@ export default {
             let rectify_rate=total>0?(data.goafHdangerStatusCompleteNum/total):0
             this.data=data
             this.total=total
-            this.rectify_rate=(rectify_rate*100).toFixed(1)
+            this.rectify_rate=parseFloat((rectify_rate*100).toFixed(1))
         },
         linkTo(){
             this.$router.push('/particulars/check')