feat :完善cameraTree接口
This commit is contained in:
parent
1bb0f26f17
commit
24f0a52bee
@ -121,7 +121,7 @@ export const option = {
|
|||||||
// name: '总数',
|
// name: '总数',
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
radius: ['50%', '70%'],
|
radius: ['50%', '70%'],
|
||||||
center: ['30%', '50%'],
|
center: ['31.4%', '50%'],
|
||||||
avoidLabelOverlap: false,
|
avoidLabelOverlap: false,
|
||||||
label: {
|
label: {
|
||||||
show: false,
|
show: false,
|
||||||
|
@ -179,6 +179,13 @@ function generateTimeRange(period: string): { startTime: string; endTime: string
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const fetchAlarmData = async ({ startTime, endTime }: { startTime: string; endTime: string }) => {
|
const fetchAlarmData = async ({ startTime, endTime }: { startTime: string; endTime: string }) => {
|
||||||
|
const defaultNoData = {
|
||||||
|
dimensions: props.chartConfig.option.dataset.dimensions,
|
||||||
|
source: [{
|
||||||
|
[props.chartConfig.option.dataset.dimensions[0]]: "无数据",
|
||||||
|
[props.chartConfig.option.dataset.dimensions[1]]: 0
|
||||||
|
}],
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(
|
const res = await axios.get(
|
||||||
`/dev/space/getNumberByAlarmLevel`, // 手动添加 dev
|
`/dev/space/getNumberByAlarmLevel`, // 手动添加 dev
|
||||||
@ -187,19 +194,20 @@ const fetchAlarmData = async ({ startTime, endTime }: { startTime: string; endTi
|
|||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (res.data.state === true) {
|
// 检查 API 响应状态和数据是否有效且非空
|
||||||
|
if (res.data.state === true && res.data.value && res.data.value.length > 0) {
|
||||||
console.log(res.data)
|
console.log(res.data)
|
||||||
return {
|
return {
|
||||||
dimensions: props.chartConfig.option.dataset.dimensions,
|
dimensions: props.chartConfig.option.dataset.dimensions,
|
||||||
source: res.data.value,
|
source: res.data.value,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
console.error('API调用失败:', res.data)
|
console.warn('API调用成功但数据为空或状态异常,显示默认无数据。', res.data)
|
||||||
return {}
|
return defaultNoData;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取图表数据失败:', error)
|
console.error('获取图表数据失败:', error)
|
||||||
return {}
|
return defaultNoData;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -207,11 +215,8 @@ const handleBorderSelectChange = async (newValue: string) => {
|
|||||||
props.chartConfig.option.selectOption.selectValue = newValue;
|
props.chartConfig.option.selectOption.selectValue = newValue;
|
||||||
const { startTime, endTime } = generateTimeRange(newValue);
|
const { startTime, endTime } = generateTimeRange(newValue);
|
||||||
const fetchedData = await fetchAlarmData({ startTime, endTime });
|
const fetchedData = await fetchAlarmData({ startTime, endTime });
|
||||||
if (fetchedData) {
|
dataHandle(fetchedData);
|
||||||
dataHandle(fetchedData);
|
|
||||||
} else {
|
|
||||||
dataHandle(undefined); // 清空图表或显示默认状态
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
@ -518,11 +518,26 @@ const getDataSource = (newData: any) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const fetchCameraTree = async () => {
|
||||||
|
console.log('fetchCameraTree: 正在获取摄像头树数据...');
|
||||||
|
try {
|
||||||
|
const res = await axios.get('/dev/api/camera/tree');
|
||||||
|
if (res.status === 200 && res.data && res.data.state) {
|
||||||
|
console.log("API 响应数据 (Camera Tree):", res.data.value);
|
||||||
|
return res.data.value;
|
||||||
|
} else {
|
||||||
|
console.warn('API 返回非预期数据结构或空数据:', res);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取摄像头树失败:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (isPreview()) {
|
if (isPreview()) {
|
||||||
yushiStore.setCurrentCameraOrgTree(yushiStore.getCameraOrgTree)
|
yushiStore.setCurrentCameraOrgTree(yushiStore.getCameraOrgTree)
|
||||||
|
props.chartConfig.option.dataset.list = await fetchCameraTree();
|
||||||
await initplayer(props.chartConfig.option.dataset)
|
await initplayer(props.chartConfig.option.dataset)
|
||||||
if (props.chartConfig.option.dataset.list) {
|
if (props.chartConfig.option.dataset.list) {
|
||||||
//加载title
|
//加载title
|
||||||
@ -533,7 +548,8 @@ onMounted(async () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
onDeactivated(() => {
|
onDeactivated(() => {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
Loading…
Reference in New Issue
Block a user