From 1e40123788202111364a71734e8da41a35dacf47 Mon Sep 17 00:00:00 2001 From: 1zilc <44715458+1zilc@users.noreply.github.com> Date: Thu, 20 Jul 2023 15:10:00 +0800 Subject: [PATCH] V8.0.1 (#631) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复数据合并导致的折叠问题 * fix: 修复股吧数据 * fix: 修复row折叠问题 * fix: 修复QuotationFlow样式 * fix: 修复基金经理页面错误 * bump: 8.0.1 --- release/app/package.json | 2 +- .../Home/FundView/DetailFundContent/index.tsx | 3 +- .../FundView/FundManagerContent/index.tsx | 3 +- .../QuotationFlow/index.module.scss | 2 +- src/renderer/helpers/base.ts | 10 + src/renderer/services/news.ts | 264 +++++++++++------- src/renderer/store/features/wallet.ts | 29 +- 7 files changed, 210 insertions(+), 103 deletions(-) diff --git a/release/app/package.json b/release/app/package.json index abe3f91eb..23c6d90a2 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -1,7 +1,7 @@ { "name": "fishing-funds", "productName": "Fishing Funds", - "version": "8.0.0", + "version": "8.0.1", "main": "./dist/main/index.js", "description": "基金,大盘,股票,虚拟货币状态栏显示小应用,基于Electron开发,支持 MacOS,Windows,Linux客户端,数据源来自天天基金,蚂蚁基金,爱基金,腾讯证券等", "author": { diff --git a/src/renderer/components/Home/FundView/DetailFundContent/index.tsx b/src/renderer/components/Home/FundView/DetailFundContent/index.tsx index 900872206..23fa61f17 100644 --- a/src/renderer/components/Home/FundView/DetailFundContent/index.tsx +++ b/src/renderer/components/Home/FundView/DetailFundContent/index.tsx @@ -87,8 +87,7 @@ export const DetailFund: React.FC = (props) => { const { star: fundStar, type: fundType } = useFundRating(code); const codeMap = useAppSelector((state) => state.wallet.fundConfigCodeMap); const { data: addCode, show: showAddDrawer, set: setAddDrawer, close: closeAddDrawer } = useDrawer(code); - const [showManagerDrawer, { setTrue: openManagerDrawer, setFalse: closeManagerDrawer, toggle: ToggleManagerDrawer }] = - useBoolean(false); + const [showManagerDrawer, { setTrue: openManagerDrawer, setFalse: closeManagerDrawer }] = useBoolean(false); const { data: fund = {} } = useRequest(() => Services.Fund.GetFixFromEastMoney(code)); const { data: pingzhongdata = {} as Fund.PingzhongData | Record, run: runGetFundDetailFromEastmoney } = diff --git a/src/renderer/components/Home/FundView/FundManagerContent/index.tsx b/src/renderer/components/Home/FundView/FundManagerContent/index.tsx index 60d9a9d15..2a50ca7e6 100644 --- a/src/renderer/components/Home/FundView/FundManagerContent/index.tsx +++ b/src/renderer/components/Home/FundView/FundManagerContent/index.tsx @@ -25,7 +25,7 @@ export interface ManagerDetail { } const FundManagerContent: React.FC = (props) => { - const { manager } = props; + const { manager = {} as Fund.Manager.Info } = props; const ref = useRef(null); const position = useScroll(ref, (val) => val.top <= 520); const miniMode = position && position.top > 40; @@ -37,6 +37,7 @@ const FundManagerContent: React.FC = (props) => { }, } = useRequest(Services.Fund.GetFundManagerDetailFromEastMoney, { defaultParams: [manager.id], + ready: !!manager.id, }); return ( diff --git a/src/renderer/components/Home/QuotationView/QuotationFlow/index.module.scss b/src/renderer/components/Home/QuotationView/QuotationFlow/index.module.scss index 32316d2d5..858ac950d 100644 --- a/src/renderer/components/Home/QuotationView/QuotationFlow/index.module.scss +++ b/src/renderer/components/Home/QuotationView/QuotationFlow/index.module.scss @@ -1,4 +1,4 @@ .content { display: block; - height: calc(100vh - 202px); + height: calc(100vh - 220px); } diff --git a/src/renderer/helpers/base.ts b/src/renderer/helpers/base.ts index 5dc69e312..9f7999f1a 100644 --- a/src/renderer/helpers/base.ts +++ b/src/renderer/helpers/base.ts @@ -31,6 +31,16 @@ export function Update(config: { key: keyof T; list: T[]; data: T return list as Required[]; } +export function Merge(config: { data: T; overide: Partial }) { + const { overide, data } = config; + + Object.keys(overide).forEach((k) => { + (data[k as keyof T] as any) = overide[k as keyof T]; + }); + + return data; +} + export function Delete(config: { key: keyof T; list: T[]; data: string }) { const { list, key, data } = config; diff --git a/src/renderer/services/news.ts b/src/renderer/services/news.ts index 29ce30564..4e58d7835 100644 --- a/src/renderer/services/news.ts +++ b/src/renderer/services/news.ts @@ -1,3 +1,4 @@ +import dayjs from 'dayjs'; import request from '@/utils/request'; import cheerio from 'cheerio'; import * as Enums from '@/utils/enums'; @@ -5,12 +6,15 @@ import * as Enums from '@/utils/enums'; // 获取股市直播 export async function GetLiveList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_zhiboall_ajaxResult_70_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_zhiboall_ajaxResult_70_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -24,12 +28,15 @@ export async function GetLiveList() { // 获取焦点新闻 export async function GetFocusList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_101_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_101_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -43,12 +50,15 @@ export async function GetFocusList() { // 获取上市公司新闻 export async function GetListedList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_103_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_103_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -62,12 +72,15 @@ export async function GetListedList() { // 获取全球新闻 export async function GetGlobalList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_102_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_102_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -81,12 +94,15 @@ export async function GetGlobalList() { // 获取商品 export async function GetGoodsList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_106_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_106_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -100,12 +116,15 @@ export async function GetGoodsList() { // 获取外汇 export async function GetExchangeList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_107_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_107_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -119,12 +138,15 @@ export async function GetExchangeList() { // 获取债券 export async function GetBondList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_108_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_108_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -138,12 +160,15 @@ export async function GetBondList() { // 获取基金 export async function GetFundList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_109_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_109_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -157,12 +182,15 @@ export async function GetFundList() { // 获取中国央行 export async function GetChinaList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_118_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_118_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -176,12 +204,15 @@ export async function GetChinaList() { // 获取美联储 export async function GetUsaList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_119_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_119_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -195,12 +226,15 @@ export async function GetUsaList() { // 获取欧洲央行 export async function GetEuList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_120_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_120_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -214,12 +248,15 @@ export async function GetEuList() { // 获取英国央行 export async function GetUkList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_121_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_121_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -233,12 +270,15 @@ export async function GetUkList() { // 获取日本央行 export async function GetJpList() { try { - const { body: script } = await request(`https://newsapi.eastmoney.com/kuaixun/v1/getlist_122_ajaxResult_50_1_.html`, { - responseType: 'text', - searchParams: { - _: Date.now(), - }, - }); + const { body: script } = await request( + `https://newsapi.eastmoney.com/kuaixun/v1/getlist_122_ajaxResult_50_1_.html`, + { + responseType: 'text', + searchParams: { + _: Date.now(), + }, + } + ); const list: News.ResponseItem[] = eval(`(()=>{ ${script} @@ -268,7 +308,14 @@ export async function GetRecent(keyword: string, pageindex: number, type: string clientType: 'web', clientVersion: 'curr', param: { - cmsArticleWebOld: { searchScope: type, sort: 'default', pageindex, pageSize: 10, preTag: '', postTag: '' }, + cmsArticleWebOld: { + searchScope: type, + sort: 'default', + pageindex, + pageSize: 10, + preTag: '', + postTag: '', + }, }, }), cb: 'cb', @@ -305,7 +352,9 @@ export async function GetGuBaList(code: string, category: '' | '100' | '102' | ' client: 'web', clientVersion: 'curr', clientType: 'web', - param: { gubaCodetableWeb: { pageSize: 90, pageIndex: 1, postTag: '', preTag: '', filter: `category:${category}` } }, + param: { + gubaCodetableWeb: { pageSize: 90, pageIndex: 1, postTag: '', preTag: '', filter: `category:${category}` }, + }, }), _: Date.now(), }, @@ -334,25 +383,46 @@ export async function GetGuBaList(code: string, category: '' | '100' | '102' | ' searchId: '3b5b60e7-a060-4faa-bc24-9ee6fe89d5d5'; } = eval(script); - const { body: html } = await request(data.result.gubaCodetableWeb[0].url, { + const url = data.result.gubaCodetableWeb[0].url; + const { body: html } = await request(url, { responseType: 'text', }); - const $ = cheerio.load(html); - const list = $('.articleh.normal_post') - .map(function () { - const a = $(this).find('.l3 > a'); - const time = $(this).find('.l5').text(); - const title = a.text(); - const url = a.attr('href'); - return { title, url, time }; - }) - .toArray() - .filter((item) => item.url?.startsWith('/news')) - .map((item) => ({ - ...item, - url: `http://guba.eastmoney.com${item.url}`, - })); - return list; + + // 旧版股吧 + if (category === '105') { + const $ = cheerio.load(html); + const list = $('.articleh.normal_post') + .map(function () { + const a = $(this).find('.l3 > a'); + const time = $(this).find('.l5').text(); + const title = a.text(); + const url = a.attr('href'); + return { title, url, time }; + }) + .toArray() + .filter((item) => item.url?.startsWith('/news')) + .map((item) => ({ + ...item, + url: `http://guba.eastmoney.com${item.url}`, + })); + return list; + } else { + const script = html.match(/var article_list=.*?;/); + const article_list = eval(`(()=>{ + ${script} + return article_list; + })()`); + + return article_list.re + .filter((item: any) => item.post_type === 0) + .map((item: any) => { + return { + time: dayjs(item.post_publish_time).format('MM-DD HH:mm'), + title: item.post_title, + url: `${url.replace('list', 'news').replace('.html', '')},${item.post_id}.html`, + }; + }); + } } catch (e) { return []; } diff --git a/src/renderer/store/features/wallet.ts b/src/renderer/store/features/wallet.ts index 858dad2ef..96c54f0c7 100644 --- a/src/renderer/store/features/wallet.ts +++ b/src/renderer/store/features/wallet.ts @@ -101,11 +101,23 @@ const walletSlice = createSlice({ key: 'fundcode', data: payload, }); + Helpers.Base.Replace({ + list: state.wallets, + key: 'code', + data: state.currentWalletCode, + cover: state.currentWallet, + }); }, toggleAllFundsCollapseAction(state) { Helpers.Base.CollapseAll({ list: state.currentWallet.funds, }); + Helpers.Base.Replace({ + list: state.wallets, + key: 'code', + data: state.currentWalletCode, + cover: state.currentWallet, + }); }, toggleStockCollapseAction(state, { payload }: PayloadAction) { Helpers.Base.Collapse({ @@ -113,11 +125,23 @@ const walletSlice = createSlice({ key: 'secid', data: payload, }); + Helpers.Base.Replace({ + list: state.wallets, + key: 'code', + data: state.currentWalletCode, + cover: state.currentWallet, + }); }, toggleAllStocksCollapseAction(state) { Helpers.Base.CollapseAll({ list: state.currentWallet.stocks, }); + Helpers.Base.Replace({ + list: state.wallets, + key: 'code', + data: state.currentWalletCode, + cover: state.currentWallet, + }); }, }, }); @@ -284,10 +308,13 @@ export const setWalletStateAction = createAsyncThunk< wallet: { wallets }, } = getState(); + const currentWallet = Helpers.Wallet.GetCurrentWalletState(state.code, wallets); + const mergedWallet = Helpers.Base.Merge({ data: Utils.DeepCopy(currentWallet), overide: state }); + const config = Helpers.Base.Update({ list: Utils.DeepCopy(wallets), key: 'code', - data: state, + data: mergedWallet, }); dispatch(syncWalletsAction(config));