|
|
@@ -184,46 +184,46 @@ export const quote = new (class {
|
|
|
|
|
|
// 接收行情服务断线重连成功通知
|
|
|
this.quoteServerReconnectNotify = eventBus.$on('quoteServerReconnectNotify', () => {
|
|
|
- startSubscribe();
|
|
|
+ this.subscribe();
|
|
|
})
|
|
|
}
|
|
|
-})
|
|
|
|
|
|
-/**
|
|
|
- * 开始订阅
|
|
|
- */
|
|
|
-export function startSubscribe() {
|
|
|
- const subscribeData: Proto.GoodsQuoteReq[] = [];
|
|
|
+ /**
|
|
|
+ * 开始订阅
|
|
|
+ */
|
|
|
+ subscribe() {
|
|
|
+ const subscribeData: Proto.GoodsQuoteReq[] = [];
|
|
|
|
|
|
- quote.subscribeMap.forEach((value) => {
|
|
|
- const item = value.map((code) => ({
|
|
|
- goodsCode: code,
|
|
|
- exchangeCode: 250,
|
|
|
- subState: 0
|
|
|
- }))
|
|
|
- subscribeData.push(...item);
|
|
|
- })
|
|
|
+ this.subscribeMap.forEach((value) => {
|
|
|
+ const item = value.map((code) => ({
|
|
|
+ goodsCode: code,
|
|
|
+ exchangeCode: 250,
|
|
|
+ subState: 0
|
|
|
+ }))
|
|
|
+ subscribeData.push(...item);
|
|
|
+ })
|
|
|
|
|
|
- if (subscribeData.length) {
|
|
|
- console.log('开始行情订阅', subscribeData)
|
|
|
- quoteServerRequest({
|
|
|
- data: subscribeData,
|
|
|
- success: (res) => {
|
|
|
- if (res.length) {
|
|
|
- console.log('行情订阅成功', res)
|
|
|
- } else {
|
|
|
- console.error('行情订阅失败')
|
|
|
+ if (subscribeData.length) {
|
|
|
+ console.log('开始行情订阅', subscribeData)
|
|
|
+ quoteServerRequest({
|
|
|
+ data: subscribeData,
|
|
|
+ success: (res) => {
|
|
|
+ if (res.length) {
|
|
|
+ console.log('行情订阅成功', res)
|
|
|
+ } else {
|
|
|
+ console.error('行情订阅失败')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('行情订阅失败', err)
|
|
|
}
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- console.error('行情订阅失败', err)
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- // 没有订阅商品的时候,断开连接
|
|
|
- socket.closeQuoteServer();
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 没有订阅商品的时候,断开连接
|
|
|
+ socket.closeQuoteServer();
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+})
|
|
|
|
|
|
/**
|
|
|
* 添加订阅
|
|
|
@@ -237,14 +237,14 @@ export function addSubscribe(goodsCodes: string[], key?: string) {
|
|
|
|
|
|
// 对相同 key 订阅的商品进行合并处理
|
|
|
quote.subscribeMap.set(uuid, [...value, ...goodsCodes]);
|
|
|
- startSubscribe();
|
|
|
+ quote.subscribe();
|
|
|
|
|
|
return {
|
|
|
uuid,
|
|
|
stop: () => {
|
|
|
console.log('删除订阅', uuid);
|
|
|
quote.subscribeMap.delete(uuid);
|
|
|
- startSubscribe();
|
|
|
+ quote.subscribe();
|
|
|
},
|
|
|
}
|
|
|
}
|
|
|
@@ -262,5 +262,5 @@ export function removeSubscribe(...keys: string[]) {
|
|
|
} else {
|
|
|
quote.subscribeMap.clear();
|
|
|
}
|
|
|
- startSubscribe();
|
|
|
+ quote.subscribe();
|
|
|
}
|