refact: @/utils/totalCost.tx
This commit is contained in:
18
src/utils/totalCost.ts
Normal file
18
src/utils/totalCost.ts
Normal 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`);
|
||||
}
|
||||
Reference in New Issue
Block a user