历史分析界面优化

pull/3/head
liutao 1 week ago
parent 2dfbe31f0d
commit 4121523db9

@ -162,6 +162,15 @@ export const DeviceApi = {
})
},
getHistoryAnalyse: async (params: HistoryRecordParams) => {
return await request.get({
url: `/iot/device/historyAnalyse`,
params,
paramsSerializer: (p) => qs.stringify(p, { allowDots: true, arrayFormat: 'repeat' })
})
},
devicePointList: async () => {
return await request.get({ url: `/iot/device/devicePointList` })
},

@ -562,6 +562,7 @@ async function handleAnalyze() {
const res: any = await DeviceApi.getHistoryAnalyse(params)
//oneHistoryData.value = res;
//historyData.value = res.data;
if (res && res.analyseData) {
resultData.value = res.analyseData;
// 2. API
if (res && res.data) {
@ -574,9 +575,16 @@ async function handleAnalyze() {
calculateAnalysis()
ElMessage.success('已重新分析,图表与统计结果已更新')
} else {
//
ElMessage.warning('未查询到相关数据')
initializeEmptyCharts()
}
} catch (error) {
console.error('分析失败:', error)
ElMessage.error('分析失败,请检查网络连接或参数设置')
//
initializeEmptyCharts()
} finally {
analyzing.value = false
}
@ -588,6 +596,7 @@ async function handleAnalyze() {
// API
function transformApiDataToChartFormat(apiData) {
if (!apiData || apiData.length === 0) {
historyData.value = []
oneHistoryData.value = {
time: [],
series: []
@ -868,8 +877,24 @@ const getDiviceList = async () => {
const data = await DeviceApi.getDeviceAttributeGroupList({deviceId: route.query.id})
pointGroups.value = data;
activePointGroup.value = data[0]?.typeNames;
selectedPointCodes.value = data[0]?.codes;
let deviceDO = data[0]?.deviceDO;
if (deviceDO && deviceDO.contactInfo) {
selectedPointCodes.value = data[0]?.codes;
const contactInfo = JSON.parse(deviceDO.contactInfo)
//
if (contactInfo.startTime) {
queryParams.startTime = contactInfo.startTime
}
if (contactInfo.endTime) {
queryParams.endTime = contactInfo.endTime
}
if (contactInfo.codes && Array.isArray(contactInfo.codes)) {
selectedPointCodes.value = contactInfo.codes
await handleAnalyze() //
}
}
} finally {
loading.value = false
}
@ -942,6 +967,8 @@ function handleEndTimeChange(value) {
}
}
}
//
const pageLoaded = ref(false)
//
const endTimeOptions = computed(() => {
@ -957,13 +984,87 @@ const endTimeOptions = computed(() => {
}
})
//
function initializeEmptyCharts() {
const chartDom = document.getElementById('historyTrendChart')
if (chartDom && !oneChartInstance) {
oneChartInstance = echarts.init(chartDom)
}
//
if (oneChartInstance) {
oneChartInstance.setOption({
title: {
text: '请选择分析条件后点击"开始分析"',
left: 'center',
top: 'center',
textStyle: {
color: '#909399',
fontSize: 16,
fontWeight: 'normal'
}
},
xAxis: { show: false },
yAxis: { show: false },
series: []
})
}
//
resultData.value = []
historyData.value = []
summaryData.value = [
{
title: '已选点位数',
value: 0,
desc: '请先选择点位'
},
{
title: '分析时间跨度',
value: '未设置',
desc: '请设置开始和结束时间'
},
{
title: '最大波动点位',
value: '-',
desc: '无数据'
},
{
title: '最小波动点位',
value: '-',
desc: '无数据'
},
{
title: '最高值点位',
value: '-',
desc: '无数据'
}
]
}
//
onMounted(() => {
onMounted(async () => {
getDiviceList()
calculateAnalysis()
nextTick(() => {
updateChart()
})
// 2.
const hasContactInfo = selectedPointCodes.value && selectedPointCodes.value.length > 0
if (hasContactInfo) {
// 3.
console.log('检测到保存的分析条件,自动查询...')
await handleAnalyze() //
} else {
// 4.
console.log('无保存的分析条件,显示空状态')
initializeEmptyCharts()
calculateAnalysis() //
}
//
pageLoaded.value = true
/* calculateAnalysis()
nextTick(() => {
updateChart()
})*/
})
//

Loading…
Cancel
Save