Browse Source

fix: 设备密匙查询

lvkun996 2 năm trước cách đây
mục cha
commit
ad046ae291

+ 13 - 0
src/api/iot/device.ts

@@ -30,6 +30,19 @@ export const getDeviceById = (id: string) => {
   })
 }
 
+/**
+ *
+ * @param id
+ * @param authType 设备授权方式
+ */
+export const getDeviceSecret = (params: {deviceId: string, authType: 'SECRET' | 'X509CERT'}) => {
+  return request<string>({
+    url: '/deviceSecret',
+    method: 'GET',
+    params
+  })
+}
+
 export const addDevice = (data: IOT.API.DEVICE.BodyParams) => {
   return request<string>({
     url: '/device',

+ 6 - 1
src/controller/iot/device.ts

@@ -2,7 +2,7 @@ import {
   addDevice, addSubDevice, delDevice, delDeviceMul, delDeviceTag,
   getDeviceById, getDeviceCount, getDeviceList, getDeviceMsgList, addDeviceMsg, getDeviceTag,
   getSubDeviceList, updateDeviceLabel, addDeviceCmd, getDeviceCmdList, addDeviceTag, addDeviceGroup,
-  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup, getDevicePage, delSubDevice, getDeviceAttribute, getDevicShadow, getDeviceTopology, getDeviceSession, getDeviceAttributes
+  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup, getDevicePage, delSubDevice, getDeviceAttribute, getDevicShadow, getDeviceTopology, getDeviceSession, getDeviceAttributes, getDeviceSecret
 } from '@/api/iot/device'
 import { DeviceMsgEnum } from '@/enum/common'
 import { message } from 'ant-design-vue'
@@ -92,6 +92,11 @@ export class DeviceContriller {
     return await getSubDeviceList(id, params)
   }
 
+  /** 获取设备密匙 */
+  static async secret (params: {deviceId: string, authType: 'SECRET' | 'X509CERT'}) {
+    return await getDeviceSecret(params)
+  }
+
   /** 新增子设备 */
   static async postSub (data: IOT.API.DEVICE.SubBodyParams) {
     await addSubDevice(data)

+ 1 - 1
src/pages/Iot/dashboard/deviceAccess/index.vue

@@ -54,7 +54,7 @@
 <script setup lang="ts" >
 import { CommonController, DeviceContriller, ModelController, RuleController } from '@/controller/index'
 import { useStaticImg } from '@/utils/static'
-import { onMounted, reactive } from 'vue'
+import { nextTick, onMounted, reactive, Ref, ref, watch, watchEffect } from 'vue'
 
 const staticImg = useStaticImg()
 

+ 29 - 6
src/pages/Iot/device/components/overview.vue

@@ -22,12 +22,20 @@
       :contentStyle="{fontSize: '12px'}"
       style="margin-top: 20px;"
     >
-        <a-descriptions-item label="设备标识码">{{state.deviceDetail?.modelLabel}}</a-descriptions-item>
+        <a-descriptions-item label="设备标识码">{{state.deviceDetail?.deviceStatus}}</a-descriptions-item>
         <a-descriptions-item label="设备ID">{{state.deviceDetail?.id}}</a-descriptions-item>
-        <a-descriptions-item label="认证类型">{{state.deviceDetail?.deviceNodeType}}</a-descriptions-item>
-        <a-descriptions-item label="设备密钥">{{state.deviceDetail?.deviceCode}}</a-descriptions-item>
-        <a-descriptions-item label="注册时间">{{state.deviceDetail?.lastActivityTs}}</a-descriptions-item>
-        <a-descriptions-item label="节点类型">{{  state.deviceDetail?.deviceNodeType === 'GATEWAY' ? '直连' : '非直连'}}</a-descriptions-item>
+        <a-descriptions-item label="认证类型">{{state.deviceDetail?.authType === 'SECRET' ? '密钥认证' : '证书'}}</a-descriptions-item>
+        <a-descriptions-item label="设备密钥">
+          <a-space>
+            <span  >{{ secretState.visible ? secretState.secret : '******' }}</span>
+            <span>
+              <eye-invisible-two-tone v-if="secretState.visible" style="font-size: 20px;" @click="secretState.visible = false" />
+              <eye-two-tone v-else style="font-size: 20px;" @click="getSecret" />
+            </span>
+          </a-space>
+        </a-descriptions-item>
+        <a-descriptions-item label="注册时间">{{ dayjs(state.deviceDetail?.createAt).format('YYYY-MM-DD hh:mm:ss') }}</a-descriptions-item>
+        <a-descriptions-item label="节点类型">{{ state.deviceDetail?.deviceNodeType === 'GATEWAY' ? '直连' : '非直连'}}</a-descriptions-item>
     </a-descriptions>
 
     <a-row  justify="space-between" align="middle" style="width: 100%;height: 68px; margin-bottom: 10px;" class="title">
@@ -68,9 +76,11 @@
 <script lang="ts" setup >
 import { CommonController, DeviceContriller } from '@/controller'
 import { useScheduler } from '@/hooks'
-import { onMounted, reactive } from 'vue'
+import { onMounted, reactive, h } from 'vue'
 import { useRoute } from 'vue-router'
 import dayjs from 'dayjs'
+import { EyeTwoTone, EyeInvisibleTwoTone } from '@ant-design/icons-vue'
+import { message } from 'ant-design-vue'
 
 const route = useRoute()
 const deviceId = route.query.id as string
@@ -81,6 +91,11 @@ interface IProps {
 
 const props = defineProps<IProps>()
 
+const secretState = reactive({
+  visible: false,
+  secret: '*******'
+})
+
 const state = reactive <{
   deviceDetail: IOT.API.DEVICE.Device | null,
   visible: boolean,
@@ -93,6 +108,14 @@ const state = reactive <{
   liveDataSource: []
 })
 
+const getSecret = async () => {
+  message.info('查询中')
+  const { data } = await DeviceContriller.secret({ deviceId: state.deviceDetail!.id, authType: state.deviceDetail!.authType })
+  secretState.visible = true
+  message.success('查询成功')
+  secretState.secret = data
+}
+
 const ok = async () => {
   await DeviceContriller.updateLabel({ id: props.deviceId, deviceLabel: state.deviceLabel })
   state.visible = false

+ 0 - 3
src/service/request.ts

@@ -2,9 +2,6 @@ import { message } from 'ant-design-vue'
 import axios, { AxiosInstance, AxiosResponse } from 'axios'
 import defaultSetting from '../../config/defaultSetting'
 import { useModule } from '@/hooks'
-import { useRoute } from 'vue-router'
-
-console.log('defaultSetting:', defaultSetting)
 
 const instance = axios.create({
   baseURL: '',

+ 1 - 0
src/type/iot.d.ts

@@ -132,6 +132,7 @@ declare namespace IOT {
         deviceNodeType: string
         lastConnectTs: string
         lastActivityTs: string
+        authType: 'SECRET' | 'X509CERT'
       }
 
       interface DeviceTag {