li.shaoyi 4 年之前
父节点
当前提交
b672bfe32c
共有 2 个文件被更改,包括 10 次插入1 次删除
  1. 8 0
      src/hooks/account/index.ts
  2. 2 1
      src/services/socket/quota/index.ts

+ 8 - 0
src/hooks/account/index.ts

@@ -8,9 +8,11 @@ import { Taaccount } from "@/services/go/TaAccount/interface";
 import { geLoginID_number } from '@/services/bus/login';
 import { Systemparam } from '@/services/go/useInfo/interface';
 import { getSelectedAccountId, setSelectedAccount } from '@/services/bus/account';  // 为了兼容以前代码,待优化后期废除
+import { subcriteGoodsQuote } from '@/common/setup/table/tableQuote';
 import { TradeAccount, TradePosition } from './interface'
 import APP from '@/services';
 
+let stopSubcribe: () => void;
 // 加载状态
 const loading = ref<boolean>(false);
 // 资金账户列表
@@ -63,12 +65,18 @@ export function useTradeAccount() {
 
     // 切换资金账户
     const tradeAccountChange = (accountId: number) => {
+        // 停止上次订阅
+        stopSubcribe && stopSubcribe();
+
         const account = tradeAccountList.find((account) => account.accountid === accountId);
         if (account) {
             tradePositionList.length = 0;
             tradeAccount.value = account;
             tradePositionList.push(...account.positionList);
             setSelectedAccount(account); // 为了兼容以前代码,待优化后期废除
+
+            // 开始行情订阅
+            stopSubcribe = subcriteGoodsQuote(account.positionList.map((e) => e.goodscode));
         }
     }
 

+ 2 - 1
src/services/socket/quota/index.ts

@@ -62,11 +62,12 @@ export function addSubscribeQuotation(uuid: string, subscribeInfos: SubscribeInf
 export function removeSubscribeQuotation(uuid: string) {
     if (subscribeGoodsList.has(uuid)) {
         subscribeGoodsList.delete(uuid);
+        console.log('删除订阅', uuid)
         if (subscribeGoodsList.size) {
             actionSubcribe();
         } else {
             // 没有订阅商品时候,主动断开行情链路
-            APP.closeQuote();
+            // APP.closeQuote();
         }
     }
 }