<!-- 说说 -->
<template>
  <iframe id="iframe_chat" ref="iframe1" :src="src + yiqiu_id" @load="iframeLoaded" loading="lazy" width="100%" frameborder="0" allowfullscreen></iframe>
</template>

<script lang="ts">

export default ({
  name: 'GameTalk',
  props: {
    yiqiu_id: {
      type: Number,
      required: true
    }
  },
  mounted (): any {

    var topMain = document.getElementById('topMain');
    if (topMain) {
      (document.getElementById("iframe_chat") as any).style.height = `calc(100vh - ${topMain.offsetHeight + 58}px)`;
    }

  },
  data (): any {
    return {
      src: `/forum/zq_chat?matchid=`
    };
  },
  methods: {
    iframeLoaded () {
      window.addEventListener('message', this.handleMessage, false);
    },
    handleMessage (event: any) {
      console.info(event.data);
      // // 注意：出于安全考虑，应该验证发送者
      // if (event.origin !== 'https://example.com') return; // 确保消息来自正确的来源

      // if (event.data.event === 'buttonClicked') {
      //     // 处理按钮点击事件
      //     console.log('Button clicked in the iframe:', event.data.data);
      // }
    },
  }
});
</script>