Newer
Older
carbon-metering-front / src / views / data / environment / page.vue
<!-- 分布式/楼宇/储能 -->
<script lang="ts" setup name="environmentPage">
// 查询参数
const searchQuery = reactive({
  offset: 1,
  limit: 20,
  startTime: '',
  endTime: '',
})
// 查询时间段范围
const TimeRanges = ref()
// 监听时间段范围
watch(() => TimeRanges.value, (newVal: string[]) => {
  if (newVal && newVal.length) {
    searchQuery.startTime = newVal[0]
    searchQuery.endTime = newVal[1]
  }
}, { deep: true })
const loadingTable = ref(true)
const columns = ref([
  { text: '环境温度', value: 'temperature', align: 'center' },
  { text: '相对湿度', value: 'humidity', align: 'center' },
  { text: '风速', value: 'windSpeed', align: 'center' },
  { text: '风向', value: 'windDirection', align: 'center' },
  { text: '大气压力', value: 'atmos', align: 'center' },
  { text: '降雨量', value: 'rainfall', align: 'center' },
  { text: '关照/总辐射量', value: 'radiation', align: 'center' },
  { text: '上传时间', value: 'uploadTime', align: 'center' },
]) // 表格
const total = ref<number>(0)
const list = ref<any[]>([])
// 搜索
const search = () => {
  loadingTable.value = true
  setTimeout(() => {
    list.value = [
      {
        id: '1',
        temperature: '15 ℃',
        humidity: '22',
        windSpeed: '9 m/s',
        windDirection: '西北',
        atmos: '1.1',
        rainfall: '115',
        radiation: '1/13',
        uploadTime: '2023-3-8 00:00:00',
      },
      {
        id: '1',
        temperature: '13 ℃',
        humidity: '14',
        windSpeed: '16 m/s',
        windDirection: '西',
        atmos: '1.1',
        rainfall: '135',
        radiation: '1/13',
        uploadTime: '2023-3-8 00:00:00',
      },
      {
        id: '1',
        temperature: '18 ℃',
        humidity: '22',
        windSpeed: '16 m/s',
        windDirection: '北',
        atmos: '1.1',
        rainfall: '15',
        radiation: '1/13',
        uploadTime: '2023-3-8 00:00:00',
      },
      {
        id: '1',
        temperature: '13 ℃',
        humidity: '22',
        windSpeed: '0 m/s',
        windDirection: '',
        atmos: '1.2',
        rainfall: '0',
        radiation: '1/13',
        uploadTime: '2023-3-8 00:00:00',
      },
      {
        id: '1',
        temperature: '14 ℃',
        humidity: '21',
        windSpeed: '18 m/s',
        windDirection: '东',
        atmos: '1.4',
        rainfall: '0',
        radiation: '12/13',
        uploadTime: '2023-3-8 00:00:00',
      },
    ]
    total.value = 5
    loadingTable.value = false
  }, 1000)
}
// 重置
const reset = () => {
  // searchQuery.deviceNo = ''
  searchQuery.offset = 1
  searchQuery.limit = 20
  searchQuery.startTime = ''
  searchQuery.endTime = ''
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    searchQuery.limit = val.size
  }
  if (val && val.page) {
    searchQuery.offset = val.page
  }
  search()
}
// 表格被选中的行
const selectList = ref<any[]>([])
// 表格多选
const multiSelect = (row: any[]) => {
  selectList.value = row
}
onMounted(() => {
  search()
})
</script>

<template>
  <div>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="search" @clear="reset">
      <search-item>
        <el-date-picker
          v-model="TimeRanges"
          type="datetimerange"
          format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
          range-separator="至"
          start-placeholder="上传开始时间"
          end-placeholder="上传结束时间"
          clearable
        />
      </search-item>
    </search-area>
    <table-container>
      <!-- 表格区域 -->
      <normal-table
        :data="list" :total="total" :columns="columns as any"
        :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable"
        :is-showmulti-select="true" :is-multi="true" @change="changePage" @multiSelect="multiSelect"
      >
        <template #preColumns>
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </div>
</template>