guonan
2025-05-20 f1fbe8049ba01186f033037e6ae36d51915c7418
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<template>
  <div class="message">
    <div class="message-top">方案详情</div>
    <div class="message-close" @click="closeMsg"></div>
    <div class="message-context">
      <div v-for="(item, key) in messageList" :key="key" class="message-item">
        <div class="message-name">{{ item.name }}</div>
        <div class="message-value" v-if="!item.name.includes('雨量计列表')">
          {{ item.value }}
        </div>
        <div
          v-if="item.name.includes('雨量计列表')"
          @click="openDialog"
          style="color: #5bc0de; cursor: pointer"
        >
          查看雨量计列表
        </div>
      </div>
    </div>
 
    <!-- 雨量计弹窗 -->
    <el-dialog
      title="雨量计详情"
      v-model="dialogVisible"
      width="60%"
      :before-close="handleClose"
      style="background-color: rgb(5, 75, 69)"
    >
      <div class="table-container">
        <el-table :data="gaugesData" border stripe height="100%">
          <el-table-column prop="name" label="名称"></el-table-column>
          <el-table-column prop="x" label="经度(X)"></el-table-column>
          <el-table-column prop="y" label="纬度(Y)"></el-table-column>
          <el-table-column prop="r" label="半径(r)"></el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>
 
<script setup>
import { ElMessage } from "element-plus";
import { ref, defineProps, defineEmits, watch } from "vue";
 
// 定义 props
const props = defineProps({
  mesData: {
    type: Object,
    default: () => ({}),
  },
});
 
// 响应式数据
const messageList = ref([]);
const gaugesData = ref([]); // 存储雨量计数据
const dialogVisible = ref(false); // 控制弹窗是否可见
 
// 打开弹窗
function openDialog() {
  if (gaugesData.value.length > 0) {
    dialogVisible.value = true;
  } else {
    ElMessage({
      message: "未找到雨量计数据!",
      type: "warning",
    });
  }
}
 
// 关闭弹窗
function handleClose(done) {
  done();
}
 
// 监听 mesData 变化并更新 messageList 和 gaugesData
watch(
  () => props.mesData,
  (newMesData) => {
    if (!newMesData || typeof newMesData !== "object") {
      console.warn("Invalid mesData received:", newMesData);
      messageList.value = [];
      return;
    }
 
    const formattedData = [];
    const areaType =
      newMesData.areaType !== undefined ? newMesData.areaType : null;
 
    // 获取当前的 type 值
    const currentType = newMesData.type;
 
    for (const [key, value] of Object.entries(newMesData)) {
      if (
        [
          "geom",
          "id",
          "serviceName",
          "updateTime",
          "updateUser",
          "createUser",
          "bak",
        ].includes(key)
      )
        continue;
 
      if (key === "createTime" && typeof value === "number") {
        formattedData.push({ name: "创建时间:", value: formatDate(value) });
        continue;
      }
 
      if (key === "areaType") {
        const areaTypeMap = {
          0: "自定义区域仿真",
          1: "行政区划仿真",
          2: "重点区域仿真",
          3: "重点沟仿真",
        };
        formattedData.push({
          name: "区域类别:",
          value: areaTypeMap[value] || "未知",
        });
        continue;
      }
 
      if (key === "status") {
        const statusMap = {
          0: "创建仿真",
          1: "预处理",
          2: "分析中",
          10: "完成",
          20: "出错",
        };
        formattedData.push({
          name: "仿真状态:",
          value: statusMap[value] || "未知",
        });
        continue;
      }
 
      if (key === "type") {
        if (![1, 2].includes(areaType)) {
          const typeMap = { 1: "预测模拟", 2: "实时模拟", 3: "历史模拟" };
          formattedData.push({
            name: "模拟类别:",
            value: typeMap[value] || "未知",
          });
        }
        continue;
      }
 
      if (key === "result") {
        formattedData.push({ name: "仿真结果:", value: value || "无" });
        continue;
      }
 
      if (key === "areaName") {
        formattedData.push({ name: "区域名称:", value: value || "无" });
        continue;
      }
 
      if (key === "name") {
        formattedData.push({ name: "仿真方案:", value: value || "无" });
        continue;
      }
 
      if (key === "data" && typeof value === "string") {
        try {
          const parsedData = JSON.parse(value);
 
          // 处理 data 中的各个字段
          const addField = (fieldKey, label) => {
            if (parsedData[fieldKey] !== undefined) {
              formattedData.push({
                name: `${label}:`,
                value: parsedData[fieldKey] || "无",
              });
            }
          };
 
          addField("total", "降雨总量(mm)");
          addField("duration", "降雨时长(分钟)");
          addField("intensity", "降雨强度(mm/小时)");
          addField("prediction", "降雨场次");
          addField("model", "降雨模式");
          addField("history", "历史降雨");
 
          // 判断 type 是否为 2,决定是否添加雨量计信息
          if (
            currentType == 2 &&
            parsedData.gauges &&
            Array.isArray(parsedData.gauges)
          ) {
            gaugesData.value = parsedData.gauges.map((gauge) => ({
              name: gauge.name || "未知",
              x: gauge.x != null ? gauge.x.toFixed(2) : "-",
              y: gauge.y != null ? gauge.y.toFixed(2) : "-",
              r: gauge.r || "-",
            }));
 
            const gaugeNames = gaugesData.value.map((g) => g.name).join(", ");
            formattedData.push({
              name: "雨量计列表:",
              value: gaugeNames || "无",
            });
          }
        } catch (e) {
          formattedData.push({ name: "数据:", value: value || "无" });
        }
        continue;
      }
 
      formattedData.push({ name: `${key}:`, value: value || "无" });
    }
 
    messageList.value = formattedData;
  },
  { immediate: true }
);
 
// 格式化时间戳
function formatDate(timestamp) {
  const date = new Date(timestamp);
  return date.toLocaleString();
}
 
// 定义 emit 方法
const emit = defineEmits(["close"]);
const closeMsg = () => {
  emit("close");
};
</script>
 
<style lang="less" scoped>
.message {
  background: url("@/assets/img/tools/messagebg.png");
  width: 391px;
  height: 392px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
 
.message-top {
  position: absolute;
  top: 5px;
  left: 20px;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  line-height: 40px;
  width: 270px;
  cursor: pointer;
}
 
.message-close {
  position: absolute;
  right: 3px;
  top: 10px;
  width: 20px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  color: #fff;
  cursor: pointer;
}
 
.message-context {
  position: absolute;
  top: 50px;
  left: 20px;
  width: 350px;
  height: 65%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: stretch;
}
 
.message-item {
  display: flex;
  align-items: center;
  margin: 2px 0;
  padding: 4px 4px;
  border-radius: 4px;
}
 
.message-name {
  font-weight: 700;
  color: #94e0c4;
  white-space: nowrap;
}
 
.message-value {
  color: #e1eee9;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: 200px;
}
.table-container {
  max-height: 500px;
  overflow-y: auto;
  padding: 10px;
  border-radius: 4px;
}
 
.el-dialog__body {
  padding-top: 10px;
  padding-bottom: 10px;
}
/deep/.el-dialog__title {
  color: #fff !important;
}
.table-container .el-table {
  font-size: 14px;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
</style>