Newer
Older
SpaceIntegration_front / src / views / main / recognition / index.vue
liyaguang on 9 Nov 2023 12 KB feat(*): 列表批量删除
<!-- 第三方智能识别管理 -->
<script name="IdentifyList" setup lang="ts">
import { getCurrentInstance, onMounted, ref, watch } from 'vue'
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { DateModelType } from 'element-plus'
import type { dictType } from '../../../global'
import detailDialog from './detail.vue'
import handlerAlarmDialog from '@/views/inspection/task/handlerAlarmDialog.vue'
import { getDictByCode } from '@/api/system/dict'
import { exportFile } from '@/utils/exportUtils'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { batchDeleteIdentify, exportIdentify, getIdentifyListPage } from '@/api/page/recognition'
import { getLocation } from '@/api/map'
import { exportExcel } from '@/utils/exportXlsx'
const $router = useRouter()
const { proxy } = getCurrentInstance() as any
const baseUrl = import.meta.env.VITE_APP_API_BASEURL
// 查询条件
const listQuery = ref({
  // recognitionCode: '', // 第三方code
  recognitionType: '', // 识别类型
  // recognitionTime: '', // 识别时间
  // position: '', // 地理位置
  // recognitionPrecision: '', // 准确度
  // recognitionLevel: '', // 风险等级
  taskName: '', // 任务名称
  alarmStatus: '', // 报警状态
  riskLevel: '',
  begTime: '',
  endTime: '',
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
// 表头
const columns = ref<TableColumn[]>([
  { text: '智能识别编号', value: 'recognitionCode', align: 'center', width: '160' },
  { text: '识别类型', value: 'recognitionType', align: 'center' },
  { text: '识别时间', value: 'recognitionTime', align: 'center' },
  { text: '识别经纬度', value: 'latlng', align: 'center' },
  { text: '识别位置', value: 'position', align: 'center' },
  { text: '识别准确度', value: 'recognitionPrecision', align: 'center' },
  { text: '风险等级', value: 'recognitionLevel', align: 'center' },
  { text: '巡检任务名称', value: 'taskName', align: 'center' },
  // { text: '图片', value: 'alarmPicture', align: 'center' },
  // { text: '报警状态', value: 'alarmStatus', align: 'center' },
])
const list = ref([]) // 表格数据
// 选中的内容
const checkoutList = ref<string[]>([])
// 筛选时间段数据
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 identifyTypeList = ref<{ name: string;value: string;id: string }[]>([]) // 识别类型
const riskGradeList = ref<{ name: string;value: string;id: string }[]>() // 风险等级
const alarmStatusList = ref<{ name: string;value: string;id: string }[]>() // 报警状态
const recognitionLevelDict: { [key: string]: string } = {
  low: '低风险',
  middle: '一般风险',
  high: '较高风险',
  suphigh: '严重风险',
}
// 数据查询
async function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getIdentifyListPage(listQuery.value).then((res) => {
    console.log(res.data, '第三方')
    list.value = res.data.rows.map((item: any) => ({
      ...item,
      latlng: `${item.longitude},${item.latitude}`,
      recognitionLevel: recognitionLevelDict[item.recognitionLevel],
      // recognitionType: identifyTypeList.value.filter((ele: any) => ele.value === item.recognitionType)[0].name,
    }))
    // list.value.forEach((item: any) => {
    //   getLocation(`${item.longitude},${item.latitude}`).then((res) => {
    //     if (res.data.info === 'OK') {
    // item.position = res.data.regeocode.formatted_address
    // if (res.data.pois.length) {
    //   item.position = res.data.pois[0].address
    // }
    // else {
    //   item.position = '/'
    // }
    //     }
    //     else {
    //       item.position = '/'
    //     }
    //   })
    // })
    total.value = parseInt(res.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置
const reset = () => {
  listQuery.value = {
    taskName: '', // 任务名称
    alarmStatus: '', // 报警状态
    riskLevel: '',
    begTime: '',
    endTime: '',
    recognitionType: '',
    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)',
  })
  // exportIdentify({ 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,
      alarmStatus: item.alarmStatus,
    }
  })
  exportExcel({
    json,
    name: '第三方施工智能识别列表',
    titleArr,
    sheetName: 'sheet1',
  })
  loading.close()
}
// 删除
const deleteList = () => {
  if (!checkoutList.value.length) {
    ElMessage.warning('请选择需要删除的数据')
    return
  }
  ElMessageBox.confirm(
    '确认删除所选数据吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    batchDeleteIdentify({ ids: checkoutList.value.map((item: any) => item.id) }).then((res) => {
      ElMessage.success('操作成功')
      fetchData(true) // 获取数据
    })
  })
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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 handleEdit = (row: any) => {
  detailRef.value.initDialog(row)
}
// 处置报警
const alarmRef = ref()
const handlerAlarm = (row: any) => {
  alarmRef.value.initDialog(row)
}

