Files
xian_vue_new/src/component/rain-earthquake/HiddenPointComponent.vue
T

106 lines
3.1 KiB
Vue
Raw Normal View History

2026-04-11 10:09:40 +08:00
<!-- 隐患点组件 -->
<template>
<div>
<!-- 加载基础隐患点 -->
<LoadingPoints
v-if="
useViewerStore().getViewerLoadingCompleted() &&
baseHiddenPoints.length > 0
"
:base-points="baseHiddenPoints"
:get-disaster-icon="getDisasterIcon"
:prefix="config.prefix.hiddenDangerPointId"
/>
2026-04-11 10:09:40 +08:00
<!-- 显示信息框 -->
<InformationBox
:data="hiddenDangerPointDetail as Record<string, any>"
:field="field"
v-if="
useLoadingInformationStore().getLoadingHiddenPointInformationStatus()
"
:title="informationBoxTitle"
:offset-x="offsetX"
:offset-y="offsetY"
:key="useLoadingInformationStore().getHiddenPointId()"
/>
2026-04-11 10:09:40 +08:00
</div>
</template>
<script setup lang="ts">
import { DisasterType } from '@/types/common/DisasterType';
import { ref, watch } from 'vue';
import { $api } from '@/api/api.ts';
import type { Point } from '@/types/base/Point';
import LoadingPoints from '@/component/rain-earthquake/LoadingPoints.vue';
import config from '@/config/config.json';
import InformationBox from '@/component/common/InformationBox.vue';
import { useViewerStore } from '@/stores/useViewerStore';
import { useLoadingInformationStore } from '@/stores/useLoadingInformation';
import { CesiumUtilsSingleton } from '@/utils/cesium/CesiumUtils';
import { useHiddenPoint } from '@/hooks/rain-earthquake/useHiddenPoint';
// 接收父组件传递的参数
const props = defineProps<{
disasterType: DisasterType;
}>();
// 基本隐患点数据
const baseHiddenPoints = ref<Point[]>([]);
// 信息框相关字段
const informationBoxTitle = ref('');
const offsetX = ref(0);
const offsetY = ref(0);
const hiddenDangerPointDetail = ref<Point>();
// 获取钩子函数
const { field, getDisasterIcon } = useHiddenPoint();
$api.hiddenDangerSpots.getBasePoins(props.disasterType).then((res) => {
baseHiddenPoints.value = res.data;
});
// 监听id变化
watch(
() => useLoadingInformationStore().getHiddenPointId(),
async (newId: number) => {
if (newId === -1) {
return;
}
// 获取隐患点数据
const clickObject = useLoadingInformationStore().getClickObject();
if (!clickObject || !clickObject.primitive) {
console.warn('点击对象或图元不存在');
return;
}
const res = await $api.hiddenDangerSpots.getPointDetailById(
useLoadingInformationStore().getHiddenPointId()
);
// 更新数据
hiddenDangerPointDetail.value = res.data;
informationBoxTitle.value = res.data.disasterType + '隐患点';
try {
// 将坐标转换为偏移量
const screenPos = CesiumUtilsSingleton.convertScreenPosition(
clickObject.primitive.position
);
offsetX.value = screenPos.x;
offsetY.value = screenPos.y;
// 显示新的信息框
useLoadingInformationStore().setLoadingHiddenPointInformationStatus(
true
);
} catch (error) {
throw new Error(`坐标转换失败:${error}`);
}
}
);
2026-04-11 10:09:40 +08:00
</script>
<style scoped></style>