<!-- Description: 设备运维-轨迹查询 Author: 李亚光 Date: 2024-09-04 --> <script lang="ts" setup name="DeviceTrajectorySearch"> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import deviceTrajectoryDetail from './detail.vue' import { getDeviceTypeListPage } from '@/api/home/device/type' // 设备类型列表 import { getTrajectoryListPage } from '@/api/home/operation/trajectory' import { shortcuts } from '@/utils/common' import showPosition from '@/views/home/device/device/components/showPosition.vue' const deviceTypeList = ref<any[]>([]) // 表格数据 const list = ref([]) const total = ref(0) // 初始展示列 const columns = ref<any>([ { text: '设备编号', value: 'devcode', align: 'center' }, { text: '设备类型', value: 'typeName', align: 'center' }, { text: '管理单位', value: 'deptName', align: 'center' }, { text: '原始位置', value: 'startPosition', align: 'center', isCustom: true }, { text: '当前位置', value: 'currentPosition', align: 'center', isCustom: true }, { text: '上传时间', value: 'createTime', align: 'center' }, ]) // 最终展示列 const columnsConfig = ref([]) // 修改列 const editColumns = (data: any) => { columnsConfig.value = data } const loadingTable = ref(true) // 查询条件 const listQuery = ref({ limit: 20, offset: 1, begTime: '', endTime: '', deptId: '', devCode: '', devTypeId: '', }) // 开始结束时间 const datetimerange = ref() watch(() => datetimerange.value, (newVal) => { listQuery.value.begTime = '' listQuery.value.endTime = '' if (Array.isArray(newVal)) { if (newVal.length) { listQuery.value.begTime = `${newVal[0]}` listQuery.value.endTime = `${newVal[1]}` } } }) // 查询数据 const fetchData = () => { loadingTable.value = true getTrajectoryListPage(listQuery.value).then((res) => { list.value = res.data.rows total.value = res.data.total loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 重置查询条件f const reset = () => { datetimerange.value = [] listQuery.value = { limit: 20, offset: 1, begTime: '', endTime: '', deptId: '', devCode: '', devTypeId: '', } fetchData() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size: number; page: number }) => { if (val && val.size) { listQuery.value.limit = val.size } if (val && val.page) { listQuery.value.offset = val.page } fetchData() } // 查看轨迹详情 const trajectoryRef = ref() const detail = (row: any) => { trajectoryRef.value.initDialog(row) } // 查看位置 const mapRef = ref() const viewPostion = (type: string, row: any) => { if (type === '原始位置' && !row.startPosition) { return } else if (type === '当前位置' && !row.currentPosition) { return } // 展示位置 const position = type === '原始位置' ? row.startPosition?.split(',') || [] : row.currentPosition?.split(',') || [] if (!position.length) { ElMessage.warning('位置无效') return } mapRef.value.initDialog(position) // console.log(type === '原始位置' ? row.startPosition?.split(',') || [] : row.currentPosition?.split(',') || []) } // 获取字典 const fetchDict = async () => { // 获取设备类型 const res = await getDeviceTypeListPage({ limit: 9999, offset: 1 }) deviceTypeList.value = res.data.rows.filter((item: any) => item.typeName.includes('管网哨兵')) } onMounted(async () => { await fetchDict() fetchData() }) const { proxy } = getCurrentInstance() as any </script> <template> <!-- 布局 --> <app-container> <!-- 展示坐标位置 --> <show-position ref="mapRef" /> <!-- 展示轨迹 --> <device-trajectory-detail ref="trajectoryRef" /> <!-- 筛选条件 --> <search-area :need-clear="true" @search="fetchData" @clear="reset"> <search-item> <el-input v-model="listQuery.devCode" placeholder="设备编号" clearable style="width: 162px;" /> </search-item> <search-item> <el-select v-model="listQuery.devTypeId" placeholder="设备类型" clearable filterable class="select" style="width: 162px;" > <el-option v-for="item in deviceTypeList" :key="item.id" :label="item.typeName" :value="item.id" /> </el-select> </search-item> <search-item> <dept-select v-model="listQuery.deptId" placeholder="管理单位" :clearable="true" class="select" style="width: 162px;" /> </search-item> <search-item> <el-date-picker v-model="datetimerange" type="datetimerange" format="YYYY-MM-DD HH:mm:ss" :shortcuts="shortcuts" value-format="YYYY-MM-DD HH:mm:ss" range-separator="至" start-placeholder="上传开始时间" end-placeholder="上传结束时间" clearable /> </search-item> </search-area> <!-- 表头标题 --> <table-container :is-config="true" config-title="device-trajectory" :columns="columns" :config-columns="columnsConfig" :edit="editColumns" > <!-- 查询结果Table显示 --> <normal-table :data="list" :total="total" :columns="columnsConfig" :query="listQuery" :list-loading="loadingTable" @change="changePage" > <template #preColumns> <el-table-column label="序号" width="80" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #isCustom="{ scope, column }"> <span class="click" @click="viewPostion(column.text, scope.row)"> <span> {{ column.text === '原始位置' ? scope.row.startPosition : scope.row.currentPosition }} </span> </span> </template> <template #columns> <el-table-column v-if="proxy.hasPerm('/operation/trajectory/detail')" label="操作" width="80" align="center"> <template #default="scope"> <el-button type="primary" link size="small" @click="detail(scope.row)"> 查看 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template> <style lang="scss" scoped> .click { &:hover { cursor: pointer; } } </style>