Files
admin-govern/src/components/cockpit/indicatorFittingChart/index.vue

243 lines
7.6 KiB
Vue
Raw Normal View History

<template>
<div>
<!--主要监测点列表 -->
2025-11-06 14:24:15 +08:00
<TableHeader :showReset="false" @selectChange="selectChange" v-if="fullscreen">
<template v-slot:select>
2025-11-06 14:24:15 +08:00
<el-form-item label="日期">
<DatePicker
ref="datePickerRef"
:nextFlag="false"
:theCurrentTime="true"
:initialInterval="getInitialInterval()"
:initialTimeValue="getInitialTimeValue()"
@change="handleDatePickerChange"
></DatePicker>
</el-form-item>
<el-form-item label="关键词">
<el-input v-model="tableStore.table.params.searchValue" clearable placeholder="请输关键字" />
</el-form-item>
</template>
</TableHeader>
2025-11-06 14:24:15 +08:00
<Table
ref="tableRef"
@cell-click="cellClickEvent"
:height="`calc(${prop.height} - ${headerHeight}px + ${fullscreen ? 0 : 56}px )`"
></Table>
<!-- 指标越限详情 -->
<OverLimitDetails ref="OverLimitDetailsRef" />
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide, reactive, watch, h } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { useDictData } from '@/stores/dictData'
import { ElMessage, ElMessageBox } from 'element-plus'
import { getTimeOfTheMonth } from '@/utils/formatTime'
import { ElTag } from 'element-plus'
import OverLimitDetails from '@/components/cockpit/listOfMainMonitoringPoints/components/overLimitDetails.vue'
2025-11-06 14:24:15 +08:00
import { useRoute } from 'vue-router'
import { useTimeCacheStore } from '@/stores/timeCache'
import DatePicker from '@/components/form/datePicker/index.vue'
const prop = defineProps({
2025-11-05 14:45:56 +08:00
w: { type: String },
h: { type: String },
width: { type: String },
height: { type: String },
timeKey: { type: String },
timeValue: { type: Object }
})
const dictData = useDictData()
const OverLimitDetailsRef = ref()
2025-11-05 14:45:56 +08:00
const headerHeight = ref(57)
2025-11-06 14:24:15 +08:00
const route = useRoute()
const timeCacheStore = useTimeCacheStore()
const datePickerRef = ref()
2025-11-05 14:45:56 +08:00
const selectChange = (showSelect: any, height: any) => {
headerHeight.value = height
}
// 计算是否全屏展示
const fullscreen = computed(() => {
const w = Number(prop.w)
const h = Number(prop.h)
if (!isNaN(w) && !isNaN(h) && w === 12 && h === 6) {
// 执行相应逻辑
return true
} else {
return false
}
})
2025-11-06 14:24:15 +08:00
// 处理 DatePicker 值变化事件
const handleDatePickerChange = (value: any) => {
console.log('DatePicker value changed:', value)
// 将值缓存到 timeCache
if (value) {
timeCacheStore.setCache(route.path, value.interval, value.timeValue)
}
}
const tableStore: any = new TableStore({
2025-11-06 14:24:15 +08:00
url: '/system-boot/dashboard/queryPage',
method: 'POST',
2025-11-06 14:24:15 +08:00
showPage: false,
exportName: '主要监测点列表',
column: [
{
field: 'index',
title: '序号',
2025-10-21 16:11:00 +08:00
width: '80',
formatter: (row: any) => {
return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
}
},
{
title: '监测点名称',
field: 'name',
minWidth: '90',
render: 'customTemplate',
customTemplate: (row: any) => {
return `<span style='cursor: pointer;text-decoration: underline;'>${row.name}</span>`
}
},
{
title: '监测对象类型',
field: 'type',
minWidth: '90'
},
{
title: '是否治理',
field: 'whetherToGovern',
minWidth: '70'
},
{ title: '主要存在的电能质量问题', field: 'question', minWidth: '150' }
],
beforeSearchFun: () => {
2025-11-06 14:24:15 +08:00
// 尝试从缓存获取时间值
let beginTime, endTime
if (fullscreen.value) {
const cached = timeCacheStore.getCache(route.path)
if (cached && cached.timeValue) {
beginTime = cached.timeValue[0]
endTime = cached.timeValue[1]
}
}
// 如果缓存中没有则使用默认值
tableStore.table.params.searchBeginTime = beginTime || prop.timeValue?.[0] || getTimeOfTheMonth(prop.timeKey)[0]
tableStore.table.params.searchEndTime = endTime || prop.timeValue?.[1] || getTimeOfTheMonth(prop.timeKey)[1]
},
loadCallback: () => {
tableStore.table.data = [
{
name: '10kV1#电动机',
type: '电动机',
whetherToGovern: '否',
question: '3次谐波电压、5次谐波电流、电压不平衡度超标'
},
{
name: '10kV2#(治理后)',
type: '电焊机',
whetherToGovern: '100A APF',
question: '所有指标均合格'
},
{
name: '380V电焊机(治理前)',
type: '电焊机',
whetherToGovern: '100A APF',
question: '5次谐波电流、电压不平衡度超标'
},
{
name: '380V水泵机',
type: '电动机',
whetherToGovern: '否',
question: '所有指标均合格'
}
]
tableStore.table.height = `calc(${prop.height} - 80px)`
}
})
const tableRef = ref()
provide('tableRef', tableRef)
tableStore.table.params.type = ''
tableStore.table.params.searchValue = ''
provide('tableStore', tableStore)
// 点击行
const cellClickEvent = ({ row, column }: any) => {
if (column.field == 'name') {
console.log(row)
OverLimitDetailsRef.value.open(row)
}
}
2025-11-06 14:24:15 +08:00
// 获取缓存的初始值
const getInitialInterval = () => {
if (fullscreen.value) {
const cached = timeCacheStore.getCache(route.path)
if (cached && cached.interval !== undefined) {
return cached.interval
}
}
return 3 // 默认值
}
const getInitialTimeValue = () => {
if (fullscreen.value) {
const cached = timeCacheStore.getCache(route.path)
if (cached && cached.timeValue) {
return cached.timeValue
}
}
return prop.timeValue // 使用传入的默认值
}
// 在组件挂载时设置缓存值到 DatePicker
onMounted(() => {
2025-11-06 14:24:15 +08:00
if (datePickerRef.value) {
const cached = timeCacheStore.getCache(route.path)
if (cached) {
// 如果有缓存值,设置到 DatePicker 组件
if (cached.interval !== undefined) {
datePickerRef.value.setInterval(cached.interval)
}
if (cached.timeValue) {
datePickerRef.value.timeValue = cached.timeValue
}
}
}
tableStore.index()
})
watch(
() => prop.timeKey,
val => {
tableStore.index()
}
)
watch(
() => prop.timeValue, // 监听的目标(函数形式避免直接传递 props 导致的警告)
(newVal, oldVal) => {
tableStore.index()
},
{
deep: true // 若 timeValue 是对象/数组,需开启深度监听
}
)
const addMenu = () => {}
</script>
<style lang="scss" scoped></style>