wangjuncheng
2025-04-29 47af17665d9e8b0f49c2a5f91a75812e9b5d73f0
change
已修改1个文件
261 ■■■■■ 文件已修改
src/components/tools/Message.vue 261 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/tools/Message.vue
@@ -5,10 +5,31 @@
    <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">{{ item.value }}</div>
        <div class="message-value" v-if="!(item.name.includes('雨量计列表'))">
          {{ item.value }}
        </div>
        <div v-if="item.name.includes('雨量计列表')" @click.stop="openDialog"
          style="color: #5bc0de; cursor: pointer;">
          查看雨量计列表
        </div>
      </div>
    </div>
    <!-- <div class="message-btn" @click="startPlay">开始模拟</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>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">关 闭</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
@@ -22,40 +43,45 @@
    default: () => ({}),
  },
});
// 响应式数据
const messageList = ref([]);
// 监听 props.mesData 的变化
const gaugesData = ref([]); // 存储雨量计数据
const dialogVisible = ref(false); // 控制弹窗是否可见
// 打开弹窗
function openDialog() {
  if (gaugesData.value.length > 0) {
    dialogVisible.value = true;
  }
}
// 关闭弹窗
function handleClose(done) {
  done();
}
// 监听 mesData 变化并更新 messageList 和 gaugesData
watch(
  () => props.mesData,
  (newMesData) => {
    // console.log(newMesData, '弹窗的数据');
    // 检查数据有效性
    if (!newMesData || typeof newMesData !== "object") {
      console.warn("Invalid mesData received:", newMesData);
      messageList.value = [];
      return;
    }
    // 将所有字段转换为列表形式
    const formattedData = [];
    // 提前解析 areaType,确保其存在性
    const areaType = newMesData.areaType !== undefined ? newMesData.areaType : null;
    for (const [key, value] of Object.entries(newMesData)) {
      // 跳过不需要的字段
      if (["geom", "id", "serviceName", "updateTime", "updateUser", "createUser", "bak"].includes(key)) continue;
      // 特殊处理 createTime 字段
      if (key === "createTime" && typeof value === "number") {
        formattedData.push({
          name: "创建时间:",
          value: formatDate(value),
        });
        formattedData.push({ name: "创建时间:", value: formatDate(value) });
        continue;
      }
      // 处理 areaType 字段
      if (key === "areaType") {
        const areaTypeMap = {
          0: "自定义区域仿真",
@@ -63,149 +89,90 @@
          2: "重点区域仿真",
          3: "重点沟仿真",
        };
        formattedData.push({
          name: "区域类别:",
          value: areaTypeMap[value] || "未知",
        });
        formattedData.push({ name: "区域类别:", value: areaTypeMap[value] || "未知" });
        continue;
      }
      // 处理 status 字段
      if (key === "status") {
          const statusMap = {
            0: "创建仿真",
            1: "预处理",
            2: "分析中",
            10: "完成",
            20: "出错",
          };
          formattedData.push({
          name: "仿真状态:",
          value: statusMap[value] || "未知",
        });
        const statusMap = {
          0: "创建仿真",
          1: "预处理",
          2: "分析中",
          10: "完成",
          20: "出错",
        };
        formattedData.push({ name: "仿真状态:", value: statusMap[value] || "未知" });
        continue;
      }
      // 处理 type 字段(仅在 areaType 不为 1 或 2 时显示)
      if (key === "type") {
        if (![1, 2].includes(areaType)) {
          const typeMap = {
            1: "预测模拟",
            2: "实时模拟",
            3: "历史模拟",
          };
          formattedData.push({
            name: "模拟类别:",
            value: typeMap[value] || "未知",
          });
          const typeMap = { 1: "预测模拟", 2: "实时模拟", 3: "历史模拟" };
          formattedData.push({ name: "模拟类别:", value: typeMap[value] || "未知" });
        }
        continue;
      }
      // 处理 result 字段
      if (key === "result") {
        formattedData.push({
          name: "仿真结果:",
          value: value || "无",
        });
        formattedData.push({ name: "仿真结果:", value: value || "无" });
        continue;
      }
      // 处理 name 字段
      if (key === "name") {
        formattedData.push({
          name: "仿真方案:",
          value: value || "无",
        });
        formattedData.push({ name: "仿真方案:", value: value || "无" });
        continue;
      }
      // 处理 data 字段
      if (key === "data" && typeof value === "string") {
        try {
          const parsedData = JSON.parse(value);
          console.log('Parsed Data:', parsedData);
          // 处理 data 中的各个字段
          const addField = (fieldKey, label) => {
            if (parsedData[fieldKey] !== undefined) {
              formattedData.push({ name: `${label}:`, value: parsedData[fieldKey] || "无" });
            }
          };
          // 处理 data.total 字段
          if (parsedData.total !== undefined) {
            formattedData.push({
              name: "降雨总量(mm):",
              value: parsedData.total || "无",
            });
          }
          addField("total", "降雨总量(mm)");
          addField("duration", "降雨时长(分钟)");
          addField("intensity", "降雨强度(mm/小时)");
          addField("prediction", "降雨场次");
          addField("model", "降雨模式");
          addField("history", "历史降雨");
          // 处理 data.duration 字段
          if (parsedData.duration !== undefined) {
            formattedData.push({
              name: "降雨时长(分钟):",
              value: parsedData.duration || "无",
            });
          }
          // 处理雨量计数据
          if (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 || "-",
            }));
          // 处理 data.intensity 字段
          if (parsedData.intensity !== undefined) {
            formattedData.push({
              name: "降雨强度(mm/小时):",
              value: parsedData.intensity || "无",
            });
          }
          // 处理 data.prediction 字段
          if (parsedData.prediction !== undefined) {
            formattedData.push({
              name: "降雨场次:",
              value: parsedData.prediction || "无",
            });
          }
          // 处理 data.model 字段
          if (parsedData.model !== undefined) {
            formattedData.push({
              name: "降雨模式:",
              value: parsedData.model || "无",
            });
          }
          // 处理 data.history 字段
          if (parsedData.history !== undefined) {
            formattedData.push({
              name: "历史降雨:",
              value: parsedData.history || "无",
            });
          }
          // 处理 data.gauges 字段
          if (parsedData.gauges !== undefined) {
            formattedData.push({
              name: "雨量计列表:",
              value: Array.isArray(parsedData.gauges) ? parsedData.gauges.join(", ") : "无",
            });
            const gaugeNames = gaugesData.value.map(g => g.name).join(", ");
            formattedData.push({ name: "雨量计列表:", value: gaugeNames || "无" });
          }
        } catch (e) {
          formattedData.push({
            name: "数据:",
            value: value || "无",
          });
          formattedData.push({ name: "数据:", value: value || "无" });
        }
        continue;
      }
      // 其他字段直接展示
      formattedData.push({
        name: `${key}:`,
        value: value || "无",
      });
      formattedData.push({ name: `${key}:`, value: value || "无" });
    }
    // 更新 messageList
    messageList.value = formattedData;
    console.log(messageList.value, 'wwwwwwwwwwwwwwwwwwwwwwwwwwwwww');
  },
  { immediate: true } // 立即执行一次
  { immediate: true }
);
// 格式化时间戳为日期
// 格式化时间戳
function formatDate(timestamp) {
  const date = new Date(timestamp);
  return date.toLocaleString(); // 使用本地化的日期格式
  return date.toLocaleString();
}
// 定义 emit 方法
@@ -214,6 +181,7 @@
  emit("close");
};
</script>
<style lang="less" scoped>
.message {
  background: url("@/assets/img/tools/messagebg.png");
@@ -222,7 +190,7 @@
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between; /* 确保上下内容均匀分布 */
  justify-content: space-between;
}
.message-top {
@@ -255,46 +223,51 @@
  left: 20px;
  width: 350px;
  height: 65%;
  overflow-y: auto; /* 如果内容过多,可以滚动 */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: space-around; /* 均匀分布子元素 */
  align-items: stretch; /* 子元素宽度拉伸 */
  justify-content: space-around;
  align-items: stretch;
}
.message-item {
  display: flex;
  // justify-content: space-between; /* 左右对齐 */
  align-items: center; /* 垂直居中 */
  margin: 2px 0; /* 上下间距 */
  padding: 4px 4px; /* 内边距 */
  border-radius: 4px; /* 圆角 */
  align-items: center;
  margin: 2px 0;
  padding: 4px 4px;
  border-radius: 4px;
}
.message-name {
  font-weight: 700;
  color: #94e0c4;
  white-space: nowrap; /* 防止换行 */
  white-space: nowrap;
}
.message-value {
  color: #e1eee9;
  white-space: nowrap; /* 防止换行 */
  text-overflow: ellipsis; /* 超出省略 */
  overflow: hidden; /* 隐藏超出部分 */
  max-width: 200px; /* 最大宽度限制 */
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: 200px;
}
.table-container {
  max-height: 500px;  // 控制最大高度,超过则出现滚动条
  overflow-y: auto;   // 垂直滚动
  padding: 10px;
  border-radius: 4px;
}
.message-btn {
  background: url("@/assets/img/tools/messagebtn.png") no-repeat;
  position: absolute;
  bottom: 60px;
  right: 60px;
  width: 105px;
  height: 26px;
  text-align: center;
  color: #fff;
  cursor: pointer;
  line-height: 26px;
.el-dialog__body {
  padding-top: 10px;
  padding-bottom: 10px;
}
</style>
/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>