Browse Source

优化市场列表显示逻辑,新增符号市场映射和弹出框可见性管理,改进数据更新机制以支持延迟加载和合并市场数据。

master
TorsenLi 3 hours ago
parent
commit
80a5d8b97b
  1. 172
      src/views/exchangeStock/index.vue

172
src/views/exchangeStock/index.vue

@ -47,6 +47,8 @@
ref="popover"
width="400"
trigger="click"
@show="popoverVisible = true"
@hide="popoverVisible = false"
>
<div slot="reference">
<!-- {{ activeContract.pair_name }} -->
@ -56,52 +58,45 @@
</el-button>
</div>
<div
v-if="popoverVisible"
class="markets-pair-list"
style="max-height:300px;overflow:auto;"
>
<template v-for="parent in marketList">
<div class="px-3 text-primary" :key="parent.coin_name">
<!-- {{ parent.coin_name }} -->
</div>
<table class="table" :key="parent.coin_name + 1">
<thead>
<tr class="text-secondary">
<th class="w-10/24">{{ $t("contract.h5") }}</th>
<th class="w-7/24">{{ $t("contract.g3") }}</th>
<th class="w-7/24 text-right">
{{ $t("contract.h6") }}
</th>
</tr>
</thead>
<tbody>
<!-- @click="symbol = item.symbol" -->
<tr
v-for="item in parent.marketInfoList"
:key="item.symbol"
:class="{ active: item.symbol == symbol }"
@click="ispopover1(item.symbol)"
<table class="table">
<thead>
<tr class="text-secondary">
<th class="w-10/24">{{ $t("contract.h5") }}</th>
<th class="w-7/24">{{ $t("contract.g3") }}</th>
<th class="w-7/24 text-right">
{{ $t("contract.h6") }}
</th>
</tr>
</thead>
<tbody>
<tr
v-for="item in flatMarketList"
:key="item.symbol"
:class="{ active: item.symbol == symbol }"
@click="ispopover1(item.symbol)"
>
<td class="w-10/24">
{{ item.coin_name }}
</td>
<td
class="w-7/24"
:class="item.increase < 0 ? 'decreace' : 'increace'"
>
<td class="w-10/24">
<!-- {{ item.symbol }}/{{ parent.coin_name }} -->
{{ item.coin_name }}
</td>
<td
class="w-7/24 "
:class="item.increase < 0 ? 'decreace' : 'increace'"
>
{{item.price}}
<!-- item.symbol == symbol ? price1 : -->
</td>
<td
class="w-7/24"
:class="item.increase < 0 ? 'decreace' : 'increace'"
>
{{ item.increaseStr }}
</td>
</tr>
</tbody>
</table>
</template>
{{ item.price }}
</td>
<td
class="w-7/24"
:class="item.increase < 0 ? 'decreace' : 'increace'"
>
{{ item.increaseStr }}
</td>
</tr>
</tbody>
</table>
</div>
</el-popover>
</div>
@ -207,6 +202,10 @@
to: '-',
},
marketList: [], // symbol
symbolMarketMap: {},
popoverVisible: false,
marketListPending: null,
marketListUpdateTimer: null,
trade: [],
pcBannerList: [],
newTrade: null,
@ -312,15 +311,18 @@
};
}
},
activeContract(val) {
let marketList=this.marketList
.map(item => item.marketInfoList)
.flat()
.find(item => item.symbol == this.symbol) || {}
if(val.price){
delete marketList.price
}
return marketList;
activeContract() {
return this.symbolMarketMap[this.symbol] || {};
},
flatMarketList() {
if (!this.popoverVisible) return [];
const list = [];
this.marketList.forEach(group => {
(group.marketInfoList || []).forEach(item => {
list.push(item);
});
});
return list;
},
},
@ -405,6 +407,59 @@
ispopover1(item){
this.symbol=item;
},
rebuildSymbolMarketMap() {
const map = {};
this.marketList.forEach(group => {
(group.marketInfoList || []).forEach(item => {
map[item.symbol] = item;
});
});
this.symbolMarketMap = map;
},
mergeMarketListInPlace(newData) {
const symbolMap = {};
newData.forEach(group => {
(group.marketInfoList || []).forEach(item => {
symbolMap[item.symbol] = item;
});
});
this.marketList.forEach(group => {
(group.marketInfoList || []).forEach((item, index) => {
const updated = symbolMap[item.symbol];
if (updated) {
this.$set(group.marketInfoList, index, Object.assign({}, item, updated));
}
});
});
this.rebuildSymbolMarketMap();
},
updateMarketList(data) {
if (!data || !data.length) return;
if (!this.marketList.length) {
this.marketList = data;
this.rebuildSymbolMarketMap();
} else {
this.mergeMarketListInPlace(data);
}
if (!this.symbol) {
this.initDefaultSymbol(data);
} else {
this.findMarketBySymbol();
}
},
scheduleMarketListUpdate(data) {
if (!this.popoverVisible) {
this.updateMarketList(data);
return;
}
this.marketListPending = data;
if (this.marketListUpdateTimer) return;
this.marketListUpdateTimer = setTimeout(() => {
this.updateMarketList(this.marketListPending);
this.marketListPending = null;
this.marketListUpdateTimer = null;
}, 300);
},
initMarket() {
// marketList
this.ws.send({
@ -652,13 +707,7 @@
case "exchangeMarketList":
this.marketList = data;
if (!this.symbol) {
this.initDefaultSymbol(data);
} else {
this.findMarketBySymbol();
}
this.scheduleMarketListUpdate(data);
break;
@ -708,13 +757,16 @@
this.indexList()
Market.getstockMarketList().then(data => {
this.marketList = data;
this.initDefaultSymbol(data);
this.updateMarketList(data);
}).catch(err => {});
// this.update();
},
beforeDestroy() {
clearInterval(this.timer);
if (this.marketListUpdateTimer) {
clearTimeout(this.marketListUpdateTimer);
this.marketListUpdateTimer = null;
}
},
mounted() {

Loading…
Cancel
Save