Skip to content

Commit

Permalink
净值确认标识及使用说明
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed Aug 17, 2020
1 parent 954cbcc commit 90ead98
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 38 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
- 自选基金助手,数据来源于天天基金
- 支持新增删除自选基金,可填入持有份额,实时计算当天收益

#### 使用说明
![image](src/assets/img/Instructions.gif)

#### v1.3.0

- 最后净值确认增加 ✅ 标识

#### v1.2.0

Expand Down
2 changes: 2 additions & 0 deletions src/Helper/HttpHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import axios, { AxiosRequestConfig } from 'axios';
import { IncomingMessage } from 'electron';
import { convert } from 'encoding';

// 超时时间
axios.defaults.timeout = 1000 * 1;
// 添加请求拦截器
axios.interceptors.request.use(request => {
// // 默认请求头
Expand Down
Binary file added src/assets/img/Instructions.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/img/loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 57 additions & 37 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TemplatePlugin, CallbackListItem, DBItem, FilesPayload } from '@/types/utools';
import { TemplatePlugin, CallbackListItem, DBItem, FilesPayload, CallbackSetList } from '@/types/utools';
import { get } from './Helper/HttpHelper';
import FundDBHelper from './Helper/FundDBHelper';
import { ISearchFundResult } from './model/ISearchFundResult';
Expand All @@ -16,40 +16,48 @@ const getMyFundDetails = async () => {
const dbList = FundDBHelper.getAll();
await Promise.all(
dbList.map(async db => {
const oldData = db.data;
const fundValuationDetail = await get<IFundValuationDetailResult>(
`https://fundmobapi.eastmoney.com/FundMApi/FundVarietieValuationDetail.ashx?FCODE=${oldData.id}&deviceid=D03E8A22-9E0A-473F-B045-3745FC7931C4&plat=Iphone&product=EFund&version=6.2.9&GTOKEN=793EAE9248BC4181A9380C49938D1E31`
);
if (fundValuationDetail.ErrCode !== 0) {
utools.showMessageBox({
message: fundValuationDetail.ErrMsg,
});
return;
}
let lastTime = fundValuationDetail.Expansion.GZTIME;
let nowJJJZ = Number(fundValuationDetail.Expansion.GZ);
const searchFundResult = await get<ISearchFundResult>(`http://fundsuggest.eastmoney.com/FundSearch/api/FundSearchAPI.ashx?m=1&key=${oldData.id}`);
if (searchFundResult.ErrCode !== 0) {
utools.showMessageBox({
message: searchFundResult.ErrMsg,
});
return;
} else {
const searchFundDetail = searchFundResult.Datas[0];
// 最后单位净值
if (lastTime.includes(searchFundDetail.FundBaseInfo.FSRQ)) {
lastTime = searchFundDetail.FundBaseInfo.FSRQ;
nowJJJZ = Number(searchFundDetail.FundBaseInfo.DWJZ);
try {
const oldData = db.data;
const fundValuationDetail = await get<IFundValuationDetailResult>(
`https://fundmobapi.eastmoney.com/FundMApi/FundVarietieValuationDetail.ashx?FCODE=${oldData.id}&deviceid=D03E8A22-9E0A-473F-B045-3745FC7931C4&plat=Iphone&product=EFund&version=6.2.9&GTOKEN=793EAE9248BC4181A9380C49938D1E31`
);
if (fundValuationDetail.ErrCode !== 0) {
utools.showMessageBox({
message: fundValuationDetail.ErrMsg,
});
return;
}
let lastTime = fundValuationDetail.Expansion.GZTIME;
let nowJJJZ = Number(fundValuationDetail.Expansion.GZ);
let isValuation = true;
const searchFundResult = await get<ISearchFundResult>(`http://fundsuggest.eastmoney.com/FundSearch/api/FundSearchAPI.ashx?m=1&key=${oldData.id}`);
if (searchFundResult.ErrCode !== 0) {
utools.showMessageBox({
message: searchFundResult.ErrMsg,
});
return;
} else {
const searchFundDetail = searchFundResult.Datas[0];
// 最后单位净值
if (lastTime.includes(searchFundDetail.FundBaseInfo.FSRQ)) {
// console.log(`净值:`, searchFundDetail.FundBaseInfo);
lastTime = searchFundDetail.FundBaseInfo.FSRQ;
nowJJJZ = Number(searchFundDetail.FundBaseInfo.DWJZ);
isValuation = false;
}
}
db.data = {
...oldData,
yesJJJZ: Number(fundValuationDetail.Expansion.DWJZ),
nowJJJZ: Number(nowJJJZ),
lastTime,
isValuation,
};
FundDBHelper.update(db);
// console.log(JSON.stringify(db.data));
} catch (error) {
console.error(error);
}
db.data = {
...oldData,
yesJJJZ: Number(fundValuationDetail.Expansion.DWJZ),
nowJJJZ: Number(nowJJJZ),
lastTime,
};
FundDBHelper.update(db);
console.log(JSON.stringify(db.data));
return db;
})
);
Expand All @@ -65,15 +73,15 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
sumIncome += income;
const cb: CallbackListItem = {
fundCode: fund.id,
title: `${fund.id} ${fund.name}`,
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',
};
return cb;
});
cbList = [
{
title: `今日总收益`,
title: `今日总收益 ${dbList.every(x => !x.data.isValuation) ? '✅' : ''}`,
description: `¥${sumIncome.toFixed(2)}`,
icon: sumIncome >= 0 ? 'assets/img/up.png' : 'assets/img/down.png',
},
Expand All @@ -94,21 +102,31 @@ const getFundMarketIndexs = async (searchWord = '') => {
f14: string;
}[];
};
}>(`https://push2.eastmoney.com/api/qt/ulist.np/get?fltt=2&fields=f2,f3,f4,f12,f14&secids=1.000001,1.000300,0.399001,0.399006&_=1597632105416`);
}>(`https://push2.eastmoney.com/api/qt/ulist.np/get?fltt=2&secids=1.000001,0.399001,0.399006,100.HSI,1.000300&fields=f2,f3,f4,f12,f14`);
if (searchWord) {
marketResult.data.diff = marketResult.data.diff.filter(x => x.f12.includes(searchWord) || x.f14.includes(searchWord));
}
const cbList = marketResult.data.diff.map(x => {
const cb: CallbackListItem = {
title: x.f14,
description: `涨幅:${x.f3}% 最新:${x.f2}`,
description: `涨幅:${x.f3}% --- 最新:${x.f2} `,
icon: x.f3 >= 0 ? 'assets/img/up.png' : 'assets/img/down.png',
};
return cb;
});
return cbList;
};

