Skip to content

Commit dba6f55

Browse files
- 持有份额防止误输入优化
1 parent ed61f74 commit dba6f55

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

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

14+
15+
#### v1.3.6
16+
17+
- 持有份额防止误输入优化
18+
1419
#### v1.3.5
1520

1621
- 移除网络失败提示

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "utools-fund",
3-
"version": "v1.3.5",
3+
"version": "v1.3.6",
44
"description": "自选基金助手",
55
"main": "main.ts",
66
"scripts": {

src/features/fundMy.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { IFundEnt } from '@/model/IFundEnt';
77

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

1414
const getMyFundDetails = async () => {
@@ -64,7 +64,7 @@ const getMyFundDetails = async () => {
6464
return FundDBHelper.getAll();
6565
};
6666

67-
const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
67+
const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[], searchWord = '') => {
6868
let sumIncome = 0;
6969
let cbList = dbList.map(db => {
7070
const fund = db.data;
@@ -76,6 +76,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
7676
title: `${fund.id} ${fund.name} ${fund.isValuation ? '' : '✅'}`,
7777
description: `${(rate * 100).toFixed(2)}% ¥${income.toFixed(2)}`,
7878
icon: rate >= 0 ? 'assets/img/up.png' : 'assets/img/down.png',
79+
searchWord,
7980
};
8081
return cb;
8182
});
@@ -85,6 +86,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
8586
title: ``,
8687
description: ``,
8788
icon: 'assets/img/add.png',
89+
searchWord,
8890
},
8991
];
9092
} else {
@@ -93,6 +95,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
9395
title: `今日总收益 ${dbList.every(x => !x.data.isValuation) ? '✅' : ''}`,
9496
description: `¥${sumIncome.toFixed(2)}`,
9597
icon: sumIncome >= 0 ? 'assets/img/up.png' : 'assets/img/down.png',
98+
searchWord,
9699
},
97100
...cbList,
98101
];
@@ -117,7 +120,6 @@ const showFundDetails = async (cb: CallbackSetList, isShowLoading = true) => {
117120
const dbList = await getMyFundDetails();
118121
// 缓存
119122
CACHE_FUND_DB_LIST = dbList;
120-
CURRENT_FUND_HOLD_COUNT = 0;
121123
const cbList = fundDetailsToCbList(dbList);
122124
cb(cbList);
123125
// 定时展示
@@ -139,8 +141,7 @@ const fundMy: TplFeature = {
139141
},
140142
search: async (action, searchWord, callbackSetList) => {
141143
let dbList = CACHE_FUND_DB_LIST && CACHE_FUND_DB_LIST.length > 0 ? CACHE_FUND_DB_LIST : await getMyFundDetails();
142-
CURRENT_FUND_HOLD_COUNT = Number(searchWord);
143-
const cbList = fundDetailsToCbList(dbList);
144+
const cbList = fundDetailsToCbList(dbList, searchWord);
144145
callbackSetList(cbList);
145146
}, // 用户选择列表中某个条目时被调用
146147
select: (action, itemData, callbackSetList) => {
@@ -150,8 +151,13 @@ const fundMy: TplFeature = {
150151
}
151152
if (action.type === 'text' && itemData.fundCode) {
152153
const fundDb = FundDBHelper.get(itemData.fundCode);
153-
fundDb.data.holdCount = CURRENT_FUND_HOLD_COUNT;
154-
FundDBHelper.update(fundDb);
154+
if (itemData.searchWord) {
155+
const holdCount = parseFloat(itemData.searchWord);
156+
if (!Number.isNaN(holdCount)) {
157+
fundDb.data.holdCount = holdCount;
158+
FundDBHelper.update(fundDb);
159+
}
160+
}
155161
}
156162
utools.redirect('我的自选基金', '');
157163
},

0 commit comments

Comments
 (0)