@tbox.cn/app-module-promotion 1.0.0-alpha.13 → 1.0.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ import {
7
7
  resolvePromotionEntitlementsPort,
8
8
  resolvePromotionOffersPort,
9
9
  serverModule
10
- } from "../chunk-5GWOZC6X.js";
10
+ } from "../chunk-2S7WUHX4.js";
11
11
  export {
12
12
  InMemoryPromotionService,
13
13
  inMemoryPromotion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-module-promotion",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.14",
4
4
  "type": "module",
5
5
  "description": "商圈营销模块:资格校验、推荐降级链、券卡(codegen 源)。",
6
6
  "exports": {
@@ -20,16 +20,16 @@
20
20
  "dependencies": {
21
21
  "jsbarcode": "^3.12.3",
22
22
  "qrcode": "^1.5.4",
23
- "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.13",
24
- "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.13",
25
- "@tbox.cn/app-contracts-mall": "1.0.0-alpha.13",
26
- "@tbox.cn/app-contracts": "1.0.0-alpha.13"
23
+ "@tbox.cn/app-contracts": "1.0.0-alpha.14",
24
+ "@tbox.cn/app-contracts-mall": "1.0.0-alpha.14",
25
+ "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.14",
26
+ "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.14"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@phosphor-icons/react": "2.1.10",
30
30
  "react": "18.3.1",
31
31
  "zod": "3.25.76",
32
- "@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.13"
32
+ "@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.14"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/express": "4.17.25",
@@ -8,3 +8,4 @@ export { default as PromotionActivityListCard } from './promotion-activity-list'
8
8
  export { default as PromotionActivityDetailCard } from './promotion-activity-detail';
9
9
  export { default as PromotionActivityCategoryListCard } from './promotion-activity-category-list';
10
10
  export { default as PromotionBestDealCard } from './promotion-best-deal';
11
+ export { default as PromotionDealRecallCard } from './promotion-deal-recall';
@@ -0,0 +1,60 @@
1
+ import { sendCardAction } from '@tbox.cn/app-agent-sdk-client';
2
+ import { useId } from 'react';
3
+ import type { DealRecallCardData } from '../../../deal-recall-card';
4
+ import { CouponListRow } from '../../components/CouponListRow';
5
+ import { COUPON_LIST_TOGGLE_CLASS } from '../../components/CouponListToggle';
6
+
7
+ export default function PromotionDealRecallCard({ data, cardId = '' }: {
8
+ data: DealRecallCardData;
9
+ cardId?: string;
10
+ }) {
11
+ return (
12
+ <section className="bg-card px-4 py-3 text-sm text-foreground">
13
+ <h3 className="text-base font-semibold">{data.title}</h3>
14
+ <DealRecallList items={data.items} partial={data.partial} cardId={cardId} />
15
+ </section>
16
+ );
17
+ }
18
+
19
+ export function DealRecallList({ items, partial, cardId, more }: Pick<DealRecallCardData, 'items' | 'partial'> & {
20
+ cardId: string;
21
+ more?: { load: () => void; pending: boolean; error?: string };
22
+ }) {
23
+ const listId = useId();
24
+ return (
25
+ <>
26
+ {partial && <p className="mt-1 text-xs text-muted-foreground">部分结果暂时无法查询</p>}
27
+ <ul id={listId} className="promotion-list__items m-0 list-none px-0 pb-1">
28
+ {items.map((item) => {
29
+ const url = item.url;
30
+ return (
31
+ <li key={item.id}>
32
+ <CouponListRow
33
+ title={item.title}
34
+ imageUrl={item.imageUrl}
35
+ subtitle={item.subtitle ? { text: item.subtitle } : undefined}
36
+ price={item.price}
37
+ action={url ? { label: item.kind === 'item' ? '抢购' : '查看', onClick: () => sendCardAction(cardId, { type: 'openLink', url }) } : undefined}
38
+ />
39
+ </li>
40
+ );
41
+ })}
42
+ </ul>
43
+ {more && (
44
+ <>
45
+ <button
46
+ type="button"
47
+ className={`${COUPON_LIST_TOGGLE_CLASS} disabled:cursor-wait`}
48
+ aria-controls={listId}
49
+ aria-busy={more.pending}
50
+ disabled={more.pending}
51
+ onClick={more.load}
52
+ >
53
+ {more.pending ? '正在查找更多…' : more.error ? '重试查看更多' : '查看更多'}
54
+ </button>
55
+ {more.error && <p role="status" className="m-0 text-center text-xs text-secondary-foreground">{more.error}</p>}
56
+ </>
57
+ )}
58
+ </>
59
+ );
60
+ }
@@ -1,5 +1,5 @@
1
1
  import { CalendarBlank, CaretDown, Copy, MapPinLine, NavigationArrow, ShieldCheck, Ticket } from '@phosphor-icons/react';
2
- import { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import { useEffect, useRef, useState } from 'react';
3
3
  import { callJsapi, httpGet } from '@tbox.cn/app-agent-sdk-client';
4
4
  import type { PromotionEntitlementListCardData } from '@tbox.cn/app-contracts-mall';
5
5
  import { CouponSheet } from '../../components/CouponSheet';
@@ -7,7 +7,7 @@ import { CouponBarcode, CouponQrCode } from '../../components/CouponQrCode';
7
7
  import type { SheetFact } from '../../components/CouponSheet';
8
8
  import { ImageWithFallback } from '../../components/ImageWithFallback';
9
9
  import { sanitizeActivityHtml } from '../../utils/sanitize-activity-html';
10
- import { scrollCardBottom } from '../../utils/scroll-card-bottom';
10
+ import { useCouponListExpansion } from '../../components/use-coupon-list-expansion';
11
11
  import { entitlementStatusLabel } from '../view';
12
12
  import {
13
13
  PROMOTION_CHIP_COUPON_CLASS,
@@ -19,32 +19,12 @@ export function PromotionEntitlementListCard(props: {
19
19
  cardId?: string;
20
20
  isHistory?: boolean;
21
21
  }) {
22
- const { data } = props;
22
+ const { data, isHistory = false } = props;
23
23
  const [openRef, setOpenRef] = useState<string | null>(null);
24
- const [expanded, setExpanded] = useState(false);
25
- const [listHeights, setListHeights] = useState({ collapsed: 0, expanded: 0 });
26
- const listRef = useRef<HTMLDivElement>(null);
27
- const bottomRef = useRef<HTMLDivElement>(null);
28
- const initialRenderRef = useRef(true);
29
- useEffect(() => {
30
- if (initialRenderRef.current) {
31
- initialRenderRef.current = false;
32
- return;
33
- }
34
- if (bottomRef.current) scrollCardBottom(bottomRef.current);
35
- }, [expanded]);
36
- useLayoutEffect(() => {
37
- const list = listRef.current;
38
- if (!list) return;
39
- const rows = [...list.children] as HTMLElement[];
40
- const boundary = rows[Math.min(maxItems, rows.length) - 1];
41
- const listTop = list.getBoundingClientRect().top;
42
- const collapsed = boundary ? boundary.getBoundingClientRect().bottom - listTop : list.scrollHeight;
43
- setListHeights({ collapsed, expanded: list.scrollHeight });
44
- }, [data.items.length, data.maxItems]);
45
- const toggleExpanded = () => {
46
- setExpanded((value) => !value);
47
- };
24
+ const maxItems = data.maxItems ?? 4;
25
+ const { expanded, listRef, bottomRef, toggleExpanded, onTransitionEnd, maxHeight } = useCouponListExpansion(
26
+ data.items.length, maxItems, isHistory,
27
+ );
48
28
  const target = openRef ? data.items.find((item) => item.entitlementRef === openRef) : undefined;
49
29
  const [detailTarget, setDetailTarget] = useState<typeof target>();
50
30
  const [detailLoading, setDetailLoading] = useState(false);
@@ -71,7 +51,7 @@ export function PromotionEntitlementListCard(props: {
71
51
  return () => controller.abort();
72
52
  }, [openRef, target]);
73
53
  const sheetTarget = detailTarget ?? target;
74
- const maxItems = data.maxItems ?? 4;
54
+ const visibleItems = isHistory && !expanded ? data.items.slice(0, maxItems) : data.items;
75
55
  const copyCode = async (code: string) => {
76
56
  try { await navigator.clipboard?.writeText(code); setCopied(true); window.setTimeout(() => setCopied(false), 1600); } catch { setCopied(false); }
77
57
  };
@@ -87,8 +67,8 @@ export function PromotionEntitlementListCard(props: {
87
67
  </div>
88
68
  </header>
89
69
  {!data.items.length ? <div className="promotion-card__empty flex min-h-[94px] items-center justify-center gap-2 p-5 text-xs leading-[normal] text-secondary-foreground"><Ticket size={28} weight="duotone" /><span>{data.noResultsReason ?? '当前账户暂无可用权益'}</span></div> : (
90
- <div ref={listRef} className={`promotion-list__items overflow-hidden px-3.5 pb-1 ${expanded ? ' promotion-list__items--expanded transition-none' : ' transition-[max-height] duration-[320ms] ease-[ease]'}`} style={{ maxHeight: expanded ? listHeights.expanded || undefined : listHeights.collapsed || undefined }} onTransitionEnd={() => { if (bottomRef.current) scrollCardBottom(bottomRef.current); }}>
91
- {data.items.map((item) => (
70
+ <div ref={listRef} className={`promotion-list__items overflow-hidden px-3.5 pb-1 ${expanded ? ' promotion-list__items--expanded transition-none' : ' transition-[max-height] duration-[320ms] ease-[ease]'}`} style={{ maxHeight }} onTransitionEnd={onTransitionEnd}>
71
+ {visibleItems.map((item) => (
92
72
  <article
93
73
  key={item.entitlementRef}
94
74
  className={`promotion-coupon-row relative grid min-h-[77px] w-full cursor-pointer grid-cols-[56px_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-0 overflow-hidden border-t border-[#f0f1f4] py-[9px] text-left text-inherit first:border-t-0 focus-visible:rounded-[6px] focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-[#2368ec] ${item.status === 'EFFECTIVE' ? '' : ' promotion-coupon-row--disabled opacity-72'}`}
@@ -0,0 +1,120 @@
1
+ import { Ticket } from '@phosphor-icons/react';
2
+ import { httpPost, readHelloContext } from '@tbox.cn/app-agent-sdk-client';
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import type { DealRecallResult } from '@tbox.cn/app-contracts-mall';
5
+ import { DealRecallList } from '../promotion-deal-recall';
6
+
7
+ type Response = DealRecallResult & { message?: string };
8
+ const unavailable: Response = { status: 'unavailable' };
9
+
10
+ async function fetchNearbyDeals(signal: AbortSignal, excludedDealIds?: string[]): Promise<Response> {
11
+ const { data, status } = await httpPost<Response>('/api/m/promotion/nearby-deals', {
12
+ context: readHelloContext(),
13
+ ...(excludedDealIds ? { excludedDealIds } : {}),
14
+ }, { signal });
15
+ return data?.status ? data : status === 401 ? { status: 'login-required' } : unavailable;
16
+ }
17
+
18
+ function NearbyDealsLoading() {
19
+ return (
20
+ <div role="status" className="promotion-deals-loading flex min-h-[136px] flex-col items-center justify-center gap-2 bg-white px-3 py-3 text-center">
21
+ <span aria-hidden="true" className="relative grid size-[58px] shrink-0 place-items-center overflow-hidden rounded-full border-2 border-white bg-[#f1ecd6] text-[#6a7448] shadow-[0_3px_9px_rgba(93,100,46,0.14)]">
22
+ <Ticket size={26} weight="duotone" />
23
+ <span className="promotion-deals-loading__mascot absolute inset-0 bg-cover bg-center bg-[image:var(--tbox-asset-member-mascot,none)]" />
24
+ </span>
25
+ <div className="min-w-0">
26
+ <p className="m-0 text-sm font-semibold leading-5 text-[#37432b]">正在找附近神券…</p>
27
+ <span aria-hidden="true" className="promotion-deals-loading__dots mt-2 flex justify-center gap-1.5">
28
+ <span className="size-1.5 rounded-full bg-[#687c45] motion-safe:animate-pulse" />
29
+ <span className="size-1.5 rounded-full bg-[#87964c] motion-safe:animate-pulse motion-safe:[animation-delay:180ms]" />
30
+ <span className="size-1.5 rounded-full bg-[#a18a53] motion-safe:animate-pulse motion-safe:[animation-delay:360ms]" />
31
+ </span>
32
+ </div>
33
+ </div>
34
+ );
35
+ }
36
+
37
+ export function NearbyDealsPanel({ cardId, hidden }: { cardId: string; hidden: boolean }) {
38
+ const [attempt, setAttempt] = useState(0);
39
+ const [result, setResult] = useState<Response>();
40
+ const [moreState, setMoreState] = useState<'ready' | 'pending' | 'ended'>('ready');
41
+ const [moreError, setMoreError] = useState<string>();
42
+ const moreRequest = useRef<AbortController | null>(null);
43
+ useEffect(() => () => moreRequest.current?.abort(), []);
44
+
45
+ useEffect(() => {
46
+ const controller = new AbortController();
47
+ void fetchNearbyDeals(controller.signal)
48
+ .then((data) => {
49
+ if (controller.signal.aborted) return;
50
+ setResult(data);
51
+ })
52
+ .catch(() => {
53
+ if (!controller.signal.aborted) setResult(unavailable);
54
+ });
55
+ return () => controller.abort();
56
+ }, [attempt]);
57
+
58
+ const retry = () => {
59
+ setResult(undefined);
60
+ setAttempt((value) => value + 1);
61
+ };
62
+ const loadMore = async () => {
63
+ if (result?.status !== 'ok' || moreState === 'ended' || moreRequest.current) return;
64
+ const controller = new AbortController();
65
+ moreRequest.current = controller;
66
+ setMoreState('pending');
67
+ setMoreError(undefined);
68
+ const recalled = new Set([...result.items.map((item) => item.id), ...result.scannedDealIds ?? []]);
69
+ try {
70
+ const page = await fetchNearbyDeals(controller.signal, [...recalled]);
71
+ if (controller.signal.aborted) return;
72
+ if (page.status !== 'ok') {
73
+ setMoreError(page.message ?? '暂时无法加载更多神券,请稍后重试。');
74
+ setMoreState('ready');
75
+ return;
76
+ }
77
+ const fresh = [...new Map(page.items.filter((item) => !recalled.has(item.id)).map((item) => [item.id, item])).values()];
78
+ if (!fresh.length) {
79
+ setMoreState('ended');
80
+ return;
81
+ }
82
+ setResult({
83
+ status: 'ok',
84
+ items: [...result.items, ...fresh],
85
+ partial: result.partial || page.partial,
86
+ scannedDealIds: [...new Set([...recalled, ...page.scannedDealIds ?? []])],
87
+ });
88
+ setMoreState('ready');
89
+ } catch {
90
+ if (!controller.signal.aborted) {
91
+ setMoreError('暂时无法加载更多神券,请稍后重试。');
92
+ setMoreState('ready');
93
+ }
94
+ } finally {
95
+ moreRequest.current = null;
96
+ }
97
+ };
98
+ const message = !result ? undefined : result.status === 'ok' ? '附近暂无可展示的神券。'
99
+ : result.message ?? (result.status === 'login-required' ? '请先在支付宝内登录,再查询团购。' : '团购服务暂不可用,请稍后再试。');
100
+ return (
101
+ <div hidden={hidden} className="px-3.5">
102
+ {!result ? <NearbyDealsLoading />
103
+ : result.status === 'ok' && result.items.length > 0
104
+ ? <DealRecallList
105
+ items={result.items}
106
+ partial={result.partial}
107
+ cardId={cardId}
108
+ more={moreState === 'ended' ? undefined : { load: () => void loadMore(), pending: moreState === 'pending', error: moreError }}
109
+ />
110
+ : <div className="min-h-[88px] py-5 text-center text-xs text-secondary-foreground">
111
+ {message && <p role="status">{message}</p>}
112
+ {(result.status === 'unavailable' || result.status === 'location-required') && (
113
+ <button type="button" className="mt-1 min-h-8 cursor-pointer font-medium text-primary" onClick={retry}>
114
+ 重试
115
+ </button>
116
+ )}
117
+ </div>}
118
+ </div>
119
+ );
120
+ }
@@ -1,20 +1,25 @@
1
1
  import { CalendarBlank, CalendarDots, CaretDown, Lightbulb, MapPin, Sparkle, Ticket } from '@phosphor-icons/react';
2
- import { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import { useEffect, useState } from 'react';
3
3
  import { ItemActionsRow, markSelfRendering, navigateToAlipayPage, sendCardAction } from '@tbox.cn/app-agent-sdk-client';
4
4
  import type { PromotionOfferListCardData } from '@tbox.cn/app-contracts-mall';
5
5
  import { CouponSheet } from '../../components/CouponSheet';
6
6
  import type { SheetFact } from '../../components/CouponSheet';
7
+ import { CouponListRow } from '../../components/CouponListRow';
8
+ import { CouponListToggle, DEFAULT_VISIBLE_COUPONS } from '../../components/CouponListToggle';
7
9
  import { ImageWithFallback } from '../../components/ImageWithFallback';
8
10
  import { offerTypeLabel } from '../view';
9
- import { scrollCardBottom } from '../../utils/scroll-card-bottom';
11
+ import { useCouponListExpansion } from '../../components/use-coupon-list-expansion';
12
+ import { NearbyDealsPanel } from './NearbyDealsPanel';
10
13
  import {
11
14
  PROMOTION_CHIP_CLASS,
12
- PROMOTION_CHIP_COUPON_CLASS,
13
15
  PROMOTION_CHIP_COUPON_LG_CLASS,
14
16
  PROMOTION_STATUS_CLASS,
15
17
  PROMOTION_STATUS_TONE_CLASS,
16
18
  } from '../../components/class-names';
17
19
 
20
+ const OFFER_TAB_CLASS = 'relative flex min-h-7 shrink-0 cursor-pointer items-center justify-center border-0 bg-transparent px-px pb-[7px] text-xs font-medium whitespace-nowrap text-[#6b706d] transition-colors duration-150 [font-family:inherit] tracking-normal';
21
+ const ACTIVE_OFFER_TAB_CLASS = 'relative flex min-h-7 shrink-0 cursor-pointer items-center justify-center border-0 bg-transparent px-px pb-[7px] text-xs font-semibold whitespace-nowrap text-foreground transition-colors duration-150 [font-family:inherit] tracking-normal after:absolute after:bottom-0 after:left-1/2 after:h-[3px] after:w-[18px] after:-translate-x-1/2 after:rounded-[1.5px] after:bg-[#30372f]';
22
+
18
23
  const statusText = (status?: string, claimable?: boolean) => {
19
24
  if (status === 'REQUIRES_ACTION') return '需操作';
20
25
  if (status === 'UNKNOWN') return '待确认';
@@ -48,33 +53,18 @@ export function PromotionOfferListCard(props: {
48
53
  actionTokens?: Record<string, string>;
49
54
  }) {
50
55
  const { data, cardId = '', isHistory = false, actionTokens } = props;
56
+ const hasDealRecall = data.mode === 'claimable' && data.showDealRecall === true;
57
+ const isDealRecallHistory = hasDealRecall && isHistory;
58
+ const showTabs = hasDealRecall && !isHistory;
59
+ const [showMallOffers, setShowMallOffers] = useState(false);
60
+ const showNearby = showTabs && !showMallOffers;
51
61
  const [openRef, setOpenRef] = useState<string | null>(null);
52
62
  const [claimingRef, setClaimingRef] = useState<string | null>(null);
53
63
  const [claimedRefs, setClaimedRefs] = useState<Set<string>>(() => new Set());
54
- const [expanded, setExpanded] = useState(false);
55
- const [listHeights, setListHeights] = useState({ collapsed: 0, expanded: 0 });
56
- const listRef = useRef<HTMLDivElement>(null);
57
- const bottomRef = useRef<HTMLDivElement>(null);
58
- const initialRenderRef = useRef(true);
59
- useEffect(() => {
60
- if (initialRenderRef.current) {
61
- initialRenderRef.current = false;
62
- return;
63
- }
64
- if (bottomRef.current) scrollCardBottom(bottomRef.current);
65
- }, [expanded]);
66
- useLayoutEffect(() => {
67
- const list = listRef.current;
68
- if (!list) return;
69
- const rows = [...list.children] as HTMLElement[];
70
- const boundary = rows[Math.min(maxItems, rows.length) - 1];
71
- const listTop = list.getBoundingClientRect().top;
72
- const collapsed = boundary ? boundary.getBoundingClientRect().bottom - listTop : list.scrollHeight;
73
- setListHeights({ collapsed, expanded: list.scrollHeight });
74
- }, [data.items.length, data.maxItems]);
75
- const toggleExpanded = () => {
76
- setExpanded((value) => !value);
77
- };
64
+ const maxItems = data.maxItems ?? DEFAULT_VISIBLE_COUPONS;
65
+ const { expanded, listRef, bottomRef, toggleExpanded, onTransitionEnd, maxHeight } = useCouponListExpansion(
66
+ data.items.length, maxItems, isHistory, showNearby,
67
+ );
78
68
  useEffect(() => {
79
69
  if (!cardId || typeof window === 'undefined') return undefined;
80
70
  const onNotice = (event: Event) => {
@@ -114,14 +104,14 @@ export function PromotionOfferListCard(props: {
114
104
  const promotion = data.presentation === 'promotion';
115
105
  const hero = data.items[0];
116
106
  const coupon = data.presentation === 'coupon' || data.mode === 'claimable';
117
- const title = promotion ? '本周营销活动' : coupon ? '商场神券' : '活动与优惠';
118
- const eyebrow = promotion ? '活动发现' : coupon ? '当前商场 · 优惠精选' : '优惠精选';
107
+ const title = isDealRecallHistory ? '历史优惠' : promotion ? '本周营销活动' : showTabs ? '今日优惠' : coupon ? '商场神券' : '活动与优惠';
108
+ const eyebrow = isDealRecallHistory ? '商场优惠' : promotion ? '活动发现' : coupon ? '当前商场 · 优惠精选' : '优惠精选';
119
109
  // summary 由服务端下发,可能与 eyebrow 撞词(券列表实测就撞了)——同一句话不占两行
120
110
  const summary = data.summary && data.summary !== eyebrow ? data.summary : undefined;
121
111
  // 只在「可领券列表」里滤掉领不了的(列出来用户点一次才知道点不动);
122
112
  // 定向出某一张券时不过滤——那是用户指名要看的,滤掉就成了空列表
123
113
  const items = data.mode === 'claimable' ? data.items.filter((item) => item.claimable) : data.items;
124
- const maxItems = data.maxItems ?? 4;
114
+ const visibleItems = isHistory && !expanded ? items.slice(0, maxItems) : items;
125
115
  return (
126
116
  <section className={`promotion-card promotion-list relative w-full overflow-hidden bg-card text-sm leading-[normal] tracking-[0] text-foreground ${promotion ? ' promotion-list--promotion' : ''}${coupon ? ' promotion-list--coupon promotion-list--offers pb-3' : ''}`} aria-label={title}>
127
117
  {promotion && hero && <div className="promotion-list__hero relative h-[92px] overflow-hidden bg-[#eef2f8]"><ImageWithFallback src={hero.imageUrl} alt={title} className="promotion-list__hero-image h-full w-full object-cover" /><div className="promotion-list__glass absolute right-3 bottom-2.5 left-3 grid gap-[1px] rounded-[7px] border border-[rgba(255,255,255,0.68)] bg-[rgba(255,255,255,0.78)] px-2.5 py-2 shadow-[0_8px_20px_rgba(21,45,88,0.15)] backdrop-blur-[6px]"><span className="text-xs font-bold leading-[normal] text-[#128356]">刚刚更新</span><strong className="text-sm leading-[18px]">{data.items.length} 个活动正在进行</strong></div></div>}
@@ -142,37 +132,34 @@ export function PromotionOfferListCard(props: {
142
132
  <b className="promotion-card__count flex-none rounded-full border border-[rgba(83,91,108,0.13)] bg-[#f0f3f8] px-2 py-1.25 text-xs leading-[normal] text-secondary-foreground max-[380px]:hidden">{data.items.length} 个</b>
143
133
  </header>
144
134
  )}
145
- {!items.length ? <Empty text={data.noResultsReason ?? '暂未找到符合条件的优惠'} /> : (
146
- <div ref={listRef} className={coupon ? `promotion-list__items overflow-hidden px-3.5 pb-1 ${expanded ? ' promotion-list__items--expanded transition-none' : ' transition-[max-height] duration-[320ms] ease-[ease]'}` : `promotion-list__items px-4 pb-1 max-[380px]:px-[13px]${expanded ? ' promotion-list__items--expanded' : ''}`} style={{ maxHeight: expanded ? listHeights.expanded || undefined : listHeights.collapsed || undefined }} onTransitionEnd={() => { if (bottomRef.current) scrollCardBottom(bottomRef.current); }}>
147
- {items.map((item) => coupon ? (
148
- <article
135
+ {showTabs && (
136
+ <>
137
+ <div className="mx-3.5 mt-[9px] flex gap-4" aria-label="今日优惠分类" role="group">
138
+ <button type="button" aria-pressed={showNearby} className={showNearby ? ACTIVE_OFFER_TAB_CLASS : OFFER_TAB_CLASS} onClick={() => setShowMallOffers(false)}>神券</button>
139
+ <button type="button" aria-pressed={!showNearby} className={!showNearby ? ACTIVE_OFFER_TAB_CLASS : OFFER_TAB_CLASS} onClick={() => setShowMallOffers(true)}>商场优惠</button>
140
+ </div>
141
+ <NearbyDealsPanel key={cardId} cardId={cardId} hidden={!showNearby} />
142
+ </>
143
+ )}
144
+ {!showNearby && <>
145
+ {!items.length ? (
146
+ isDealRecallHistory
147
+ ? <p className="m-0 px-3.5 pt-3 text-xs leading-5 text-secondary-foreground">暂无可回看的优惠</p>
148
+ : <Empty text={data.noResultsReason ?? '暂未找到符合条件的优惠'} />
149
+ ) : (
150
+ <div ref={listRef} className={coupon ? `promotion-list__items overflow-hidden px-3.5 pb-1 ${expanded ? ' promotion-list__items--expanded transition-none' : ' transition-[max-height] duration-[320ms] ease-[ease]'}` : `promotion-list__items px-4 pb-1 max-[380px]:px-[13px]${expanded ? ' promotion-list__items--expanded' : ''}`} style={{ maxHeight }} onTransitionEnd={onTransitionEnd}>
151
+ {visibleItems.map((item) => coupon ? (
152
+ <CouponListRow
149
153
  key={item.offerRef}
150
- className="promotion-coupon-row relative grid min-h-[77px] w-full cursor-pointer grid-cols-[68px_minmax(0,1fr)_auto] items-center gap-x-[9px] gap-y-0 overflow-hidden border-0 py-2.5 text-left text-inherit focus-visible:rounded-[6px] focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-[#2368ec]"
151
- role="button"
152
- tabIndex={0}
153
- aria-label={`${item.claimActionLabel ?? '领取'}「${item.title}」`}
154
- onClick={() => setOpenRef(item.offerRef)}
155
- onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setOpenRef(item.offerRef); } }}
156
- >
157
- <ImageWithFallback src={item.imageUrl} alt={item.title} className="promotion-coupon-row__thumb h-[68px] w-[68px] shrink-0 rounded-[9px] object-cover shadow-[inset_0_0_0_1px_rgba(11,15,23,0.04)] [&:not(.promotion-image--fallback)]:block" />
158
- <div className="promotion-coupon-row__main relative flex min-w-0 flex-col justify-center gap-1 self-stretch pr-0.5">
159
- <strong className="promotion-coupon-row__title line-clamp-2 text-sm font-semibold leading-[19px] text-foreground">{item.title}</strong>
160
- {item.tags.some((tag) => !/^TOP[1-5]$/i.test(tag)) && <span className="promotion-coupon-row__tags mt-0 flex gap-1 overflow-hidden">{item.tags.filter((tag) => !/^TOP[1-5]$/i.test(tag)).slice(0, 3).map((tag) => <em key={tag} className={`${/^(精选|餐饮|购物|生活)$/.test(tag) ? 'promotion-coupon-row__tag--category' : 'promotion-coupon-row__tag--meta'} shrink-0 max-w-[80px] truncate rounded-[3.5px] bg-[#fff4df] px-[5px] py-[1px] text-xs font-normal not-italic leading-[14px] text-[#986415]`}>{tag}</em>)}</span>}
161
- {item.subtitle && !couponSubtitleIsTime(item.subtitle)
162
- && <span className="promotion-coupon-row__sub line-clamp-2 text-xs leading-[11.5px] text-[rgba(11,15,23,0.55)]" dangerouslySetInnerHTML={{ __html: item.subtitle }} />}
163
- <span className="promotion-coupon-row__price mt-[1px] flex min-w-0 items-baseline gap-1">
164
- {/* 售价缺省时退回 benefitText:老 provider 没有价格字段,不能让这行空着 */}
165
- <b className="shrink-0 text-sm font-extrabold leading-[17px] text-[#e8471c]">{item.priceText ?? item.benefitText ?? offerTypeLabel(item.offerType)}</b>
166
- {item.discountLabel && <em className="promotion-coupon-row__discount shrink-0 rounded-[2px] bg-[#fff1eb] px-[3.5px] py-[1px] text-xs font-bold not-italic leading-[10.5px] text-[#e8471c]">{item.discountLabel}</em>}
167
- {item.priceText && item.originalPriceText && <s className="truncate text-xs leading-3 text-[rgba(11,15,23,0.38)]">{item.originalPriceText}</s>}
168
- </span>
169
- </div>
170
- {/* 领/抢是拉起浮层的入口,不是成交按钮:整行已是可交互控件,
171
- 这里只做视觉承诺——真正的领取动作只在浮层里出现一次 */}
172
- <span className="promotion-item-actions promotion-item-actions--coupon contents shrink-0" aria-hidden="true">
173
- <span className={`promotion-chip promotion-chip--coupon ${PROMOTION_CHIP_COUPON_CLASS}`}>{item.claimActionLabel ?? '领取'}</span>
174
- </span>
175
- </article>
154
+ title={item.title}
155
+ imageUrl={item.imageUrl}
156
+ tags={item.tags}
157
+ subtitle={item.subtitle && !couponSubtitleIsTime(item.subtitle) ? { html: item.subtitle } : undefined}
158
+ price={item.priceText ?? item.benefitText ?? offerTypeLabel(item.offerType)}
159
+ originalPrice={item.priceText ? item.originalPriceText : undefined}
160
+ discount={item.discountLabel}
161
+ action={{ label: isDealRecallHistory ? '查看详情' : item.claimActionLabel ?? '领取', onClick: () => setOpenRef(item.offerRef) }}
162
+ />
176
163
  ) : (
177
164
  <article key={item.offerRef} className="grid min-h-[66px] w-full grid-cols-[52px_minmax(0,1fr)_auto_12px] items-center gap-[9px] border-t border-border py-2 text-left text-inherit first:border-t-0 max-[380px]:grid-cols-[46px_minmax(0,1fr)_auto_10px] max-[380px]:gap-[7px]">
178
165
  <span className="promotion-list__visual relative h-[48px] w-[52px] max-[380px]:w-[46px]"><ImageWithFallback src={item.imageUrl} alt={item.title} className="promotion-list__thumb h-[48px] w-[52px] rounded-[7px] object-cover max-[380px]:w-[46px]" /><em className="absolute right-[3px] bottom-[3px] max-w-[47px] truncate rounded-[4px] border border-[rgba(255,255,255,0.7)] bg-[rgba(255,255,255,0.82)] px-1 py-0.5 text-xs font-extrabold not-italic leading-[normal] text-[var(--tbox-domain-promotion-accent,#e42f46)] backdrop-blur-[3.5px]">{item.benefitText ?? offerTypeLabel(item.offerType)}</em></span>
@@ -187,20 +174,21 @@ export function PromotionOfferListCard(props: {
187
174
  ))}
188
175
  </div>
189
176
  )}
190
- {items.length > maxItems && (
177
+ {items.length > maxItems && (coupon ? (
178
+ <CouponListToggle expanded={expanded} remainingCount={items.length - maxItems} onToggle={toggleExpanded} />
179
+ ) : (
191
180
  <button
192
181
  type="button"
193
- className={coupon ? `promotion-list__toggle flex min-h-8 w-full cursor-pointer items-center justify-center gap-0.5 mt-0.5 border-0 bg-transparent px-0 py-0 text-xs font-normal leading-[normal] text-[#686d69] [font-family:inherit] hover:brightness-100 focus-visible:rounded-[5px] focus-visible:outline-3 focus-visible:outline-offset-2 focus-visible:outline-[rgba(9,107,250,0.28)] [&_svg]:transition-transform [&_svg]:duration-[160ms] [&_svg]:ease-[ease] [&_svg[data-rotated=true]]:rotate-180` : `promotion-list__toggle inline-flex w-full cursor-pointer items-center justify-center gap-[3px] mt-0.5 border-0 border-t border-[rgba(188,205,191,0.42)] bg-[linear-gradient(105deg,#fffaf0_0%,#f9f5e9_46%,#eaf6f3_100%)] px-3 pt-[7px] pb-2 text-xs font-semibold leading-[normal] text-foreground [font-family:inherit] hover:brightness-[0.94] focus-visible:outline-3 focus-visible:outline-foreground focus-visible:outline-offset-[-3px] [&_svg]:transition-transform [&_svg]:duration-[160ms] [&_svg]:ease-[ease] [&_svg[data-rotated=true]]:rotate-180`}
182
+ className="promotion-list__toggle inline-flex w-full cursor-pointer items-center justify-center gap-[3px] mt-0.5 border-0 border-t border-[rgba(188,205,191,0.42)] bg-[linear-gradient(105deg,#fffaf0_0%,#f9f5e9_46%,#eaf6f3_100%)] px-3 pt-[7px] pb-2 text-xs font-semibold leading-[normal] text-foreground [font-family:inherit] hover:brightness-[0.94] focus-visible:outline-3 focus-visible:outline-foreground focus-visible:outline-offset-[-3px] [&_svg]:transition-transform [&_svg]:duration-[160ms] [&_svg]:ease-[ease] [&_svg[data-rotated=true]]:rotate-180"
194
183
  aria-expanded={expanded}
195
184
  onClick={toggleExpanded}
196
185
  >
197
- {!coupon && <CaretDown size={16} data-rotated={expanded || undefined} />}
186
+ <CaretDown size={16} data-rotated={expanded || undefined} />
198
187
  {expanded ? '收起' : `查看更多(${items.length - maxItems} 条)`}
199
- {coupon && <CaretDown size={17} aria-hidden="true" data-rotated={expanded || undefined} />}
200
188
  </button>
201
- )}
189
+ ))}
202
190
  {items.length > maxItems && <div ref={bottomRef} className="promotion-list__bottom-anchor h-0 flex-none scroll-mb-[max(96px,calc(var(--tbox-chat-bottom-height,0px)_+_24px))]" aria-hidden="true" />}
203
- {data.nextCursor && <p className="promotion-list__more px-4 pt-1 pb-[9px] text-center text-xs leading-[normal] text-secondary-foreground">还有更多内容,可继续查询</p>}
191
+ {data.nextCursor && !isDealRecallHistory && <p className="promotion-list__more px-4 pt-1 pb-[9px] text-center text-xs leading-[normal] text-secondary-foreground">还有更多内容,可继续查询</p>}
204
192
  {openRef && (() => {
205
193
  const target = items.find((i) => i.offerRef === openRef);
206
194
  if (!target) return null;
@@ -225,7 +213,7 @@ export function PromotionOfferListCard(props: {
225
213
  imageFit={sheetImageFit(target)}
226
214
  noticeText={target.usageNoticeText}
227
215
  guaranteeText={target.guaranteeText}
228
- subtitle={redirectOnly
216
+ subtitle={redirectOnly && !isDealRecallHistory
229
217
  ? [target.subtitle, target.purchaseUrl
230
218
  ? `该优惠需前往小程序完成${purchaseOnly ? '购买' : '领取'}`
231
219
  : `该优惠的${purchaseOnly ? '抢购' : '领取'}链接暂不可用`].filter(Boolean).join(' · ')
@@ -244,7 +232,7 @@ export function PromotionOfferListCard(props: {
244
232
  return next;
245
233
  });
246
234
  }}
247
- foot={<>
235
+ foot={isDealRecallHistory ? undefined : <>
248
236
  <span className="promotion-sheet__foot-price flex min-w-0 items-baseline gap-1">
249
237
  <b className="text-xl font-extrabold leading-[normal] text-[#e8471c]">{target.priceText ?? target.benefitText ?? ''}</b>
250
238
  {target.priceText && target.originalPriceText && <s className="text-xs leading-[normal] text-[rgba(11,15,23,0.4)]">{target.originalPriceText}</s>}
@@ -290,6 +278,7 @@ export function PromotionOfferListCard(props: {
290
278
  />
291
279
  );
292
280
  })()}
281
+ </>}
293
282
  </section>
294
283
  );
295
284
  }
@@ -0,0 +1,51 @@
1
+ import { ImageWithFallback } from './ImageWithFallback';
2
+ import { PROMOTION_CHIP_COUPON_CLASS } from './class-names';
3
+
4
+ interface CouponListRowProps {
5
+ title: string;
6
+ imageUrl?: string;
7
+ subtitle?: { text: string } | { html: string };
8
+ tags?: readonly string[];
9
+ price?: string;
10
+ originalPrice?: string;
11
+ discount?: string;
12
+ action?: { label: string; onClick: () => void };
13
+ }
14
+
15
+ export function CouponListRow({ title, imageUrl, subtitle, tags, price, originalPrice, discount, action }: CouponListRowProps) {
16
+ const visibleTags = tags?.filter((tag) => !/^TOP[1-5]$/i.test(tag)).slice(0, 3);
17
+ return (
18
+ <article
19
+ className={`promotion-coupon-row relative grid min-h-[77px] w-full grid-cols-[68px_minmax(0,1fr)_auto] items-center gap-x-[9px] gap-y-0 overflow-hidden border-0 py-2.5 text-left text-inherit focus-visible:rounded-[6px] focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-[#2368ec]${action ? ' cursor-pointer' : ''}`}
20
+ role={action ? 'button' : undefined}
21
+ tabIndex={action ? 0 : undefined}
22
+ aria-label={action ? `${action.label}「${title}」` : undefined}
23
+ onClick={action?.onClick}
24
+ onKeyDown={action ? (event) => {
25
+ if (event.key !== 'Enter' && event.key !== ' ') return;
26
+ event.preventDefault();
27
+ action.onClick();
28
+ } : undefined}
29
+ >
30
+ <ImageWithFallback src={imageUrl} alt={title} className="promotion-coupon-row__thumb h-[68px] w-[68px] shrink-0 rounded-[9px] object-cover shadow-[inset_0_0_0_1px_rgba(11,15,23,0.04)] [&:not(.promotion-image--fallback)]:block" />
31
+ <div className="promotion-coupon-row__main relative flex min-w-0 flex-col justify-center gap-1 self-stretch pr-0.5">
32
+ <strong className="promotion-coupon-row__title line-clamp-2 text-sm font-semibold leading-[19px] text-foreground">{title}</strong>
33
+ {!!visibleTags?.length && <span className="promotion-coupon-row__tags mt-0 flex gap-1 overflow-hidden">
34
+ {visibleTags.map((tag) => <em key={tag} className={`${/^(精选|餐饮|购物|生活)$/.test(tag) ? 'promotion-coupon-row__tag--category' : 'promotion-coupon-row__tag--meta'} shrink-0 max-w-[80px] truncate rounded-[3.5px] bg-[#fff4df] px-[5px] py-[1px] text-xs font-normal not-italic leading-[14px] text-[#986415]`}>{tag}</em>)}
35
+ </span>}
36
+ {subtitle && <span
37
+ className="promotion-coupon-row__sub line-clamp-2 text-xs leading-[11.5px] text-[rgba(11,15,23,0.55)]"
38
+ {...('html' in subtitle ? { dangerouslySetInnerHTML: { __html: subtitle.html } } : { children: subtitle.text })}
39
+ />}
40
+ {(price || discount || originalPrice) && <span className="promotion-coupon-row__price mt-[1px] flex min-w-0 items-baseline gap-1">
41
+ {price && <b className="shrink-0 text-sm font-extrabold leading-[17px] text-[#e8471c]">{price}</b>}
42
+ {discount && <em className="promotion-coupon-row__discount shrink-0 rounded-[2px] bg-[#fff1eb] px-[3.5px] py-[1px] text-xs font-bold not-italic leading-[10.5px] text-[#e8471c]">{discount}</em>}
43
+ {originalPrice && <s className="truncate text-xs leading-3 text-[rgba(11,15,23,0.38)]">{originalPrice}</s>}
44
+ </span>}
45
+ </div>
46
+ {action && <span className="promotion-item-actions promotion-item-actions--coupon contents shrink-0" aria-hidden="true">
47
+ <span className={`promotion-chip promotion-chip--coupon ${PROMOTION_CHIP_COUPON_CLASS}`}>{action.label}</span>
48
+ </span>}
49
+ </article>
50
+ );
51
+ }
@@ -0,0 +1,22 @@
1
+ import { CaretDown } from '@phosphor-icons/react';
2
+
3
+ export const DEFAULT_VISIBLE_COUPONS = 4;
4
+ export const COUPON_LIST_TOGGLE_CLASS = 'promotion-list__toggle flex min-h-8 w-full cursor-pointer items-center justify-center gap-0.5 mt-0.5 border-0 bg-transparent px-0 py-0 text-xs font-normal leading-[normal] text-[#686d69] [font-family:inherit] hover:brightness-100 focus-visible:rounded-[5px] focus-visible:outline-3 focus-visible:outline-offset-2 focus-visible:outline-[rgba(9,107,250,0.28)] [&_svg]:transition-transform [&_svg]:duration-[160ms] [&_svg]:ease-[ease] [&_svg[data-rotated=true]]:rotate-180';
5
+
6
+ export function CouponListToggle({ expanded, remainingCount, onToggle }: {
7
+ expanded: boolean;
8
+ remainingCount: number;
9
+ onToggle: () => void;
10
+ }) {
11
+ return (
12
+ <button
13
+ type="button"
14
+ className={COUPON_LIST_TOGGLE_CLASS}
15
+ aria-expanded={expanded}
16
+ onClick={onToggle}
17
+ >
18
+ {expanded ? '收起' : `查看更多(${remainingCount} 条)`}
19
+ <CaretDown size={17} aria-hidden="true" data-rotated={expanded || undefined} />
20
+ </button>
21
+ );
22
+ }
@@ -0,0 +1,41 @@
1
+ import { useLayoutEffect, useRef, useState, type TransitionEvent } from 'react';
2
+ import { scrollCardBottom } from '../utils/scroll-card-bottom';
3
+
4
+ export function useCouponListExpansion(itemCount: number, maxItems: number, isHistory: boolean, hidden = false) {
5
+ const [expanded, setExpanded] = useState(false);
6
+ const [heights, setHeights] = useState({ collapsed: 0, expanded: 0 });
7
+ const listRef = useRef<HTMLDivElement>(null);
8
+ const bottomRef = useRef<HTMLDivElement>(null);
9
+ const pendingToggle = useRef(false);
10
+ const pendingCollapse = useRef(false);
11
+
12
+ useLayoutEffect(() => {
13
+ const list = listRef.current;
14
+ // 历史快照首帧只挂载可见行,聊天壳测量时就能读到折叠后的真实高度。
15
+ if (!list || isHistory || hidden) return;
16
+ const boundary = list.children[Math.min(maxItems, list.children.length) - 1];
17
+ const collapsed = boundary ? boundary.getBoundingClientRect().bottom - list.getBoundingClientRect().top : list.scrollHeight;
18
+ setHeights({ collapsed, expanded: list.scrollHeight });
19
+ }, [itemCount, maxItems, isHistory, hidden]);
20
+
21
+ useLayoutEffect(() => {
22
+ if (!pendingToggle.current) return;
23
+ pendingToggle.current = false;
24
+ if (bottomRef.current) scrollCardBottom(bottomRef.current);
25
+ }, [expanded]);
26
+
27
+ function toggleExpanded() {
28
+ pendingToggle.current = true;
29
+ pendingCollapse.current = expanded && !isHistory;
30
+ setExpanded(value => !value);
31
+ }
32
+
33
+ function onTransitionEnd(event: TransitionEvent<HTMLDivElement>) {
34
+ if (!pendingCollapse.current || event.target !== event.currentTarget || event.propertyName !== 'max-height') return;
35
+ pendingCollapse.current = false;
36
+ if (bottomRef.current) scrollCardBottom(bottomRef.current);
37
+ }
38
+
39
+ const maxHeight = expanded ? heights.expanded : heights.collapsed;
40
+ return { expanded, listRef, bottomRef, toggleExpanded, onTransitionEnd, maxHeight: isHistory ? undefined : maxHeight || undefined };
41
+ }