Selaa lähdekoodia

feat: 升级设备ota包

lvkun996 2 vuotta sitten
vanhempi
commit
f99164e2d4

+ 1 - 1
src/api/iot/device.ts

@@ -299,7 +299,7 @@ export const getOtaByDeviceId = (deviceId: string) => {
   })
 }
 
-export const getOtaPageByDeviceId = (params: IOT.API.DEVICE.OtaQueryParams) => {
+export const otaUpgradationRecordByDeviceId = (params: IOT.API.DEVICE.OtaQueryParams) => {
   return request<IOT.API.DEVICE.Ota[]>({
     url: '/deviceOta/page',
     method: 'GET',

+ 1 - 1
src/api/iot/ota.ts

@@ -10,7 +10,7 @@ export const getOtaPkgPage = (params: IOT.API.OTA.QueryParams) => {
 
 export const getOtaPkgList = (params: IOT.API.OTA.QueryParams) => {
   return request<IOT.API.OTA.Detail[]>({
-    url: '/otaPkg/page',
+    url: '/otaPkg/list',
     method: 'GET',
     params
   })

+ 20 - 6
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, getDeviceSecret, getOtaByDeviceId, getOtaPageByDeviceId, upgradationOtaByDeviceId
+  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup, getDevicePage, delSubDevice, getDeviceAttribute, getDevicShadow, getDeviceTopology, getDeviceSession, getDeviceAttributes, getDeviceSecret, getOtaByDeviceId, otaUpgradationRecordByDeviceId, upgradationOtaByDeviceId
 } from '@/api/iot/device'
 import { DeviceMsgEnum, OtaStatusEnum } from '@/enum/common'
 import { message } from 'ant-design-vue'
@@ -77,13 +77,23 @@ export class DeviceContriller {
     }
   }
 
-  static async list (params: {modelId: string, deviceLabel: string, limit: number, lastId: string } = {
+  /**
+   *
+   * @param  deviceStatus 传递对应的key,就只会返回对应状态的设备,不填写返回全部
+   * @returns
+   */
+  static async list (params: {modelId: string, deviceLabel: string, limit: number, lastId: string, deviceStatus: 'INIT' | 'CONNECT' | 'DISCONNECT' | 'DISABLED' | ''} = {
     modelId: '',
     deviceLabel: '',
     limit: 10000,
-    lastId: ''
+    lastId: '',
+    deviceStatus: ''
   }) {
-    return await getDeviceList(params)
+    const data = await getDeviceList(params)
+    return {
+      ...data,
+      data: params.deviceStatus === '' ? data.data : data.data.filter(item => item.deviceStatus === params.deviceStatus)
+    }
   }
 
   static async post (data: IOT.API.DEVICE.BodyParams) {
@@ -269,8 +279,12 @@ export class DeviceContriller {
     }
   }
 
-  static async OtaPageByDeviceId (params: IOT.API.DEVICE.OtaQueryParams) {
-    return await getOtaPageByDeviceId(params)
+  static async OtaUpgradationRecordByDeviceId (params: IOT.API.DEVICE.OtaQueryParams) {
+    const data = await otaUpgradationRecordByDeviceId(params)
+    return {
+      ...data,
+      data: data.data.map(item => ({ ...item, otaTime: dayjs(item.otaTime).format('YYYY-MM-DD HH:mm:ss') }))
+    }
   }
 
   static async upgradationOtaByDeviceId ({ deviceId, otaPkgId }: {deviceId: string, otaPkgId: string}) {

+ 9 - 3
src/controller/iot/ota.ts

@@ -1,4 +1,4 @@
-import { addOtaPkg, delOtaPkg, getOtaPkgById, getOtaPkgPage } from '@/api/iot/ota'
+import { addOtaPkg, delOtaPkg, getOtaPkgById, getOtaPkgList, getOtaPkgPage } from '@/api/iot/ota'
 import { PkgTypeEnum } from '@/enum/common'
 import { message } from 'ant-design-vue'
 
@@ -10,7 +10,13 @@ export class OtaController {
 
   static pkgTypeList = [{ value: PkgTypeEnum.FILE_URL, label: '地址访问' }, { value: PkgTypeEnum.FILE_ZIP, label: 'zip包' }]
 
-  static async page (params: IOT.API.OTA.QueryParams) {
+  static async page (params: IOT.API.OTA.QueryParams = {
+    page: 1,
+    pageSize: 10,
+    label: '',
+    version: '',
+    pkgType: ''
+  }) {
     return await getOtaPkgPage(params)
   }
 
@@ -20,7 +26,7 @@ export class OtaController {
     pkgType: '',
     limit: 10000
   }) {
-    return await getOtaPkgPage(params as any)
+    return await getOtaPkgList(params as any)
   }
 
   static async add (data: IOT.API.OTA.BodyParams) {

+ 18 - 10
src/pages/Iot/device/components/ota.vue

@@ -1,13 +1,13 @@
 <template>
   <a-card>
     <a-row  align="middle" justify="space-between" style="width: 100%;height: 68px" class="title">
-      <a-col>
+      <a-col :span="12" >
         <a-space>
           <span>设备名称:{{state.otaDetail.otaPkgLabel}}</span>
           <span>设备版本:{{state.otaDetail.otaPkgVersion}}</span>
         </a-space>
       </a-col>
-      <a-col :span="2" >
+      <a-col :span="4" >
         <a-button type="primary" @click="openModal" >下发OTA程序包</a-button>
       </a-col>
     </a-row>
@@ -42,18 +42,25 @@
         v-model:value="otaState.deviceId"
         :request="async () => {
           const { data } = await DeviceContriller.list()
-          return data.map(item => ({name: item.deviceLabel, value: item.id, key: item.id}))
+          return data.filter(_ => _.deviceStatus === 'CONNECT').map(item => ({name: item.deviceLabel, value: item.id, key: item.id}))
         }"
       />
       </a-form-item>
-      <a-form-item label="所属产品" v-bind="validateInfos.otaPkgId" >
+      <a-form-item label="所属OTA包" v-bind="validateInfos.otaPkgId" >
+        <select-tsx
+          v-model:value="otaState.otaPkgId"
+          :request="async () => {
+            const { data } = await OtaController.list()
+            return data.map(item => ({name: item.label, value: item.id, key: item.id}))
+          }"
+        />
       </a-form-item>
   </a-form>
   </modal-pro>
 </template>
 
 <script setup lang="ts" >
-import { DeviceContriller } from '@/controller'
+import { DeviceContriller, OtaController } from '@/controller'
 import { onMounted, reactive } from 'vue'
 import { useRoute } from 'vue-router'
 import { Form } from 'ant-design-vue'
@@ -73,7 +80,7 @@ const columns = [
     dataIndex: 'otaPkgVersion'
   },
   {
-    title: 'OTA升级名称',
+    title: 'OTA升级时间',
     dataIndex: 'otaTime'
   },
   {
@@ -126,17 +133,18 @@ const ok = () => {
     await DeviceContriller.upgradationOtaByDeviceId(otaState)
     state.visible = false
     getOtaPkgByDeviceId()
+    getOtaUpgradationRecordByDeviceId()
   })
 }
 
 const changePage = ({ current }) => {
   queryState.page = current
-  getOtaPkgPageByDeviceId()
+  getOtaUpgradationRecordByDeviceId()
 }
 
-const getOtaPkgPageByDeviceId = async () => {
+const getOtaUpgradationRecordByDeviceId = async () => {
   state.loading = true
-  const { data, sum } = await DeviceContriller.OtaPageByDeviceId(queryState)
+  const { data, sum } = await DeviceContriller.OtaUpgradationRecordByDeviceId(queryState)
   state.loading = false
   state.dataSource = data
   queryState.total = sum
@@ -149,7 +157,7 @@ const getOtaPkgByDeviceId = async () => {
 
 onMounted(() => {
   getOtaPkgByDeviceId()
-  getOtaPkgPageByDeviceId()
+  getOtaUpgradationRecordByDeviceId()
 })
 </script>
 

+ 3 - 2
src/pages/Iot/ota/index.vue

@@ -1,6 +1,6 @@
 <template>
-<a-card title="ota包管理" >
-  <a-row justify="space-between" >
+<a-card title="OTA包管理" >
+  <a-row style="width: 100%;" justify="space-between" >
     <a-col :span="16" >
       <a-row :gutter="[8, 8]" >
         <a-col>
@@ -29,6 +29,7 @@
       <a-button type="primary" @click="openModal('add', {})">新增</a-button>
     </a-col>
   </a-row>
+
   <a-table
       style="margin-top: 10px;"
       :columns="columns"

+ 1 - 1
src/router/index.ts

@@ -163,7 +163,7 @@ const iot = {
     },
     {
       path: '/ota',
-      name: 'ota包管理',
+      name: 'OTA程序包',
       icon: 'FolderAddOutlined',
       component: () => import('@/pages/iot/ota/index.vue')
     },

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

@@ -459,7 +459,7 @@ declare namespace IOT {
         pageSize: number
         label: string
         version: string
-        pkgType: 'FILE_URL' | 'FILE_ZIP'
+        pkgType: 'FILE_URL' | 'FILE_ZIP' | ''
       }
       interface BodyParams {
         label: string