| | |
| | | </el-form-item> |
| | | <el-form-item label="雨量数据:"> |
| | | <el-select |
| | | @change="handleChange" |
| | | v-model="formData.selectedRainfall" |
| | | placeholder="请选择" |
| | | popper-class="mySelectStyle" |
| | | > |
| | | <el-option |
| | | v-for="item in rainfallData" |
| | | v-for="item in options" |
| | | :key="item.id" |
| | | :label="item.name" |
| | | :value="item.id" |
| | | :value="item.name" |
| | | ></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | |
| | | <div class="table-container"> |
| | | <div |
| | | class="table-row" |
| | | v-for="(item, index) in filteredTableData" |
| | | v-for="(item, index) in shgList" |
| | | :key="index" |
| | | > |
| | | <input type="checkbox" v-model="item.selected" /> |
| | | <span>{{ item.name }}</span> |
| | | <span>{{ item.deviceName }}</span> |
| | | </div> |
| | | </div> |
| | | </el-form-item> |
| | |
| | | <div style="width: 100%; height: 60px; background-color: #fff;"></div> |
| | | </div> --> |
| | | <div class="buttons"> |
| | | <el-button type="primary" @click="openSaveDialog">保存方案</el-button> |
| | | <el-button type="primary" @click="saveSim">保存方案</el-button> |
| | | <el-button type="success" @click="startPlay">开始模拟</el-button> |
| | | <el-button type="success" @click="futurePredictions">未来预测</el-button> |
| | | </div> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, watch, defineProps, computed, inject, reactive } from "vue"; |
| | | import { |
| | | ref, |
| | | watch, |
| | | defineProps, |
| | | computed, |
| | | inject, |
| | | reactive, |
| | | onMounted, |
| | | } from "vue"; |
| | | import { ElMessage } from "element-plus"; |
| | | import { initeWaterPrimitiveView } from "@/utils/water"; |
| | | import { SimAPIStore } from "@/store/simAPI"; |
| | | import { EventBus } from "@/eventBus"; // 引入事件总线 |
| | | import { getDeviceInfo } from "@/api/hpApi"; |
| | | |
| | | // 获取 Store 实例 |
| | | const simStore = SimAPIStore(); |
| | |
| | | name: "方案名称", |
| | | selectedRainfall: "", |
| | | type: 2, |
| | | gauges: [ |
| | | { |
| | | id: "xxxxxxxxxxxxxx", |
| | | name: "雨量计1", |
| | | x: 119.0, |
| | | y: 28.0, |
| | | r: 10000, |
| | | }, |
| | | { |
| | | id: "xxxxxxxxxxxxxx", |
| | | name: "雨量计2", |
| | | x: 119.0, |
| | | y: 28.0, |
| | | r: 10000, |
| | | }, |
| | | ], |
| | | gauges: [], |
| | | }); |
| | | |
| | | // 工具函数:深拷贝并设置默认选中状态 |
| | | function deepCloneAndSetSelected(data) { |
| | | const newData = {}; |
| | | for (const key in data) { |
| | | newData[key] = data[key].map((item) => ({ ...item, selected: true })); |
| | | } |
| | | return newData; |
| | | } |
| | | |
| | | // 接收父组件传递的 props |
| | | const props = defineProps({ |
| | |
| | | required: true, |
| | | }, |
| | | }); |
| | | const rainfallData = ref([]); |
| | | |
| | | const tableData = ref({}); // 表格数据(按雨量数据分组) |
| | | const isCollapsed = ref(false); // 控制展开/收起状态 |
| | | |
| | | // 模拟不同区域的数据 |
| | | const areaDataMap = { |
| | | 孙胡沟: { |
| | | rainfallData: [ |
| | | { id: "1", name: "气象实时数据 - 孙胡沟" }, |
| | | { id: "2", name: "雨量计实时数据 - 孙胡沟" }, |
| | | ], |
| | | tableData: { |
| | | 1: [ |
| | | { id: "001", name: "孙胡沟气象站001" }, |
| | | { id: "002", name: "孙胡沟气象站002" }, |
| | | ], |
| | | 2: [ |
| | | { id: "003", name: "孙胡沟雨量计003" }, |
| | | { id: "004", name: "孙胡沟雨量计004" }, |
| | | ], |
| | | }, |
| | | }, |
| | | 鱼水洞后沟: { |
| | | rainfallData: [ |
| | | { id: "1", name: "气象实时数据 - 鱼水洞后沟" }, |
| | | { id: "2", name: "雨量计实时数据 - 鱼水洞后沟" }, |
| | | ], |
| | | tableData: { |
| | | 1: [ |
| | | { id: "005", name: "鱼水洞后沟气象站005" }, |
| | | { id: "006", name: "鱼水洞后沟气象站006" }, |
| | | ], |
| | | 2: [ |
| | | { id: "007", name: "鱼水洞后沟雨量计007" }, |
| | | { id: "008", name: "鱼水洞后沟雨量计008" }, |
| | | ], |
| | | }, |
| | | }, |
| | | 于家西沟: { |
| | | rainfallData: [ |
| | | { id: "1", name: "气象实时数据 - 于家西沟" }, |
| | | { id: "2", name: "雨量计实时数据 - 于家西沟" }, |
| | | ], |
| | | tableData: { |
| | | 1: [ |
| | | { id: "009", name: "于家西沟气象站009" }, |
| | | { id: "010", name: "于家西沟气象站010" }, |
| | | ], |
| | | 2: [ |
| | | { id: "011", name: "于家西沟雨量计011" }, |
| | | { id: "012", name: "于家西沟雨量计012" }, |
| | | ], |
| | | }, |
| | | }, |
| | | // 雨量计下拉框 |
| | | const options = ref([ |
| | | { id: "1", name: "气象实时数据" }, |
| | | { id: "2", name: "雨量计实时数据" }, |
| | | ]); |
| | | |
| | | // 雨量计列表 |
| | | const shgList = ref([]); |
| | | // 所有的雨量计列表 |
| | | const rainListNoFilter = ref([]); |
| | | |
| | | // 获取所有雨量计数据(来自接口) |
| | | const getRainListAll = () => { |
| | | // 雨量计类型id |
| | | const ids = "1874719366287368194"; |
| | | getDeviceInfo(ids).then((res) => { |
| | | rainListNoFilter.value = res.data.pageData; |
| | | // 根据当前选择的区域自动过滤 |
| | | updateShgListByArea(); |
| | | }); |
| | | }; |
| | | |
| | | // 根据 selectedArea 更新数据 |
| | | // 根据 props.selectedArea.label 过滤雨量计列表,并设置 selected: true |
| | | const updateShgListByArea = () => { |
| | | const currentArea = props.selectedArea?.label; |
| | | |
| | | if (!currentArea) { |
| | | shgList.value = []; |
| | | return; |
| | | } |
| | | |
| | | shgList.value = rainListNoFilter.value |
| | | .filter((item) => item.deviceName?.includes(currentArea)) |
| | | .map((device) => ({ |
| | | ...device, |
| | | selected: true, // 默认选中 |
| | | })); |
| | | }; |
| | | |
| | | // 下拉框选中值的表格数据变化 |
| | | const handleChange = async (item) => { |
| | | formData.selectedRainfall = item; |
| | | |
| | | if (item === "雨量计实时数据") { |
| | | if (!props.selectedArea) { |
| | | ElMessage.warning("请先选择区域"); |
| | | shgList.value = []; |
| | | return; |
| | | } |
| | | // 如果还没有加载过数据,则先请求接口加载 |
| | | if (rainListNoFilter.value.length === 0) { |
| | | getRainListAll(); // 加载全部数据后会自动过滤 |
| | | } else { |
| | | updateShgListByArea(); // 已有数据就直接过滤 |
| | | } |
| | | } else { |
| | | shgList.value = []; |
| | | } |
| | | }; |
| | | |
| | | // 监听区域变化,重新过滤数据 |
| | | watch( |
| | | () => props.selectedArea, |
| | | (newArea) => { |
| | | console.log(newArea.label, "new"); |
| | | if (areaDataMap[newArea.label]) { |
| | | rainfallData.value = areaDataMap[newArea.label].rainfallData; |
| | | // 使用深拷贝设置默认选中状态 |
| | | tableData.value = deepCloneAndSetSelected( |
| | | areaDataMap[newArea.label].tableData |
| | | ); |
| | | formData.selectedRainfall = ""; // 清空选中的雨量数据 |
| | | } else { |
| | | rainfallData.value = []; |
| | | tableData.value = {}; |
| | | formData.selectedRainfall = ""; |
| | | if (!newArea) { |
| | | ElMessage.warning("请选择一个区域"); |
| | | shgList.value = []; |
| | | } else if (formData.selectedRainfall === "雨量计实时数据") { |
| | | handleChange(formData.selectedRainfall); |
| | | } |
| | | } |
| | | // { immediate: true } // 立即执行一次,确保初始数据正确 |
| | | }, |
| | | { immediate: true } |
| | | ); |
| | | |
| | | // 动态计算表格数据 |
| | | const filteredTableData = computed(() => { |
| | | return formData.selectedRainfall && tableData.value[formData.selectedRainfall] |
| | | ? tableData.value[formData.selectedRainfall] |
| | | : []; |
| | | }); |
| | | |
| | | // 获取当前选中的雨量数据名称 |
| | | const selectedRainfallName = computed(() => { |
| | | const selected = rainfallData.value.find( |
| | | (item) => item.id === formData.selectedRainfall |
| | | ); |
| | | return selected ? selected.name : ""; |
| | | }); |
| | | |
| | | // 获取当前选中的设备信息 |
| | | const selectedDevices = computed(() => { |
| | | return filteredTableData.value.filter((item) => item.selected); |
| | | }); |
| | | |
| | | // 重置表单 |
| | | const resetForm = () => { |
| | | formData.name = ""; |
| | | formData.selectedRainfall = ""; |
| | | shgList.value = []; |
| | | }; |
| | | |
| | | // 打开保存方案对话框 |
| | | const openSaveDialog = async () => { |
| | | const updateSelectedGauges = () => { |
| | | formData.gauges = shgList.value |
| | | .filter((item) => item.selected) |
| | | .map((item) => ({ |
| | | id: item.deviceCode, |
| | | name: item.deviceName, |
| | | x: item.longitude, |
| | | y: item.latitude, |
| | | r: 10000, |
| | | })); |
| | | }; |
| | | |
| | | // 保存方案 |
| | | const saveSim = async () => { |
| | | try { |
| | | updateSelectedGauges(); |
| | | formData.geom = props.selectedArea; |
| | | await simStore.addSimCheme(formData); |
| | | resetForm(); |
| | |
| | | .table-container { |
| | | font-size: 12px; |
| | | height: 120px; |
| | | width: 90%; |
| | | width: 96%; |
| | | overflow-y: auto; |
| | | border: 1px solid #ddd; |
| | | border-radius: 4px; |