DJIsean
2022-08-17 c5f51306bfc8e57e4837d071e38e25fa6aa87f76
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<template>
  <div class="header">Task Plan Library</div>
  <div class="plan-panel-wrapper">
    <!-- <router-link :to=" '/' + ERouterName.CREATE_PLAN">
      <a-button type="primary">Create Plan</a-button>
    </router-link> -->
    <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 #status="{ record }">
        <span v-if="taskProgressMap[record.bid]">
          <a-progress type="line" :percent="taskProgressMap[record.bid]?.progress?.percent"
            :status="taskProgressMap[record.bid]?.status === ETaskStatus.FAILED ? 'exception' : taskProgressMap[record.bid]?.status === ETaskStatus.OK ? 'success' : 'normal'">
            <template #format="percent">
              <a-tooltip :title="taskProgressMap[record.bid]?.status">
                <div style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden; position: absolute; left: 5px; top: -12px;">
                  {{ percent }}% {{ taskProgressMap[record.bid]?.status }}
                </div>
              </a-tooltip>
            </template>
          </a-progress>
        </span>
      </template>
      <template #action="{ record }">
        <span class="action-area">
          <a-popconfirm
            title="Are you sure execute this task?"
            ok-text="Yes"
            cancel-text="No"
            @confirm="executePlan(record.job_id)"
          >
            <a-button type="primary" size="small">Execute</a-button>
          </a-popconfirm>
        </span>
      </template>
    </a-table>
  </div>
</template>
 
<script setup lang="ts">
import { reactive, ref } from '@vue/reactivity'
import { message } from 'ant-design-vue'
import { TableState } from 'ant-design-vue/lib/table/interface'
import { computed, onMounted, watch } from 'vue'
import { IPage } from '../api/http/type'
import { executeWaylineJobs, getWaylineJobs } from '../api/wayline'
import { getRoot } from '../root'
import { useMyStore } from '../store'
import { ELocalStorageKey, ERouterName } from '../types/enums'
import router from '/@/router'
import { ETaskStatus } from '/@/types/wayline'
 
const store = useMyStore()
 
const workspaceId = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
 
const root = getRoot()
const body: IPage = {
  page: 1,
  total: 0,
  page_size: 50
}
const paginationProp = reactive({
  pageSizeOptions: ['20', '50', '100'],
  showQuickJumper: true,
  showSizeChanger: true,
  pageSize: 50,
  current: 1,
  total: 0
})
 
const columns = [
  {
    title: 'Plan Name',
    dataIndex: 'job_name'
  },
  {
    title: 'Flight Route Name',
    dataIndex: 'file_name',
    ellipsis: true
  },
  {
    title: 'Dock Name',
    dataIndex: 'dock_name',
    ellipsis: true
  },
  {
    title: 'Creator',
    dataIndex: 'username',
  },
  {
    title: 'Updated',
    dataIndex: 'update_time'
  },
  {
    title: 'Status',
    key: 'status',
    width: 200,
    slots: { customRender: 'status' }
  },
 
  {
    title: 'Action',
    slots: { customRender: 'action' }
  }
]
type Pagination = TableState['pagination']
 
interface TaskPlan {
  bid: string,
  job_id: string,
  job_name: string,
  file_name: string,
  dock_name: string,
  username: string,
  create_time: string,
}
 
const plansData = reactive({
  data: [] as TaskPlan[]
})
 
function createPlan () {
  root.$router.push('/' + ERouterName.CREATE_PLAN)
}
 
const taskProgressMap = computed(() => store.state.taskProgressInfo)
 
onMounted(() => {
  getPlans()
})
 
function getPlans () {
  getWaylineJobs(workspaceId, body).then(res => {
    if (res.code !== 0) {
      return
    }
    plansData.data = res.data.list
    paginationProp.total = res.data.pagination.total
    paginationProp.current = res.data.pagination.page
  })
}
 
function refreshData (page: Pagination) {
  body.page = page?.current!
  body.page_size = page?.pageSize!
  getPlans()
}
 
function executePlan (jobId: string) {
  executeWaylineJobs(workspaceId, jobId).then(res => {
    if (res.code === 0) {
      message.success('Executed Successfully')
      getPlans()
    }
  })
}
</script>
 
<style lang="scss" scoped>
.plan-panel-wrapper {
  width: 100%;
  padding: 16px;
  .plan-table {
    background: #fff;
    margin-top: 10px;
  }
  .action-area {
    color: $primary;
    cursor: pointer;
  }
}
.header {
  width: 100%;
  height: 60px;
  background: #fff;
  padding: 16px;
  font-size: 20px;
  font-weight: bold;
  text-align: start;
  color: #000;
}
</style>