
<!-- 气象监测站弹窗 -->
<template>
  <div class="weather-station-container" v-if="visible">
    <div class="weather-station-box">
      <div class="weather-station-header">
          <div class="weather-station-title">
          <span>信号灯XH001 | 气象监测</span>
          <img class="weather-station-status" src="../../../assets/images/weather_icon.png" alt="气象监测站" />
        </div>
        <img class="weather-station-close" src="../../../assets/images/close_icon.png" alt="" @click="close" />
      </div>
      <div class="weather-station-content">
        <!-- <div class="weather-station-title">
          <span>信号灯XH001 | 实时监测</span>
          <img class="weather-station-status" src="../../../assets/images/weather_icon.png" alt="气象监测站" />
        </div> -->
        <div class="weather-station-info-container">
          <div class="weather-station-info-row">
            <div class="weather-station-info-item">
              <span class="weather-info-label">温度:</span>
              <span class="weather-info-value">{{ weatherData.temperature }}°C</span>
            </div>
            <div class="weather-station-info-item">
              <span class="weather-info-label">湿度:</span>
              <span class="weather-info-value">{{ weatherData.humidity }}%</span>
            </div>
          </div>
          <div class="weather-station-info-row">
            <div class="weather-station-info-item">
              <span class="weather-info-label">风速:</span>
              <span class="weather-info-value">{{ weatherData.windSpeed }}m/s</span>
            </div>
            <div class="weather-station-info-item">
              <span class="weather-info-label">能见度:</span>
              <span class="weather-info-value">{{ weatherData.visibility }}km</span>
            </div>
          </div>
          <div class="weather-station-info-row">
            <div class="weather-station-info-item">
              <span class="weather-info-label">风向:</span>
              <span class="weather-info-value">{{ weatherData.windDirection }}</span>
            </div>
            <div class="weather-station-info-item">
              <span class="weather-info-label">湿滑程度:</span>
              <span class="weather-info-value">{{ weatherData.wetness }}</span>
            </div>
          </div>
          <div class="weather-station-info-row">
            <div class="weather-station-info-item">
              <span class="weather-info-label">气压:</span>
              <span class="weather-info-value">{{ weatherData.pressure }}hPa</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, defineProps, defineEmits, onMounted, onUnmounted } from 'vue';

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  stationData: {
    type: Object,
    default: () => ({})
  },
  position: {
    type: Object,
    default: () => ({ x: 0, y: 0 })
  }
});

const emit = defineEmits(['close']);

// 气象数据
const weatherData = ref({
  temperature: '22.5',
  humidity: '68',
  windSpeed: '3.2',
  visibility: '8.5',
  pressure: '1013.2',
  windDirection: '北风',
  wetness: '干燥',
  updateTime: Date.now()
});

// 模拟更新气象数据
function updateWeatherData() {
  weatherData.value = {
    temperature: '22.5',
    humidity: '68',
    windSpeed: '3.2',
    visibility: '8.5',
    pressure: '1013.2',
    windDirection: '北风',
    wetness: '干燥',
    updateTime: Date.now()
  };
}

function close() {
  emit('close');
}

// 组件挂载时设置定时更新
onMounted(() => {
  const weatherUpdateInterval = setInterval(() => {
    updateWeatherData();
  }, 60000); // 每分钟更新一次气象数据
  
  onUnmounted(() => {
    clearInterval(weatherUpdateInterval);
  });
});
</script>

<style scoped>
/* 气象监测站样式 */
.weather-station-container {
  position: fixed;
  z-index: 2000;
  width: 300px;
  left: v-bind('props.position.x + "px"');
  top: v-bind('props.position.y + "px"');
}

.weather-station-box {
  background-color: #424851;
  border-radius: 8px;
  overflow: hidden;
}

.weather-station-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom:1px solid #777777;
  background-color: #424851;
  color: #fff;
  padding: 8px 12px;
  font-size: 16px;
}

.weather-station-close {
  cursor: pointer;
  font-size: 20px;
  font-weight: bold;
}

.weather-station-content {
  padding: 12px;
  color: #fff;
}

.weather-station-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  /* margin-bottom: 12px; */
}

.weather-station-status {
  color: #4CAF50;
  font-weight: bold;
}

.weather-station-info-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.weather-station-info-row {
  display: flex;
  justify-content: space-between;
}

.weather-station-info-item {
  flex: 1;
}

.weather-info-label {
  color: #EEEEEE;
  font-size: 14px;
  margin-right: 4px;
}

.weather-info-value {
  color: #EEEEEE;
  font-size: 14px;
}
</style>