diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 406eec0..eefe6de 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -1522,50 +1522,55 @@ export default { this.brokenLine = data[0].marketInfoList.slice(0,5); this.homeList2 = data[0].marketInfoList.slice(0,4); - let allNegativeIncreaseItems = [] this.sortedNegativeItems = [] + let allNegativeIncreaseItems = [] const excludedCoins = ["CQF", "HZL", "NKA", "PMK", "GCUL", "DFU", "ACK"]; - data.forEach((item) => { - if (item.marketInfoList) { - const negativeItems = item.marketInfoList.filter((info) => { - // 条件1:increaseStr 以 "-" 开头(负增长) - // 条件2:coin_name 不在 excludedCoins 列表中 - return ( - info.increaseStr && - info.increaseStr.startsWith("-") && - !excludedCoins.includes(info.coin_name) - ); - }); - allNegativeIncreaseItems.push(...negativeItems); // 合并到总数组 - } - }); - this.sortedNegativeItems = [...allNegativeIncreaseItems].sort((a, b) => { - const numA = parseFloat(a.increaseStr); - const numB = parseFloat(b.increaseStr); - return numA - numB; // 升序排列(小的在前) + data.forEach((item) => { + if (item.marketInfoList) { + const filteredItems = item.marketInfoList.filter((info) => { + return !excludedCoins.includes(info.coin_name); + }); + allNegativeIncreaseItems.push(...filteredItems); + } + }); + this.sortedNegativeItems = [...allNegativeIncreaseItems].sort((a, b) => { + const numA = parseFloat(a.increaseStr); + const numB = parseFloat(b.increaseStr); + const isANegative = numA < 0; + const isBNegative = numB < 0; + + if (isANegative && !isBNegative) { + return -1; + } + if (!isANegative && isBNegative) { + return 1; + } + return numA - numB; }); let allPositiveIncreaseItems = []; // 存储 "+" 开头的项 this.sortedNegativeItems1 = []; // 存储排序后的结果 - data.forEach((item) => { - if (item.marketInfoList) { - const positiveItems = item.marketInfoList.filter((info) => { - return ( - info.increaseStr && - info.increaseStr.startsWith("+")&& - !excludedCoins.includes(info.coin_name) - ) - }); - allPositiveIncreaseItems.push(...positiveItems); // 合并到总数组 - } + if (item.marketInfoList) { + const filteredItems = item.marketInfoList.filter((info) => { + return !excludedCoins.includes(info.coin_name); + }); + allPositiveIncreaseItems.push(...filteredItems); + } }); - - // 按数值降序排列(大的在前) - this.sortedNegativeItems1 = [...allPositiveIncreaseItems].sort((a, b) => { + this.sortedNegativeItems1 = [...allPositiveIncreaseItems].sort((a, b) => { const numA = parseFloat(a.increaseStr); const numB = parseFloat(b.increaseStr); - return numB - numA; // 降序(大的在前) + const isANegative = numA < 0; + const isBNegative = numB < 0; + + if (isANegative && !isBNegative) { + return 1; + } + if (!isANegative && isBNegative) { + return -1; + } + return numB - numA; }); // console.log(this.sortedNegativeItems,'123');