<!-- 地下空洞管理 --> <script name="UndergroundCavity" setup lang="ts"> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import detailDialog from './detail.vue' import type { dictType } from '@/global' import { getDictByCode } from '@/api/system/dict' import { exportFile } from '@/utils/exportUtils' import type { TableColumn } from '@/components/NormalTable/table_interface' import { batchDeleteHole, exportHole, getHoleListPage, importHole, templateHole } from '@/api/page/undergroundCavity' import { exportExcel } from '@/utils/exportXlsx' const $router = useRouter() const { proxy } = getCurrentInstance() as any // 查询条件 const listQuery = ref({ // holeCode: '', // 空洞编号 // abnormolWave: '', // 异常波形 // detectionDistance: '', // 探测距离 // holeSize: '', // 空洞大小 // holeType: '', // 空洞类型 // detectionTime: '', // 探测时间 // riskLevel: '', // 风险等级 // position: '', // 空洞位置 // isHandle: '', // 是否进行治理 begTime: '', endTime: '', isProcess: '', overLevel: '', offset: 1, limit: 20, }) const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading // 表头 const columns = ref<TableColumn[]>([ // { text: '地下空洞编号', value: 'holeCode', align: 'center', width: '160' }, { text: '异常波形', value: 'abnormolWave', align: 'center' }, { text: '探测距离', value: 'detectionDistance', align: 'center' }, { text: '空洞大小', value: 'holeSize', align: 'center' }, { text: '空洞类型', value: 'holeType', align: 'center' }, // { text: '空洞图片', value: 'holePicture', align: 'center' }, { text: '探测时间', value: 'detectionTime', align: 'center' }, { text: '风险等级', value: 'riskLevel', align: 'center' }, { text: '空洞经纬度', value: 'lnglat', align: 'center' }, { text: '空洞位置', value: 'position', align: 'center' }, { text: '是否进行治理', value: 'isHandle', align: 'center' }, ]) const list = ref([]) // 表格数据 // 筛选时间段数据 const dateRange = ref<any[]>(['', '']) // 时间变更 watch(dateRange, (val) => { if (val) { listQuery.value.begTime = `${val[0]}` listQuery.value.endTime = `${val[1]}` } else { listQuery.value.begTime = '' listQuery.value.endTime = '' } }) // 选中的内容 const checkoutList = ref<string[]>([]) // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } getHoleListPage(listQuery.value).then((res) => { console.log(res.data, '地下空洞') list.value = res.data.rows.map((item: any) => { return { ...item, lnglat: `${item.longitude},${item.latitude}`, isHandle: item.isHandle === '1' ? '已治理' : '未治理', } }) total.value = parseInt(res.data.total) loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 搜索 const searchList = () => { fetchData(true) } // 重置 const reset = () => { listQuery.value = { begTime: '', endTime: '', isProcess: '', overLevel: '', offset: 1, limit: 20, } dateRange.value = ['', ''] fetchData(true) } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e } // 导出 const exportList = () => { if (!checkoutList.value.length) { ElMessage.warning('请选择需要导出的数据') return } const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) // exportHole({ ids: checkoutList.value }).then((res) => { // exportFile(res.data, '地下空洞列表.xlsx') // loading.close() // }).catch(() => { // loading.close() // }) const titleArr = ['序号', ...columns.value.map((item: any) => item.text)] const json = checkoutList.value.map((item: any, index: number) => { const obj = {} as any columns.value.map((item: any) => item.value).forEach((element: any) => { obj[element] = item[element] }) return { index: index + 1, ...obj, } }) exportExcel({ json, name: '地下空洞列表', titleArr, sheetName: 'sheet1', }) loading.close() } // 删除 const deleteList = () => { if (!checkoutList.value.length) { ElMessage.warning('请选择需要删除的数据') return } ElMessageBox.confirm( '确认删除所选数据吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then((res) => { batchDeleteHole({ ids: checkoutList.value.map((item: any) => item.id) }).then((res) => { ElMessage.success('操作成功') fetchData(true) }) }) } // 模板下载 const templateDownload = () => { templateHole({}).then((res) => { exportFile(res.data, '地下空洞模板') }) } // 导入 const importRef = ref() const importList = () => { importRef.value.click() } const onFileChange = (event: any) => { if (event.target.files?.length !== 0) { // 创建formdata对象 const fd = new FormData() fd.append('file', event.target.files[0]) // fd.append('equipmentType', $props.equipmentType) const loading = ElLoading.service({ lock: true, background: 'rgba(255, 255, 255, 0.8)', }) importHole(fd).then((res) => { // 清空上传缓存 importRef.value.value = '' if (res.code === 200) { ElMessage.success('上传成功') loading.close() fetchData(true) } else { loading.close() } }).catch(() => { // 清空上传缓存 importRef.value.value = '' loading.close() }) } } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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(true) } // 详情 const detailRef = ref() const handler = (type: string, row: any) => { detailRef.value.initDialog(type, row) } // 查询字典 const riskLevelList = ref<dictType[]>([]) // 风险等级 const handlerList = ref<dictType[]>([]) // 是否治理 const getDict = async () => { // 风险等级 getDictByCode('holeRiskLevel').then((response) => { riskLevelList.value = response.data }) getDictByCode('isAlarm').then((response) => { handlerList.value = response.data }) } onMounted(async () => { await getDict() fetchData(true) // 获取数据 }) </script> <template> <!-- 布局 --> <app-container> <search-area :need-clear="true" @search="searchList" @clear="reset"> <!-- 编辑弹窗 --> <detail-dialog ref="detailRef" @refresh="searchList" /> <!-- <search-item> <el-input v-model.trim="listQuery.holeCode" placeholder="地下空洞编号" class="short-input" clearable /> </search-item> --> <!-- <search-item> <el-input v-model.trim="listQuery.abnormolWave" placeholder="异常波形" class="short-input" clearable /> </search-item> --> <!-- <search-item> <el-input v-model.trim="listQuery.detectionDistance" placeholder="探测距离" class="short-input" clearable /> </search-item> --> <!-- <search-item> <el-input v-model.trim="listQuery.holeSize" placeholder="空洞大小" class="short-input" clearable /> </search-item> --> <!-- <search-item> <el-input v-model.trim="listQuery.holeType" placeholder="空洞类型" class="short-input" clearable /> </search-item> --> <!-- <search-item> <el-date-picker v-model="listQuery.detectionTime" type="date" placeholder="探测时间" style="width: 100%;" format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss" /> </search-item> --> <search-item> <el-date-picker v-model="dateRange" class="short-input" type="datetimerange" range-separator="至" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="探测开始时间" end-placeholder="探测结束时间" /> </search-item> <search-item> <el-select v-model="listQuery.overLevel" class="short-input" placeholder="风险等级" clearable> <el-option v-for="item in riskLevelList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <!-- <search-item> <el-input v-model.trim="listQuery.position" placeholder="空洞位置" class="short-input" clearable /> </search-item> --> <search-item> <el-select v-model="listQuery.isProcess" class="short-input" placeholder="是否进行治理" clearable> <el-option v-for="item in handlerList" :key="item.id" :label="item.name" :value="item.value" /> <!-- <el-option value="已治理" label="已治理"> 已治理 </el-option> <el-option value="未治理" label="未治理"> 未治理 </el-option> --> </el-select> </search-item> </search-area> <table-container> <template #btns-right> <icon-button icon="icon-add" title="新增" type="primary" @click="handler('create', {})" /> <icon-button icon="icon-delete" title="删除" type="primary" @click="deleteList" /> <!-- <icon-button icon="icon-template" title="模板下载" type="primary" @click="templateDownload" /> --> <!-- <icon-button icon="icon-import" title="导入" type="primary" @click="importList" /> --> <icon-button icon="icon-export" title="导出" type="primary" @click="exportList" /> <input ref="importRef" style="display: none;" type="file" accept=".xls,.xlsx" @change="onFileChange"> </template> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="操作" align="center" fixed="right" width="120"> <template #default="{ row }"> <el-button size="small" link type="primary" @click="handler('detail', row)"> 详情 </el-button> <el-button size="small" link type="primary" @click="handler('update', row)"> 编辑 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template> <style lang="scss" scoped> // 样式 </style>