export default {
  data() {
    return {
      socket: null
    };
  },
  methods: {
    connectWebSocket() {
      this.socket = new WebSocket('wss://gptsocket.malls.iformall.com:8010');
      this.socket.onopen = () => {
        console.log('WebSocket 连接成功');
      };

      this.socket.onmessage = (event) => {
        console.log('接收到 WebSocket 消息:', event.data);
      };

      this.socket.onclose = () => {
        console.log('WebSocket 连接关闭');
      };

      this.socket.onerror = (error) => {
        console.error('WebSocket 错误:', error);
      };
    },
    sendWebSocketMessage(message) {
      if (this.socket && this.socket.readyState === WebSocket.OPEN) {
        this.socket.send(message);
      }
    },
    closeWebSocket() {
      if (this.socket) {
        this.socket.close();
        this.socket = null;
      }
    }
  }
};
