From e7f9fd31d0d1af6e7d9982cd10d64ea197207cbf Mon Sep 17 00:00:00 2001 From: rick <1196363729@qq.com> Date: Thu, 17 Oct 2024 14:45:51 +0800 Subject: [PATCH] feat: add biance sort --- package.json | 15 ++++++++++++++- src/explorer/binanceProvider.ts | 20 +++++++++++++++----- src/explorer/binanceService.ts | 9 ++++----- src/registerCommand.ts | 5 +++++ 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 4c62be08..fb39e113 100644 --- a/package.json +++ b/package.json @@ -283,6 +283,14 @@ { "command": "leek-fund.toggleStatusBarVisibility", "title": "LeekFund: Toggle Status Bar Visibility" + }, + { + "command": "leek-fund.binanceSort", + "title": "升序/降序/不排序", + "icon": { + "light": "resources/light/sort.svg", + "dark": "resources/dark/sort.svg" + } } ], "menus": { @@ -377,6 +385,11 @@ "when": "view == leekFundView.binance", "group": "navigation" }, + { + "command": "leek-fund.binanceSort", + "when": "view == leekFundView.binance", + "group": "navigation" + }, { "command": "leek-fund.refreshForex", "when": "view == leekFundView.forex", @@ -795,4 +808,4 @@ "ui", "workspace" ] -} +} \ No newline at end of file diff --git a/src/explorer/binanceProvider.ts b/src/explorer/binanceProvider.ts index a3c6f0ef..e0d96e52 100644 --- a/src/explorer/binanceProvider.ts +++ b/src/explorer/binanceProvider.ts @@ -9,17 +9,17 @@ import { Event, EventEmitter, TreeDataProvider, TreeItem } from 'vscode'; import { LeekFundConfig } from '../shared/leekConfig'; import { LeekTreeItem } from '../shared/leekTreeItem'; import BinanceService from './binanceService'; +import { SortType } from '../shared/typed'; export class BinanceProvider implements TreeDataProvider { private _onDidChangeTreeData: EventEmitter = new EventEmitter(); private service: BinanceService; readonly onDidChangeTreeData: Event = this._onDidChangeTreeData.event; - // TODO: 未完成排序功能 - // private order: SortType; + private order: SortType = SortType.NORMAL; constructor(service: BinanceService) { this.service = service; - // this.order = LeekFundConfig.getConfig('leek-fund.binanceSort') || SortType.NORMAL; + this.order = LeekFundConfig.getConfig('leek-fund.binanceSort') || SortType.NORMAL; } getTreeItem(element: any): TreeItem | Thenable { @@ -28,7 +28,7 @@ export class BinanceProvider implements TreeDataProvider { getChildren(): LeekTreeItem[] | Thenable { const paris = LeekFundConfig.getConfig('leek-fund.binance') || []; - return this.service.getData(paris); + return this.service.getData(paris, this.order); } getParent?() { @@ -45,6 +45,16 @@ export class BinanceProvider implements TreeDataProvider { /** Modify order */ changeOrder(): void { // leek-fund.binanceSort - throw new Error('Method not implemented.'); + let order = this.order as number; + order += 1; + if (order > 1) { + this.order = SortType.DESC; + } else if (order === 1) { + this.order = SortType.ASC; + } else if (order === 0) { + this.order = SortType.NORMAL; + } + LeekFundConfig.setConfig('leek-fund.binanceSort', this.order); + this.refresh(); } } diff --git a/src/explorer/binanceService.ts b/src/explorer/binanceService.ts index 4dc16622..0722c45d 100644 --- a/src/explorer/binanceService.ts +++ b/src/explorer/binanceService.ts @@ -9,8 +9,8 @@ import Axios from 'axios'; import { ExtensionContext } from 'vscode'; import globalState from '../globalState'; import { LeekTreeItem } from '../shared/leekTreeItem'; -import { FundInfo, TreeItemType } from '../shared/typed'; -import { randHeader } from '../shared/utils'; +import { FundInfo, SortType, TreeItemType } from '../shared/typed'; +import { randHeader, sortData } from '../shared/utils'; import { LeekService } from './leekService'; export default class BinanceService extends LeekService { @@ -55,7 +55,7 @@ export default class BinanceService extends LeekService { }); } - async getData(codes: string[]): Promise { + async getData(codes: string[], order: SortType): Promise { const pairList: Array = []; // 20个请求的权重最低 @@ -80,7 +80,6 @@ export default class BinanceService extends LeekService { } const results = await Promise.allSettled(promises); - // console.log(results, 'results') for (const splitRes of results) { // @ts-ignore const { status, value, reason } = splitRes; @@ -123,6 +122,6 @@ export default class BinanceService extends LeekService { } } - return pairList; + return sortData(pairList, order); } } diff --git a/src/registerCommand.ts b/src/registerCommand.ts index 0824c2b2..33456909 100644 --- a/src/registerCommand.ts +++ b/src/registerCommand.ts @@ -359,6 +359,11 @@ export function registerViewEvent( }); }); + /* 排序 */ + commands.registerCommand('leek-fund.binanceSort', () => { + binanceProvider.changeOrder(); + }); + /** * Forex command */