wip(freight): migration 0017 + model/column-list groundwork for add-freight-templates

This commit is contained in:
Chengdong Zhang
2026-09-23 17:39:45 +08:00
parent a83e857bdf
commit 5b426486ac
105 changed files with 6193 additions and 1566 deletions
+19 -8
View File
@@ -12,12 +12,15 @@ export function usePrice() {
async function ensureCurrencies(): Promise<Currency[]> {
if (currencies.value.length > 0) return currencies.value;
if (!currencyRequest.value) {
currencyRequest.value = $api.listCurrencies().then((list) => {
currencies.value = list;
return list;
}).finally(() => {
currencyRequest.value = null;
});
currencyRequest.value = $api
.listCurrencies()
.then((list) => {
currencies.value = list;
return list;
})
.finally(() => {
currencyRequest.value = null;
});
}
return currencyRequest.value;
}
@@ -26,7 +29,11 @@ export function usePrice() {
return currencies.value.find((item) => item.code === code)?.exponent ?? 2;
}
async function convertAmount(amountMinor: number, from: string, to = currency.value): Promise<number> {
async function convertAmount(
amountMinor: number,
from: string,
to = currency.value,
): Promise<number> {
if (from === to) return amountMinor;
const key = `${amountMinor}:${from}:${to}`;
const cached = cache.value.get(key);
@@ -36,7 +43,11 @@ export function usePrice() {
return converted.amount_minor;
}
async function formatPrice(amountMinor: number, from: string, to = currency.value): Promise<string> {
async function formatPrice(
amountMinor: number,
from: string,
to = currency.value,
): Promise<string> {
await ensureCurrencies();
const amount = await convertAmount(amountMinor, from, to);
return formatMoney(amount, to, exponentFor(to), locale.value);