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/components/task/TaskPanel.vue |  241 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 176 insertions(+), 65 deletions(-)

diff --git a/src/components/task/TaskPanel.vue b/src/components/task/TaskPanel.vue
index 339c189..2955392 100644
--- a/src/components/task/TaskPanel.vue
+++ b/src/components/task/TaskPanel.vue
@@ -1,22 +1,23 @@
 <template>
-  <div class="header">Task Plan Library</div>
+  <div class="header">计划库</div>
   <div class="plan-panel-wrapper">
     <a-table class="plan-table" :columns="columns" :data-source="plansData.data" row-key="job_id"
       :pagination="paginationProp" :scroll="{ x: '100%', y: 600 }" @change="refreshData">
       <!-- 执行时间 -->
       <template #duration="{ record }">
-        <div>
-          <div>{{ formatTaskTime(record.execute_time) }}</div>
-          <div>{{ formatTaskTime(record.end_time) }}</div>
+        <div class="flex-row" style="white-space: pre-wrap">
+          <div v-if="record.taskType >2">
+            <div>{{ formatTaskTime(record.executeStartTime) }}</div>
+            <div>{{ formatTaskTime(record.executeEndTime) }}</div>
+          </div>
+          <div v-else>
+            <div>{{formatTaskTime(record.executeSingleTime)}}</div>
+          </div>
+          <div class="ml10">
+            <div>{{ formatTaskTime(record.execute_time) }}</div>
+            <div>{{ formatTaskTime(record.completed_time) }}</div>
+          </div>
         </div>
-      </template>
-      <!-- 任务类型 -->
-      <template #taskType="{ record }">
-        <div>{{ formatTaskType(record) }}</div>
-      </template>
-      <!-- 失控动作 -->
-      <template #lostAction="{ record }">
-        <div>{{ formatLostAction(record) }}</div>
       </template>
       <!-- 状态 -->
       <template #status="{ record }">
@@ -36,19 +37,63 @@
           </div>
         </div>
       </template>
+      <!-- 任务类型 -->
+      <template #taskType="{ record }">
+        <div>{{ formatTaskType(record) }}</div>
+      </template>
+      <!-- 失控动作 -->
+      <template #lostAction="{ record }">
+        <div>{{ formatLostAction(record) }}</div>
+      </template>
+     <!-- 媒体上传状态 -->
+      <template #media_upload="{ record }">
+        <div>
+          <div class="flex-display flex-align-center">
+            <span class="circle-icon" :style="{backgroundColor: formatMediaTaskStatus(record).color}"></span>
+            {{ formatMediaTaskStatus(record).text }}
+          </div>
+          <div class="pl15">
+            {{ formatMediaTaskStatus(record).number }}
+            <a-tooltip v-if="formatMediaTaskStatus(record).status === MediaStatus.ToUpload" placement="bottom" arrow-point-at-center >
+              <template #title>
+              <div>Upload now</div>
+              </template>
+              <UploadOutlined class="ml5" :style="{color: commonColor.BLUE, fontSize: '16px' }"  @click="onUploadMediaFileNow(record.job_id)"/>
+            </a-tooltip>
+          </div>
+        </div>
+      </template>
       <!-- 操作 -->
       <template #action="{ record }">
-        <span class="action-area">
+        <div class="action-area">
           <a-popconfirm
             v-if="record.status === TaskStatus.Wait"
-            title="Are you sure you want to delete flight task?"
-            ok-text="Yes"
-            cancel-text="No"
+            title="是否删除飞行计划?"
+            ok-text="是"
+            cancel-text="否"
             @confirm="onDeleteTask(record.job_id)"
           >
-            <a-button type="primary" size="small">Delete</a-button>
+            <a-button type="primary" size="small">删除</a-button>
           </a-popconfirm>
