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 ed61f74 commit dba6f55
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

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


#### v1.3.6

- 持有份额防止误输入优化

#### v1.3.5

- 移除网络失败提示
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.5",
"version": "v1.3.6",
"description": "自选基金助手",
"main": "main.ts",
"scripts": {
Expand Down
22 changes: 14 additions & 8 deletions src/features/fundMy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { IFundEnt } from '@/model/IFundEnt';

// 缓存基金详情
let CACHE_FUND_DB_LIST: DBItem<IFundEnt>[];
// 当前基金持有数量
let CURRENT_FUND_HOLD_COUNT = 0;
// 当前搜索关键字
let CURRENT_SEARCH_WORD = '';
let QUERY_TIMER: NodeJS.Timeout;

const getMyFundDetails = async () => {
Expand Down Expand Up @@ -64,7 +64,7 @@ const getMyFundDetails = async () => {
return FundDBHelper.getAll();
};

const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[], searchWord = '') => {
let sumIncome = 0;
let cbList = dbList.map(db => {
const fund = db.data;
Expand All @@ -76,6 +76,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
title: `${fund.id} ${fund.name} ${fund.isValuation ? '' : '✅'}`,
description: `${(rate * 100).toFixed(2)}% ¥${income.toFixed(2)}`,
icon: rate >= 0 ? 'assets/img/up.png' : 'assets/img/down.png',
searchWord,
};
return cb;
});
Expand All @@ -85,6 +86,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
title: ``,
description: ``,
icon: 'assets/img/add.png',
searchWord,
},
];
} else {
Expand All @@ -93,6 +95,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
title: `今日总收益 ${dbList.every(x => !x.data.isValuation) ? '✅' : ''}`,
description: `¥${sumIncome.toFixed(2)}`,
icon: sumIncome >= 0 ? 'assets/img/up.png' : 'assets/img/down.png',
searchWord,
},
...cbList,
];
Expand All @@ -117,7 +120,6 @@ const showFundDetails = async (cb: CallbackSetList, isShowLoading = true) => {
const dbList = await getMyFundDetails();
// 缓存
CACHE_FUND_DB_LIST = dbList;
CURRENT_FUND_HOLD_COUNT = 0;
const cbList = fundDetailsToCbList(dbList);
cb(cbList);
// 定时展示
Expand All @@ -139,8 +141,7 @@ const fundMy: TplFeature = {
},
search: async (action, searchWord, callbackSetList) => {
let dbList = CACHE_FUND_DB_LIST && CACHE_FUND_DB_LIST.length > 0 ? CACHE_FUND_DB_LIST : await getMyFundDetails();
CURRENT_FUND_HOLD_COUNT = Number(searchWord);
const cbList = fundDetailsToCbList(dbList);
const cbList = fundDetailsToCbList(dbList, searchWord);
callbackSetList(cbList);
}, // 用户选择列表中某个条目时被调用
select: (action, itemData, callbackSetList) => {
Expand All @@ -150,8 +151,13 @@ const fundMy: TplFeature = {
}
if (action.type === 'text' && itemData.fundCode) {
const fundDb = FundDBHelper.get(itemData.fundCode);
fundDb.data.holdCount = CURRENT_FUND_HOLD_COUNT;
FundDBHelper.update(fundDb);
if (itemData.searchWord) {
const holdCount = parseFloat(itemData.searchWord);
if (!Number.isNaN(holdCount)) {
fundDb.data.holdCount = holdCount;
FundDBHelper.update(fundDb);
}
}
}
utools.redirect('我的自选基金', '');
},
Expand Down

0 comments on commit dba6f55

Please sign in to comment.