feat🔫: new labels

This commit is contained in:
车厘子 2022-11-26 01:17:48 +08:00
parent 53ac383f5b
commit 1d928b8a23
3 changed files with 38 additions and 26 deletions

View File

@ -133,10 +133,10 @@ function Record() {
let classData: string[] = [] let classData: string[] = []
switch (billType) { switch (billType) {
case BillType.CONSUME: case BillType.CONSUME:
classData = Object.keys(cls2label.consume) classData = cls2label.consume.map(it => it.name)
break break
case BillType.INCOME: case BillType.INCOME:
classData = cls2label.income classData = cls2label.income.map(it => it.name)
break break
} }
@ -170,7 +170,7 @@ function Record() {
value={cls === "" ? null : cls} value={cls === "" ? null : cls}
onChange={c => { onChange={c => {
setCls(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} value={label === "" ? null : label}
onChange={setLabel}> onChange={setLabel}>
{cls !== "" && {cls !== "" &&
cls2label.consume[cls] cls2label.consume
.find(it => it.name === cls)?.labels
.map(la => <Select.Option key={la} value={la}>{la}</Select.Option>) .map(la => <Select.Option key={la} value={la}>{la}</Select.Option>)
} }
<Select.Option key={"other"} value={"其他"}>{"其他"}</Select.Option>) <Select.Option key={"other"} value={"其他"}>{"其他"}</Select.Option>)

View File

@ -3,6 +3,8 @@ import { createContext } from "react";
import { createBill, getBills, getLabels } 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"
import { BillLabel } from "./types";
/** /**
* *
@ -10,7 +12,7 @@ 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: [], income: [] } = { consume: [], income: [] } private _cls2label: BillLabel = { consume: [], income: [] }
constructor() { constructor() {
makeAutoObservable(this) makeAutoObservable(this)
@ -135,7 +137,7 @@ export class Bill {
async fetchLabels() { async fetchLabels() {
const cls2label = await getLabels() const cls2label = await getLabels()
runInAction(() => { runInAction(() => {
this._cls2label == cls2label this._cls2label = cls2label
}) })
} }
} }

9
src/store/types.ts Normal file
View File

@ -0,0 +1,9 @@
export type BillLabel = {
consume: Array<BillLabelOption>,
income: Array<BillLabelOption>,
}
type BillLabelOption = {
name: string,
labels: Array<string>,
}