From 8b2796fffef8d0436639b997b662a8b5790404e5 Mon Sep 17 00:00:00 2001
From: husq <931347610@qq.com>
Date: Wed, 13 Sep 2023 20:33:05 +0800
Subject: [PATCH] demo环境初步搭建

---
 src/pages/page-web/projects/devices.vue |   78 +++++++++++++++++++++------------------
 1 files changed, 42 insertions(+), 36 deletions(-)

diff --git a/src/pages/page-web/projects/devices.vue b/src/pages/page-web/projects/devices.vue
index 5a2f055..cbc676f 100644
--- a/src/pages/page-web/projects/devices.vue
+++ b/src/pages/page-web/projects/devices.vue
@@ -8,7 +8,6 @@
       机场
     </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 }"
@@ -27,7 +26,6 @@
           </template>
         </div>
       </template>
-
       <template v-for="col in ['sn', 'workspace']" #[col]="{ text }" :key="col">
         <a-tooltip :title="text">
             <span>{{ text }}</span>
@@ -49,11 +47,11 @@
       <template #status="{ text }">
         <span v-if="text" class="flex-row flex-align-center">
             <span class="mr5" style="width: 12px; height: 12px; border-radius: 50%; background-color: green;" />
-            <span>Online</span>
+            <span>在线</span>
         </span>
         <span class="flex-row flex-align-center" v-else>
             <span class="mr5" style="width: 12px; height: 12px; border-radius: 50%; background-color: red;" />
-            <span>Offline</span>
+            <span>离线</span>
         </span>
       </template>
       <!-- 操作 -->
@@ -61,10 +59,10 @@
         <div class="editable-row-operations">
           <!-- 编辑态操作 -->
           <div v-if="editableData[record.device_sn]">
-            <a-tooltip title="Confirm changes">
+            <a-tooltip title="保存">
               <span @click="save(record)" style="color: #28d445;"><CheckOutlined /></span>
             </a-tooltip>
-            <a-tooltip title="Modification canceled">
+            <a-tooltip title="取消">
               <span @click="() => delete editableData[record.device_sn]" style="color: #e70102;"><CloseOutlined /></span>
             </a-tooltip>
           </div>
@@ -73,13 +71,13 @@
             <a-tooltip v-if="current.indexOf(EDeviceTypeName.Dock) !== -1" title="设备日志">
               <CloudServerOutlined @click="showDeviceLogUploadRecord(record)"/>
             </a-tooltip>
-            <a-tooltip v-if="current.indexOf(EDeviceTypeName.Dock) !== -1" title="Hms Info">
+            <a-tooltip v-if="current.indexOf(EDeviceTypeName.Dock) !== -1" title="Hms信息">
               <FileSearchOutlined @click="showHms(record)"/>
             </a-tooltip>
-            <a-tooltip title="Edit">
+            <a-tooltip title="编辑">
               <EditOutlined @click="edit(record)"/>
             </a-tooltip>
-            <a-tooltip title="Delete">
+            <a-tooltip title="删除">
               <DeleteOutlined @click="() => { deleteTip = true, deleteSn = record.device_sn }"/>
             </a-tooltip>
           </div>
@@ -88,10 +86,10 @@
 
     </a-table>
     <a-modal v-model:visible="deleteTip" width="450px" :closable="false" centered :okButtonProps="{ danger: true }" @ok="unbind">
-        <p class="pt10 pl20" style="height: 50px;">Delete device from workspace?</p>
+        <p class="pt10 pl20" style="height: 50px;">确定从项目中删除该设备吗?</p>
         <template #title>
             <div class="flex-row flex-justify-center">
-                <span>Delete devices</span>
+                <span>确定</span>
             </div>
         </template>
     </a-modal>
@@ -115,13 +113,12 @@
       :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, getDeviceList, unbindDevice, updateDevice } from '/@/api/manage'
+import { BindBody, bindDevice, getBindingDevices, 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'
@@ -138,12 +135,12 @@
   device: Device[]
 }
 
-const loading = ref(true)
+const loading = ref(false)
 const deleteTip = ref<boolean>(false)
 const deleteSn = ref<string>()
 const columns: ColumnProps[] = [
-  { title: '设备型号', dataIndex: 'deviceName', width: 100, className: 'titleStyle' },
-  { title: '设备SN', dataIndex: 'deviceSn', width: 100, className: 'titleStyle', ellipsis: true, slots: { customRender: 'sn' } },
+  { title: '设备型号', dataIndex: 'device_name', width: 100, className: 'titleStyle' },
+  { title: '设备SN', dataIndex: 'device_sn', width: 100, className: 'titleStyle', ellipsis: true, slots: { customRender: 'sn' } },
   {
     title: '设备组织名称',
     dataIndex: 'nickname',
@@ -153,11 +150,11 @@
     ellipsis: true,
     slots: { customRender: 'nickname' }
   },
-  { title: '固件版本', dataIndex: 'firmwareVersion', width: 150, className: 'titleStyle', slots: { customRender: 'firmware_version' } },
+  { title: '固件版本', dataIndex: 'firmware_version', width: 150, className: 'titleStyle', slots: { customRender: 'firmware_version' } },
   { title: '在线状态', dataIndex: 'status', width: 100, className: 'titleStyle', slots: { customRender: 'status' } },
   {
     title: '所属项目',
-    dataIndex: 'workspaceName',
+    dataIndex: 'workspace_name',
     width: 100,
     className: 'titleStyle',
     ellipsis: true,
@@ -175,8 +172,8 @@
       return obj
     }
   },
-  { 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: '加入组织时间', dataIndex: 'bound_time', width: 150, sorter: (a: Device, b: Device) => a.bound_time.localeCompare(b.bound_time), className: 'titleStyle' },
+  { title: '在线时间', dataIndex: 'login_time', width: 150, sorter: (a: Device, b: Device) => a.login_time.localeCompare(b.login_time), className: 'titleStyle' },
   {
     title: '操作',
     dataIndex: 'actions',
@@ -224,8 +221,8 @@
 // 获取分页信息
 function getPaginationBody () {
   return {
-    current: paginationProp.current,
-    size: paginationProp.pageSize
+    page: paginationProp.current,
+    page_size: paginationProp.pageSize
   } as IPage
 }
 
@@ -300,22 +297,31 @@
 useDeviceUpgradeEvent(onDeviceUpgradeWs)
 
 // 获取设备列表信息
-function getDevices (params:any) {
-  loading.value = true
-  const paginationBody = getPaginationBody()
-
-  getDeviceList(Object.assign(params, paginationBody)).then(res => {
-    if (res.code !== 5000) {
+function getDevices (domain: number, closeLoading?: boolean) {
+  if (!closeLoading) {
+    loading.value = true
+  }
+  getBindingDevices(workspaceId, getPaginationBody(), domain).then(res => {
+    if (res.code !== 0) {
+      loading.value = false
       return
     }
-
-    console.log(res, '++++++++++')
-    const list = res.data.records
-    data.device = list
-
+    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
     loading.value = false
-  }).catch(err => {
-    console.log('错误:', err)
+  }).catch(e => {
     loading.value = false
   })
 }
@@ -375,7 +381,7 @@
 }
 
 onMounted(() => {
-  // getDevices(current.value[0])
+  getDevices(current.value[0])
 })
 </script>
 

--
Gitblit v1.9.3