guonan
2025-04-23 11cef93fa041289db9fafd4cb654b20d53cb2c51
src/views/left/KGSimOption/HistorySimulation.vue
@@ -19,7 +19,7 @@
              v-for="item in HistoricalRainData"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              :value="item.name"
            ></el-option>
          </el-select>
        </div>
@@ -104,9 +104,11 @@
import { initeWaterPrimitiveView } from "@/utils/water";
import { useSimStore } from "@/store/simulation.js"; // 引入 Store
import { getRainfallData } from "@/api/hpApi.js";
import { SimAPIStore } from "@/store/simAPI";
// 获取 Store 实例
const simStore = useSimStore();
const simStore = SimAPIStore();
// 测试获取雨量数据
// const getRainData = () => {
//   getRainfallData()
@@ -127,7 +129,7 @@
});
// 数据绑定
const rainfallHistory = ref("2"); // 默认选中第二项
const rainfallHistory = ref("XX年50mm降雨"); // 默认选中第二项
const totalRainfall = ref(50); // 降雨总量
const schemeName = ref("方案名称"); // 方案名称
const rainfallIntensity = ref(70); // 降雨强度
@@ -147,7 +149,7 @@
// 获取当前选中的历史雨情名称
const selectedRainfallName = computed(() => {
  const selected = HistoricalRainData.find(
    (item) => item.id === rainfallHistory.value
    (item) => item.name === rainfallHistory.value
  );
  return selected ? selected.name : "";
});
@@ -158,102 +160,23 @@
};
// 打开保存方案对话框
const openSaveDialog = () => {
  if (
    !props.selectedArea ||
    !rainfallHistory.value ||
    !totalRainfall.value ||
    !schemeName.value ||
    !rainfallIntensity.value ||
    !rainfallDuration.value
  ) {
    ElMessage.warning("请先填写所有必填项");
    return;
  }
  ElMessageBox.confirm("确定要保存当前方案吗?", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(confirmSave)
    .catch(() => {
      ElMessage({
        type: "info",
        message: "已取消保存",
      });
    });
  // saveDialogVisible.value = true;
};
const params = {
  name: schemeName.value,
  type: "历史模拟",
  data: {
    rainFall: totalRainfall.value,
    rainfallIntensity: rainfallIntensity.value,
    rainfallDuration: rainfallDuration.value,
    rainfallHistory: rainfallHistory.value,
  },
};
const isLoading = ref(false);
const confirmSave = async () => {
  if (isLoading.value) {
    ElMessage.warning("正在保存,请稍候...");
    return; // 防止重复提交
  }
  isLoading.value = true; // 开始加载状态
  console.log("当前选中的区域 (selectedArea):", props.selectedArea);
  const params = {
const openSaveDialog = async () => {
  const forms = {
    name: schemeName.value,
    type: "历史模拟",
    eares: props.selectedArea,
    data: {
      rainFall: totalRainfall.value,
      rainfallIntensity: rainfallIntensity.value,
      rainfallDuration: rainfallDuration.value,
      rainfallHistory: rainfallHistory.value,
    },
    geom: props.selectedArea,
    type: 3,
    rainfall: totalRainfall.value,
    intensity: rainfallIntensity.value,
    duration: rainfallDuration.value,
    history: rainfallHistory.value,
  };
  try {
    await simStore.createSimulation(params); // 调用 Store 中的保存方法
    ElMessage.success("保存成功");
    saveDialogVisible.value = false; // 关闭保存对话框
  } catch (error) {
    console.error("保存失败:", error);
    ElMessage.error("保存失败,请稍后重试");
  } finally {
    isLoading.value = false; // 结束加载状态
  }
  await simStore.addSimCheme(forms);
};
// 关闭保存方案对话框
const handleClose = () => {
  saveDialogVisible.value = false;
};
// // 确认保存
// const confirmSave = () => {
//   // 构造新的方案对象
//   const newScheme = {
//     id: Date.now().toString(), // 唯一 ID
//     area: props.selectedArea, // 区域
//     name: selectedRainfallName.value, // 方案名称
//     createTime: new Date().toISOString(), // 创建时间
//     taskStatus: 1, // 初始状态为未开始
//     totalRainfall: totalRainfall.value, // 降雨总量
//     schemeName: schemeName.value, // 降雨总量
//     rainfallIntensity: rainfallIntensity.value, // 降雨强度
//     rainfallDuration: rainfallDuration.value, // 降雨时长
//   };
//   simStore.addSchemCard(newScheme);
//   ElMessage.success("方案已保存");
//   // 关闭对话框
//   saveDialogVisible.value = false;
// };
// 开始模拟
function startPlay() {