feat(mall): live flash-sale page and activity price snapshots
The flash-sale page loads active sessions and their items through the shared client with live sale price, remaining activity stock, sell-through, and a countdown, and adds the SKU to the existing cart so checkout resolves the authoritative price. Payment and order detail tag and render the snapshotted activity unit price. The flash-sale fixtures leave the page; the fixed-data adapter still serves the domain as the rollback path.
This commit is contained in:
@@ -11,6 +11,8 @@ export default {
|
|||||||
originalPrice: "Original price",
|
originalPrice: "Original price",
|
||||||
progress: "Sold {n}%",
|
progress: "Sold {n}%",
|
||||||
buyNow: "Grab now",
|
buyNow: "Grab now",
|
||||||
|
grabFailed: "Unable to add this item right now.",
|
||||||
|
flashTag: "Flash sale",
|
||||||
noSeckillProducts: "No flash-sale products right now.",
|
noSeckillProducts: "No flash-sale products right now.",
|
||||||
collectiveTitle: "Group deals",
|
collectiveTitle: "Group deals",
|
||||||
collectiveBreadcrumb: "Group deals",
|
collectiveBreadcrumb: "Group deals",
|
||||||
@@ -69,6 +71,8 @@ export default {
|
|||||||
originalPrice: "原价",
|
originalPrice: "原价",
|
||||||
progress: "已抢 {n}%",
|
progress: "已抢 {n}%",
|
||||||
buyNow: "马上抢",
|
buyNow: "马上抢",
|
||||||
|
grabFailed: "加入购物车失败,请稍后重试。",
|
||||||
|
flashTag: "秒杀价",
|
||||||
noSeckillProducts: "当前暂无秒杀商品。",
|
noSeckillProducts: "当前暂无秒杀商品。",
|
||||||
collectiveTitle: "拼团购",
|
collectiveTitle: "拼团购",
|
||||||
collectiveBreadcrumb: "拼团",
|
collectiveBreadcrumb: "拼团",
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ import type {
|
|||||||
Coupon,
|
Coupon,
|
||||||
CouponTemplate,
|
CouponTemplate,
|
||||||
CouponTemplateInput,
|
CouponTemplateInput,
|
||||||
|
FlashSaleItem,
|
||||||
|
FlashSaleItemInput,
|
||||||
|
FlashSaleSession,
|
||||||
|
FlashSaleSessionInput,
|
||||||
HomeContent,
|
HomeContent,
|
||||||
IntegralOrder,
|
IntegralOrder,
|
||||||
IntegralProduct,
|
IntegralProduct,
|
||||||
@@ -23,6 +27,7 @@ import type {
|
|||||||
InvoiceKind,
|
InvoiceKind,
|
||||||
Order,
|
Order,
|
||||||
Product,
|
Product,
|
||||||
|
PublicFlashSaleSession,
|
||||||
RedeemPointsBody,
|
RedeemPointsBody,
|
||||||
Shipment,
|
Shipment,
|
||||||
ShopProfile,
|
ShopProfile,
|
||||||
@@ -43,9 +48,11 @@ import {
|
|||||||
USER_STATS,
|
USER_STATS,
|
||||||
MOCK_ADDRESSES,
|
MOCK_ADDRESSES,
|
||||||
defaultAddress,
|
defaultAddress,
|
||||||
|
lowestSku,
|
||||||
mockConvertMinor,
|
mockConvertMinor,
|
||||||
productById,
|
productById,
|
||||||
searchMockProducts,
|
searchMockProducts,
|
||||||
|
seckillProducts,
|
||||||
seedOrders,
|
seedOrders,
|
||||||
storeById,
|
storeById,
|
||||||
} from "./data";
|
} from "./data";
|
||||||
@@ -150,6 +157,46 @@ function seedPointsProducts(): IntegralProduct[] {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** One synthesized active session covering the fixed seckill fixtures. */
|
||||||
|
function mockFlashSales(): PublicFlashSaleSession[] {
|
||||||
|
const now = Date.now();
|
||||||
|
const items = seckillProducts().map((entry, index) => {
|
||||||
|
const sku = lowestSku(entry.product);
|
||||||
|
const stock = sku?.stock ?? 100;
|
||||||
|
const sold = Math.round((stock * entry.soldPct) / 100);
|
||||||
|
return {
|
||||||
|
id: `fsi${index + 1}`,
|
||||||
|
session_id: "fs1",
|
||||||
|
sku_id: sku?.id ?? "",
|
||||||
|
product_id: entry.product.id,
|
||||||
|
product_slug: entry.product.slug,
|
||||||
|
product_name: entry.product.name,
|
||||||
|
image: entry.product.images[0] ?? null,
|
||||||
|
sku_code: sku?.sku_code ?? "",
|
||||||
|
sale_price_minor: entry.seckillPriceMinor,
|
||||||
|
currency: sku?.currency ?? BASE_CURRENCY,
|
||||||
|
original_price_minor: sku?.price_minor ?? entry.seckillPriceMinor,
|
||||||
|
original_currency: sku?.currency ?? BASE_CURRENCY,
|
||||||
|
reserved_stock: Math.max(stock - sold, 0),
|
||||||
|
sold_count: sold,
|
||||||
|
per_customer_limit: 2,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: "fs1",
|
||||||
|
shop_id: MOCK_STORES[0].id,
|
||||||
|
label: { en: "Flash sale", zh: "限时秒杀" },
|
||||||
|
starts_at: new Date(now - 3_600_000).toISOString(),
|
||||||
|
ends_at: new Date(now + 6 * 3_600_000).toISOString(),
|
||||||
|
enabled: true,
|
||||||
|
created_at: "2026-01-01T00:00:00.000Z",
|
||||||
|
updated_at: "2026-01-01T00:00:00.000Z",
|
||||||
|
items,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
function initialState(): MockState {
|
function initialState(): MockState {
|
||||||
const persisted = loadPersisted();
|
const persisted = loadPersisted();
|
||||||
// Coupons and points are session-only, so a restored snapshot re-seeds them.
|
// Coupons and points are session-only, so a restored snapshot re-seeds them.
|
||||||
@@ -397,6 +444,7 @@ export function createMockApi(): ApiClient {
|
|||||||
unit_price_minor: i.unit_price_minor,
|
unit_price_minor: i.unit_price_minor,
|
||||||
qty: i.qty,
|
qty: i.qty,
|
||||||
image: i.image,
|
image: i.image,
|
||||||
|
flash_sale_item_id: null,
|
||||||
})),
|
})),
|
||||||
shipping_address: shippingAddress,
|
shipping_address: shippingAddress,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
@@ -630,6 +678,8 @@ export function createMockApi(): ApiClient {
|
|||||||
state.pointsProducts.filter((p) => p.published).map((p) => ({ ...p })),
|
state.pointsProducts.filter((p) => p.published).map((p) => ({ ...p })),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
listFlashSales: () => Promise.resolve(mockFlashSales()),
|
||||||
|
|
||||||
listMyRedemptions: () => Promise.resolve(state.redemptions.map((o) => ({ ...o }))),
|
listMyRedemptions: () => Promise.resolve(state.redemptions.map((o) => ({ ...o }))),
|
||||||
|
|
||||||
redeemPoints: (body: RedeemPointsBody) => {
|
redeemPoints: (body: RedeemPointsBody) => {
|
||||||
@@ -693,6 +743,13 @@ export function createMockApi(): ApiClient {
|
|||||||
createCouponTemplate: (_body: CouponTemplateInput) => unsupported(),
|
createCouponTemplate: (_body: CouponTemplateInput) => unsupported(),
|
||||||
updateCouponTemplate: (_id: string, _body: CouponTemplateInput) => unsupported(),
|
updateCouponTemplate: (_id: string, _body: CouponTemplateInput) => unsupported(),
|
||||||
deleteCouponTemplate: (_id: string) => unsupported(),
|
deleteCouponTemplate: (_id: string) => unsupported(),
|
||||||
|
listFlashSales: () => unsupported(),
|
||||||
|
createFlashSale: (_body: FlashSaleSessionInput) => unsupported(),
|
||||||
|
updateFlashSale: (_id: string, _body: FlashSaleSessionInput) => unsupported(),
|
||||||
|
deleteFlashSale: (_id: string) => unsupported(),
|
||||||
|
addFlashSaleItem: (_sessionId: string, _body: FlashSaleItemInput) => unsupported(),
|
||||||
|
updateFlashSaleItem: (_id: string, _body: FlashSaleItemInput) => unsupported(),
|
||||||
|
deleteFlashSaleItem: (_id: string) => unsupported(),
|
||||||
},
|
},
|
||||||
admin: {
|
admin: {
|
||||||
listUsers: () => unsupported(),
|
listUsers: () => unsupported(),
|
||||||
|
|||||||
@@ -692,6 +692,7 @@ export function seedOrders(userId: string): MockOrderSeed {
|
|||||||
unit_price_minor: sku.price_minor,
|
unit_price_minor: sku.price_minor,
|
||||||
qty,
|
qty,
|
||||||
image: product.images[0] ?? null,
|
image: product.images[0] ?? null,
|
||||||
|
flash_sale_item_id: null,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const total = items.reduce((sum, it) => sum + it.unit_price_minor * it.qty, 0);
|
const total = items.reduce((sum, it) => sum + it.unit_price_minor * it.qty, 0);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default defineNuxtConfig({
|
|||||||
// Domains served by the live backend; every other domain stays on the
|
// Domains served by the live backend; every other domain stays on the
|
||||||
// fixed-data adapter. Override with NUXT_PUBLIC_LIVE_DOMAINS='["catalog"]'.
|
// fixed-data adapter. Override with NUXT_PUBLIC_LIVE_DOMAINS='["catalog"]'.
|
||||||
// See openspec/changes/replace-mock-api-wave-1/design.md and waves 2-3.
|
// See openspec/changes/replace-mock-api-wave-1/design.md and waves 2-3.
|
||||||
liveDomains: ["catalog", "currency", "content", "shops", "brands", "auth", "account", "cart", "orders", "shipments", "invoices", "addresses", "coupons", "points"],
|
liveDomains: ["catalog", "currency", "content", "shops", "brands", "auth", "account", "cart", "orders", "shipments", "invoices", "addresses", "coupons", "points", "flashSales"],
|
||||||
appName: "mall",
|
appName: "mall",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ onMounted(() => void loadOrders());
|
|||||||
<div class="item-info">
|
<div class="item-info">
|
||||||
<strong>{{ pick(item.product_name, locale) }}</strong>
|
<strong>{{ pick(item.product_name, locale) }}</strong>
|
||||||
<span class="muted">{{ item.sku_code }}</span>
|
<span class="muted">{{ item.sku_code }}</span>
|
||||||
|
<span v-if="item.flash_sale_item_id" class="activity-tag">{{ t("marketing.flashTag") }}</span>
|
||||||
</div>
|
</div>
|
||||||
<PriceText :amount-minor="item.unit_price_minor" :currency="order.currency" />
|
<PriceText :amount-minor="item.unit_price_minor" :currency="order.currency" />
|
||||||
<span class="qty">× {{ item.qty }}</span>
|
<span class="qty">× {{ item.qty }}</span>
|
||||||
@@ -233,6 +234,13 @@ onMounted(() => void loadOrders());
|
|||||||
.discount-value {
|
.discount-value {
|
||||||
color: var(--mall-red);
|
color: var(--mall-red);
|
||||||
}
|
}
|
||||||
|
.activity-tag {
|
||||||
|
align-self: flex-start;
|
||||||
|
padding: 1px 6px;
|
||||||
|
border: 1px solid var(--mall-red);
|
||||||
|
color: var(--mall-red);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
.payment-panel {
|
.payment-panel {
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
padding: 0 18px 16px;
|
padding: 0 18px 16px;
|
||||||
|
|||||||
+88
-58
@@ -1,12 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { t as pick } from "@vmall/shared";
|
import { t as pick } from "@vmall/shared";
|
||||||
import { lowestSku, SECKILL_SESSIONS, seckillProducts } from "~/mock/data";
|
import type { PublicFlashSaleItem, PublicFlashSaleSession } from "@vmall/shared";
|
||||||
import type { Product } from "@vmall/shared";
|
|
||||||
|
|
||||||
const { locale, t } = useI18n();
|
const { locale, t } = useI18n();
|
||||||
|
const { $api } = useNuxtApp();
|
||||||
|
const cart = useCartStore();
|
||||||
|
const sessions = ref<PublicFlashSaleSession[]>([]);
|
||||||
const activeSessionIndex = ref(0);
|
const activeSessionIndex = ref(0);
|
||||||
const remainingSeconds = ref(0);
|
const remainingSeconds = ref(0);
|
||||||
const products = seckillProducts();
|
const loading = ref(true);
|
||||||
|
const addingSkuId = ref("");
|
||||||
|
const error = ref("");
|
||||||
let countdownTimer: ReturnType<typeof setInterval> | undefined;
|
let countdownTimer: ReturnType<typeof setInterval> | undefined;
|
||||||
|
|
||||||
const breadcrumb = computed(() => [
|
const breadcrumb = computed(() => [
|
||||||
@@ -14,31 +18,20 @@ const breadcrumb = computed(() => [
|
|||||||
{ label: t("marketing.seckillBreadcrumb") },
|
{ label: t("marketing.seckillBreadcrumb") },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const activeSession = computed(() => SECKILL_SESSIONS[activeSessionIndex.value] ?? SECKILL_SESSIONS[0]);
|
const activeSession = computed<PublicFlashSaleSession | null>(
|
||||||
|
() => sessions.value[activeSessionIndex.value] ?? sessions.value[0] ?? null,
|
||||||
function setCurrentSession(): void {
|
);
|
||||||
const hour = new Date().getHours();
|
|
||||||
const index = SECKILL_SESSIONS.findIndex((session) => hour >= session.startHour && hour < session.endHour);
|
|
||||||
activeSessionIndex.value = index >= 0 ? index : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateCountdown(): void {
|
function updateCountdown(): void {
|
||||||
const now = new Date();
|
|
||||||
const session = activeSession.value;
|
const session = activeSession.value;
|
||||||
const end = new Date(now);
|
if (!session) {
|
||||||
if (session.endHour === 24) {
|
remainingSeconds.value = 0;
|
||||||
end.setDate(end.getDate() + 1);
|
|
||||||
end.setHours(0, 0, 0, 0);
|
|
||||||
} else {
|
|
||||||
end.setHours(session.endHour, 0, 0, 0);
|
|
||||||
}
|
|
||||||
const seconds = Math.max(0, Math.ceil((end.getTime() - now.getTime()) / 1000));
|
|
||||||
if (seconds === 0) {
|
|
||||||
setCurrentSession();
|
|
||||||
updateCountdown();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
remainingSeconds.value = seconds;
|
remainingSeconds.value = Math.max(
|
||||||
|
0,
|
||||||
|
Math.ceil((new Date(session.ends_at).getTime() - Date.now()) / 1000),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatCountdown(seconds: number): string {
|
function formatCountdown(seconds: number): string {
|
||||||
@@ -49,29 +42,42 @@ function formatCountdown(seconds: number): string {
|
|||||||
return `${p(h)}:${p(m)}:${p(s)}`;
|
return `${p(h)}:${p(m)}:${p(s)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sessionState(index: number): "current" | "upcoming" | "ended" {
|
function soldPct(item: PublicFlashSaleItem): number {
|
||||||
if (index === activeSessionIndex.value) return "current";
|
const total = item.sold_count + item.reserved_stock;
|
||||||
return index < activeSessionIndex.value ? "ended" : "upcoming";
|
if (total <= 0) return 100;
|
||||||
|
return Math.round((item.sold_count / total) * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sessionStateLabel(index: number): string {
|
// The listing price is display only: the shopper adds the SKU to the cart and
|
||||||
const state = sessionState(index);
|
// checkout resolves the authoritative price server-side.
|
||||||
if (state === "current") return t("marketing.currentSession");
|
async function addToCart(item: PublicFlashSaleItem): Promise<void> {
|
||||||
if (state === "ended") return t("marketing.ended");
|
addingSkuId.value = item.sku_id;
|
||||||
return t("marketing.upcoming");
|
error.value = "";
|
||||||
}
|
try {
|
||||||
function priceMinorOf(product: Product): number {
|
await $api.addCartItem(item.sku_id, 1);
|
||||||
return lowestSku(product)?.price_minor ?? 0;
|
await cart.refresh();
|
||||||
|
} catch {
|
||||||
|
error.value = t("marketing.grabFailed");
|
||||||
|
} finally {
|
||||||
|
addingSkuId.value = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function currencyOf(product: Product): string {
|
async function load(): Promise<void> {
|
||||||
return lowestSku(product)?.currency ?? "USD";
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
sessions.value = await $api.listFlashSales();
|
||||||
|
activeSessionIndex.value = 0;
|
||||||
|
updateCountdown();
|
||||||
|
} catch {
|
||||||
|
sessions.value = [];
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
onMounted(() => {
|
await load();
|
||||||
setCurrentSession();
|
|
||||||
updateCountdown();
|
|
||||||
countdownTimer = setInterval(updateCountdown, 1000);
|
countdownTimer = setInterval(updateCountdown, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -89,37 +95,49 @@ onBeforeUnmount(() => {
|
|||||||
</header>
|
</header>
|
||||||
<div class="session-tabs" role="tablist">
|
<div class="session-tabs" role="tablist">
|
||||||
<button
|
<button
|
||||||
v-for="(session, index) in SECKILL_SESSIONS"
|
v-for="(session, index) in sessions"
|
||||||
:key="session.label"
|
:key="session.id"
|
||||||
type="button"
|
type="button"
|
||||||
class="session-tab"
|
class="session-tab"
|
||||||
:class="{ active: sessionState(index) === 'current', ended: sessionState(index) === 'ended' }"
|
:class="{ active: index === activeSessionIndex }"
|
||||||
role="tab"
|
role="tab"
|
||||||
:aria-selected="sessionState(index) === 'current'"
|
:aria-selected="index === activeSessionIndex"
|
||||||
|
@click="activeSessionIndex = index; updateCountdown()"
|
||||||
>
|
>
|
||||||
<strong>{{ session.label }}</strong>
|
<strong>{{ pick(session.label, locale) }}</strong>
|
||||||
<span>{{ sessionStateLabel(index) }}</span>
|
<span>{{ index === activeSessionIndex ? t("marketing.currentSession") : t("marketing.upcoming") }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="countdown" aria-live="polite">{{ t("marketing.countdown", { time: formatCountdown(remainingSeconds) }) }}</p>
|
<p v-if="activeSession" class="countdown" aria-live="polite">
|
||||||
|
{{ t("marketing.countdown", { time: formatCountdown(remainingSeconds) }) }}
|
||||||
|
</p>
|
||||||
|
<p v-if="error" class="seckill-error" role="alert">{{ error }}</p>
|
||||||
|
|
||||||
<div v-if="products.length" class="seckill-grid">
|
<div v-if="loading" class="muted">{{ t("common.loading") }}</div>
|
||||||
<article v-for="item in products" :key="item.product.id" class="seckill-card hover-lift">
|
<div v-else-if="activeSession && activeSession.items.length" class="seckill-grid">
|
||||||
<NuxtLink :to="`/goods/${item.product.slug}`" class="product-image">
|
<article v-for="item in activeSession.items" :key="item.id" class="seckill-card hover-lift">
|
||||||
<img :src="item.product.images[0]" :alt="pick(item.product.name, locale)" loading="lazy" />
|
<NuxtLink :to="`/goods/${item.product_slug}`" class="product-image">
|
||||||
|
<img :src="item.image || '/mock/product-1.svg'" :alt="pick(item.product_name, locale)" loading="lazy" />
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<div class="product-body">
|
<div class="product-body">
|
||||||
<NuxtLink :to="`/goods/${item.product.slug}`" class="product-name">{{ pick(item.product.name, locale) }}</NuxtLink>
|
<NuxtLink :to="`/goods/${item.product_slug}`" class="product-name">{{ pick(item.product_name, locale) }}</NuxtLink>
|
||||||
<p class="price-line">
|
<p class="price-line">
|
||||||
<span class="sale-price"><PriceText :amount-minor="item.seckillPriceMinor" :currency="currencyOf(item.product)" /></span>
|
<span class="sale-price"><PriceText :amount-minor="item.sale_price_minor" :currency="item.currency" /></span>
|
||||||
<s class="original-price"><PriceText :amount-minor="priceMinorOf(item.product)" :currency="currencyOf(item.product)" /></s>
|
<s class="original-price"><PriceText :amount-minor="item.original_price_minor" :currency="item.original_currency" /></s>
|
||||||
</p>
|
</p>
|
||||||
<div class="progress-line">
|
<div class="progress-line">
|
||||||
<div class="progress-track"><span :style="{ width: `${item.soldPct}%` }"></span></div>
|
<div class="progress-track"><span :style="{ width: `${soldPct(item)}%` }"></span></div>
|
||||||
<span>{{ t("marketing.progress", { n: item.soldPct }) }}</span>
|
<span>{{ t("marketing.progress", { n: soldPct(item) }) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<NuxtLink :to="`/goods/${item.product.slug}`" class="mbtn red grab-button">{{ t("marketing.buyNow") }}</NuxtLink>
|
<p class="stock-line">{{ t("marketing.stock", { n: item.reserved_stock }) }}</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="mbtn red grab-button"
|
||||||
|
:disabled="item.reserved_stock <= 0 || addingSkuId === item.sku_id"
|
||||||
|
@click="addToCart(item)"
|
||||||
|
>
|
||||||
|
{{ addingSkuId === item.sku_id ? t("common.loading") : t("marketing.buyNow") }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
@@ -191,6 +209,18 @@ onBeforeUnmount(() => {
|
|||||||
.session-tab.ended strong {
|
.session-tab.ended strong {
|
||||||
color: var(--mall-faint);
|
color: var(--mall-faint);
|
||||||
}
|
}
|
||||||
|
.seckill-error {
|
||||||
|
margin: 12px 0 0;
|
||||||
|
padding: 10px 14px;
|
||||||
|
color: #b42318;
|
||||||
|
background: #fff1f0;
|
||||||
|
border: 1px solid #ffd6d2;
|
||||||
|
}
|
||||||
|
.stock-line {
|
||||||
|
margin: 8px 0 10px;
|
||||||
|
color: var(--mall-faint);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
.countdown {
|
.countdown {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
border: 1px solid var(--mall-line);
|
border: 1px solid var(--mall-line);
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ onMounted(() => {
|
|||||||
<td class="prod-col">
|
<td class="prod-col">
|
||||||
<img :src="item.image || '/mock/product-1.svg'" :alt="pick(item.product_name, locale)" />
|
<img :src="item.image || '/mock/product-1.svg'" :alt="pick(item.product_name, locale)" />
|
||||||
<span>{{ pick(item.product_name, locale) }}</span>
|
<span>{{ pick(item.product_name, locale) }}</span>
|
||||||
|
<span v-if="item.flash_sale_item_id" class="activity-tag">{{ t("marketing.flashTag") }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td><PriceText :amount-minor="item.unit_price_minor" :currency="order.currency" /></td>
|
<td><PriceText :amount-minor="item.unit_price_minor" :currency="order.currency" /></td>
|
||||||
<td>{{ item.qty }}</td>
|
<td>{{ item.qty }}</td>
|
||||||
@@ -228,6 +229,13 @@ onMounted(() => {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: var(--mall-red);
|
color: var(--mall-red);
|
||||||
}
|
}
|
||||||
|
.activity-tag {
|
||||||
|
margin-left: 6px;
|
||||||
|
padding: 1px 6px;
|
||||||
|
border: 1px solid var(--mall-red);
|
||||||
|
color: var(--mall-red);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
.order-total {
|
.order-total {
|
||||||
margin: 16px 0 0;
|
margin: 16px 0 0;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ type LiveDomain =
|
|||||||
| "invoices"
|
| "invoices"
|
||||||
| "addresses"
|
| "addresses"
|
||||||
| "coupons"
|
| "coupons"
|
||||||
| "points";
|
| "points"
|
||||||
|
| "flashSales";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explicit per-domain method picks rather than a string allowlist: indexing
|
* Explicit per-domain method picks rather than a string allowlist: indexing
|
||||||
@@ -78,6 +79,7 @@ const LIVE_PICKS = {
|
|||||||
listMyRedemptions: a.listMyRedemptions,
|
listMyRedemptions: a.listMyRedemptions,
|
||||||
redeemPoints: a.redeemPoints,
|
redeemPoints: a.redeemPoints,
|
||||||
}),
|
}),
|
||||||
|
flashSales: (a: ApiClient) => ({ listFlashSales: a.listFlashSales }),
|
||||||
} satisfies Record<LiveDomain, (a: ApiClient) => Partial<ApiClient>>;
|
} satisfies Record<LiveDomain, (a: ApiClient) => Partial<ApiClient>>;
|
||||||
|
|
||||||
const KNOWN_DOMAINS = Object.keys(LIVE_PICKS) as LiveDomain[];
|
const KNOWN_DOMAINS = Object.keys(LIVE_PICKS) as LiveDomain[];
|
||||||
@@ -98,6 +100,7 @@ const DEFAULT_LIVE_DOMAINS: LiveDomain[] = [
|
|||||||
"addresses",
|
"addresses",
|
||||||
"coupons",
|
"coupons",
|
||||||
"points",
|
"points",
|
||||||
|
"flashSales",
|
||||||
];
|
];
|
||||||
|
|
||||||
export default defineNuxtPlugin(() => {
|
export default defineNuxtPlugin(() => {
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ import type {
|
|||||||
CouponTemplate,
|
CouponTemplate,
|
||||||
CouponTemplateInput,
|
CouponTemplateInput,
|
||||||
Currency,
|
Currency,
|
||||||
|
FlashSaleItem,
|
||||||
|
FlashSaleItemInput,
|
||||||
|
FlashSaleSession,
|
||||||
|
FlashSaleSessionInput,
|
||||||
HomeContent,
|
HomeContent,
|
||||||
IntegralOrder,
|
IntegralOrder,
|
||||||
IntegralProduct,
|
IntegralProduct,
|
||||||
@@ -25,9 +29,11 @@ import type {
|
|||||||
Paged,
|
Paged,
|
||||||
Product,
|
Product,
|
||||||
ProductStatus,
|
ProductStatus,
|
||||||
|
PublicFlashSaleSession,
|
||||||
RedeemPointsBody,
|
RedeemPointsBody,
|
||||||
Shipment,
|
Shipment,
|
||||||
Shop,
|
Shop,
|
||||||
|
ShopFlashSaleSession,
|
||||||
ShopProfile,
|
ShopProfile,
|
||||||
ShopProfileInput,
|
ShopProfileInput,
|
||||||
Sku,
|
Sku,
|
||||||
@@ -208,6 +214,8 @@ export interface ApiClient {
|
|||||||
listPointsProducts(): Promise<IntegralProduct[]>;
|
listPointsProducts(): Promise<IntegralProduct[]>;
|
||||||
listMyRedemptions(): Promise<IntegralOrder[]>;
|
listMyRedemptions(): Promise<IntegralOrder[]>;
|
||||||
redeemPoints(body: RedeemPointsBody): Promise<IntegralOrder>;
|
redeemPoints(body: RedeemPointsBody): Promise<IntegralOrder>;
|
||||||
|
/** Public: active flash-sale sessions with their purchasable items. */
|
||||||
|
listFlashSales(): Promise<PublicFlashSaleSession[]>;
|
||||||
shop: {
|
shop: {
|
||||||
getMyShop(): Promise<Shop>;
|
getMyShop(): Promise<Shop>;
|
||||||
listMyProducts(q?: ShopProductQuery): Promise<Paged<Product>>;
|
listMyProducts(q?: ShopProductQuery): Promise<Paged<Product>>;
|
||||||
@@ -233,6 +241,13 @@ export interface ApiClient {
|
|||||||
createCouponTemplate(body: CouponTemplateInput): Promise<CouponTemplate>;
|
createCouponTemplate(body: CouponTemplateInput): Promise<CouponTemplate>;
|
||||||
updateCouponTemplate(id: string, body: CouponTemplateInput): Promise<CouponTemplate>;
|
updateCouponTemplate(id: string, body: CouponTemplateInput): Promise<CouponTemplate>;
|
||||||
deleteCouponTemplate(id: string): Promise<void>;
|
deleteCouponTemplate(id: string): Promise<void>;
|
||||||
|
listFlashSales(): Promise<ShopFlashSaleSession[]>;
|
||||||
|
createFlashSale(body: FlashSaleSessionInput): Promise<FlashSaleSession>;
|
||||||
|
updateFlashSale(id: string, body: FlashSaleSessionInput): Promise<FlashSaleSession>;
|
||||||
|
deleteFlashSale(id: string): Promise<void>;
|
||||||
|
addFlashSaleItem(sessionId: string, body: FlashSaleItemInput): Promise<FlashSaleItem>;
|
||||||
|
updateFlashSaleItem(id: string, body: FlashSaleItemInput): Promise<FlashSaleItem>;
|
||||||
|
deleteFlashSaleItem(id: string): Promise<void>;
|
||||||
};
|
};
|
||||||
admin: {
|
admin: {
|
||||||
listUsers(page?: number): Promise<Paged<User>>;
|
listUsers(page?: number): Promise<Paged<User>>;
|
||||||
@@ -303,6 +318,7 @@ export function createApi(opts: ApiClientOptions): ApiClient {
|
|||||||
listPointsProducts: () => r("GET", "/points/products"),
|
listPointsProducts: () => r("GET", "/points/products"),
|
||||||
listMyRedemptions: () => r("GET", "/points/redemptions"),
|
listMyRedemptions: () => r("GET", "/points/redemptions"),
|
||||||
redeemPoints: (body) => r("POST", "/points/redemptions", body),
|
redeemPoints: (body) => r("POST", "/points/redemptions", body),
|
||||||
|
listFlashSales: () => r("GET", "/flash-sales"),
|
||||||
shop: {
|
shop: {
|
||||||
getMyShop: () => r("GET", "/shop/profile"),
|
getMyShop: () => r("GET", "/shop/profile"),
|
||||||
listMyProducts: (q = {}) => r("GET", "/shop/products", undefined, { ...q }),
|
listMyProducts: (q = {}) => r("GET", "/shop/products", undefined, { ...q }),
|
||||||
@@ -328,6 +344,14 @@ export function createApi(opts: ApiClientOptions): ApiClient {
|
|||||||
createCouponTemplate: (body) => r("POST", "/shop/coupon-templates", body),
|
createCouponTemplate: (body) => r("POST", "/shop/coupon-templates", body),
|
||||||
updateCouponTemplate: (id, body) => r("PUT", `/shop/coupon-templates/${id}`, body),
|
updateCouponTemplate: (id, body) => r("PUT", `/shop/coupon-templates/${id}`, body),
|
||||||
deleteCouponTemplate: (id) => r("DELETE", `/shop/coupon-templates/${id}`),
|
deleteCouponTemplate: (id) => r("DELETE", `/shop/coupon-templates/${id}`),
|
||||||
|
listFlashSales: () => r("GET", "/shop/flash-sales"),
|
||||||
|
createFlashSale: (body) => r("POST", "/shop/flash-sales", body),
|
||||||
|
updateFlashSale: (id, body) => r("PUT", `/shop/flash-sales/${id}`, body),
|
||||||
|
deleteFlashSale: (id) => r("DELETE", `/shop/flash-sales/${id}`),
|
||||||
|
addFlashSaleItem: (sessionId, body) =>
|
||||||
|
r("POST", `/shop/flash-sales/${sessionId}/items`, body),
|
||||||
|
updateFlashSaleItem: (id, body) => r("PUT", `/shop/flash-sale-items/${id}`, body),
|
||||||
|
deleteFlashSaleItem: (id) => r("DELETE", `/shop/flash-sale-items/${id}`),
|
||||||
},
|
},
|
||||||
admin: {
|
admin: {
|
||||||
listUsers: (page = 1) => r("GET", "/admin/users", undefined, { page }),
|
listUsers: (page = 1) => r("GET", "/admin/users", undefined, { page }),
|
||||||
|
|||||||
@@ -145,6 +145,8 @@ export interface OrderItem {
|
|||||||
unit_price_minor: number;
|
unit_price_minor: number;
|
||||||
qty: number;
|
qty: number;
|
||||||
image: string | null;
|
image: string | null;
|
||||||
|
/** Set when this line received flash-sale pricing. */
|
||||||
|
flash_sale_item_id: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Order {
|
export interface Order {
|
||||||
@@ -310,6 +312,92 @@ export interface RedeemPointsBody {
|
|||||||
shipping_address: Address;
|
shipping_address: Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- flash sales ----
|
||||||
|
|
||||||
|
/** Shop-owned timed session. */
|
||||||
|
export interface FlashSaleSession {
|
||||||
|
id: string;
|
||||||
|
shop_id: string;
|
||||||
|
label: LocalizedText;
|
||||||
|
starts_at: string;
|
||||||
|
ends_at: string;
|
||||||
|
enabled: boolean;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FlashSaleSessionInput {
|
||||||
|
label: LocalizedText;
|
||||||
|
starts_at: string;
|
||||||
|
ends_at: string;
|
||||||
|
enabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FlashSaleItemInput {
|
||||||
|
sku_id: string;
|
||||||
|
sale_price_minor: number;
|
||||||
|
currency: string;
|
||||||
|
reserved_stock: number;
|
||||||
|
per_customer_limit: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FlashSaleItem {
|
||||||
|
id: string;
|
||||||
|
session_id: string;
|
||||||
|
sku_id: string;
|
||||||
|
sale_price_minor: number;
|
||||||
|
currency: string;
|
||||||
|
/** Remaining activity inventory. */
|
||||||
|
reserved_stock: number;
|
||||||
|
sold_count: number;
|
||||||
|
per_customer_limit: number;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shop-side item joined with its SKU and catalog price. */
|
||||||
|
export interface ShopFlashSaleItem {
|
||||||
|
id: string;
|
||||||
|
session_id: string;
|
||||||
|
sku_id: string;
|
||||||
|
sku_code: string;
|
||||||
|
product_name: LocalizedText;
|
||||||
|
sale_price_minor: number;
|
||||||
|
currency: string;
|
||||||
|
original_price_minor: number;
|
||||||
|
original_currency: string;
|
||||||
|
reserved_stock: number;
|
||||||
|
sold_count: number;
|
||||||
|
per_customer_limit: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ShopFlashSaleSession extends FlashSaleSession {
|
||||||
|
items: ShopFlashSaleItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Public discovery item carrying everything needed to add it to the cart. */
|
||||||
|
export interface PublicFlashSaleItem {
|
||||||
|
id: string;
|
||||||
|
session_id: string;
|
||||||
|
sku_id: string;
|
||||||
|
product_id: string;
|
||||||
|
product_slug: string;
|
||||||
|
product_name: LocalizedText;
|
||||||
|
image: string | null;
|
||||||
|
sku_code: string;
|
||||||
|
sale_price_minor: number;
|
||||||
|
currency: string;
|
||||||
|
original_price_minor: number;
|
||||||
|
original_currency: string;
|
||||||
|
reserved_stock: number;
|
||||||
|
sold_count: number;
|
||||||
|
per_customer_limit: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PublicFlashSaleSession extends FlashSaleSession {
|
||||||
|
items: PublicFlashSaleItem[];
|
||||||
|
}
|
||||||
|
|
||||||
export type ShipmentStatus = "pending" | "shipped" | "delivered";export interface Shipment {
|
export type ShipmentStatus = "pending" | "shipped" | "delivered";export interface Shipment {
|
||||||
id: string;
|
id: string;
|
||||||
shipment_no: string;
|
shipment_no: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user