+
+ 前往点位
+
{
// 确认按钮
const onHandleConfirm = () => {
// emits('onHandleConfirm', markerParams.value)
+
handleRobotActionApi({
puId: deviceInfo.value?.puId,
type: '2',
@@ -249,36 +260,66 @@ const onHandleConfirm = () => {
console.log(res.data, 'res?.data')
const { Robot_x, Robot_y, PTZ_x, PTZ_y, PTZ_zoom, Robot_theta } = res?.data.data
- markerParams.value.xCount = Robot_x
- markerParams.value.yCount = Robot_y
- markerParams.value.PTZ_x = PTZ_x
- markerParams.value.PTZ_y = PTZ_y
- markerParams.value.markerAngle = Robot_theta
- markerParams.value.PTZ_zoom = PTZ_zoom
- // 组装参数
- // const { PTZ_zoom, markerAngle, PTZ_x, PTZ_y, xCount, yCount, mapId, markerName } =
- // markerParams.value
+ // 如果是修改时判断当前位置是否与点位一致
+ if (markerParams.value.type === '修改') {
+ if (
+ Math.abs(Robot_x - markerParams.value.xCount) > 2 ||
+ Math.abs(Robot_y - markerParams.value.yCount) > 2
+ ) {
+ dialog.warning({
+ title: '温馨提示',
+ content:
+ '机器人当前位置与预置点位不一致,您可以点击前往点位按钮,也可以选择继续修改?',
+ positiveText: '前往点位',
+ negativeText: '继续修改',
+ onPositiveClick: () => {
+ onHandleGoToPoint()
+ },
+ onNegativeClick: async () => {
+ markerParams.value.xCount = Robot_x
+ markerParams.value.yCount = Robot_y
+ markerParams.value.PTZ_x = PTZ_x
+ markerParams.value.PTZ_y = PTZ_y
+ markerParams.value.markerAngle = Robot_theta
+ markerParams.value.PTZ_zoom = PTZ_zoom
- const addMarkerParams = {
- ptzz: markerParams.value.PTZ_zoom,
- theta: markerParams.value.markerAngle,
- ptzx: markerParams.value.PTZ_x,
- ptzy: markerParams.value.PTZ_y,
- positionX: Math.ceil(markerParams.value.xCount),
- positionY: Math.ceil(markerParams.value.yCount),
- mapId: markerParams.value.mapId,
- pointName: markerParams.value.markerName,
- }
- const { data: result } = await addMarkerApi(addMarkerParams)
+ const addMarkerParams = {
+ ptzz: markerParams.value.PTZ_zoom,
+ theta: markerParams.value.markerAngle,
+ ptzx: markerParams.value.PTZ_x,
+ ptzy: markerParams.value.PTZ_y,
+ positionX: Math.ceil(markerParams.value.xCount),
+ positionY: Math.ceil(markerParams.value.yCount),
+ mapId: markerParams.value.mapId,
+ pointName: markerParams.value.markerName,
+ }
- if (result.code == 200) {
- message.success('新增点位成功')
- onHandleCloseAddModal()
+ if (markerParams.value.type === '修改') {
+ addMarkerParams.id = markerParams.value.id
+ }
+
+ const { data: result } = await addMarkerApi(addMarkerParams)
+
+ if (result.code == 200) {
+ message.success(
+ markerParams.value.type === '新增'
+ ? '新增点位成功'
+ : '修改点位成功',
+ )
+ onHandleCloseAddModal()
+ }
+ },
+ })
+ }
}
})
}
+const onHandleGoToPoint = () => {
+ handleRobotAction(Math.ceil(markerParams.value.xCount), Math.ceil(markerParams.value.yCount))
+}
+
const onlyAllowNumber = (value) => !value || /^\d+$/.test(value)
watch(
@@ -294,6 +335,15 @@ watch(
markerParams.value.markerPreset = newVal?.markerPreset
markerParams.value.xCount = Math.ceil(newVal?.xCount).toString()
markerParams.value.yCount = Math.ceil(newVal?.yCount).toString()
+
+ if (newVal?.type === '新增') {
+ handleRobotAction(
+ Math.ceil(markerParams.value.xCount),
+ Math.ceil(markerParams.value.yCount),
+ )
+ } else {
+ markerParams.value.id = newVal?.id
+ }
},
{
immediate: true,
@@ -314,17 +364,4 @@ onBeforeUnmount(() => {
clearInterval(isCurrentPosition.value)
}
})
-
-watch(
- () => deviceInfo.value,
- (newVal) => {
- if (newVal.puId) {
- handleRobotAction(
- Math.ceil(markerParams.value.xCount),
- Math.ceil(markerParams.value.yCount),
- deviceInfo.value?.puId,
- )
- }
- },
-)
diff --git a/src/views/home/components/modal-content/inspection-task.vue b/src/views/home/components/modal-content/inspection-task.vue
index 8171eae..ab23a2a 100644
--- a/src/views/home/components/modal-content/inspection-task.vue
+++ b/src/views/home/components/modal-content/inspection-task.vue
@@ -24,13 +24,14 @@
-
+
+ 共{{ total }}条
import DialogModal from '@/components/DialogModal/index.vue'
-import { AddCircleSharp } from '@vicons/ionicons5'
-import { NIcon } from 'naive-ui'
-import { NButton, NSwitch, NTag, useMessage } from 'naive-ui'
-import { ref } from 'vue'
-import { getTaskListApi, updateTaskEnableApi, handleRobotActionApi } from '@/api/home'
-import { getRobotDeviceListFn } from '@/utils/getRobotInfo'
+import { ref, watch } from 'vue'
+import { NButton, NSwitch, useMessage, useDialog } from 'naive-ui'
+import {
+ getTaskListApi,
+ updateTaskEnableApi,
+ handleRobotActionApi,
+ deleteTaskApi,
+} from '@/api/home'
const emits = defineEmits(['onHandleCloseModal', 'onHandleAddInspectionTask'])
-const modalTitle = ref('巡视任务') // 弹框标题
-const addOrEditVisible = ref(false) // 新增或编辑弹框
-const addOrEditTitle = ref('新增巡视任务') // 新增或编辑弹框标题
const total = ref(0)
+const modalTitle = ref('巡视任务') // 弹框标题
const message = useMessage()
+const dialog = useDialog()
+const props = defineProps({
+ isChange: {
+ type: Object,
+ default: () => ({
+ is_change: 'error',
+ }),
+ },
+})
const queryParams = ref({
pageNum: 1,
pageSize: 10,
taskName: '',
- // robotId: 'WTBLS204766',
})
const btnList = [
@@ -102,11 +111,7 @@ const columns = ref([
key: 'robotName',
align: 'center',
},
- // {
- // title: '地盘名称',
- // key: 'age',
- // align: 'center',
- // },
+
{
title: '任务频次',
key: 'count',
@@ -147,7 +152,7 @@ const columns = ref([
render(row) {
return h(NSwitch, {
value: row.enable == 1 ? true : false,
- onChange: (value) => onHandleSwitch(row, value),
+ 'onUpdate:value': (value) => onHandleSwitch(row, value),
})
},
},
@@ -157,62 +162,60 @@ const columns = ref([
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',
+ const buttonS = btnList
+ .filter((btn) => {
+ // 根据条件过滤按钮
+ switch (btn.btnType) {
+ case 1: // 编辑按钮 - 总是显示
+ return true
+ case 2:
+ return row.taskStatus == 1 && row.enable == 1
+ case 3: // 下发 - 只在任务未开始时显示
+ return row.enable == 1
+ case 4: // 删除 - 只在任务未开始时显示
+ return true
+ }
+ })
+ .map((btn) => {
+ return h(
+ NButton,
+ {
+ size: 'small',
+ type: btn.type,
+ style: {
+ marginRight: '4px',
+ },
+ onClick: () => onHandleBtn(row, btn.btnType),
},
- },
- { default: () => btn.label },
- )
- })
+ { 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 tableData = ref([])
// 新增按钮
const onHandleAdd = () => {
- console.log('新增')
- // addOrEditVisible.value = true
- // addOrEditTitle.value = '新增巡视任务'
- emits('onHandleAddInspectionTask')
+ emits('onHandleAddInspectionTask', {
+ type: '新增',
+ id: '',
+ })
}
// 获取巡视任务列表
const getTaskList = async () => {
const { data: res } = await getTaskListApi(queryParams.value)
total.value = res.total
- data.value = res.rows
+ tableData.value = res.rows
}
getTaskList()
// 按钮操作组
const onHandleBtn = (row, type) => {
- console.log(row, type)
// 1. 编辑 2. 立即执行 3. 下发 4. 删除
switch (type) {
case 1:
@@ -227,14 +230,18 @@ const onHandleBtn = (row, type) => {
case 4:
onHandleDelete(row)
break
+ case 5:
+ onHandleStop(row)
+ break
}
}
// 编辑
const onHandleEditTable = (row) => {
- console.log(row)
- addOrEditVisible.value = true
- addOrEditTitle.value = '编辑巡视任务'
+ emits('onHandleAddInspectionTask', {
+ type: '编辑',
+ id: row.id,
+ })
}
// 立即执行
@@ -244,12 +251,10 @@ const onHandleImmediateExecution = async (row) => {
type: '13',
puId: row.puid,
})
- console.log(res, '立即执行结果')
}
// 下发
const onHandleSend = async (row) => {
- console.log(row)
const { data: res } = await updateTaskEnableApi({
taskStatus: '1',
id: row.id,
@@ -265,8 +270,26 @@ const onHandleSend = async (row) => {
}
// 删除
-const onHandleDelete = (row) => {
- console.log(row)
+const onHandleDelete = async (row) => {
+ dialog.success({
+ title: '温馨提示',
+ content: '确定要删除该任务吗?',
+ positiveText: '确定',
+ negativeText: '取消',
+ draggable: true,
+ onPositiveClick: async () => {
+ const { data: res } = await deleteTaskApi({
+ id: row.id,
+ puid: row.puid,
+ })
+
+ if (res.data.code == 200) {
+ message.success('删除成功')
+ getTaskList()
+ }
+ },
+ onNegativeClick: () => {},
+ })
}
// 关闭弹框外层
@@ -274,14 +297,8 @@ const onHandleCloseModal = () => {
emits('onHandleCloseModal')
}
-// 关闭弹框内层
-const onHandleCloseModalInner = () => {
- addOrEditVisible.value = false
-}
-
// 启用开关
const onHandleSwitch = async (row, value) => {
- console.log(row, value)
const { data: res } = await updateTaskEnableApi({
enable: value ? '1' : '0',
id: row.id,
@@ -295,6 +312,16 @@ const onHandleSwitch = async (row, value) => {
message.error('启动失败')
}
}
+
+watch(
+ props.isChange,
+ (newVal) => {
+ if (newVal.is_change === 'success') {
+ getTaskList()
+ }
+ },
+ { immediate: true },
+)
diff --git a/src/views/home/index.vue b/src/views/home/index.vue
index 485de21..e018f3e 100644
--- a/src/views/home/index.vue
+++ b/src/views/home/index.vue
@@ -100,7 +100,7 @@ const { baseWidth, baseHeight, scale } = useScale(appRef)
const cameraNode_1 = ref({
token: '',
puid: '',
- idx: 0,
+ idx: 1,
stream: 0,
name: '',
operateType: 1,
@@ -110,7 +110,7 @@ const cameraNode_1 = ref({
const cameraNode_2 = ref({
token: '',
puid: '',
- idx: 1,
+ idx: 0,
stream: 0,
name: '',
operateType: 1,