1
PC-20250623MANY\Administrator
2025-08-24 f6eb2c4e1b1392576a6592aa4cce19f2efd3a978
1
1 files modified
44 ■■■■■ changed files
src/views/home/components/HomeLtl.vue 44 ●●●●● patch | view | raw | blame | history
src/views/home/components/HomeLtl.vue
@@ -102,7 +102,42 @@
    this.opt.stockType = this.activeName; // 赋值类型
    this.apiInterface = api.getStockByType; // 赋值接口
    this.init(); // 获取记录列表
    this.initWebSocket(); // 连接ws实时监控变动
    // this.initWebSocket(); // 连接ws实时监控变动
  },
  watch: {
    activeName: {
      handler(val) {
        // 根据当前股票类型连接对应的ws
        if (val == "US")
          this.initWebSocket("wss://usws.yanshiz.com/websocket-server");
        else this.initWebSocket("wss://ws.acapl.net/websocket-server");
      },
      immediate: true,
      deep: true,
    },
  },
  computed: {
    tableData() {
      return this.list;
    },
  },
  props: {
    total: {
      type: Number,
      default: 0,
    },
    pageNum: {
      type: Number,
      default: 1,
    },
  },
  components: {},
  mounted() {},
  beforeDestroy() {
    if (this.Trade) {
      this.Trade.close();
      console.log("WebSocket disconnected");
    }
  },
  methods: {
    handleClick() {
@@ -118,10 +153,13 @@
      this.$emit("choice", val.code);
    },
    // 连接ws实时监控变动
    initWebSocket() {
    initWebSocket(url) {
      console.log("initWebSocket");
      if (this.Trade) {
        this.Trade.close();
      }
      this.Trade = new WhrWebSocket({
        path: `wss://ws.acapl.net/websocket-server `,
        path: url,
        onmessage: this.getTradeMessage,
      });