guonan
2025-04-23 11cef93fa041289db9fafd4cb654b20d53cb2c51
新建方案
已修改4个文件
171 ■■■■ 文件已修改
src/store/simAPI.js 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/left/CitySim.vue 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/left/KGSimOption/HistorySimulation.vue 107 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/left/KGSimOption/PredictiveSimulation.vue 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/simAPI.js
@@ -38,7 +38,11 @@
            ElMessage.warning('请输入方案名称')
            return false
        }
        if (!forms.name) {
        if (!forms.name
            || !forms.geom
            || !forms.rainfall
            || !forms.intensity
            || !forms.duration) {
            ElMessage.warning('请确保表单均已填写')
            return false
        }
@@ -56,7 +60,7 @@
        try {
            const params = {
                geom: forms.eare,
                geom: forms.geom,
                areaType: getAreaType(selectTab.value),
                createTime: Date.now(),
                name: forms.name,
@@ -68,7 +72,8 @@
                    duration: forms.duration,
                    intensity: forms.intensity,
                    prediction: forms.prediction,
                    mode: forms.mode
                    history: forms.history,
                    mode: forms.mode,
                })
            }
            const res = await createSimData(params)
src/views/left/CitySim.vue
@@ -41,7 +41,7 @@
          v-if="simStore.selectTab == '行政区划仿真'"
        >
          <el-select
            v-model="forms.eare"
            v-model="forms.geom"
            placeholder="Select"
            style="max-width: 600px"
          >
@@ -58,7 +58,7 @@
          v-if="simStore.selectTab == '重点区域仿真'"
        >
          <el-select
            v-model="forms.eares"
            v-model="forms.geom"
            placeholder="Select"
            style="max-width: 600px"
          >
@@ -166,8 +166,7 @@
// 表单数据
const forms = reactive({
  name: "",
  eare: "",
  eares: "孙胡沟",
  geom: "",
  rainfall: "",
  duration: "",
  intensity: "",
@@ -181,7 +180,7 @@
// 重置表单
const resetForm = () => {
  forms.eare = "";
  forms.geom = "";
  forms.eares = "孙胡沟";
  forms.rainfall = "";
  forms.duration = "";
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() {
src/views/left/KGSimOption/PredictiveSimulation.vue
@@ -185,13 +185,12 @@
const toggleDetails = () => {
  isCollapsed.value = !isCollapsed.value;
};
// const simStore = SimAPIStore();
// 打开保存方案对话框
const openSaveDialog = async () => {
  const forms = {
    name: schemeName.value,
    eares: props.selectedArea,
    geom: props.selectedArea,
    type: 1,
    rainfall: totalRainfall.value,
    duration: rainfallDuration.value,
@@ -199,21 +198,7 @@
    mode: selectedRainfallPatterns.value,
    prediction: selectedForecastDataName.value,
  };
  console.log(forms, "forms");
  await simStore.addSimCheme(forms);
  // if (
  //   !props.selectedArea ||
  //   !selectedForecastData.value ||
  //   !schemeName.value ||
  //   !totalRainfall.value ||
  //   !rainfallIntensity.value ||
  //   !selectedRainfallPatterns.value ||
  //   !rainfallDuration.value
  // ) {
  //   ElMessage.warning("请先填写所有必填项");
  //   return;
  // }
  // saveDialogVisible.value = true;
};
// 关闭保存方案对话框
@@ -221,33 +206,6 @@
  saveDialogVisible.value = false;
};
// 确认保存
const confirmSave = () => {
  // 构造新的方案对象
  const newScheme = {
    id: Date.now().toString(), // 唯一 ID
    area: props.selectedArea, // 区域
    name: selectedForecastDataName.value, // 方案名称(预测数据类型)
    createTime: new Date().toISOString(), // 创建时间
    taskStatus: 1, // 初始状态为未开始
    simulationType: "预测模拟", // 模拟类型
    forecastData: selectedForecastDataName.value, // 预测数据
    totalRainfall: `${totalRainfall.value} mm`, // 降雨雨量
    schemeName: schemeName.value, // 降雨总量
    rainfallIntensity: `${rainfallIntensity.value} mm/h`, // 降雨强度
    rainfallPattern: selectedRainfallPatternsName.value, // 降雨模式
    rainfallDuration: `${rainfallDuration.value} h`, // 预计时长
  };
  // 调用 Store 的方法添加方案
  simStore.addSchemCard(newScheme);
  console.log("保存方案成功", newScheme);
  ElMessage.success("方案已保存");
  // 关闭对话框
  saveDialogVisible.value = false;
};
// 打开方案
const openPlan = () => {