Skip to content

Commit 74624ef

Browse files
committed
stock history
1 parent 2e50cf8 commit 74624ef

File tree

10 files changed

+269
-38
lines changed

10 files changed

+269
-38
lines changed

src/@types/global.d.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@ declare global {
2222
status: number
2323
}
2424

25+
type XExtends<T, K extends string | number | symbol, V = any> = T & { [P in K]: V }
26+
27+
interface IPager {
28+
count: number
29+
page: number
30+
pageSize: number
31+
total: number
32+
totalPage: number
33+
showTotal: (total: number) => React.ReactNode
34+
}
35+
2536
interface IPageData<T = any> {
2637
data: T[]
27-
meta: {
28-
count?: number
29-
page: number
30-
pageSize: number
31-
total?: number
32-
totalPage?: number
33-
showTotal?: (total: number) => React.ReactNode
34-
}
38+
meta: Partial<IPager>
3539
msg?: string
3640
status?: number
3741
}

src/pages/stocks/history.tsx

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,68 @@
11
import React, { useState, useEffect } from 'react'
2+
import { Row, Col, Form, Table, Input, Button, Spin, Select } from 'antd'
3+
import { historyColumns } from './util'
4+
import { stockHistoryPageList, StockQuery } from '../../services/stockHistory'
5+
import { data2PageData, pageData2Params } from '../../utils/tools'
6+
import { marketOpts, blockOpts } from '../../types/stock'
7+
import { StockHistory } from '../../types/stockHistory'
28