const getDict = async () => {
  // 识别类型
  getDictByCode('identifyType').then((response) => {
    identifyTypeList.value = response.data
  })
  // 风险等级
  getDictByCode('riskGrade').then((response) => {
    riskGradeList.value = response.data
  })
  // 报警状态
  getDictByCode('alarmStatus').then((response) => {
    alarmStatusList.value = response.data
  })
}

onMounted(async () => {
  await getDict()
  fetchData(true) // 获取数据
})
const url = ref('')
const showBig = ref(false)
const show = (imgUrl: string) => {
  url.value = imgUrl
  showBig.value = !showBig.value
}
</script>

<template>
  <!-- 布局 -->
  <app-container>
    <!-- 处置报警 -->
    <handler-alarm-dialog ref="alarmRef" @refresh="searchList" />
    <!-- 详情 -->
    <detail-dialog ref="detailRef" />
    <search-area :need-clear="true" @search="searchList" @clear="reset">
      <!-- <search-item>
        <el-input
          v-model.trim="listQuery.recognitionCode"
          placeholder="施工智能识别编号"
          class="short-input"
          clearable
        />
      </search-item> -->
      <search-item>
        <el-select v-model="listQuery.recognitionType" class="short-input" placeholder="识别类型" clearable>
          <el-option v-for="item in identifyTypeList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <!-- <search-item>
        <el-date-picker
          v-model="listQuery.recognitionTime"
          type="datetime"
          placeholder="识别时间"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
        />
      </search-item> -->
      <!-- <search-item>
        <el-input
          v-model.trim="listQuery.position"
          placeholder="地理位置信息"
          class="short-input"
          clearable
        />
      </search-item> -->
      <!-- <search-item>
        <el-input
          v-model.trim="listQuery.recognitionPrecision"
          placeholder="识别准确度范围"
          class="short-input"
          clearable
          style="width: 100%;"
        />
      </search-item> -->
      <search-item>
        <el-select v-model="listQuery.riskLevel" class="short-input" placeholder="风险等级" clearable>
          <el-option v-for="item in riskGradeList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </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-input
          v-model.trim="listQuery.taskName"
          placeholder="巡检任务名称"
          class="short-input"
          clearable
          style="width: 100%;"
        />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.alarmStatus" class="short-input" placeholder="报警状态" clearable>
          <el-option v-for="item in alarmStatusList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
    </search-area>
    <table-container>
      <template #btns-right>
        <icon-button icon="icon-delete" title="删除" type="primary" @click="deleteList" />
        <icon-button icon="icon-export" title="导出" type="primary" @click="exportList" />
      </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">
            <template #default="{ row }">
              <el-image calss="img" style="width: 40px; height: 40px;z-index: 99999999; position: relative;" :src="`${baseUrl}/static/${row.alarmPicture}`" @click="show(`${baseUrl}/static/${row.alarmPicture}`)" />
              <div v-if="showBig" class="big-view-pic">
                <el-image style="width: 750px; height: 350px; position: relative;" :src="url" />
                <div class="big-view-pic-close" @click="show('')">
                  x
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="报警状态" align="center">
            <template #default="{ row }">
              {{ row.alarmStatus }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="120">
            <template #default="{ row }">
              <el-button size="small" link type="primary" @click="handleEdit(row)">
                详情
              </el-button>
              <el-button size="small" type="primary" link :disabled="row.alarmStatus !== '未处置'" @click="handlerAlarm(row)">
                报警处置
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>

<style lang="scss" scoped>
// 样式
.img {
  cursor: pointer;
}

.big-view-pic {
  position: fixed;
  z-index: 99999;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  .big-view-pic-close {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 44px;
    height: 44px;
    font-size: 24px;
    color: #555;
    // background-color: #606266;
    border-color: #fff;
    border-radius: 50%;
    text-align: center;
    line-height: 44px;

    &:hover {
      cursor: pointer;
    }
  }
}
</style>