guonan
2025-04-22 dd527b7615517c53d7e4de92ae6cc87c18fa844c
src/views/left/CitySim.vue
@@ -108,7 +108,7 @@
        <el-button type="success" @click="startPlay">开始模拟</el-button>
      </div>
      <!---------------------------- 保存方案对话框(接口版本需删除) -------------------------------->
      <el-dialog
      <!-- <el-dialog
        v-model="saveDialogVisible"
        :title="dialogTitle"
        width="50%"
@@ -134,7 +134,7 @@
            <el-button type="primary" @click="confirmSave">确定保存</el-button>
          </span>
        </template>
      </el-dialog>
      </el-dialog> -->
    </div>
  </div>
</template>
@@ -145,8 +145,6 @@
import Papa from "papaparse";
import { ElMessage, ElMessageBox } from "element-plus";
import { initeWaterPrimitiveView } from "@/utils/water";
import { createSimData } from "@/api/trApi";
import { useSimStore } from "@/store/simulation";
const simStore = useSimStore();
@@ -206,44 +204,7 @@
});
////////////////////////////////////// 接口版本需删除//////////////////////////////////////
// 打开保存方案对话框
const openSaveDialog = () => {
  if (
    !forms.rainfall ||
    !forms.duration ||
    !forms.intensity ||
    (simStore.selectTab === "行政区划仿真" && !forms.eare) ||
    (simStore.selectTab === "重点区域仿真" && !forms.eares)
  ) {
    ElMessage.warning("请先填写所有必填项");
    return;
  }
  saveDialogVisible.value = true;
}
const handleClose = () => {
  saveDialogVisible.value = false;
};
// 确认保存
const confirmSave = () => {
  console.log("保存方案成功", {
    模拟类型: dialogTitle.value,
    行政区域: simStore.selectTab === "行政区划仿真" ? forms.eare : null,
    重点区域: simStore.selectTab === "重点区域仿真" ? forms.eares : null,
    降雨量: `${forms.rainfall} mm`,
    降雨时长: `${forms.duration} h`,
    降雨强度: `${forms.intensity} mm/h`,
    上传文件: forms.fileList.map((file) => file.name),
  });
  ElMessage.success("方案已保存");
  saveDialogVisible.value = false;
  resetForm();
};
////////////////////////////////////// 结束删除//////////////////////////////////////
//////////////////////////////////接口版本启用//////////////////////////////////
// const isLoading = ref(false);
// // 保存方案
// // 打开保存方案对话框
// const openSaveDialog = () => {
//   if (
//     !forms.rainfall ||
@@ -255,36 +216,73 @@
//     ElMessage.warning("请先填写所有必填项");
//     return;
//   }
//   ElMessageBox.confirm("确定要保存当前方案吗?", dialogTitle.value, {
//     confirmButtonText: "确定",
//     cancelButtonText: "取消",
//     type: "warning",
//   })
//     .then(confirmSave)
//     .catch(() => {
//       ElMessage({
//         type: "info",
//         message: "已取消保存",
//       });
//     });
//   saveDialogVisible.value = true;
// }
// const handleClose = () => {
//   saveDialogVisible.value = false;
// };
// const confirmSave = async () => {
//   if (isLoading.value) {
//     ElMessage.warning("正在保存,请稍候...");
//     return; // 防止重复提交
//   }
//   isLoading.value = true; // 开始加载状态
//   try {
//     await simStore.createSimulation(forms); // 调用 Store 中的保存方法
//     ElMessage.success("保存成功");
//     saveDialogVisible.value = true; // 显示保存对话框(如果需要)
//   } catch (error) {
//     console.error("保存失败:", error);
//     ElMessage.error("保存失败,请稍后重试");
//   } finally {
//     isLoading.value = false; // 结束加载状态
//   }
// // 确认保存
// const confirmSave = () => {
//   console.log("保存方案成功", {
//     模拟类型: dialogTitle.value,
//     行政区域: simStore.selectTab === "行政区划仿真" ? forms.eare : null,
//     重点区域: simStore.selectTab === "重点区域仿真" ? forms.eares : null,
//     降雨量: `${forms.rainfall} mm`,
//     降雨时长: `${forms.duration} h`,
//     降雨强度: `${forms.intensity} mm/h`,
//     上传文件: forms.fileList.map((file) => file.name),
//   });
//   ElMessage.success("方案已保存");
//   saveDialogVisible.value = false;
//   resetForm();
// };
////////////////////////////////////// 结束删除//////////////////////////////////////
//////////////////////////////////接口版本启用//////////////////////////////////
const isLoading = ref(false);
// 保存方案
const openSaveDialog = () => {
  if (
    !forms.rainfall ||
    !forms.duration ||
    !forms.intensity ||
    (simStore.selectTab === "行政区划仿真" && !forms.eare) ||
    (simStore.selectTab === "重点区域仿真" && !forms.eares)
  ) {
    ElMessage.warning("请先填写所有必填项");
    return;
  }
  ElMessageBox.confirm("确定要保存当前方案吗?", dialogTitle.value, {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(confirmSave)
    .catch(() => {
      ElMessage({
        type: "info",
        message: "已取消保存",
      });
    });
};
const confirmSave = async () => {
  if (isLoading.value) {
    ElMessage.warning("正在保存,请稍候...");
    return; // 防止重复提交
  }
  isLoading.value = true; // 开始加载状态
  try {
    await simStore.createSimulation(forms); // 调用 Store 中的保存方法
    ElMessage.success("保存成功");
    saveDialogVisible.value = true; // 显示保存对话框(如果需要)
  } catch (error) {
    console.error("保存失败:", error);
    ElMessage.error("保存失败,请稍后重试");
  } finally {
    isLoading.value = false; // 结束加载状态
  }
};
//////////////////////////////////接口版本启用//////////////////////////////////
// 重置表单