feat🔫: new labels
This commit is contained in:
parent
53ac383f5b
commit
1d928b8a23
|
@ -133,10 +133,10 @@ function Record() {
|
|||
let classData: string[] = []
|
||||
switch (billType) {
|
||||
case BillType.CONSUME:
|
||||
classData = Object.keys(cls2label.consume)
|
||||
classData = cls2label.consume.map(it => it.name)
|
||||
break
|
||||
case BillType.INCOME:
|
||||
classData = cls2label.income
|
||||
classData = cls2label.income.map(it => it.name)
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ function Record() {
|
|||
value={cls === "" ? null : cls}
|
||||
onChange={c => {
|
||||
setCls(c)
|
||||
if (billType === BillType.CONSUME) setLabel(cls2label.consume[c][0])
|
||||
// if (billType === BillType.CONSUME) setLabel(cls2label.consume[c][0])
|
||||
}}
|
||||
>
|
||||
{
|
||||
|
@ -189,7 +189,8 @@ function Record() {
|
|||
value={label === "" ? null : label}
|
||||
onChange={setLabel}>
|
||||
{cls !== "" &&
|
||||
cls2label.consume[cls]
|
||||
cls2label.consume
|
||||
.find(it => it.name === cls)?.labels
|
||||
.map(la => <Select.Option key={la} value={la}>{la}</Select.Option>)
|
||||
}
|
||||
<Select.Option key={"other"} value={"其他"}>{"其他"}</Select.Option>)
|
||||
|
|
|
@ -3,6 +3,8 @@ import { createContext } from "react";
|
|||
import { createBill, getBills, getLabels } from "../api/bills";
|
||||
import { BillType, IBill } from "../model";
|
||||
import * as R from "ramda"
|
||||
import { BillLabel } from "./types";
|
||||
|
||||
|
||||
/**
|
||||
* 仅存储一个月的数据
|
||||
|
@ -10,7 +12,7 @@ import * as R from "ramda"
|
|||
export class Bill {
|
||||
private _bills: IBill[] = [];
|
||||
// _cls2label: IClass = {consume: new Map<string, string[]>(), income: []}
|
||||
private _cls2label: { consume: [], income: [] } = { consume: [], income: [] }
|
||||
private _cls2label: BillLabel = { consume: [], income: [] }
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this)
|
||||
|
@ -135,7 +137,7 @@ export class Bill {
|
|||
async fetchLabels() {
|
||||
const cls2label = await getLabels()
|
||||
runInAction(() => {
|
||||
this._cls2label == cls2label
|
||||
this._cls2label = cls2label
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
9
src/store/types.ts
Normal file
9
src/store/types.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
export type BillLabel = {
|
||||
consume: Array<BillLabelOption>,
|
||||
income: Array<BillLabelOption>,
|
||||
}
|
||||
|
||||
type BillLabelOption = {
|
||||
name: string,
|
||||
labels: Array<string>,
|
||||
}
|
Loading…
Reference in New Issue
Block a user