index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <div class="taskList">
  3. <div class="taskList-left" v-if="state.collapsed">
  4. <div class="taskList-left-title">
  5. <div>
  6. 当前机场
  7. </div>
  8. <a-checkbox v-model:checked="checkState.checkAll" :indeterminate="checkState.indeterminate"
  9. @change="onCheckAllChange">
  10. 全选
  11. </a-checkbox>
  12. </div>
  13. <div v-for="(dock, index) in state.onlineDockList" :key="dock.sn">
  14. <div :class="[
  15. 'taskList-left-item',
  16. checkState.checkSnList.includes(dock.sn) ? 'taskList-left-item-selected' : ''
  17. ]" @click="onClickCheckItem(dock.sn)">
  18. <Airport :dock="dock" :look-info="false" />
  19. </div>
  20. </div>
  21. </div>
  22. <div :style="{ width: state.collapsed ? 'calc(100% - 250px)' : '100%' }">
  23. <Search :onClickCollapsed="() => { state.collapsed = !state.collapsed }" :onClickCreateTask="() => { }"
  24. :onClickSearch="onClickSearch" :onClickReset="onClickReset" />
  25. <a-table :scroll="{ x: '100%', y: 500 }" rowKey="job_id" :loading="state.listLoading" :columns="columns"
  26. :dataSource="state.list" @change="refreshData" :rowClassName="rowClassName" :pagination="paginationConfig">
  27. <!-- 计划|实际时间 -->
  28. <template #duration="{ record }">
  29. <div class="flex-row" style="white-space: pre-wrap">
  30. <div>
  31. <div>
  32. {{ record.begin_time }}
  33. </div>
  34. <div>
  35. {{ record.end_time }}
  36. </div>
  37. </div>
  38. <div class="ml10">
  39. <div>
  40. {{ record.execute_time }}
  41. </div>
  42. <div>
  43. {{ record.completed_time }}
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <!-- 执行状态 -->
  49. <template #status="{ record }">
  50. <div style="color: #2B85E4;" v-if="record.status === 1">
  51. 待执行
  52. </div>
  53. <div style="color: #2B85E4;" v-else-if="record.status === 2">
  54. 执行中
  55. </div>
  56. <div style="color: #19BE6B;" v-else-if="record.status === 3">
  57. 完成
  58. </div>
  59. <div style="color: #E02020;" v-else-if="record.status === 4">
  60. 取消
  61. </div>
  62. <div style="color: #E02020;" v-else-if="record.status === 5">
  63. 失败
  64. </div>
  65. <div style="color: #2B85E4;" v-else-if="record.status === 6">
  66. 暂停
  67. </div>
  68. </template>
  69. <!-- 媒体上传 -->
  70. <template #media_upload="{ record }">
  71. <div class="flex-display flex-align-center">
  72. <span class="circle-icon" :style="{ backgroundColor: formatMediaTaskStatus(record).color }"></span>
  73. {{ formatMediaTaskStatus(record).text }}
  74. </div>
  75. <div class="pl15">
  76. {{ formatMediaTaskStatus(record).number }}
  77. </div>
  78. </template>
  79. <!-- 操作 -->
  80. <template #action="{ record }">
  81. <div class="flex-align-center flex-row" style="color: #2d8cf0">
  82. <a-tooltip title="复制任务">
  83. <CopyOutlined style="margin-right: 10px;" />
  84. </a-tooltip>
  85. <a-tooltip title="查看轨迹" v-if="false">
  86. <GatewayOutlined style="margin-right: 10px;" />
  87. </a-tooltip>
  88. <a-tooltip title="删除">
  89. <DeleteOutlined @click="onClickDelete(record.job_id, record.job_name)" />
  90. </a-tooltip>
  91. </div>
  92. </template>
  93. </a-table>
  94. </div>
  95. </div>
  96. </template>
  97. <script lang="ts" setup>
  98. import { reactive, onMounted, watch, computed } from 'vue';
  99. import { Modal, message } from 'ant-design-vue';
  100. import { CopyOutlined, GatewayOutlined, DeleteOutlined } from '@ant-design/icons-vue';
  101. import Search from './components/Search.vue';
  102. import Airport from '/@/components/airport/index.vue'
  103. import { useMyStore } from '/@/store';
  104. import { useFormatTask } from '/@/components/task/use-format-task'
  105. import { apis } from '/@/api/custom';
  106. import { getDeviceTopo, getUnreadDeviceHms } from '/@/api/manage';
  107. import { getWorkspaceId } from '/@/utils';
  108. import { OnlineDevice, EModeCode } from '/@/types/device'
  109. import { EDeviceTypeName } from '/@/types'
  110. interface State {
  111. collapsed: boolean,
  112. onlineDockList: OnlineDevice[],
  113. query: any,
  114. listLoading: boolean,
  115. list: any[],
  116. };
  117. const state: State = reactive({
  118. collapsed: true,
  119. onlineDockList: [],
  120. query: undefined,
  121. listLoading: false,
  122. list: [],
  123. });
  124. const checkState = reactive({
  125. checkAll: false as boolean,
  126. indeterminate: false as boolean,
  127. checkSnList: [] as string[],
  128. });
  129. watch(() => checkState.checkSnList, val => {
  130. checkState.indeterminate = !!val.length && val.length < state.onlineDockList.length;
  131. checkState.checkAll = val.length === state.onlineDockList.length;
  132. }, { deep: true });
  133. const store = useMyStore();
  134. const { formatMediaTaskStatus } = useFormatTask();
  135. const deviceInfo = computed(() => store.state.deviceState.deviceInfo)
  136. const dockInfo = computed(() => store.state.deviceState.dockInfo)
  137. const hmsInfo = computed({
  138. get: () => store.state.hmsInfo,
  139. set: (val) => {
  140. return val
  141. }
  142. })
  143. const fetchOnlineDock = async () => {
  144. const res = await getDeviceTopo(getWorkspaceId());
  145. if (res.code !== 0) {
  146. return;
  147. }
  148. const list = state.onlineDockList;
  149. res.data.forEach((gateway: any) => {
  150. const child = gateway.children
  151. const device: OnlineDevice = {
  152. model: child?.device_name,
  153. callsign: child?.nickname,
  154. sn: child?.device_sn,
  155. mode: EModeCode.Disconnected,
  156. gateway: {
  157. model: gateway?.device_name,
  158. callsign: gateway?.nickname,
  159. sn: gateway?.device_sn,
  160. domain: gateway?.domain
  161. },
  162. payload: []
  163. }
  164. child?.payloads_list.forEach((payload: any) => {
  165. device.payload.push({
  166. index: payload.index,
  167. model: payload.model,
  168. payload_name: payload.payload_name,
  169. payload_sn: payload.payload_sn,
  170. control_source: payload.control_source,
  171. payload_index: payload.payload_index
  172. })
  173. })
  174. if (EDeviceTypeName.Dock === gateway.domain) {
  175. list.push(device)
  176. }
  177. })
  178. state.onlineDockList = list;
  179. checkState.checkAll = true;
  180. checkState.checkSnList = list.map(item => item.sn);
  181. }
  182. const fetchList = async () => {
  183. state.listLoading = true;
  184. try {
  185. const res = await apis.fetchJobList({
  186. ...state.query,
  187. snList: checkState.checkSnList.join(','),
  188. page: paginationConfig.current,
  189. page_size: paginationConfig.pageSize
  190. });
  191. if (res.code === 0) {
  192. state.list = res.data.list;
  193. paginationConfig.total = res.data.pagination.total
  194. paginationConfig.current = res.data.pagination.page
  195. paginationConfig.pageSize = res.data.pagination.page_size
  196. }
  197. } catch (e) {
  198. console.error(e);
  199. } finally {
  200. state.listLoading = false;
  201. }
  202. }
  203. function getUnreadHms(sn: string) {
  204. getUnreadDeviceHms(getWorkspaceId(), sn).then(res => {
  205. if (res.data.length !== 0) {
  206. hmsInfo.value[sn] = res.data
  207. }
  208. })
  209. }
  210. function getOnlineDeviceHms() {
  211. const snList = Object.keys(dockInfo.value)
  212. if (snList.length === 0) {
  213. return
  214. }
  215. snList.forEach(sn => {
  216. getUnreadHms(sn)
  217. })
  218. const deviceSnList = Object.keys(deviceInfo.value)
  219. if (deviceSnList.length === 0) {
  220. return
  221. }
  222. deviceSnList.forEach(sn => {
  223. getUnreadHms(sn)
  224. })
  225. }
  226. onMounted(async () => {
  227. await fetchOnlineDock();
  228. setTimeout(() => {
  229. watch(() => store.state.deviceStatusEvent, async data => {
  230. await fetchOnlineDock()
  231. if (data.deviceOnline.sn) {
  232. getUnreadHms(data.deviceOnline.sn)
  233. }
  234. }, { deep: true })
  235. getOnlineDeviceHms()
  236. }, 1000)// 默认3秒,此时改成1秒
  237. await fetchList();
  238. });
  239. // 全选
  240. const onCheckAllChange = async (e: any) => {
  241. Object.assign(checkState, {
  242. checkSnList: e.target.checked ? state.onlineDockList.map(item => item.sn) : [],
  243. indeterminate: false,
  244. });
  245. await fetchList();
  246. }
  247. // 点击勾选条
  248. const onClickCheckItem = async (sn: string) => {
  249. const list = checkState.checkSnList;
  250. if (list.includes(sn)) {
  251. checkState.checkSnList = list.filter(item => item !== sn);
  252. } else {
  253. list.push(sn);
  254. checkState.checkSnList = list;
  255. }
  256. await fetchList();
  257. }
  258. const paginationConfig = reactive({
  259. pageSizeOptions: ['20', '50', '100'],
  260. showQuickJumper: true,
  261. showSizeChanger: true,
  262. pageSize: 20,
  263. current: 1,
  264. total: 0
  265. });
  266. const columns = [
  267. {
  268. title: '计划|实际时间',
  269. dataIndex: 'duration',
  270. width: 200,
  271. slots: { customRender: 'duration' },
  272. },
  273. {
  274. title: '执行状态',
  275. dataIndex: 'status',
  276. width: 100,
  277. slots: { customRender: 'status' },
  278. },
  279. {
  280. title: '类型',
  281. dataIndex: 'task_type',
  282. width: 120,
  283. customRender: ({ text }: any) => {
  284. let content = '';
  285. switch (text) {
  286. case 0:
  287. content = '立即执行';
  288. break;
  289. case 1:
  290. content = '单次定时';
  291. break;
  292. case 2:
  293. content = '循环定时';
  294. break;
  295. default:
  296. break;
  297. }
  298. return content;
  299. }
  300. },
  301. {
  302. title: '计划名称',
  303. dataIndex: 'job_name',
  304. width: 150,
  305. ellipsis: true,
  306. },
  307. {
  308. title: '航线名称',
  309. dataIndex: 'file_name',
  310. width: 150,
  311. ellipsis: true,
  312. },
  313. {
  314. title: '设备名称',
  315. dataIndex: 'dock_name',
  316. width: 200,
  317. ellipsis: true,
  318. },
  319. {
  320. title: '创建人',
  321. dataIndex: 'username',
  322. width: 150,
  323. },
  324. {
  325. title: '媒体上传',
  326. dataIndex: 'media_upload',
  327. width: 200,
  328. slots: { customRender: 'media_upload' },
  329. },
  330. {
  331. title: '操作',
  332. dataIndex: 'actions',
  333. fixed: 'right',
  334. width: 100,
  335. slots: { customRender: 'action' },
  336. },
  337. ];
  338. const rowClassName = (record: any, index: number) => {
  339. const className = []
  340. if ((index & 1) === 0) {
  341. className.push('table-striped')
  342. }
  343. return className.toString().replaceAll(',', ' ')
  344. }
  345. const refreshData = async (page: any) => {
  346. paginationConfig.current = page?.current!
  347. paginationConfig.pageSize = page?.pageSize!
  348. await fetchList();
  349. }
  350. // 点击搜索
  351. const onClickSearch = async (query: any) => {
  352. state.query = query;
  353. await fetchList();
  354. }
  355. // 点击重置
  356. const onClickReset = async (query: any) => {
  357. state.query = query;
  358. await fetchList();
  359. }
  360. // 点击删除
  361. const onClickDelete = (id: string, name: string) => {
  362. Modal.confirm({
  363. title: '删除任务',
  364. content: `确定删除${name}吗?`,
  365. okType: 'danger',
  366. onOk: async () => {
  367. try {
  368. await apis.deleteJob({ job_id: id });
  369. await fetchList();
  370. message.success('删除成功');
  371. } catch (error) {
  372. message.error('删除失败: ' + error);
  373. }
  374. },
  375. })
  376. }
  377. </script>
  378. <style lang="scss">
  379. .taskList {
  380. padding: 20px;
  381. display: flex;
  382. &-left {
  383. width: 230px;
  384. height: calc(100vh - 146px);
  385. padding: 10px 8px 0;
  386. background-color: #232323;
  387. margin-right: 20px;
  388. &-title {
  389. display: flex;
  390. justify-content: space-between;
  391. align-items: center;
  392. color: #FFFFFF;
  393. .ant-checkbox-wrapper {
  394. color: #FFFFFF !important;
  395. }
  396. }
  397. &-item {
  398. border-radius: 4px;
  399. border: 2px solid transparent;
  400. overflow: hidden;
  401. margin-top: 10px;
  402. &-selected {
  403. border-color: #1fa3f6;
  404. }
  405. }
  406. }
  407. }
  408. .ant-table {
  409. border-top: 1px solid rgb(0, 0, 0, 0.06);
  410. border-bottom: 1px solid rgb(0, 0, 0, 0.06);
  411. }
  412. .ant-table-tbody tr td {
  413. border: 0;
  414. }
  415. .table-striped {
  416. background-color: #f7f9fa;
  417. }
  418. </style>