diff --git a/README.md b/README.md index ccd159d..f451f06 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,20 @@ - 自选基金助手,数据来源于天天基金 - 支持新增删除自选基金,可填入持有份额,实时计算当天收益 +#### 源码 + +> https://github.com/adams549659584/utools-fund + #### 使用说明 ![Instructions.gif](https://img03.sogoucdn.com/app/a/100520146/4d63e4c89eb939f009344792b5f3afe8) +#### v1.3.4 + +- 移除 encoding +- 修复重构导致导入 bug +- 优化无基金时删除及我的自选基金列表展示 + #### v1.3.3 - 重构代码 diff --git a/package.json b/package.json index bd2b221..e5010a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "utools-fund", - "version": "v1.3.3", + "version": "v1.3.4", "description": "自选基金助手", "main": "main.ts", "scripts": { @@ -23,7 +23,6 @@ "typescript": "^3.9.7" }, "dependencies": { - "axios": "^0.19.2", - "encoding": "^0.1.13" + "axios": "^0.19.2" } -} \ No newline at end of file +} diff --git a/rollup.config.js b/rollup.config.js index 64c36bc..1f601a5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -54,7 +54,11 @@ const rollupOptions = { replace({ ENV: JSON.stringify(NODE_ENV), }), - NODE_ENV === 'production' && terser(), + // NODE_ENV === 'production' && terser({ + // format: { + // comments: false + // } + // }), ], }; export default rollupOptions; diff --git a/src/Helper/HttpHelper.ts b/src/Helper/HttpHelper.ts index bfaabf6..0b0422c 100644 --- a/src/Helper/HttpHelper.ts +++ b/src/Helper/HttpHelper.ts @@ -1,6 +1,6 @@ import axios, { AxiosRequestConfig } from 'axios'; import { IncomingMessage } from 'electron'; -import { convert } from 'encoding'; +// import { convert } from 'encoding'; // 超时时间 axios.defaults.timeout = 1000 * 10; @@ -35,42 +35,6 @@ const get = async (url: string, params?: { [key: string]: any }, con return res.data as T; }; -/** - * get 请求中文站点等等 - * @param url 请求链接 - * @param coding 编码,默认gb2312 - * @param params 参数 - * @param config 配置 - */ -const getByCoding = async (url: string, coding: string = 'gb2312', params?: { [key: string]: any }, config?: AxiosRequestConfig): Promise => { - // const oldResponseType = (config && config.responseType) || 'text'; - config = { - ...config, - responseType: 'stream', - }; - const resData = await get(url, params, config); - // 编码处理 - return await hanldeCodingData(resData, coding); -}; - -const hanldeCodingData = async (data: IncomingMessage, coding: string = 'gb2312'): Promise => { - // 编码处理 - return new Promise((resolve, reject) => { - const chunks = []; - data.on('data', chunk => { - chunks.push(chunk); - }); - data.on('end', () => { - const buffer = Buffer.concat(chunks); - const convertResult = convert(buffer, 'UTF-8', coding); - resolve(convertResult.toString()); - }); - data.on('error', () => { - reject('请求失败'); - }); - }); -}; - /** * post 请求 * @param url 请求链接 @@ -82,17 +46,7 @@ const post = async (url: string, data?: { [key: string]: any }, conf return res.data as T; }; -const postByCoding = async (url: string, coding: string = 'gb2312', data?: { [key: string]: any }, config?: AxiosRequestConfig): Promise => { - config = { - ...config, - responseType: 'stream', - }; - const resData = await post(url, data, config); - // 编码处理 - return await hanldeCodingData(resData, coding); -}; - -export { get, post, getByCoding, postByCoding }; +export { get, post }; export default class HttpHelper { /** diff --git a/src/features/fundDel.ts b/src/features/fundDel.ts index cd13f62..2d83983 100644 --- a/src/features/fundDel.ts +++ b/src/features/fundDel.ts @@ -7,6 +7,9 @@ const fundDel: TplFeature = { placeholder: '选择需删除的基金,回车键确认', enter: (action, callbackSetList) => { const dbList = FundDBHelper.getAll(); + if (dbList.length === 0) { + utools.redirect('我的自选基金', ''); + } const cbList = dbList.map(db => { const cb: CallbackListItem = { title: db.data.id, diff --git a/src/features/fundMy.ts b/src/features/fundMy.ts index 9c465a8..52cd1bf 100644 --- a/src/features/fundMy.ts +++ b/src/features/fundMy.ts @@ -56,6 +56,7 @@ const getMyFundDetails = async () => { // console.log(JSON.stringify(db.data)); } catch (error) { console.error(error); + utools.showNotification(`网络请求失败,请稍后再试`); } return db; }) @@ -78,14 +79,24 @@ const fundDetailsToCbList = (dbList: DBItem[]) => { }; return cb; }); - cbList = [ - { - title: `今日总收益 ${dbList.every(x => !x.data.isValuation) ? '✅' : ''}`, - description: `¥${sumIncome.toFixed(2)}`, - icon: sumIncome >= 0 ? 'assets/img/up.png' : 'assets/img/down.png', - }, - ...cbList, - ]; + if (cbList.length === 0) { + cbList = [ + { + title: ``, + description: ``, + icon: 'assets/img/add.png', + }, + ]; + } else { + cbList = [ + { + title: `今日总收益 ${dbList.every(x => !x.data.isValuation) ? '✅' : ''}`, + description: `¥${sumIncome.toFixed(2)}`, + icon: sumIncome >= 0 ? 'assets/img/up.png' : 'assets/img/down.png', + }, + ...cbList, + ]; + } return cbList; }; diff --git a/src/main.ts b/src/main.ts index ca79ccb..533ca9b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import fundDel from './features/fundDel'; import fundMarket from './features/fundMarket'; import fundExport from './features/fundExport'; import fundMy from './features/fundMy'; +import fundImport from './features/fundImport'; const preload: TemplatePlugin = { utools_fund_add: fundAdd, @@ -11,7 +12,7 @@ const preload: TemplatePlugin = { utools_fund_my: fundMy, utools_fund_market: fundMarket, utools_fund_config_export: fundExport, - utools_fund_config_import: fundExport, + utools_fund_config_import: fundImport, }; window.exports = preload; diff --git a/yarn.lock b/yarn.lock index 5e08275..5c40963 100644 --- a/yarn.lock +++ b/yarn.lock @@ -156,13 +156,6 @@ dir-glob@^3.0.1: dependencies: path-type "^4.0.0" -encoding@^0.1.13: - version "0.1.13" - resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9" - integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A== - dependencies: - iconv-lite "^0.6.2" - escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.npm.taobao.org/escape-string-regexp/download/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -260,13 +253,6 @@ has-flag@^4.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== -iconv-lite@^0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.2.tgz#ce13d1875b0c3a674bd6a04b7f76b01b1b6ded01" - integrity sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ== - dependencies: - safer-buffer ">= 2.1.2 < 3.0.0" - ignore@^5.1.1: version "5.1.8" resolved "https://registry.npm.taobao.org/ignore/download/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57" @@ -494,11 +480,6 @@ safe-buffer@^5.1.0: resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== -"safer-buffer@>= 2.1.2 < 3.0.0": - version "2.1.2" - resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" - integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== - serialize-javascript@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa"