wangjuncheng
2025-07-09 2a02d981f6d5ed2ef3b3a09d5a3b5bc0d07cf742
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import instance from "./requestTR.js";
 
// 获取区域数据
export async function getRegionData(params = {}) {
  try {
    const defaultParams = {
      id: undefined,
      name: undefined,
      type: undefined,
      pageNum: 1,
      pageSize: 100000,
    };
    const finalParams = { ...defaultParams, ...params };
    const response = await instance.get("/region/selectPage", {
      params: finalParams,
    });
    return response.data;
  } catch (error) {
    console.error("Error fetching data:", error);
    throw error;
  }
}
 
// 获取方案列表
export async function getSimData() {
  try {
    const res = await instance.get("/simu/selectPage", {
      params: { pageSize: 100 },
    });
    return res.data;
  } catch (error) {
    console.error("Error fetching data:", error);
    throw error; // 抛出错误,让调用方可以捕获
  }
}
 
// 根据方案id获取方案列表
export async function getSimDataById(id) {
  try {
    const res = await instance.get(`/simu/selectPage?id=${id}`);
    return res.data;
  } catch (error) {
    console.error("Error fetching data:", error);
    throw error; // 抛出错误,让调用方可以捕获
  }
}
 
// 新建仿真方案
export async function createSimData(simData) {
  try {
    const res = await instance.post("/simu/insert", simData, {
      headers: {
        "Content-Type": "application/json",
      },
    });
    return res;
  } catch (error) {
    console.error("Error creating simulation data:", error);
    throw error; // 抛出错误,让调用方可以捕获
  }
}
 
// 删除仿真方案
export async function deleteSimData(ids) {
  try {
    const res = await instance.delete(`/simu/deleteByIds?ids=${ids}`);
    return res.data;
  } catch (error) {
    console.error("Error deleting simulation data:", error);
    throw error;
  }
}
 
// 开始模拟
export async function getSimStart(ids) {
  try {
    const res = await instance.get(`/simu/start?id=${ids}`);
    return res.data;
  } catch (error) {
    console.error("Error deleting simulation data:", error);
    throw error;
  }
}
 
// 实时模拟的结果
export async function getSimresult(ids) {
  try {
    const res = await instance.get(`/simu/results?id=${ids}`);
    return res.data;
  } catch (error) {
    console.error("Error deleting simulation data:", error);
    throw error;
  }
}
 
// 结束实时模拟
export async function stopSim(ids) {
  try {
    const res = await instance.get(`/simu/stop?id=${ids}`);
    return res.data;
  } catch (error) {
    console.error("Error deleting simulation data:", error);
    throw error;
  }
}
// **************************************************************************************************************
// 解析json获取泥石流参数
export function parseWaterSimulationData(jsonData) {
  try {
    const startTime = jsonData.duration.start; // 直接使用原始时间
    const endTime = jsonData.duration.end; // 直接使用原始时间
    const extension = jsonData.extension;
    const terrainSizes = jsonData.terrain.size; // 分辨率
    const waterTimestamps = jsonData.waters.data.map((timestamp) => {
      return timestamp; // 不进行时间格式化
    });
    return {
      startTime: startTime, // 原始时间
      endTime: endTime, // 原始时间
      extension: {
        maxHeight: extension.maxHeight,
        minHeight: extension.minHeight,
        maxX: extension.maxx,
        maxY: extension.maxy,
        minX: extension.minx,
        minY: extension.miny,
      },
      terrainSizes: terrainSizes,
      flowUrl: jsonData.flowUrl,
      waterUrl: jsonData.waterUrl,
      version: jsonData.version,
      waterTimestamps: waterTimestamps,
      watersMaxHeight: jsonData.waters.maxHeight,
      watersMinHeight: jsonData.waters.minHeight,
    };
  } catch (error) {
    console.error("解析水模拟数据时出错:", error);
    return null;
  }
}
 
// // 通过接口去请求json,将请求的json解析获取泥石流参数
// export async function fetchWaterSimulationData(serviceInfo) {
//   try {
//     const response = await fetch(`/simu/${serviceInfo}/layer.json`); // 发起请求
//     // const response = await fetch(`/simu/c2h1dc/layer.json`); // 发起请求
//     if (!response.ok) {
//       throw new Error(`HTTP error! status: ${response.status}`);
//     }
//     const jsonData = await response.json(); // 解析 JSON 数据
//     // console.log(jsonData, "jsonjsonjsonjson");
//     return parseWaterSimulationData(jsonData); // 调用解析函数
//   } catch (error) {
//     console.error("请求或解析数据时出错:", error);
//     return null;
//   }
// }
 
export async function fetchWaterSimulationData(serviceInfo, timestamp = null) {
  try {
    // 根据是否提供时间戳来决定文件名
    let fileName = timestamp ? timestamp : 'layer.json';
    const url = `/simu/${serviceInfo}/${fileName}`;
 
    const response = await fetch(url); // 发起请求  
 
    // console.log(url,'aaaaaaaaa')
 
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    const jsonData = await response.json(); // 解析 JSON 数据
    return parseWaterSimulationData(jsonData); // 调用解析函数处理数据
  } catch (error) {
    console.error("请求或解析数据时出错:", error);
    return null;
  }
}
 
// 获取水位水深
export async function getFlowRate(data) {
  // console.log(data,'发送的数据!');
 
  try {
    const res = await instance.get("/simu/position", {
      params: data
    });
    return res.data; // 返回实际数据(通常 res.data 才是接口返回的内容)
  } catch (error) {
    console.error("Error fetching data:", error);
    throw error; // 抛出错误,让调用方可以捕获
  }
}
 
export async function getCrossSection(data) {
  // console.log(data,'发送的数据!');
 
  try {
    const res = await instance.get("/simu/crossSection", {
      params: data
    });
    return res.data; // 返回实际数据(通常 res.data 才是接口返回的内容)
  } catch (error) {
    console.error("Error fetching data:", error);
    throw error; // 抛出错误,让调用方可以捕获
  }
}
// **************************************************************************************************************