3-
const ShareHistories: React.FC = () => {
4-
return <div></div>
9+
const ShareList: React.FC = () => {
10+
11+
const [form] = Form.useForm<StockQuery>()
12+
13+
const [loading, setLoading] = useState(false)
14+
const [pageData, setPageData] = useState(data2PageData<StockHistory>({
15+
data: [],
16+
meta: {page: 1, pageSize: 20, total: 0}
17+
}))
18+
19+
const onQuery = (params = pageData2Params(pageData.meta)) => {
20+
const vals = form.getFieldsValue()
21+
if(!vals.code) {
22+
return;
23+
}
24+
setLoading(true)
25+
stockHistoryPageList({...params, ...vals, }).then(res => {
26+
const data = data2PageData(res)
27+
setPageData(data)
28+
}).finally(() => setLoading(false))
29+
}
30+
31+
useEffect(() => {
32+
onQuery()
33+
}, [])
34+
35+
36+
return <Spin spinning={loading}>
37+
<Form form={form}>
38+
<Row gutter={16}>
39+
<Col span={6}>
40+
<Form.Item name="code">
41+
<Input allowClear placeholder="代码"/>
42+
</Form.Item>
43+
</Col>
44+
<Col span={6}>
45+
<Form.Item name="name">
46+
<Input allowClear placeholder="名称"/>
47+
</Form.Item>
48+
</Col>
49+
<Col span={6} offset={18}>
50+
<Button onClick={() => onQuery()}>查询</Button>
51+
</Col>
52+
</Row>
53+
</Form>
54+
<Table
55+
columns={historyColumns()}
56+
dataSource={pageData.data}
57+
key="code"
58+
scroll={{x: 2400}}
59+
pagination={{
60+
...pageData.meta,
61+
onChange: (page, pageSize) => onQuery({page, pageSize})
62+
}}
63+
/>
64+
</Spin>
565
}
666

7-
export default ShareHistories
67+
68+
export default ShareList

src/pages/stocks/historyDetail.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React, { useState, useEffect } from 'react'
2+
3+
const ShareHistories: React.FC = () => {
4+
return <div></div>
5+
}
6+
7+
export default ShareHistories

src/pages/stocks/index.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import React, { useState, useEffect } from 'react'
22
import { Row, Col, Form, Table, Input, Button, Spin, Select } from 'antd'
33
import { listColumns } from './util'
4-
import { stockPageList, IStockQuery } from '../../services/stock'
4+
import { stockPageList, StockQuery } from '../../services/stock'
55
import { data2PageData, pageData2Params } from '../../utils/tools'
6-
import { marketOpts, blockOpts } from '../../types/stock'
6+
import { Stock, marketOpts, blockOpts } from '../../types/stock'
77

88
const ShareList: React.FC = () => {
99

10-
const [code, setCode] = useState('')
11-
const [name, setName] = useState('')
10+
const [form] = Form.useForm<StockQuery>()
11+
1212
const [loading, setLoading] = useState(false)
13-
const [pageData, setPageData] = useState(data2PageData())
13+
const [pageData, setPageData] = useState(data2PageData<Stock>())
1414

15-
const onQuery = (params: Partial<IStockQuery> = pageData2Params(pageData.meta)) => {
15+
const onQuery = (params = pageData2Params(pageData.meta)) => {
16+
const vals = form.getFieldsValue()
1617
setLoading(true)
17-
stockPageList({...params, code, name}).then(res => {
18+
stockPageList({...params, ...vals}).then(res => {
1819
const data = data2PageData(res)
1920
setPageData(data)
2021
}).finally(() => setLoading(false))
@@ -26,26 +27,26 @@ const ShareList: React.FC = () => {
2627

2728

2829
return <Spin spinning={loading}>
29-
<Form>
30+
<Form form={form}>
3031
<Row gutter={16}>
3132
<Col span={6}>
32-
<Form.Item>
33-
<Input placeholder="代码" onChange={({target: {value}}) => setCode(value)}/>
33+
<Form.Item name="code">
34+
<Input allowClear placeholder="代码"/>
3435
</Form.Item>
3536
</Col>
3637
<Col span={6}>
37-
<Form.Item>
38-
<Input placeholder="名称" onChange={({target: {value}}) => setName(value)}/>
38+
<Form.Item name="name">
39+
<Input allowClear placeholder="名称"/>
3940
</Form.Item>
4041
</Col>
4142
<Col span={6}>
42-
<Form.Item>
43-
<Select placeholder="请选择市场"/>
43+
<Form.Item name="market">
44+
<Select allowClear placeholder="请选择市场" options={marketOpts()}/>
4445
</Form.Item>
4546
</Col>
4647
<Col span={6}>
47-
<Form.Item>
48-
<Select placeholder="请选择板块"/>
48+
<Form.Item name="block">
49+
<Select allowClear placeholder="请选择板块" options={blockOpts()}/>
4950
</Form.Item>
5051
</Col>
5152
</Row>
@@ -58,6 +59,7 @@ const ShareList: React.FC = () => {
5859
<Table
5960
columns={listColumns()}
6061
dataSource={pageData.data}
62+
key="code"
6163
pagination={{
6264
...pageData.meta,
6365
onChange: (page, pageSize) => onQuery({page, pageSize})

src/pages/stocks/util.tsx

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react'
22
import { ColumnProps } from 'antd/lib/table'
33
import { Stock, EMarket, EBlock } from '../../types/stock'
4+
import { StockHistory } from 'types/stockHistory'
45
import { Button } from 'antd'
56

67
export const listColumns = (): ColumnProps<Stock>[] => {
@@ -28,4 +29,121 @@ export const listColumns = (): ColumnProps<Stock>[] => {
2829
width: '30px',
2930
render: (v, data) => <Button type="link">查看</Button>
3031
}]
32+
}
33+
34+
export const historyColumns = (): ColumnProps<StockHistory>[] => {
35+
return [
36+
{
37+
title: '名称',
38+
dataIndex: 'name',
39+
width: '120px',
40+
fixed: 'left',
41+
},
42+
{
43+
title: '代码',
44+
dataIndex: 'code'
45+
},
46+
{
47+
title: '日期',
48+
dataIndex: 'tradeAt'
49+
},
50+
{
51+
title: '交易量',
52+
dataIndex: 'volume'
53+
},
54+
{
55+
title: '开盘',
56+
dataIndex: 'open'
57+
},
58+
{
59+
title: '最高',
60+
dataIndex: 'high'
61+
},
62+
{
63+
title: '最低',
64+
dataIndex: 'low'
65+
},
66+
{
67+
title: '收盘',
68+
dataIndex: 'close'
69+
},
70+
{
71+
title: '涨跌价',
72+
dataIndex: 'chg'
73+
},
74+
{
75+
title: '涨跌幅',
76+
dataIndex: 'percent'
77+
},
78+
{
79+
title: '换手率',
80+
dataIndex: 'turnoverrate'
81+
},
82+
{
83+
title: '成交额',
84+
dataIndex: 'amount'
85+
},
86+
// {
87+
// title: '交易量',
88+
// dataIndex: 'volume_post'
89+
// },
90+
// {
91+
// title: '交易量',
92+
// dataIndex: 'amount_post'
93+
// },
94+
{
95+
title: '市盈率(TTM)',
96+
dataIndex: 'pe'
97+
},
98+
{
99+
title: '市净率',
100+
dataIndex: 'pb'
101+
},
102+
{
103+
title: '市销率',
104+
dataIndex: 'ps'
105+
},
106+
{
107+
title: 'pcf',
108+
dataIndex: 'pcf'
109+
},
110+
{
111+
title: '总市值',
112+
dataIndex: 'market_capital'
113+
},
114+
// {
115+
// title: '交易量',
116+
// dataIndex: 'balance'
117+
// },
118+
// {
119+
// title: '交易量',
120+
// dataIndex: 'hold_volume_cn'
121+
// },
122+
// {
123+
// title: '交易量',
124+
// dataIndex: 'hold_ratio_cn'
125+
// },
126+
// {
127+
// title: '交易量',
128+
// dataIndex: 'net_volume_cn'
129+
// },
130+
// {
131+
// title: 'xx量',
132+
// dataIndex: 'hold_volume_hk'
133+
// },
134+
// {
135+
// title: '交易量',
136+
// dataIndex: 'hold_ratio_hk'
137+
// },
138+
// {
139+
// title: '交易量',
140+
// dataIndex: 'net_volume_hk'
141+
// },
142+
// {
143+
// title: '操作',
144+
// dataIndex: '',
145+
// width: '30px',
146+
// render: (v, data) => <Button type="link">查看</Button>
147+
// }
148+
]
31149
}

src/services/stock.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ import $http from '@utils/http'
22
import { pageData2Params } from '@utils/tools'
33
import { Stock } from 'types/stock'
44

5-
export interface IStockQuery extends IPageParams {
6-
code: string
7-
name: string
8-
market: string
9-
block: number
10-
}
115

12-
export const stockPageList = (params: Partial<IStockQuery> = pageData2Params()) => {
6+
export type StockQuery = Omit<Stock & IPageParams, 'id' | 'amount'>
7+
8+
export const stockPageList = (params: Partial<StockQuery> = pageData2Params()) => {
139
return $http.get<any, IPageData<Stock>>('/api/stocks', { params })
1410
}

src/services/stockHistory.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import $http from '@utils/http'
2+
import { pageData2Params } from '@utils/tools'
3+
import { Stock } from 'types/stock'
4+
import { StockHistory } from 'types/stockHistory'
5+
6+
7+
export type StockQuery = Omit<Stock & IPageParams, 'id' | 'amount'>
8+
9+
export const stockHistoryPageList = (params: Partial<StockQuery> = pageData2Params()) => {
10+
return $http.get<any, IPageData<StockHistory>>('/api/stockhistory', { params })
11+
}

src/types/stockHistory.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
3+
export class StockHistory {
4+
id: number
5+
stockId: number
6+
timestamp: number
7+
volume: number
8+
open: number
9+
high: number
10+
low: number
11+
close: number
12+
chg: number
13+
percent: number
14+
turnoverrate: number
15+
amount: number
16+
volume_post: number
17+
amount_post: number
18+
pe: number
19+
pb: number
20+
ps: number
21+
pcf: number
22+
market_capital: number
23+
balance: number
24+
hold_volume_cn: number
25+
hold_ratio_cn: number
26+
net_volume_cn: number
27+
hold_volume_hk: number
28+
hold_ratio_hk: number
29+
net_volume_hk: number
30+
31+
tradeAt: string
32+
}

src/utils/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const $http = axios.create({
1010
transformResponse: [function (data) {
1111
return data
1212
}],
13-
timeout: 60000 * 1
13+
timeout: 60000 * 2
1414
})
1515

1616
$http.interceptors.request.use(config => {

0 commit comments

Comments
 (0)