From 3667807a7b7418efc090ee3fa6a6b734bc3080bf Mon Sep 17 00:00:00 2001
From: xieb <vip_xiaobin810@163.com>
Date: Wed, 13 Sep 2023 20:36:29 +0800
Subject: [PATCH] Merge branch 'develop' of http://s16s652780.51mypc.cn:49896/r/yskj/iot_drone_web into develop

---
 src/pages/page-web/projects/devices.vue |   86 ++++++++++++++++++++++--------------------
 1 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/src/pages/page-web/projects/devices.vue b/src/pages/page-web/projects/devices.vue
index c5fd408..5a2f055 100644
--- a/src/pages/page-web/projects/devices.vue
+++ b/src/pages/page-web/projects/devices.vue
@@ -2,12 +2,13 @@
 <template>
   <a-menu v-model:selectedKeys="current" mode="horizontal" @select="select">
     <a-menu-item :key="EDeviceTypeName.Aircraft" class="ml20">
-      Aircraft
+      飞行器
     </a-menu-item>
     <a-menu-item :key="EDeviceTypeName.Dock">
-      Dock
+      机场
     </a-menu-item>
   </a-menu>
+
   <div class="device-table-wrap table flex-display flex-column">
     <a-table :columns="columns" :data-source="data.device" :pagination="paginationProp" @change="refreshData" row-key="device_sn" :expandedRowKeys="expandRows"
     :row-selection="rowSelection" :rowClassName="rowClassName" :scroll="{ x: '100%', y: 600 }"
@@ -20,10 +21,13 @@
             style="margin: -5px 0"
           />
           <template v-else>
-            {{ text }}
+            <a-tooltip :title="text">
+              {{ text }}
+            </a-tooltip>
           </template>
         </div>
       </template>
+
       <template v-for="col in ['sn', 'workspace']" #[col]="{ text }" :key="col">
         <a-tooltip :title="text">
             <span>{{ text }}</span>
@@ -111,12 +115,13 @@
       :device="currentDevice">
     </DeviceHmsDrawer>
   </div>
+
 </template>
 <script lang="ts" setup>
 import { ColumnProps, TableState } from 'ant-design-vue/lib/table/interface'
 import { h, onMounted, reactive, ref, UnwrapRef } from 'vue'
 import { IPage } from '/@/api/http/type'
-import { BindBody, bindDevice, getBindingDevices, unbindDevice, updateDevice } from '/@/api/manage'
+import { BindBody, bindDevice, getBindingDevices, getDeviceList, unbindDevice, updateDevice } from '/@/api/manage'
 import { EDeviceTypeName, ELocalStorageKey } from '/@/types'
 import { EditOutlined, CheckOutlined, CloseOutlined, DeleteOutlined, FileSearchOutlined, CloudServerOutlined } from '@ant-design/icons-vue'
 import { Device, DeviceFirmwareStatusEnum } from '/@/types/device'
@@ -127,7 +132,7 @@
 import { DeviceCmdExecuteInfo, DeviceCmdExecuteStatus } from '/@/types/device-cmd'
 import DeviceLogUploadRecordDrawer from '/@/components/devices/device-log/DeviceLogUploadRecordDrawer.vue'
 import DeviceHmsDrawer from '/@/components/devices/device-hms/DeviceHmsDrawer.vue'
