智慧园区前端大屏
shuishen
2024-12-18 9a37c5e1b2190c3f6ec71483923922189091dd52
src/views/space/components/box/dataContent.vue
@@ -2,24 +2,248 @@
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2023-03-13 14:54:26
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2023-03-13 15:00:55
 * @FilePath: \forest-fire\src\views\statistics\components\box\dataContent.vue
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 * @LastEditTime: 2024-11-28 19:30:58
 * @FilePath: \bigScreen\src\views\space\components\box\dataContent.vue
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
-->
<script setup>
import publicContent from './publicContent.vue'
import EventBus from 'utils/bus'
import publicContent from "./publicContent.vue"
import { getList } from "@/api/space/space"
import { nextTick, onUnmounted, reactive } from "vue"
const SeachBarCondition = ref(null)
const loading = ref(false)
const TableContent = ref(null)
const curTableHeight = ref(0)
const curSelectTabType = ref('')
// 搜索项配置
const options = reactive({
  searchBtnGroup: true,
  searchBtn: true,
  resetBtn: true,
  exportBtn: false,
  columns: [
    {
      type: 'input',
      props: 'name',
      placeholder: '请输入名称',
      changeSearch: true,
      flex: 1,
    }
  ]
})
const tableData = ref([])
const pages = {
  page: 1,
  pageSize: 20,
  total: 0,
}
function positionColor () {
  return (row) => {
    if (
      (row.X && row.X != 0) ||
      (row.lng && row.lng != 0) ||
      (row.longitude && row.longitude != 0) ||
      (row.x && row.x != 0)
    ) {
      return "#1AFA29"
    } else {
      return "#ccc"
    }
  }
}
function positionDisabled () {
  return (row) => {
    if (
      (row.X && row.X != 0) ||
      (row.lng && row.lng != 0) ||
      (row.longitude && row.longitude != 0) ||
      (row.x && row.x != 0)
    ) {
      return false
    } else {
      return true
    }
  }
}
onMounted(() => {
  curTableHeight.value = TableContent.value.offsetHeight
})
// 分页改变
const handleCurrentChange = (val) => {
  pages.page = val
  getLists(SeachBarCondition.value.getSeachCondition())
}
// 查询分页数据
const getLists = (param = {}) => {
  destroyPupoLayers()
  tableData.value = []
  param.current = pages.page
  param.size = pages.pageSize
  loading.value = true
  getList({
    ...param,
    type: curSelectTabType.value
  })
    .then((res) => {
      const data = res.data.data
      data.records.forEach(item => {
        if(!item.firmName){
          item.firmName = '吉水化工园区'
        }
      })
      tableData.value = data.records
      pages.total = data.total
      loading.value = false
    })
    .catch((err) => {
      loading.value = false
      console.log(err)
    })
}
let state = reactive({
  layer: {}
})
let addPupoLayers = {}
// 行点击
function rowClick (row, column, event) {
  EventBus.emit('destroyPop', 'destroyPop')
  if (row.lng && row.lat) {
    window.$viewer.flyToPosition(new DC.Position(row.lng, row.lat, 600, 0, -90, 0))
    if (!row.firmName) {
      return
    }
    // 删除
    destroyPupoLayers()
    addPupoLayers[row.name] = new DC.HtmlLayer(row.name)
    window.$viewer.addLayer(addPupoLayers[row.name])
    let iconEl = `<div class="marsBlueGradientPnl">
            <div>企业名称:${row.firmName}</div>
            <div>作用:${row.mainFuncName}</div>
                </div>`
    let divIcon = new DC.DivIcon(
      new DC.Position(row.lng, row.lat, row.ele || 64),
      `<div class="public-map-popup-two">
                    ${iconEl}
                  </div>`
    )
    let incident = () => {
      destroyPupoLayers()
    }
    divIcon.on(DC.MouseEventType.CLICK, incident)
    addPupoLayers[row.name].addOverlay(divIcon)
  }
}
// 查看详情
function goDetail (row) { }
const searchBtn = (params) => {
  resetPage()
  getLists(params)
}
const resetBtn = (params) => {
  resetPage()
  getLists(params)
}
// 重置分页数据
const resetPage = () => {
  pages.page = 1
  pages.pageSize = 20
  pages.total = 0
}
// 分页树改变
const handleSizeChange = (val) => {
  pages.pageSize = val
  getLists(SeachBarCondition.value.getSeachCondition())
}
const spaceTabChange = (type) => {
  curSelectTabType.value = type
  nextTick(() => {
    searchBtn(SeachBarCondition.value.getSeachCondition())
  })
}
EventBus.on('spaceTabChange', spaceTabChange)
onUnmounted(() => {
  EventBus.off('spaceTabChange', spaceTabChange)
  destroyPupoLayers()
  addPupoLayers = null
})
// 销毁
function destroyPupoLayers () {
  let arr = Object.keys(addPupoLayers)
  if (arr.length > 0) {
    arr.forEach(i => {
    addPupoLayers[i] && window.$viewer && window.$viewer.removeLayer(addPupoLayers[i])
    addPupoLayers[i] = null
    delete addPupoLayers[i]
  })
  addPupoLayers = {}
  }
}
</script>
<template>
    <public-content>
        <template #content>
            <div>
  <div class="w100 h0 flex-1 flex f-d-c">
    <global-search :options="options" @searchBtn="searchBtn" @resetBtn="resetBtn"
      ref="SeachBarCondition"></global-search>
            </div>
        </template>
    </public-content>
    <div class="h0 flex-1 table-content" ref="TableContent" v-loading="loading"
      element-loading-background="rgba(46, 81, 136, 0.9)">
      <el-table empty-text="暂无数据" @row-click="rowClick" border :data="tableData" :height="curTableHeight"
        style="width: 100%">
        <el-table-column align="center" label="ID" width="42" prop="rank">
          <template #default="{ $index, row }">
            {{ (pages.page - 1) * pages.pageSize + $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="firmName" label="企业名称" />
        <el-table-column show-overflow-tooltip prop="name" label="名称" width="100" />
        <el-table-column prop="mainFuncName" label="作用" width="55" />
        <!-- <el-table-column align="center" width="62" label="操作">
          <template #default="scope">
            <el-button link type="primary" size="small" :disabled="scope.row.lng == ''" @click="rowClick(scope.row)">
              定位
            </el-button>
          </template>
        </el-table-column> -->
      </el-table>
    </div>
    <div class="el-page">
      <el-pagination background layout="prev, pager, next" :page-size="pages.pageSize" :total="pages.total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange" size="small" />
    </div>
  </div>
</template>
<style lang="scss" scoped></style>
<style lang="scss" scoped>
.el-form-item__label {
  color: #fff !important;
}
.table-content {
  flex-basis: auto;
  height: calc(100% - 40px);
}
</style>