to🛠️: new api
This commit is contained in:
parent
c4e66e2e52
commit
909adfead4
|
@ -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
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import axios from "axios";
|
||||
|
||||
const request = axios.create({
|
||||
baseURL: "/api",
|
||||
baseURL: "/api/",
|
||||
timeout: 30000,
|
||||
})
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ const Home = () => {
|
|||
</Card>
|
||||
{
|
||||
clsesForShow.map(cls => {
|
||||
return (<Card>
|
||||
return (<Card key={cls.toString()}>
|
||||
<Pie
|
||||
title={cls}
|
||||
data={transformer(billStore.groupByLabelOfClass(cls))}
|
||||
|
|
|
@ -130,7 +130,7 @@ function Record() {
|
|||
setUploadLoading(false)
|
||||
}
|
||||
|
||||
let classData: string[]
|
||||
let classData: string[] = []
|
||||
switch (billType) {
|
||||
case BillType.consume:
|
||||
classData = Object.keys(cls2label.consume)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
import { createContext } from "react";
|
||||
import { createBill, getBills, getClass } from "../api/bills";
|
||||
import { createBill, getBills, getLabels } from "../api/bills";
|
||||
import { BillType, IBill } from "../model";
|
||||
import * as R from "ramda"
|
||||
|
||||
|
@ -10,11 +10,11 @@ import * as R from "ramda"
|
|||
export class Bill {
|
||||
private _bills: IBill[] = [];
|
||||
// _cls2label: IClass = {consume: new Map<string, string[]>(), income: []}
|
||||
private _cls2label: { consume: Record<string, string[]>, 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
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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/, ""),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user