on-site-robots-screen/src/views/home/components/modal-content/inspection-task.vue

306 lines
7.3 KiB
Vue
Raw Normal View History

2025-06-24 18:12:02 +08:00
<template>
<!-- 巡视任务 -->
<DialogModal
@onHandleCloseModal="onHandleCloseModal"
:modalTitle="modalTitle"
:height="`90vh`"
2025-06-27 11:23:33 +08:00
:width="`90vw`"
2025-06-24 18:12:02 +08:00
>
<!-- 巡视任务-->
<div class="inspection-task-container" ref="inspectionTaskContainer">
<n-form
inline
ref="formRef"
size="small"
label-placement="left"
style="margin-top: 10px"
>
<n-form-item>
<n-input placeholder="任务名称" clearable style="width: 240px" />
</n-form-item>
2025-06-28 17:09:43 +08:00
<n-button type="info" @click="getTaskList"> 查询</n-button>
2025-06-24 18:12:02 +08:00
<n-button color="#6E90A9" style="margin-left: 8px" @click="onHandleAdd">
新增
</n-button>
</n-form>
<n-data-table :columns="columns" :data="data" />
<div style="margin-top: 10px; display: flex; justify-content: flex-end">
<n-pagination
2025-06-28 17:09:43 +08:00
v-if="total > 0"
2025-06-24 18:12:02 +08:00
show-size-picker
2025-06-28 17:09:43 +08:00
:page-count="total"
:page-sizes="[10, 20, 30, 50]"
v-model:page="queryParams.pageNum"
v-model:page-size="queryParams.pageSize"
2025-06-24 18:12:02 +08:00
/>
</div>
</div>
</DialogModal>
</template>
<script setup>
import DialogModal from '@/components/DialogModal/index.vue'
import { AddCircleSharp } from '@vicons/ionicons5'
import { NIcon } from 'naive-ui'
2025-06-28 17:09:43 +08:00
import { NButton, NSwitch, NTag, useMessage } from 'naive-ui'
2025-06-24 18:12:02 +08:00
import { ref } from 'vue'
2025-06-28 17:09:43 +08:00
import { getTaskListApi, updateTaskEnableApi, handleRobotActionApi } from '@/api/home'
import { getRobotDeviceListFn } from '@/utils/getRobotInfo'
2025-06-24 18:12:02 +08:00
const emits = defineEmits(['onHandleCloseModal', 'onHandleAddInspectionTask'])
const modalTitle = ref('巡视任务') // 弹框标题
const addOrEditVisible = ref(false) // 新增或编辑弹框
const addOrEditTitle = ref('新增巡视任务') // 新增或编辑弹框标题
2025-06-28 17:09:43 +08:00
const total = ref(0)
const message = useMessage()
const queryParams = ref({
pageNum: 1,
pageSize: 10,
taskName: '',
// robotId: 'WTBLS204766',
})
2025-06-24 18:12:02 +08:00
const btnList = [
{
label: '编辑',
type: 'info',
btnType: 1,
},
{
label: '立即执行',
type: 'info',
btnType: 2,
},
{
label: '下发',
type: 'info',
btnType: 3,
},
{
label: '删除',
type: 'info',
btnType: 4,
},
]
const columns = ref([
{
title: '任务ID',
2025-06-28 17:09:43 +08:00
key: 'taskId',
2025-06-24 18:12:02 +08:00
align: 'center',
},
{
title: '任务名',
2025-06-28 17:09:43 +08:00
key: 'taskName',
2025-06-24 18:12:02 +08:00
align: 'center',
},
{
title: '设备名称',
2025-06-28 17:09:43 +08:00
key: 'robotName',
2025-06-24 18:12:02 +08:00
align: 'center',
},
2025-06-28 17:09:43 +08:00
// {
// title: '地盘名称',
// key: 'age',
// align: 'center',
// },
2025-06-24 18:12:02 +08:00
{
title: '任务频次',
2025-06-28 17:09:43 +08:00
key: 'count',
2025-06-24 18:12:02 +08:00
align: 'center',
},
2025-06-28 17:09:43 +08:00
// {
// title: '执行时间',
// key: 'age',
// align: 'center',
// },
// {
// title: '任务状态',
// key: 'taskStatus',
// align: 'center',
// render(row) {
// return h(
// NTag,
// {
// style: {
// marginRight: '6px',
// },
// type: 'info',
// bordered: false,
// },
// {
// default: () => {
// return row.taskStatus == 1 ? '巡视中' : '未开始'
// },
// },
// )
// },
// },
2025-06-24 18:12:02 +08:00
{
title: '启用',
2025-06-28 17:09:43 +08:00
key: 'enable',
2025-06-24 18:12:02 +08:00
align: 'center',
render(row) {
return h(NSwitch, {
2025-06-28 17:09:43 +08:00
value: row.enable == 1 ? true : false,
2025-06-24 18:12:02 +08:00
onChange: (value) => onHandleSwitch(row, value),
})
},
},
{
title: '操作',
key: 'age',
align: 'center',
width: 260,
render(row) {
const buttonS = btnList.map((btn) => {
return h(
NButton,
{
size: 'small',
onClick: () => onHandleBtn(row, btn.btnType),
type: btn.type,
style: {
marginRight: '4px',
},
},
{ default: () => btn.label },
)
})
return buttonS
},
},
])
const data = ref([
{
age: '2025-06-01 10:00:00',
tags: ['nice'],
isEnable: true,
},
{
age: '2025-06-01 10:00:00',
tags: ['nice'],
isEnable: false,
},
{
age: '2025-06-01 10:00:00',
tags: ['nice'],
isEnable: false,
},
])
// 新增按钮
const onHandleAdd = () => {
console.log('新增')
// addOrEditVisible.value = true
// addOrEditTitle.value = '新增巡视任务'
emits('onHandleAddInspectionTask')
}
2025-06-28 17:09:43 +08:00
// 获取巡视任务列表
const getTaskList = async () => {
const { data: res } = await getTaskListApi(queryParams.value)
total.value = res.total
data.value = res.rows
}
getTaskList()
2025-06-24 18:12:02 +08:00
// 按钮操作组
const onHandleBtn = (row, type) => {
console.log(row, type)
// 1. 编辑 2. 立即执行 3. 下发 4. 删除
switch (type) {
case 1:
onHandleEditTable(row)
break
case 2:
onHandleImmediateExecution(row)
break
case 3:
onHandleSend(row)
break
case 4:
onHandleDelete(row)
break
}
}
// 编辑
const onHandleEditTable = (row) => {
console.log(row)
addOrEditVisible.value = true
addOrEditTitle.value = '编辑巡视任务'
}
// 立即执行
2025-06-28 17:09:43 +08:00
const onHandleImmediateExecution = async (row) => {
const { data: res } = await handleRobotActionApi({
taskId: row.taskId,
type: '13',
puId: row.puid,
})
console.log(res, '立即执行结果')
2025-06-24 18:12:02 +08:00
}
// 下发
2025-06-28 17:09:43 +08:00
const onHandleSend = async (row) => {
2025-06-24 18:12:02 +08:00
console.log(row)
2025-06-28 17:09:43 +08:00
const { data: res } = await updateTaskEnableApi({
taskStatus: '1',
id: row.id,
puid: row.puid,
})
if (res.data.code == 200) {
message.success('下发成功')
getTaskList()
} else {
message.error('下发失败')
}
2025-06-24 18:12:02 +08:00
}
// 删除
const onHandleDelete = (row) => {
console.log(row)
}
// 关闭弹框外层
const onHandleCloseModal = () => {
emits('onHandleCloseModal')
}
// 关闭弹框内层
const onHandleCloseModalInner = () => {
addOrEditVisible.value = false
}
// 启用开关
2025-06-28 17:09:43 +08:00
const onHandleSwitch = async (row, value) => {
2025-06-24 18:12:02 +08:00
console.log(row, value)
2025-06-28 17:09:43 +08:00
const { data: res } = await updateTaskEnableApi({
enable: value ? '1' : '0',
id: row.id,
puid: row.puid,
})
2025-06-24 18:12:02 +08:00
2025-06-28 17:09:43 +08:00
if (res.data.code == 200) {
message.success(value ? '启动成功' : '禁用成功')
getTaskList()
} else {
message.error('启动失败')
}
2025-06-24 18:12:02 +08:00
}
</script>
<style lang="scss" scoped>
.plane-map-container {
width: 100%;
height: 100%;
}
</style>