CMVR-IOT-UI/src/views/inspection/task/index.vue

386 lines
14 KiB
Vue
Raw Normal View History

2026-05-26 14:45:49 +08:00
<template>
2026-06-02 09:52:53 +08:00
<div class="app-container">
<div ref="topContainerRef">
<TableSearch :queryParams="queryParams" :showSearch="showSearch" label-width="90px" queryRef="queryRef"
@refresh="resetQuery" @search="handleQuery">
<template #one>
<el-col :lg="6" :md="12" :sm="24" :xl="6" :xs="24" :xxl="6">
<el-form-item label="任务名称" prop="taskName">
2026-06-02 10:48:03 +08:00
<el-input v-model="queryParams.taskName" clearable placeholder="请输入任务名称" style="width: 100%"
@keyup.enter="handleQuery" />
2026-06-02 09:52:53 +08:00
</el-form-item>
</el-col>
<el-col :lg="6" :md="12" :sm="24" :xl="6" :xs="24" :xxl="6">
<el-form-item label="任务类型" prop="taskType">
<el-select v-model="queryParams.taskType" clearable placeholder="请选择任务类型"
style="width: 100%">
<el-option label="巡检任务" value="1" />
<el-option label="讲解任务" value="2" />
</el-select>
</el-form-item>
</el-col>
</template>
</TableSearch>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button icon="Plus" plain type="primary" @click="handleAdd">新增
</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
</div>
<div :style="containerHeight">
<el-table v-loading="loading" height="100%" :data="tableDataList">
<el-table-column align="center" label="id" prop="id" show-overflow-tooltip />
<el-table-column align="center" label="任务名称" prop="taskName" show-overflow-tooltip />
<el-table-column align="center" label="任务描述" prop="remark" show-overflow-tooltip />
<el-table-column align="center" label="任务类型" prop="taskType">
<template #default="scope">
<el-tag :type="scope.row.taskType === '1' ? 'primary' : 'success'">
{{ scope.row.taskType === '1' ? '巡检任务' : '讲解任务' }}
</el-tag>
</template>
</el-table-column>
2026-06-05 09:07:44 +08:00
<el-table-column align="center" label="所属地图" prop="mapName" show-overflow-tooltip />
2026-06-02 09:52:53 +08:00
<el-table-column align="center" label="创建人" prop="createBy" show-overflow-tooltip />
<el-table-column align="center" label="创建时间" prop="createTime" show-overflow-tooltip />
<el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="260">
<template #default="scope">
<el-button icon="Edit" link type="primary" @click="handleUpdate(scope.row)">
修改
</el-button>
<el-button icon="Cpu" link type="primary" @click="handleBindPoint(scope.row)">绑定点位
</el-button>
<el-button icon="Delete" link type="primary" @click="handleDelete(scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNum"
:total="total" @pagination="getList" />
</div>
<el-dialog v-model="open" :title="title" append-to-body width="500px">
<el-form ref="taskRef" :model="form" :rules="rules" label-width="100px">
<el-form-item label="任务名称" prop="taskName">
<el-input v-model="form.taskName" placeholder="请输入任务名称" />
</el-form-item>
<el-form-item label="任务类型" prop="taskType">
2026-06-05 09:07:44 +08:00
<el-select v-model="form.taskType" clearable placeholder="请选择任务类型" style="width: 100%">
2026-06-02 09:52:53 +08:00
<el-option label="巡检任务" value="1" />
<el-option label="讲解任务" value="2" />
</el-select>
</el-form-item>
2026-06-05 09:07:44 +08:00
<el-form-item label="所属地图" prop="mapId">
<el-select
v-model="form.mapId"
clearable
placeholder="请选择所属地图"
style="width: 100%"
>
<el-option
v-for="item in mapList"
:key="item.id"
:label="item.mapName"
:value="item.id"
/>
</el-select>
</el-form-item>
2026-06-02 09:52:53 +08:00
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" :rows="2" placeholder="请输入备注" type="textarea" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
2026-06-02 10:48:03 +08:00
<!-- 点位绑定弹窗 -->
<el-dialog v-model="dialogVisible" title="点位绑定" width="800px">
2026-06-05 09:07:44 +08:00
<el-row>
<TableSearch :queryParams="pointQueryParams" :showSearch="showSearch" label-width="90px" @refresh="resetBindPointQuery" @search="handleBindPointQuery">
<template #one>
<el-col :lg="12" :md="12" :sm="24" :xl="12" :xs="24" :xxl="12">
<el-form-item label="点位名称" prop="waypointName">
<el-input v-model="pointQueryParams.waypointName" clearable placeholder="请输入点位名称"
style="width: 100%" @keyup.enter="handleBindPointQuery" />
</el-form-item>
</el-col>
</template>
</TableSearch>
</el-row>
<el-row :gutter="24">
<el-col :span="12">
<div style="height: 55vh">
<div class="task-title">待选择点位</div>
<draggable :animation="340" :forceFallback="true" :list="taskLeftList" class="draggable-group"
ghostClass="dragClass" group="people" itemKey="name">
<template #item="{ element, index }">
<div class="list-group-item">
<el-icon>
<Tools />
</el-icon>
{{ element.waypointName }}
</div>
</template>
</draggable>
</div>
</el-col>
<el-col :span="12">
<div style="height: 55vh">
<div class="task-title">点位排序</div>
<draggable :animation="340" :forceFallback="true" :list="taskRightList" class="draggable-group"
ghostClass="dragClass" group="people" itemKey="name">
<template #item="{ element, index }">
<div class="list-group-item">
{{ index + 1 }} 、{{ element.waypointName }}
</div>
</template>
</draggable>
</div>
</el-col>
</el-row>
<div class="custom-block">
<div class="mb5">1、将待选择点位拖拽至点位排序中</div>
<div>2、点位排序中可拖拽自定义其顺序</div>
</div>
2026-06-02 10:48:03 +08:00
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="bindPoint">确 定</el-button>
<el-button @click="cancelPoint">取 消</el-button>
</div>
</template>
2026-06-02 09:52:53 +08:00
</el-dialog>
</div>
</template>
<script name="Detect" setup>
2026-06-02 10:48:03 +08:00
import { addTask, updateTask, getTaskList, deleteTask, getWaypointByTaskId, bindWaypointsToTask } from "../../../api/inspection/task";
import { getPointList } from "../../../api/inspection/point";
2026-06-02 09:52:53 +08:00
import TableSearch from "@/components/TableSearch/index.vue";
import { useContainerHeight } from "@/hooks/tableHeight";
import { ElMessage, ElMessageBox } from "element-plus";
2026-06-05 09:07:44 +08:00
import draggable from "vuedraggable";
import { reactive, ref } from "vue";
import { getMapList } from "@/api/inspection/map";
2026-06-02 09:52:53 +08:00
const topContainerRef = ref();
const containerHeight = useContainerHeight(topContainerRef);
const { proxy } = getCurrentInstance();
const tableDataList = ref([]);
const open = ref(false);
const dialogVisible = ref(false);
const loading = ref(false);
const showSearch = ref(true);
const total = ref(0);
const title = ref("");
const data = reactive({
form: {},
queryParams: {
pageNum: 1,
pageSize: 10,
taskName: null,
taskType: null,
},
rules: {
taskName: [
{ required: true, message: "任务名称不能为空", trigger: "blur" },
],
2026-06-05 09:07:44 +08:00
taskType: [
{ required: true, message: "请选择任务类型", trigger: "blur" },
],
mapId: [
{ required: true, message: "请选择所属地图", trigger: "blur" },
],
2026-06-02 09:52:53 +08:00
},
});
const { queryParams, form, rules } = toRefs(data);
/** 查询任务列表 */
function getList() {
loading.value = false;
getTaskList(queryParams.value).then((res) => {
tableDataList.value = res.rows;
total.value = res.total;
loading.value = false;
2026-06-04 16:41:29 +08:00
}).finally(() => {
loading.value = false;
2026-06-02 09:52:53 +08:00
});
}
// 取消按钮
function cancel() {
open.value = false;
reset();
}
// 表单重置
function reset() {
taskRef.value.resetFields();
form.value = {};
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1;
getList();
}
/** 重置按钮操作 */
function resetQuery() {
handleQuery();
}
/** 新增按钮操作 */
function handleAdd() {
isNew.value = true;
open.value = true;
title.value = "添加任务";
}
2026-06-05 09:07:44 +08:00
const mapList = ref([]);
// 获取地图列表
const getMapArr = () => {
getMapList({
pageNum: 1,
pageSize: 10000,
}).then((response) => {
mapList.value = response.rows;
});
}
2026-06-02 09:52:53 +08:00
/** 修改按钮操作 */
function handleUpdate(row) {
form.value = { ...row };
isNew.value = false;
open.value = true;
title.value = "修改任务";
}
const taskRef = ref();
const isNew = ref(true);
/** 提交按钮 */
function submitForm() {
taskRef.value.validate((valid) => {
if (valid) {
if (isNew.value) {
addTask(form.value).then(() => {
ElMessage.success("添加成功");
cancel();
getList();
});
} else {
updateTask(form.value).then(() => {
ElMessage.success("修改成功");
cancel();
getList();
});
}
}
});
}
/** 删除按钮操作 */
function handleDelete(row) {
ElMessageBox.confirm("确定要删除该任务吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
deleteTask(row.id).then(() => {
ElMessage.success("删除成功");
getList();
});
});
}
2026-06-05 09:07:44 +08:00
const pointQueryParams = reactive({
pageNum: 1,
pageSize: 1000000,
waypointName: null,
mapId: null
})
/** 搜索按钮操作 */
function handleBindPointQuery() {
queryParams.value.pageNum = 1;
getList();
}
/** 重置按钮操作 */
function resetBindPointQuery() {
handleBindPointQuery();
}
2026-06-02 10:48:03 +08:00
const taskId = ref(null);
const handleBindPoint = async (row) => {
dialogVisible.value = true;
taskId.value = row.id;
2026-06-05 09:07:44 +08:00
pointQueryParams.mapId = row.mapId;
getBindPointByTaskId(row.id)
getPointListData()
2026-06-02 10:48:03 +08:00
};
2026-06-05 09:07:44 +08:00
/** 查询点位列表 */
const getPointListData = async () => {
const res = await getPointList(pointQueryParams)
if (res.code === 200) {
let ids = []
console.log(taskRightList.value)
if (taskRightList.value) {
ids = taskRightList.value.map(item => item.id)
}
taskLeftList.value = res.rows.filter(item => {
return !ids.includes(item.id)
})
}
}
2026-06-02 10:48:03 +08:00
2026-06-05 09:07:44 +08:00
const getBindPointByTaskId = async (taskId) => {
const res = await getWaypointByTaskId(taskId)
2026-06-02 10:48:03 +08:00
if (res.code === 200) {
2026-06-05 09:07:44 +08:00
taskRightList.value = res.data;
2026-06-02 10:48:03 +08:00
}
}
2026-06-05 09:07:44 +08:00
const taskLeftList = ref([])
const taskRightList = ref([])
2026-06-02 10:48:03 +08:00
2026-06-05 09:07:44 +08:00
const bindPoint = async () => {
if (taskRightList.value.length === 0) {
ElMessage.warning("请选择点位")
return
}
const ids = taskRightList.value.map(item => item.id)
const res = await bindWaypointsToTask(taskId.value, ids)
if (res.code === 200) {
ElMessage.success("绑定点位成功")
cancelPoint()
}
2026-06-02 10:48:03 +08:00
};
2026-06-02 09:52:53 +08:00
2026-06-02 10:48:03 +08:00
const cancelPoint = () => {
dialogVisible.value = false;
2026-06-02 09:52:53 +08:00
};
onMounted(() => {
getList();
2026-06-05 09:07:44 +08:00
getMapArr();
2026-06-02 09:52:53 +08:00
});
</script>