Skip to content

Commit

Permalink
重构代码
Browse files Browse the repository at this point in the history
我的自选基金固定前台展示时,定时(每分钟)获取最新
  • Loading branch information
adams549659584 committed Aug 18, 2020
1 parent 1d05fcb commit c165eea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
- 支持新增删除自选基金,可填入持有份额,实时计算当天收益

#### 使用说明

![Instructions.gif](https://img03.sogoucdn.com/app/a/100520146/4d63e4c89eb939f009344792b5f3afe8)

#### v1.3.3

- 重构代码
- 我的自选基金固定前台展示时,定时(每分钟)获取最新

#### v1.3.1

- 涨幅计算调整
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "utools-fund",
"version": "v1.3.2",
"version": "v1.3.3",
"description": "自选基金助手",
"main": "main.ts",
"scripts": {
Expand Down
30 changes: 22 additions & 8 deletions src/features/fundMy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IFundEnt } from '@/model/IFundEnt';
let CACHE_FUND_DB_LIST: DBItem<IFundEnt>[];
// 当前基金持有数量
let CURRENT_FUND_HOLD_COUNT = 0;
let QUERY_TIMER: NodeJS.Timeout;

const getMyFundDetails = async () => {
const dbList = FundDBHelper.getAll();
Expand Down Expand Up @@ -98,19 +99,32 @@ const loading = (cb: CallbackSetList, loadingTips = '加载中,请稍后。。
]);
};

const showFundDetails = async (cb: CallbackSetList, isShowLoading = true) => {
if (isShowLoading) {
loading(cb);
}
const dbList = await getMyFundDetails();
// 缓存
CACHE_FUND_DB_LIST = dbList;
CURRENT_FUND_HOLD_COUNT = 0;
const cbList = fundDetailsToCbList(dbList);
cb(cbList);
// 定时展示
QUERY_TIMER = setTimeout(() => {
showFundDetails(cb, false);
}, 1000 * 60);
};
utools.onPluginOut(() => {
clearTimeout(QUERY_TIMER);
});

const fundMy: TplFeature = {
mode: 'list',
args: {
placeholder: '输入持有份额,选择对应基金,回车键保存',
enter: async (action, callbackSetList) => {
loading(callbackSetList);
const dbList = await getMyFundDetails();
// 缓存
CACHE_FUND_DB_LIST = dbList;
CURRENT_FUND_HOLD_COUNT = 0;
const cbList = fundDetailsToCbList(dbList);
// 如果进入插件就要显示列表数据
callbackSetList(cbList);
clearTimeout(QUERY_TIMER);
showFundDetails(callbackSetList);
},
search: async (action, searchWord, callbackSetList) => {
let dbList = CACHE_FUND_DB_LIST && CACHE_FUND_DB_LIST.length > 0 ? CACHE_FUND_DB_LIST : await getMyFundDetails();
Expand Down

0 comments on commit c165eea

Please sign in to comment.