From d9c26a8b8b4336c53696b96d0ce3340758597777 Mon Sep 17 00:00:00 2001
From: guonan <guonan201020@163.com>
Date: 星期二, 22 四月 2025 15:10:22 +0800
Subject: [PATCH] 增加接口

---
 src/views/left/KGSimOption/HistorySimulation.vue |  134 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 102 insertions(+), 32 deletions(-)

diff --git a/src/views/left/KGSimOption/HistorySimulation.vue b/src/views/left/KGSimOption/HistorySimulation.vue
index ebde892..03a6708 100644
--- a/src/views/left/KGSimOption/HistorySimulation.vue
+++ b/src/views/left/KGSimOption/HistorySimulation.vue
@@ -10,30 +10,54 @@
       <div class="input-group">
         <div class="input-item">
           <label>鍘嗗彶闆ㄦ儏:</label>
-          <el-select v-model="rainfallHistory" placeholder="璇烽�夋嫨" popper-class="mySelectStyle">
-            <el-option v-for="item in HistoricalRainData" :key="item.id" :label="item.name"
-              :value="item.id"></el-option>
+          <el-select
+            v-model="rainfallHistory"
+            placeholder="璇烽�夋嫨"
+            popper-class="mySelectStyle"
+          >
+            <el-option
+              v-for="item in HistoricalRainData"
+              :key="item.id"
+              :label="item.name"
+              :value="item.id"
+            ></el-option>
           </el-select>
         </div>
       </div>
       <div class="input-group">
         <div class="input-item">
           <label>鏂规鍚嶇О:</label>
-          <el-input v-model="schemeName" type="text" placeholder="璇疯緭鍏�"></el-input>
+          <el-input
+            v-model="schemeName"
+            type="text"
+            placeholder="璇疯緭鍏�"
+          ></el-input>
         </div>
         <div class="input-item">
           <label>闄嶉洦鎬婚噺:</label>
-          <el-input v-model="totalRainfall" type="number" placeholder="璇疯緭鍏�"></el-input>
+          <el-input
+            v-model="totalRainfall"
+            type="number"
+            placeholder="璇疯緭鍏�"
+          ></el-input>
           <span>mm</span>
         </div>
         <div class="input-item">
           <label>闄嶉洦寮哄害:</label>
-          <el-input v-model="rainfallIntensity" type="number" placeholder="璇疯緭鍏�"></el-input>
+          <el-input
+            v-model="rainfallIntensity"
+            type="number"
+            placeholder="璇疯緭鍏�"
+          ></el-input>
           <span>mm/h</span>
         </div>
         <div class="input-item">
           <label>闄嶉洦鏃堕暱:</label>
-          <el-input v-model="rainfallDuration" type="number" placeholder="璇疯緭鍏�"></el-input>
+          <el-input
+            v-model="rainfallDuration"
+            type="number"
+            placeholder="璇疯緭鍏�"
+          ></el-input>
           <span>h</span>
         </div>
       </div>
@@ -48,8 +72,13 @@
     </div>
 
     <!-- 淇濆瓨鏂规瀵硅瘽妗� -->
-    <el-dialog v-model="saveDialogVisible" title="淇濆瓨鏂规" width="50%" :before-close="handleClose"
-      custom-class="custom-dialog">
+    <el-dialog
+      v-model="saveDialogVisible"
+      title="淇濆瓨鏂规"
+      width="50%"
+      :before-close="handleClose"
+      custom-class="custom-dialog"
+    >
       <div class="dialog-content">
         <p><strong>鏂规鍚嶇О锛�</strong>{{ schemeName }}</p>
         <p><strong>鎵�閫夐噸鐐规矡锛�</strong>{{ props.selectedArea }}</p>
@@ -71,10 +100,11 @@
 
 <script setup>
 import { ref, computed, inject } from "vue";
-import { ElMessage } from "element-plus";
+import { ElMessage, ElMessageBox } from "element-plus";
 import { initeWaterPrimitiveView } from "@/utils/water";
 import { useSimStore } from "@/store/simulation.js"; // 寮曞叆 Store
-import { getRainfallData  } from "@/api/hpApi.js"
+import { getRainfallData } from "@/api/hpApi.js";
+
 // 鑾峰彇 Store 瀹炰緥
 const simStore = useSimStore();
 // 娴嬭瘯鑾峰彇闆ㄩ噺鏁版嵁
@@ -99,7 +129,7 @@
 // 鏁版嵁缁戝畾
 const rainfallHistory = ref("2"); // 榛樿閫変腑绗簩椤�
 const totalRainfall = ref(50); // 闄嶉洦鎬婚噺
-const schemeName = ref('鏂规鍚嶇О'); // 鏂规鍚嶇О
+const schemeName = ref("鏂规鍚嶇О"); // 鏂规鍚嶇О
 const rainfallIntensity = ref(70); // 闄嶉洦寮哄害
 const rainfallDuration = ref(5); // 闄嶉洦鏃堕暱
 const isCollapsed = ref(false); // 鎺у埗璇︽儏鐨勫睍寮�/鏀惰捣鐘舵��
@@ -140,7 +170,47 @@
     ElMessage.warning("璇峰厛濉啓鎵�鏈夊繀濉」");
     return;
   }
-  saveDialogVisible.value = true;
+  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("姝e湪淇濆瓨锛岃绋嶅��...");
+    return; // 闃叉閲嶅鎻愪氦
+  }
+  isLoading.value = true; // 寮�濮嬪姞杞界姸鎬�
+  try {
+    await simStore.createSimulation(params); // 璋冪敤 Store 涓殑淇濆瓨鏂规硶
+    ElMessage.success("淇濆瓨鎴愬姛");
+    saveDialogVisible.value = true; // 鏄剧ず淇濆瓨瀵硅瘽妗嗭紙濡傛灉闇�瑕侊級
+  } catch (error) {
+    console.error("淇濆瓨澶辫触:", error);
+    ElMessage.error("淇濆瓨澶辫触锛岃绋嶅悗閲嶈瘯");
+  } finally {
+    isLoading.value = false; // 缁撴潫鍔犺浇鐘舵��
+  }
 };
 
 // 鍏抽棴淇濆瓨鏂规瀵硅瘽妗�
@@ -148,26 +218,26 @@
   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, // 闄嶉洦鏃堕暱
-  };
+// // 纭淇濆瓨
+// 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;
-};
+//   simStore.addSchemCard(newScheme);
+//   ElMessage.success("鏂规宸蹭繚瀛�");
+//   // 鍏抽棴瀵硅瘽妗�
+//   saveDialogVisible.value = false;
+// };
 
 // 寮�濮嬫ā鎷�
 function startPlay() {

--
Gitblit v1.9.3