This commit is contained in:
2026-01-14 15:06:59 +08:00
parent 07bc8373cc
commit 5e41d219d8
8 changed files with 48 additions and 16 deletions

View File

@@ -484,6 +484,9 @@
})
},
mounted() {
console.log('🚀 trade组件已挂载');
console.log('🔌 WebSocket状态:', this.$socket ? '已连接' : '未连接');
console.log('📱 channels对象:', this.$socket ? this.$socket.channels : 'N/A');
this._getMarkList();
this.symbol = this.$route.query.symbol
},
@@ -499,7 +502,9 @@
async _getDepth(){
let symbol = this.currentMarket.symbol;
let mergeDepth = this.chooseMergeDepth;
console.log('📊 初始化获取深度数据:', symbol, mergeDepth);
let res = await tradeApi.getDepth(symbol,mergeDepth)
console.log('📊 API返回的深度数据:', res.data);
this.depthsData = res.data
this.processDepthData()
},
@@ -665,9 +670,14 @@
// },
marketChange(currentMarket) {
this.currentMarket = currentMarket;
console.log("marketChange", currentMarket);
console.log("📍 marketChange", currentMarket);
this.switchMarketListDropdown = false;
this.timeStp = new Date().getTime();
// 先取消之前的订阅
this.unsubscribeDepths();
this.unsubscribeTrades();
//依赖marketId
this._getUserAccount(this.currentMarket.symbol);
this._serverGetTurnoverOrderList();
@@ -676,9 +686,11 @@
this.subscribeEntrust();
this.subscribeTurnover();
// 先获取初始数据
this._getDepth()
this._getTrades()
// 订阅实时更新
this.subscribeDepths();
this.subscribeTrades();
@@ -1029,37 +1041,57 @@
let symbol = this.currentMarket.symbol.toLowerCase();
let mergeDepth = this.chooseMergeDepth;
console.log('📊 订阅深度数据:', symbol, mergeDepth);
this.$socket.subscribe(`market.${symbol}.depth.${mergeDepth}`, 'market-depth');
this.$socket.on('market-depth', (data) => {
console.log('📊 收到深度数据原始:', data);
// 处理双层 JSON 字符串
try {
let parsedData = null;
if(data.result) {
console.log('📊 数据格式: data.result');
let result = JSON.parse(data.result);
if(result.tick) {
this.depthsData = JSON.parse(result.tick);
parsedData = JSON.parse(result.tick);
}
} else if(data.tick) {
this.depthsData = typeof data.tick === 'string' ? JSON.parse(data.tick) : data.tick;
console.log('📊 数据格式: data.tick');
parsedData = typeof data.tick === 'string' ? JSON.parse(data.tick) : data.tick;
} else if(data.body) {
console.log('📊 数据格式: data.body');
let body = typeof data.body === 'string' ? JSON.parse(data.body) : data.body;
parsedData = body;
}
if(this.depthsData && kline && kline.contentWindow) {
kline.contentWindow.set_current_depth(this.depthsData);
}
if(this.depthsData) {
if(parsedData) {
console.log('📊 解析后的深度数据:', parsedData);
this.depthsData = parsedData;
// 更新K线
let klineIframe = kline || document.getElementById('kline-win');
if(this.depthsData && klineIframe && klineIframe.contentWindow) {
klineIframe.contentWindow.set_current_depth(this.depthsData);
}
this.processDepthData()
} else {
console.warn('📊 无法解析深度数据,原始数据:', data);
}
} catch(e) {
console.error('解析深度数据失败:', e, data);
console.error('📊 解析深度数据失败:', e, data);
}
})
},
processDepthData(){
console.log('📊 处理深度数据开始:', this.depthsData);
if(!this.depthsData || !this.depthsData.asks || !this.depthsData.bids) {
console.warn('深度数据为空或格式错误', this.depthsData);
console.warn('📊 深度数据为空或格式错误', this.depthsData);
return;
}
let {asks, bids} = this.depthsData;
console.log('📊 asks数量:', asks.length, 'bids数量:', bids.length);
let {priceScale, buyFeeRate, sellFeeRate,numScale} = this.currentMarket;
if(this.currentBuyItem.price === '' && bids.length > 0 && this.currentBuyItem.canBuyAmount === '') {
let {buyAmount} = this.userAccount;