guonan
2025-04-22 d9c26a8b8b4336c53696b96d0ce3340758597777
src/views/left/CitySim.vue
@@ -107,34 +107,6 @@
        <el-button type="primary" @click="openSaveDialog">保存方案</el-button>
        <el-button type="success" @click="startPlay">开始模拟</el-button>
      </div>
      <!---------------------------- 保存方案对话框(接口版本需删除) -------------------------------->
      <!-- <el-dialog
        v-model="saveDialogVisible"
        :title="dialogTitle"
        width="50%"
        :before-close="handleClose"
        custom-class="custom-dialog"
      >
        <div class="dialog-content">
          <p><strong>模拟类型:</strong>{{ dialogTitle }}</p>
          <p v-if="disForm === '行政区划仿真'">
            <strong>行政区域:</strong>{{ forms.eare }}
          </p>
          <p v-if="disForm === '重点区域仿真'">
            <strong>重点区域:</strong>{{ forms.eares }}
          </p>
          <p><strong>降雨量:</strong>{{ forms.rainfall }} mm</p>
          <p><strong>降雨时长:</strong>{{ forms.duration }} h</p>
          <p><strong>降雨强度:</strong>{{ forms.intensity }} mm/h</p>
          <p><strong>上传文件:</strong>{{ uploadedFilesText }}</p>
        </div>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="saveDialogVisible = false">取消</el-button>
            <el-button type="primary" @click="confirmSave">确定保存</el-button>
          </span>
        </template>
      </el-dialog> -->
    </div>
  </div>
</template>
@@ -145,13 +117,12 @@
import Papa from "papaparse";
import { ElMessage, ElMessageBox } from "element-plus";
import { initeWaterPrimitiveView } from "@/utils/water";
import { useSimStore } from "@/store/simulation";
import { SimAPIStore } from "@/store/simAPI";
const simStore = useSimStore();
const simStore = SimAPIStore();
// 注入父组件提供的方法
const { startSimulate, endSimulate } = inject("simulateActions");
const saveDialogVisible = ref(false); // 控制保存方案对话框的显示状态(接口版本删除)
// 表单数据
const forms = reactive({
  name: "",
@@ -203,8 +174,13 @@
  return forms.fileList.map((file) => file.name).join(", ") || "无";
});
////////////////////////////////////// 接口版本需删除//////////////////////////////////////
// // 打开保存方案对话框
//////////////////////////////////接口版本启用//////////////////////////////////
const openSaveDialog = async () => {
  await simStore.openSaveDialog(forms);
};
// const isLoading = ref(false);
// // 保存方案
// const openSaveDialog = () => {
//   if (
//     !forms.rainfall ||
@@ -216,73 +192,36 @@
//     ElMessage.warning("请先填写所有必填项");
//     return;
//   }
//   saveDialogVisible.value = true;
// }
// const handleClose = () => {
//   saveDialogVisible.value = false;
//   ElMessageBox.confirm("确定要保存当前方案吗?", dialogTitle.value, {
//     confirmButtonText: "确定",
//     cancelButtonText: "取消",
//     type: "warning",
//   })
//     .then(confirmSave)
//     .catch(() => {
//       ElMessage({
//         type: "info",
//         message: "已取消保存",
//       });
//     });
// };
// // 确认保存
// 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 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 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; // 结束加载状态
  }
};
//////////////////////////////////接口版本启用//////////////////////////////////
// 重置表单
@@ -410,7 +349,6 @@
  }
  return true;
};
// 开始模拟
function startPlay() {