diff --git a/README.md b/README.md index e2f7c4e..99c225a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,11 @@ ![Instructions.gif](https://img03.sogoucdn.com/app/a/100520146/4d63e4c89eb939f009344792b5f3afe8) + +#### v1.3.6 + +- 持有份额防止误输入优化 + #### v1.3.5 - 移除网络失败提示 diff --git a/package.json b/package.json index 3c2bc60..6ab7566 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "utools-fund", - "version": "v1.3.5", + "version": "v1.3.6", "description": "自选基金助手", "main": "main.ts", "scripts": { diff --git a/src/features/fundMy.ts b/src/features/fundMy.ts index f502ad8..e77b596 100644 --- a/src/features/fundMy.ts +++ b/src/features/fundMy.ts @@ -7,8 +7,8 @@ import { IFundEnt } from '@/model/IFundEnt'; // 缓存基金详情 let CACHE_FUND_DB_LIST: DBItem[]; -// 当前基金持有数量 -let CURRENT_FUND_HOLD_COUNT = 0; +// 当前搜索关键字 +let CURRENT_SEARCH_WORD = ''; let QUERY_TIMER: NodeJS.Timeout; const getMyFundDetails = async () => { @@ -64,7 +64,7 @@ const getMyFundDetails = async () => { return FundDBHelper.getAll(); }; -const fundDetailsToCbList = (dbList: DBItem[]) => { +const fundDetailsToCbList = (dbList: DBItem[], searchWord = '') => { let sumIncome = 0; let cbList = dbList.map(db => { const fund = db.data; @@ -76,6 +76,7 @@ const fundDetailsToCbList = (dbList: DBItem[]) => { 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; }); @@ -85,6 +86,7 @@ const fundDetailsToCbList = (dbList: DBItem[]) => { title: ``, description: ``, icon: 'assets/img/add.png', + searchWord, }, ]; } else { @@ -93,6 +95,7 @@ const fundDetailsToCbList = (dbList: DBItem[]) => { title: `今日总收益 ${dbList.every(x => !x.data.isValuation) ? '✅' : ''}`, description: `¥${sumIncome.toFixed(2)}`, icon: sumIncome >= 0 ? 'assets/img/up.png' : 'assets/img/down.png', + searchWord, }, ...cbList, ]; @@ -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); // 定时展示 @@ -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) => { @@ -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('我的自选基金', ''); },