-import { message } from 'ant-design-vue'
+import { message, notification } from 'ant-design-vue'
 
 interface DeviceData {
   device: Device[]
@@ -137,10 +142,10 @@
 const deleteTip = ref<boolean>(false)
 const deleteSn = ref<string>()
 const columns: ColumnProps[] = [
-  { title: 'Model', dataIndex: 'device_name', width: 100, className: 'titleStyle' },
-  { title: 'SN', dataIndex: 'device_sn', width: 100, className: 'titleStyle', ellipsis: true, slots: { customRender: 'sn' } },
+  { title: '设备型号', dataIndex: 'deviceName', width: 100, className: 'titleStyle' },
+  { title: '设备SN', dataIndex: 'deviceSn', width: 100, className: 'titleStyle', ellipsis: true, slots: { customRender: 'sn' } },
   {
-    title: 'Name',
+    title: '设备组织名称',
     dataIndex: 'nickname',
     width: 100,
     sorter: (a: Device, b: Device) => a.nickname.localeCompare(b.nickname),
@@ -148,11 +153,11 @@
     ellipsis: true,
     slots: { customRender: 'nickname' }
   },
-  { title: 'Firmware Version', dataIndex: 'firmware_version', width: 150, className: 'titleStyle', slots: { customRender: 'firmware_version' } },
-  { title: 'Status', dataIndex: 'status', width: 100, className: 'titleStyle', slots: { customRender: 'status' } },
+  { title: '固件版本', dataIndex: 'firmwareVersion', width: 150, className: 'titleStyle', slots: { customRender: 'firmware_version' } },
+  { title: '在线状态', dataIndex: 'status', width: 100, className: 'titleStyle', slots: { customRender: 'status' } },
   {
-    title: 'Workspace',
-    dataIndex: 'workspace_name',
+    title: '所属项目',
+    dataIndex: 'workspaceName',
     width: 100,
     className: 'titleStyle',
     ellipsis: true,
@@ -170,10 +175,10 @@
       return obj
     }
   },
-  { title: 'Joined', dataIndex: 'bound_time', width: 150, sorter: (a: Device, b: Device) => a.bound_time.localeCompare(b.bound_time), className: 'titleStyle' },
-  { title: 'Last Online', dataIndex: 'login_time', width: 150, sorter: (a: Device, b: Device) => a.login_time.localeCompare(b.login_time), className: 'titleStyle' },
+  { title: '加入组织时间', dataIndex: 'boundTime', width: 150, sorter: (a: Device, b: Device) => a.bound_time.localeCompare(b.bound_time), className: 'titleStyle' },
+  { title: '在线时间', dataIndex: 'loginTime', width: 150, sorter: (a: Device, b: Device) => a.login_time.localeCompare(b.login_time), className: 'titleStyle' },
   {
-    title: 'Actions',
+    title: '操作',
     dataIndex: 'actions',
     width: 100,
     className: 'titleStyle',
@@ -219,8 +224,8 @@
 // 获取分页信息
 function getPaginationBody () {
   return {
-    page: paginationProp.current,
-    page_size: paginationProp.pageSize
+    current: paginationProp.current,
+    size: paginationProp.pageSize
   } as IPage
 }
 
@@ -268,13 +273,18 @@
   for (let i = 0; i < devices.length; i++) {
     if (devices[i].device_sn === payload.sn) {
       if (!payload.output) return
-      const { status, progress } = payload.output
+      const { status, progress, ext } = payload.output
       if (status === DeviceCmdExecuteStatus.Sent || status === DeviceCmdExecuteStatus.InProgress) { // 升级中
+        const rate = ext?.rate ? (ext.rate / 1024).toFixed(2) + 'kb/s' : ''
         devices[i].firmware_status = DeviceFirmwareStatusEnum.DuringUpgrade
-        devices[i].firmware_progress = progress?.percent || 0
+        devices[i].firmware_progress = (progress?.percent || 0) + '% ' + rate
       } else { // 终态:成功,失败,超时
         if (status === DeviceCmdExecuteStatus.Failed || status === DeviceCmdExecuteStatus.Timeout) {
-          message.error(`设备(${payload.sn}) 升级失败`)
+          notification.error({
+            message: `(${payload.sn}) Upgrade failed`,
+            description: `Error Code: ${payload.result}`,
+            duration: null
+          })
         }
         // 拉取列表
         getDevices(current.value[0], true)
@@ -290,28 +300,22 @@
 useDeviceUpgradeEvent(onDeviceUpgradeWs)
 
 // 获取设备列表信息
-function getDevices (domain: string, closeLoading?: boolean) {
-  if (!closeLoading) {
-    loading.value = true
-  }
-  getBindingDevices(workspaceId, getPaginationBody(), domain).then(res => {
-    if (res.code !== 0) {
+function getDevices (params:any) {
+  loading.value = true
+  const paginationBody = getPaginationBody()
+
+  getDeviceList(Object.assign(params, paginationBody)).then(res => {
+    if (res.code !== 5000) {
       return
     }
-    const resData: Device[] = res.data.list
-    expandRows.value = []
-    resData.forEach((val: any) => {
-      if (val.children) {
-        val.children = [val.children]
-      }
-      if (judgeCurrentType(EDeviceTypeName.Dock)) {
-        expandRows.value.push(val.device_sn)
-      }
-    })
-    data.device = resData
-    paginationProp.total = res.data.pagination.total
-    paginationProp.current = res.data.pagination.page
-    paginationProp.pageSize = res.data.pagination.page_size
+
+    console.log(res, '++++++++++')
+    const list = res.data.records
+    data.device = list
+
+    loading.value = false
+  }).catch(err => {
+    console.log('错误:', err)
     loading.value = false
   })
 }
@@ -371,7 +375,7 @@
 }
 
 onMounted(() => {
-  getDevices(current.value[0])
+  // getDevices(current.value[0])
 })
 </script>
 

--
Gitblit v1.9.3