const loading = (cb: CallbackSetList, loadingTips = '加载中,请稍后。。。') => {
cb([
{
title: loadingTips,
description: '~~~~~~~~~~~~~~~',
icon: 'assets/img/loading.png',
},
]);
};

const preload: TemplatePlugin = {
utools_fund_add: {
mode: 'list',
Expand Down Expand Up @@ -149,6 +167,7 @@ const preload: TemplatePlugin = {
yesJJJZ: 0,
nowJJJZ: itemData.DWJZ,
lastTime: itemData.FSRQ,
isValuation: true,
});
}
utools.redirect('继续添加自选基金', '');
Expand Down Expand Up @@ -196,6 +215,7 @@ const preload: TemplatePlugin = {
args: {
placeholder: '输入持有份额,选择对应基金,回车键保存',
enter: async (action, callbackSetList) => {
loading(callbackSetList);
const dbList = await getMyFundDetails();
// 缓存
CACHE_FUND_DB_LIST = dbList;
Expand Down
7 changes: 6 additions & 1 deletion src/model/IFundEnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ export interface IFundEnt {
yesJJJZ: number;

/**
* 现在基金净值
* 现在基金估值或净值
*/
nowJJJZ: number;

/**
* 当前是否是估值
*/
isValuation: boolean;

/**
* 当前净值对应时间
*/
Expand Down

0 comments on commit 90ead98

Please sign in to comment.