-        </span>
+          <a-popconfirm
+            v-if="record.status === TaskStatus.Carrying"
+            title="是否暂停?"
+            ok-text="是"
+            cancel-text="否"
+            @confirm="onSuspendTask(record.job_id)"
+          >
+            <a-button type="primary" size="small">暂停</a-button>
+          </a-popconfirm>
+          <a-popconfirm
+            v-if="record.status === TaskStatus.Paused"
+            title="是否重新开始?"
+            ok-text="是"
+            cancel-text="否"
+            @confirm="onResumeTask(record.job_id)"
+          >
+            <a-button type="primary" size="small">重启</a-button>
+          </a-popconfirm>
+        </div>
       </template>
     </a-table>
   </div>
@@ -60,18 +105,18 @@
 import { TableState } from 'ant-design-vue/lib/table/interface'
 import { onMounted } from 'vue'
 import { IPage } from '/@/api/http/type'
-import { deleteTask, getWaylineJobs, Task } from '/@/api/wayline'
+import { deleteTask, updateTaskStatus, UpdateTaskStatus, getWaylineJobs, Task, uploadMediaFileNow } from '/@/api/wayline'
 import { useMyStore } from '/@/store'
 import { ELocalStorageKey } from '/@/types/enums'
 import { useFormatTask } from './use-format-task'
-import { TaskStatus, TaskProgressInfo, TaskProgressStatus, TaskProgressWsStatusMap } from '/@/types/task'
-import { useTaskProgressEvent } from './use-task-progress-event'
+import { TaskStatus, TaskProgressInfo, TaskProgressStatus, TaskProgressWsStatusMap, MediaStatus, MediaStatusProgressInfo, TaskMediaHighestPriorityProgressInfo } from '/@/types/task'
+import { useTaskWsEvent } from './use-task-ws-event'
 import { getErrorMessage } from '/@/utils/error-code/index'
 import { commonColor } from '/@/utils/color'
-import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
+import { ExclamationCircleOutlined, UploadOutlined } from '@ant-design/icons-vue'
 
 const store = useMyStore()
-const workspaceId = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
+const workspaceId = store.state.common.projectId
 
 const body: IPage = {
   page: 1,
@@ -89,60 +134,52 @@
 
 const columns = [
   {
-    title: 'Planned/Actual Time',
+    title: '计划|实际时间',
     dataIndex: 'duration',
-    width: 180,
+    width: 200,
     slots: { customRender: 'duration' },
   },
   {
-    title: 'Plan Name',
-    dataIndex: 'job_name',
+    title: '执行状态',
+    key: 'status',
     width: 150,
-    ellipsis: true
+    slots: { customRender: 'status' }
   },
   {
-    title: 'Type',
+    title: '类型',
     dataIndex: 'taskType',
-    width: 120,
+    width: 100,
     slots: { customRender: 'taskType' },
   },
   {
-    title: 'Flight Route Name',
-    dataIndex: 'file_name',
-    width: 150,
+    title: '计划名称',
+    dataIndex: 'name',
+    width: 100,
+  },
+  {
+    title: '航线名称',
+    dataIndex: 'fileName',
+    width: 100,
+  },
+  {
+    title: '设备名称',
+    dataIndex: 'dockName',
+    width: 100,
     ellipsis: true
   },
   {
-    title: 'Dock Name',
-    dataIndex: 'dock_name',
-    width: 120,
-    ellipsis: true
-  },
-  {
-    title: 'RTH Altitude Relative to Dock (m)',
-    dataIndex: 'rth_altitude',
-    width: 120,
-    ellipsis: true
-  },
-  {
-    title: 'Lost Action',
-    dataIndex: 'out_of_control_action',
-    width: 120,
-    slots: { customRender: 'lostAction' },
-  },
-  {
-    title: 'Creator',
+    title: '创建人',
     dataIndex: 'username',
     width: 120,
   },
   {
-    title: 'Status',
-    key: 'status',
-    width: 200,
-    slots: { customRender: 'status' }
+    title: '媒体上传',
+    key: 'media_upload',
+    width: 160,
+    slots: { customRender: 'media_upload' }
   },
   {
-    title: 'Action',
+    title: '操作',
     width: 120,
     slots: { customRender: 'action' }
   }
@@ -153,7 +190,7 @@
   data: [] as Task[]
 })
 
