Browse Source

连油监控mqtt请求token

Zimo 1 day ago
parent
commit
67623ebf70

+ 3 - 0
src/api/pms/device/index.ts

@@ -53,6 +53,9 @@ export const IotDeviceApi = {
   saveMaxMin: async (data: any) => {
     return await request.post({ url: `rq/iot-alarm-setting/save`, data })
   },
+  getToken: async () => {
+    return await request.get({ url: `/rq/iot-device/yf/token` })
+  },
   deleteMaxMin: async (params: any) => {
     return await request.delete({ url: `rq/iot-alarm-setting/delete`, params })
   },

+ 5 - 1
src/views/oli-connection/monitoring-board/chart.vue

@@ -51,6 +51,10 @@ const props = defineProps({
   date: {
     type: Array as PropType<Array<string>>,
     required: true
+  },
+  token: {
+    type: String,
+    required: true
   }
 })
 
@@ -582,7 +586,7 @@ async function initLoadChartData(real_time: boolean = true) {
   }
 
   if (real_time) {
-    connect(`wss://aims.deepoil.cc/mqtt`, {}, handleMessageUpdate)
+    connect(`wss://aims.deepoil.cc/mqtt`, { password: props.token }, handleMessageUpdate)
   }
 }
 

+ 13 - 1
src/views/oli-connection/monitoring-board/index.vue

@@ -170,6 +170,18 @@ function handleRest() {
 function handleInlineChange() {
   loadDeviceOptions()
 }
+
+const token = ref('')
+
+async function getToken() {
+  const res = await IotDeviceApi.getToken()
+
+  token.value = res
+}
+
+onMounted(() => {
+  getToken()
+})
 </script>
 
 <template>
@@ -299,7 +311,7 @@ function handleInlineChange() {
 
     <div class="p-4 grid grid-cols-2 3xl:grid-cols-3 gap-6">
       <template v-for="item in deviceList" :key="item.id">
-        <chart v-bind="item" :date="query.time" />
+        <chart v-bind="item" :date="query.time" :token="token" />
       </template>
     </div>
   </div>