to🛠️: new api

This commit is contained in:
车厘子 2022-11-17 17:13:09 +08:00
parent c4e66e2e52
commit 909adfead4
6 changed files with 27 additions and 15 deletions

View File

@ -2,16 +2,16 @@ import request from "./request";
import {IBill} from "../model"; import {IBill} from "../model";
export async function getBills(year: number, month: number) { 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 return data.data
} }
export async function getClass() { export async function getLabels() {
const data = await request.get(`/class`) const data = await request.get(`/label/`)
return data.data return data.data
} }
export async function createBill(bill: IBill) { export async function createBill(bill: IBill) {
const data = await request.post(`/create`, bill) const data = await request.post(`/bill/`, bill)
return data.data return data.data
} }

View File

@ -1,7 +1,7 @@
import axios from "axios"; import axios from "axios";
const request = axios.create({ const request = axios.create({
baseURL: "/api", baseURL: "/api/",
timeout: 30000, timeout: 30000,
}) })

View File

@ -111,7 +111,7 @@ const Home = () => {
</Card> </Card>
{ {
clsesForShow.map(cls => { clsesForShow.map(cls => {
return (<Card> return (<Card key={cls.toString()}>
<Pie <Pie
title={cls} title={cls}
data={transformer(billStore.groupByLabelOfClass(cls))} data={transformer(billStore.groupByLabelOfClass(cls))}

View File

@ -130,7 +130,7 @@ function Record() {
setUploadLoading(false) setUploadLoading(false)
} }
let classData: string[] let classData: string[] = []
switch (billType) { switch (billType) {
case BillType.consume: case BillType.consume:
classData = Object.keys(cls2label.consume) classData = Object.keys(cls2label.consume)

View File

@ -1,6 +1,6 @@
import { makeAutoObservable, runInAction } from "mobx"; import { makeAutoObservable, runInAction } from "mobx";
import { createContext } from "react"; import { createContext } from "react";
import { createBill, getBills, getClass } from "../api/bills"; import { createBill, getBills, getLabels } from "../api/bills";
import { BillType, IBill } from "../model"; import { BillType, IBill } from "../model";
import * as R from "ramda" import * as R from "ramda"
@ -10,11 +10,11 @@ import * as R from "ramda"
export class Bill { export class Bill {
private _bills: IBill[] = []; private _bills: IBill[] = [];
// _cls2label: IClass = {consume: new Map<string, string[]>(), income: []} // _cls2label: IClass = {consume: new Map<string, string[]>(), income: []}
private _cls2label: { consume: Record<string, string[]>, income: [] } = { consume: {}, income: [] } private _cls2label: { consume: [], income: [] } = { consume: [], income: [] }
constructor() { constructor() {
makeAutoObservable(this) makeAutoObservable(this)
this.fetchClass().then() this.fetchLabels().then()
} }
get bills() { get bills() {
@ -118,14 +118,26 @@ export class Bill {
async fetch(year: number, month: number) { async fetch(year: number, month: number) {
const data = await getBills(year, month) const data = await getBills(year, month)
runInAction(() => { 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() { async fetchLabels() {
const cls2label = await getClass() const cls2label = await getLabels()
runInAction(() => { runInAction(() => {
this._cls2label = cls2label if (cls2label.length > 0) {
this._cls2label == cls2label
}
}) })
} }
} }

View File

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