-const { formatTaskType, formatTaskTime, formatLostAction, formatTaskStatus } = useFormatTask()
+const { formatTaskType, formatTaskTime, formatLostAction, formatTaskStatus, formatMediaTaskStatus } = useFormatTask()
 
 // 设备任务执行进度更新
 function onTaskProgressWs (data: TaskProgressInfo) {
@@ -174,11 +211,44 @@
   }
 }
 
+// 媒体上传进度更新
+function onTaskMediaProgressWs (data: MediaStatusProgressInfo) {
+  const { media_count: mediaCount, uploaded_count: uploadedCount, job_id: jobId } = data
+  if (isNaN(mediaCount) || isNaN(uploadedCount) || !jobId) {
+    return
+  }
+  const taskItem = plansData.data.find(task => task.job_id === jobId)
+  if (!taskItem) return
+  if (mediaCount === uploadedCount) {
+    taskItem.uploading = false
+  } else {
+    taskItem.uploading = true
+  }
+  taskItem.media_count = mediaCount
+  taskItem.uploaded_count = uploadedCount
+}
+
+function onoTaskMediaHighestPriorityWS (data: TaskMediaHighestPriorityProgressInfo) {
+  const { pre_job_id: preJobId, job_id: jobId } = data
+  const preTaskItem = plansData.data.find(task => task.job_id === preJobId)
+  const taskItem = plansData.data.find(task => task.job_id === jobId)
+  if (preTaskItem) {
+    preTaskItem.uploading = false
+  }
+  if (taskItem) {
+    taskItem.uploading = true
+  }
+}
+
 function getCodeMessage (code: number) {
   return getErrorMessage(code) + `(code: ${code})`
 }
 
-useTaskProgressEvent(onTaskProgressWs)
+useTaskWsEvent({
+  onTaskProgressWs,
+  onTaskMediaProgressWs,
+  onoTaskMediaHighestPriorityWS,
+})
 
 onMounted(() => {
   getPlans()
@@ -186,12 +256,15 @@
 
 function getPlans () {
   getWaylineJobs(workspaceId, body).then(res => {
-    if (res.code !== 0) {
+    console.log('计划数据', res)
+    const data = res.data
+
+    if (res.code !== 5000) {
       return
     }
-    plansData.data = res.data.list
-    paginationProp.total = res.data.pagination.total
-    paginationProp.current = res.data.pagination.page
+    plansData.data = data.records
+    paginationProp.total = data.records.total
+    paginationProp.current = data.records.current
   })
 }
 
@@ -211,6 +284,39 @@
     getPlans()
   }
 }
+
+// 挂起任务
+async function onSuspendTask (jobId: string) {
+  const { code } = await updateTaskStatus(workspaceId, {
+    job_id: jobId,
+    status: UpdateTaskStatus.Suspend
+  })
+  if (code === 0) {
+    message.success('Suspended successfully')
+    getPlans()
+  }
+}
+
+// 解除挂起任务
+async function onResumeTask (jobId: string) {
+  const { code } = await updateTaskStatus(workspaceId, {
+    job_id: jobId,
+    status: UpdateTaskStatus.Resume
+  })
+  if (code === 0) {
+    message.success('Resumed successfully')
+    getPlans()
+  }
+}
+
+// 立即上传媒体
+async function onUploadMediaFileNow (jobId: string) {
+  const { code } = await uploadMediaFileNow(workspaceId, jobId)
+  if (code === 0) {
+    message.success('Upload Media File successfully')
+    getPlans()
+  }
+}
 </script>
 
 <style lang="scss" scoped>
@@ -222,8 +328,13 @@
     margin-top: 10px;
   }
   .action-area {
-    color: $primary;
-    cursor: pointer;
+
+    &::v-deep {
+      .ant-btn {
+        margin-right: 10px;
+        margin-bottom: 10px;
+      }
+    }
   }
 
   .circle-icon {

--
Gitblit v1.9.3