diff --git a/src/api/bills.ts b/src/api/bills.ts index f4fe86c..ac58057 100644 --- a/src/api/bills.ts +++ b/src/api/bills.ts @@ -2,16 +2,16 @@ import request from "./request"; import {IBill} from "../model"; export async function getBills(year: number, month: number) { - const data = await request.get(`/search/${year}/${month}`) + const data = await request.get(`/bill/${year}/${month}`) return data.data } -export async function getClass() { - const data = await request.get(`/class`) +export async function getLabels() { + const data = await request.get(`/label/`) return data.data } export async function createBill(bill: IBill) { - const data = await request.post(`/create`, bill) + const data = await request.post(`/bill/`, bill) return data.data } \ No newline at end of file diff --git a/src/api/request.ts b/src/api/request.ts index bc6a9d0..01b6b75 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -1,7 +1,7 @@ import axios from "axios"; const request = axios.create({ - baseURL: "/api", + baseURL: "/api/", timeout: 30000, }) diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index ee3ff60..90db489 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -111,7 +111,7 @@ const Home = () => { { clsesForShow.map(cls => { - return ( + return ( (), income: []} - private _cls2label: { consume: Record, income: [] } = { consume: {}, income: [] } + private _cls2label: { consume: [], income: [] } = { consume: [], income: [] } constructor() { makeAutoObservable(this) - this.fetchClass().then() + this.fetchLabels().then() } get bills() { @@ -118,14 +118,26 @@ export class Bill { async fetch(year: number, month: number) { const data = await getBills(year, month) runInAction(() => { - this._bills = data + this._bills = data.map((data: any) => { + return { + id: data.id, + type: data.type.toLowerCase() === 'income' ? BillType.income : BillType.consume, + date: data.date, + money: data.money, + cls: data.cls, + label: data.label, + options: data.options + } + }) }) } - async fetchClass() { - const cls2label = await getClass() + async fetchLabels() { + const cls2label = await getLabels() runInAction(() => { - this._cls2label = cls2label + if (cls2label.length > 0) { + this._cls2label == cls2label + } }) } } diff --git a/vite.config.ts b/vite.config.ts index 42d2d5c..98fba33 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ server: { proxy: { "/api/": { - target: "http://www.fadinglight.cn:8088/", + target: "http://localhost:8080/api/v1/", changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ""), }