feat🔫: bar点击 & fix🛠️: 修改部署脚本

This commit is contained in:
车厘子 2022-10-09 12:55:04 +08:00
parent 820226c08d
commit d27e2d9aae
8 changed files with 50 additions and 14 deletions

View File

@ -2,7 +2,7 @@ docker build . -t registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev
docker push registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev docker push registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev
ssh aliyun "cd /root/docker/bill-sys/; ssh fadinglight "cd /root/docker/bill-sys/;
docker compose down; docker compose down;
docker pull registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev; docker pull registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev;
docker compose up -d" docker compose up -d"

View File

@ -2,7 +2,7 @@ docker build . -t registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev
docker push registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev docker push registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react:dev
ssh aliyun "cd /root/docker/bill-sys/; ssh fadinglight "cd /root/docker/bill-sys/;
docker compose down; docker compose down;
docker pull registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-go:dev; docker pull registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-go:dev;
docker compose up -d" docker compose up -d"

View File

@ -17,6 +17,7 @@ interface IProps {
data: BarData[]; data: BarData[];
title?: string; title?: string;
subTitle?: string; subTitle?: string;
onClickItem?: (date: string) => void;
} }
export const Bar = (props: IProps) => { export const Bar = (props: IProps) => {
@ -84,9 +85,13 @@ export const Bar = (props: IProps) => {
}; };
}, [data, title, subTitle]) }, [data, title, subTitle])
const bar = useMemo(() => { const bar = useMemo(() => {
return chartRef.current ? echarts.init(chartRef.current, undefined, { renderer: "svg" }) : null; const chart = chartRef.current ? echarts.init(chartRef.current, undefined, { renderer: "svg" }) : null;
chart?.on('click', (params) => {
const date = dayjs(props.data[0].x).format("YYYY-") + params.name
if (props.onClickItem) props.onClickItem(date)
})
return chart
}, [chartRef.current]) }, [chartRef.current])
useEffect(() => { useEffect(() => {

View File

@ -1,4 +1,4 @@
.pie { .pie {
width: 100%; width: 400px;
height: 100%; height: 400px;
} }

View File

@ -6,9 +6,9 @@ import 'antd/dist/antd.css';
import './index.css' import './index.css'
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode> // <React.StrictMode>
<BrowserRouter> <BrowserRouter>
<App /> <App />
</BrowserRouter> </BrowserRouter>
</React.StrictMode> // </React.StrictMode>
) )

View File

@ -6,7 +6,13 @@ import { useContext, useEffect, useState } from "react";
import { BillContext } from "../../store"; import { BillContext } from "../../store";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import Pie from "../../components/charts/pie"; import Pie from "../../components/charts/pie";
import { Card, DatePicker, Radio, Space } from "antd"; import {
Card,
Modal,
DatePicker,
Radio,
Space,
} from "antd";
import moment from 'moment'; import moment from 'moment';
import 'moment/locale/zh-cn'; import 'moment/locale/zh-cn';
import dayjs from 'dayjs' import dayjs from 'dayjs'
@ -52,6 +58,14 @@ const Home = () => {
]; ];
const [billType, setBillType] = useState(BillType.consume) const [billType, setBillType] = useState(BillType.consume)
// 点击bar弹出当天pie
const [isModalOpen, setIsModalOpen] = useState(false);
const [modalTitle, setModalTitle] = useState("");
const [modalData, setModalData] = useState<{
x: string
y: number
}[]>([]);
return ( return (
<div className={styles.home}> <div className={styles.home}>
<div className={styles.total}> <div className={styles.total}>
@ -75,16 +89,33 @@ const Home = () => {
</Space> </Space>
</div> </div>
<div className={styles.monthBar}> <div className={styles.monthBar}>
<Bar data={transformer(billStore.groupByDate(billType))} /> <Bar
data={transformer(billStore.groupByDate(billType))}
onClickItem={date => {
setIsModalOpen(true)
setModalTitle(date)
setModalData(transformer(billStore.groupByClass(billType, date)))
}}
/>
</div> </div>
<div className={styles.cards}> <div className={styles.cards}>
<Card bodyStyle={{ height: 400, width: 400 }}> <Card >
<Pie <Pie
title="本月消费分类" title="本月消费分类"
data={transformer(billStore.groupByClass(billType))} data={transformer(billStore.groupByClass(billType))}
/> />
</Card> </Card>
</div> </div>
<Modal
visible={isModalOpen}
onOk={() => setIsModalOpen(false)}
onCancel={() => setIsModalOpen(false)}
title={modalTitle}
>
<Pie
data={modalData}
/>
</Modal>
</div> </div>
) )
} }

View File

@ -34,8 +34,8 @@ export class Bill {
return functions(this._bills) return functions(this._bills)
} }
groupByClass(type?: BillType) { groupByClass(type?: BillType, date?: string) {
const classFun = R.filter((bill: IBill) => R.of(bill.type).length === 0 || bill.type === type) const classFun = R.filter((bill: IBill) => R.of(bill.type).length === 0 || bill.type === type && (date ? bill.date === date : true))
const functions = R.compose( const functions = R.compose(
R.groupBy((bill: IBill) => bill.cls), R.groupBy((bill: IBill) => bill.cls),
classFun, classFun,

View File

@ -7,7 +7,7 @@ export default defineConfig({
server: { server: {
proxy: { proxy: {
"/api/": { "/api/": {
target: "http://www.fadinglight.cn:8080/", target: "http://www.fadinglight.cn:8088/",
changeOrigin: true, changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""), rewrite: (path) => path.replace(/^\/api/, ""),
} }