refact: @/utils/totalCost.tx

This commit is contained in:
2024-10-15 15:07:05 +08:00
parent ad291bd72e
commit 2670183343
5 changed files with 53 additions and 56 deletions

18
src/utils/totalCost.ts Normal file
View File

@@ -0,0 +1,18 @@
import { STORAGE_NAME_TOTALCOST } from "@/const";
export function addTotalCost(cost: number) {
let totalCost = getTotalCost();
totalCost += cost;
localStorage.setItem(STORAGE_NAME_TOTALCOST, `${totalCost}`);
}
export function getTotalCost(): number {
let totalCost = parseFloat(
localStorage.getItem(STORAGE_NAME_TOTALCOST) ?? "0"
);
return totalCost;
}
export function clearTotalCost() {
localStorage.setItem(STORAGE_NAME_TOTALCOST, `0`);
}