@tbox.cn/app-module-shopping-guide 0.2.1 → 0.8.3
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.
- package/AGENTS.md +16 -0
- package/README.md +96 -0
- package/dist/chunk-AYQZO2FV.js +1496 -0
- package/dist/chunk-VKDA6RXQ.js +1676 -0
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -8
- package/dist/server/index.d.ts +2512 -608
- package/dist/server/index.js +1 -7
- package/dist/shopping-guide-EGRHPEDA.css +2598 -0
- package/package.json +25 -16
- package/skills/shopping-guide/SKILL.md +127 -24
- package/src/client/cards/category-list/index.tsx +113 -0
- package/src/client/cards/human-guide-list/index.tsx +72 -0
- package/src/client/cards/index.ts +14 -0
- package/src/client/cards/location-handoff/index.tsx +52 -0
- package/src/client/cards/mall-directory/index.tsx +77 -0
- package/src/client/cards/nearby-mall-list/index.tsx +40 -0
- package/src/client/cards/product-comparison/index.tsx +100 -0
- package/src/client/cards/product-detail/index.tsx +97 -0
- package/src/client/cards/product-list/index.tsx +223 -0
- package/src/client/cards/recommend-merchants/index.tsx +147 -0
- package/src/client/cards/shop-detail/index.tsx +133 -0
- package/src/client/cards/shop-list/index.tsx +216 -0
- package/src/client/cards/view.ts +147 -0
- package/src/client/categories.ts +38 -0
- package/src/client/components/ImageWithFallback.tsx +34 -0
- package/src/client/components/MerchantRow.tsx +78 -0
- package/src/client/components/ShopDetailSheet.tsx +383 -0
- package/src/client/components/ShopGuideHeader.tsx +23 -0
- package/src/client/components/ShopGuideSectionLabel.tsx +10 -0
- package/src/client/components/ShopListSheet.tsx +293 -0
- package/src/client/index.ts +8 -6
- package/src/client/styles/shopping-guide.css +2598 -0
- package/src/client/types/css.d.ts +2 -0
- package/src/server/cards/category-list/meta.ts +0 -2
- package/src/server/cards/human-guide-list/meta.ts +0 -2
- package/src/server/cards/index.ts +10 -10
- package/src/server/cards/location-handoff/meta.ts +0 -2
- package/src/server/cards/mall-directory/meta.ts +0 -2
- package/src/server/cards/nearby-mall-list/meta.ts +1 -3
- package/src/server/cards/product-comparison/meta.ts +0 -2
- package/src/server/cards/product-detail/meta.ts +0 -2
- package/src/server/cards/product-list/meta.ts +0 -2
- package/src/server/cards/recommend-merchants/meta.ts +37 -0
- package/src/server/cards/recommend-merchants/samples.ts +189 -0
- package/src/server/cards/{merchant-detail → shop-detail}/meta.ts +6 -6
- package/src/server/cards/shop-detail/samples.ts +72 -0
- package/src/server/cards/{merchant-list → shop-list}/meta.ts +9 -9
- package/src/server/cards/shop-list/samples.ts +154 -0
- package/src/server/domain/value-objects.ts +1 -2
- package/src/server/handler.ts +63 -0
- package/src/server/index.ts +161 -101
- package/src/server/ports/index.ts +120 -91
- package/src/server/ports/local-adapters.ts +5 -55
- package/src/server/projections/index.ts +159 -41
- package/src/server/tools/index.ts +590 -315
- package/tbox.module.json +137 -0
- package/tests/cards-render.test.tsx +830 -0
- package/tests/floor-pretool.test.ts +275 -0
- package/tests/handler.test.ts +259 -0
- package/tests/merchant-list-limit.test.ts +53 -0
- package/tests/ports-resolve.test.ts +112 -0
- package/tests/samples.test.ts +71 -0
- package/tests/shopping-guide.test.ts +402 -234
- package/tests/skill.test.ts +86 -0
- package/tests/view.test.ts +42 -0
- package/tsup.config.ts +9 -1
- package/dist/chunk-AGBLC6XI.js +0 -1294
- package/dist/chunk-U4WDS5PQ.js +0 -173
- package/skills/shopping-guide/references/comparison-format.md +0 -5
- package/skills/shopping-guide/references/faq-answers.md +0 -5
- package/skills/shopping-guide/references/floor-directory.md +0 -4
- package/skills/shopping-guide/references/intent-patterns.md +0 -5
- package/skills/shopping-guide/references/location-format.md +0 -5
- package/skills/shopping-guide/references/policy-lookup.md +0 -5
- package/skills/shopping-guide/references/product-search-tips.md +0 -6
- package/skills/shopping-guide/references/recommendation-style.md +0 -5
- package/src/client/cards/index.tsx +0 -267
- package/src/server/cards/customer-service-faq/meta.ts +0 -18
- package/src/server/integrations/joycity/adapter.ts +0 -226
- package/src/server/integrations/joycity/auth-strategy.ts +0 -38
- package/src/server/integrations/joycity/gateway.ts +0 -128
- package/tbox.component.json +0 -48
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
import { Clock, Phone } from '@phosphor-icons/react';
|
|
3
|
+
import { httpGet, markSelfRendering } from '@tbox.cn/app-sdk/client';
|
|
4
|
+
import { MerchantRow } from '../../components/MerchantRow';
|
|
5
|
+
import { ShopGuideHeader } from '../../components/ShopGuideHeader';
|
|
6
|
+
import { ShopDetailSheet } from '../../components/ShopDetailSheet';
|
|
7
|
+
import type { ShopDetailSheetData } from '../../components/ShopDetailSheet';
|
|
8
|
+
import type { ShopDetailCardData } from '@tbox.cn/app-contracts-mall';
|
|
9
|
+
|
|
10
|
+
function projectSheetDataFromCardData(data: ShopDetailCardData): ShopDetailSheetData {
|
|
11
|
+
return {
|
|
12
|
+
name: data.name,
|
|
13
|
+
logoUrl: data.logoUrl,
|
|
14
|
+
coverUrl: data.coverUrls[0],
|
|
15
|
+
brand: data.brand,
|
|
16
|
+
businessCategories: data.businessCategories,
|
|
17
|
+
location: data.location,
|
|
18
|
+
status: data.status,
|
|
19
|
+
description: data.description,
|
|
20
|
+
contactInfo: data.contactInfo,
|
|
21
|
+
services: data.services,
|
|
22
|
+
itemActions: data.itemActions,
|
|
23
|
+
coupons: data.coupons,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function ShopDetailCard(props: {
|
|
28
|
+
data: ShopDetailCardData;
|
|
29
|
+
cardId: string;
|
|
30
|
+
isHistory: boolean;
|
|
31
|
+
actionTokens?: Record<string, string>;
|
|
32
|
+
}) {
|
|
33
|
+
const { data, cardId, isHistory, actionTokens } = props;
|
|
34
|
+
const [sheetOpen, setSheetOpen] = useState(false);
|
|
35
|
+
const [sheetData, setSheetData] = useState<ShopDetailSheetData | null>(null);
|
|
36
|
+
const [detailLoading, setDetailLoading] = useState(false);
|
|
37
|
+
// 防止旧请求覆盖最新 Sheet
|
|
38
|
+
const fetchControllerRef = useRef<AbortController | null>(null);
|
|
39
|
+
|
|
40
|
+
const openDetail = useCallback(() => {
|
|
41
|
+
// 取消上一次未完成的请求
|
|
42
|
+
fetchControllerRef.current?.abort();
|
|
43
|
+
const controller = new AbortController();
|
|
44
|
+
fetchControllerRef.current = controller;
|
|
45
|
+
|
|
46
|
+
// 1. 立即用卡片数据开 Sheet
|
|
47
|
+
setSheetData(projectSheetDataFromCardData(data));
|
|
48
|
+
setSheetOpen(true);
|
|
49
|
+
|
|
50
|
+
// 2. 后台拉取完整 detail 补全
|
|
51
|
+
const { merchantId, mallId, miniAppId } = data;
|
|
52
|
+
if (!mallId || !miniAppId) {
|
|
53
|
+
setDetailLoading(false);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
setDetailLoading(true);
|
|
57
|
+
|
|
58
|
+
const url = `/api/m/shopping-guide/shop-detail?shopId=${encodeURIComponent(merchantId)}&mallId=${encodeURIComponent(mallId)}&miniAppId=${encodeURIComponent(miniAppId)}`;
|
|
59
|
+
httpGet<{ data: ShopDetailCardData }>(url, { signal: controller.signal })
|
|
60
|
+
.then(({ data: payload }) => {
|
|
61
|
+
if (fetchControllerRef.current === controller) {
|
|
62
|
+
if (payload) setSheetData(projectSheetDataFromCardData(payload.data));
|
|
63
|
+
setDetailLoading(false);
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
.catch((err: unknown) => {
|
|
67
|
+
// AbortError 是主动取消,其余错误静默降级(Sheet 维持卡片数据继续展示)
|
|
68
|
+
if (fetchControllerRef.current !== controller) return;
|
|
69
|
+
if (err instanceof Error && err.name === 'AbortError') return;
|
|
70
|
+
// 请求失败不上抛,Sheet 已有数据可继续浏览
|
|
71
|
+
setDetailLoading(false);
|
|
72
|
+
});
|
|
73
|
+
}, [data]);
|
|
74
|
+
|
|
75
|
+
const closeDetail = useCallback(() => {
|
|
76
|
+
fetchControllerRef.current?.abort();
|
|
77
|
+
fetchControllerRef.current = null;
|
|
78
|
+
setDetailLoading(false);
|
|
79
|
+
setSheetOpen(false);
|
|
80
|
+
setSheetData(null);
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
// 卡面事实行(2026-09-02 用户反馈营业时间未透出):contactInfo 的营业时间/电话直接上卡面。
|
|
84
|
+
// 营业时间缺省 → 商场默认营业时间(2026-09-03 用户裁定:周一-周日 10:00-22:00)
|
|
85
|
+
const hoursText = data.contactInfo?.find((item) => /hours|营业时间/i.test(item.channel))?.value
|
|
86
|
+
?? '周一-周日 10:00-22:00';
|
|
87
|
+
const phone = data.contactInfo?.find((item) => /phone|电话/i.test(item.channel));
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
<section className="sg-card sg-recommend-merchants sg-shop-detail">
|
|
92
|
+
<ShopGuideHeader subtitle={data.brand ?? data.businessCategories.join(' · ') ?? '门店详情'} />
|
|
93
|
+
|
|
94
|
+
<ul className="sg-rm-list">
|
|
95
|
+
<li className="sg-rm-item">
|
|
96
|
+
{/* 与列表卡一致:历史卡仍可下钻只读详情,故不传 disabled。 */}
|
|
97
|
+
<MerchantRow merchant={data} onSelect={openDetail} />
|
|
98
|
+
</li>
|
|
99
|
+
</ul>
|
|
100
|
+
{(hoursText || phone) && (
|
|
101
|
+
<div className="sg-shop-detail__facts">
|
|
102
|
+
<span className="sg-shop-detail__fact">
|
|
103
|
+
<Clock size={15} weight="duotone" aria-hidden="true" />
|
|
104
|
+
{hoursText}
|
|
105
|
+
</span>
|
|
106
|
+
{phone && (
|
|
107
|
+
<span className="sg-shop-detail__fact">
|
|
108
|
+
<Phone size={15} weight="duotone" aria-hidden="true" />
|
|
109
|
+
{phone.value}
|
|
110
|
+
</span>
|
|
111
|
+
)}
|
|
112
|
+
</div>
|
|
113
|
+
)}
|
|
114
|
+
</section>
|
|
115
|
+
|
|
116
|
+
<ShopDetailSheet
|
|
117
|
+
open={sheetOpen}
|
|
118
|
+
data={sheetData}
|
|
119
|
+
loading={detailLoading}
|
|
120
|
+
cardId={cardId}
|
|
121
|
+
isHistory={isHistory}
|
|
122
|
+
actionTokens={actionTokens}
|
|
123
|
+
claimActionId="promotion.acquire-from-shop-detail"
|
|
124
|
+
onClose={closeDetail}
|
|
125
|
+
/>
|
|
126
|
+
</>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 富卡范式(0.3.2 D10):shop-detail 卡本体不渲染默认动作条——领取按钮只存在于
|
|
131
|
+
// 详情浮层的券条目里(卡级注册的 promotion.acquire-from-shop-detail 仅用于给浮层签发 contextToken)。
|
|
132
|
+
markSelfRendering(ShopDetailCard);
|
|
133
|
+
export default ShopDetailCard;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { CaretRight } from '@phosphor-icons/react';
|
|
3
|
+
import { markSelfRendering } from '@tbox.cn/app-sdk/client';
|
|
4
|
+
import { ShopDetailSheet } from '../../components/ShopDetailSheet';
|
|
5
|
+
import type { ShopDetailSheetData } from '../../components/ShopDetailSheet';
|
|
6
|
+
import { MerchantRow } from '../../components/MerchantRow';
|
|
7
|
+
import { resolveCategoryTabs } from '../../categories';
|
|
8
|
+
import { ShopGuideHeader } from '../../components/ShopGuideHeader';
|
|
9
|
+
import { ShopGuideSectionLabel } from '../../components/ShopGuideSectionLabel';
|
|
10
|
+
import { ShopListSheet } from '../../components/ShopListSheet';
|
|
11
|
+
import { httpGet } from '@tbox.cn/app-sdk/client';
|
|
12
|
+
import type { ShopListCardData, ShopDetailCardData } from '@tbox.cn/app-contracts-mall';
|
|
13
|
+
|
|
14
|
+
const PREVIEW_ITEM_COUNT = 3;
|
|
15
|
+
type Merchant = ShopListCardData['items'][number];
|
|
16
|
+
type OverlayState =
|
|
17
|
+
| { readonly kind: 'closed' }
|
|
18
|
+
| { readonly kind: 'list' }
|
|
19
|
+
| { readonly kind: 'detail'; readonly merchant: Merchant };
|
|
20
|
+
|
|
21
|
+
/** 从列表 item 快速投影 ShopDetailSheetData(即时展示用,不含电话/营业时间/coupons 等完整字段) */
|
|
22
|
+
function projectSheetDataFromItem(merchant: Merchant): ShopDetailSheetData {
|
|
23
|
+
return {
|
|
24
|
+
name: merchant.name,
|
|
25
|
+
logoUrl: merchant.logoUrl,
|
|
26
|
+
coverUrl: merchant.coverUrl,
|
|
27
|
+
brand: merchant.brand,
|
|
28
|
+
businessCategories: merchant.businessCategories,
|
|
29
|
+
location: merchant.location,
|
|
30
|
+
status: merchant.status,
|
|
31
|
+
contactInfo: merchant.contactInfo,
|
|
32
|
+
services: merchant.services,
|
|
33
|
+
itemActions: merchant.itemActions,
|
|
34
|
+
coupons: merchant.coupons,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 从 detail HTTP 响应投影 ShopDetailSheetData(完整字段) */
|
|
39
|
+
function projectSheetDataFromDetail(detail: ShopDetailCardData): ShopDetailSheetData {
|
|
40
|
+
return {
|
|
41
|
+
name: detail.name,
|
|
42
|
+
logoUrl: detail.logoUrl,
|
|
43
|
+
coverUrl: detail.coverUrls[0],
|
|
44
|
+
brand: detail.brand,
|
|
45
|
+
businessCategories: detail.businessCategories,
|
|
46
|
+
location: detail.location,
|
|
47
|
+
status: detail.status,
|
|
48
|
+
description: detail.description,
|
|
49
|
+
contactInfo: detail.contactInfo,
|
|
50
|
+
services: detail.services,
|
|
51
|
+
itemActions: detail.itemActions,
|
|
52
|
+
coupons: detail.coupons,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function ShopListCard(props: {
|
|
57
|
+
data: ShopListCardData;
|
|
58
|
+
cardId: string;
|
|
59
|
+
isHistory: boolean;
|
|
60
|
+
actionTokens?: Record<string, string>;
|
|
61
|
+
}) {
|
|
62
|
+
const { data, cardId, isHistory, actionTokens } = props;
|
|
63
|
+
const [activeTabCode, setActiveTabCode] = useState('');
|
|
64
|
+
const [overlay, setOverlay] = useState<OverlayState>({ kind: 'closed' });
|
|
65
|
+
// 存放当前打开的 Sheet 数据(先投影列表数据,detail 请求完成后替换为完整数据)
|
|
66
|
+
const [sheetData, setSheetData] = useState<ShopDetailSheetData | null>(null);
|
|
67
|
+
const [detailLoading, setDetailLoading] = useState(false);
|
|
68
|
+
// 用 ref 追踪当前打开的 merchantId,避免旧请求覆盖新打开的 Sheet
|
|
69
|
+
const openedMerchantIdRef = useRef<string | null>(null);
|
|
70
|
+
const fetchControllerRef = useRef<AbortController | null>(null);
|
|
71
|
+
|
|
72
|
+
// 与半屏同源:契约的 categoryTabs 打底 + 门店实际业态补充,两处因此看到同一份品类。
|
|
73
|
+
const allTabs = useMemo(() => resolveCategoryTabs(data.categoryTabs, data.items), [data.categoryTabs, data.items]);
|
|
74
|
+
const activeTab = allTabs.find((tab) => tab.code === activeTabCode);
|
|
75
|
+
const filteredItems = activeTab
|
|
76
|
+
? data.items.filter((item) => item.businessCategories.includes(activeTab.name))
|
|
77
|
+
: data.items;
|
|
78
|
+
const previewItems = filteredItems.slice(0, PREVIEW_ITEM_COUNT);
|
|
79
|
+
|
|
80
|
+
const closeOverlay = useCallback(() => {
|
|
81
|
+
fetchControllerRef.current?.abort();
|
|
82
|
+
fetchControllerRef.current = null;
|
|
83
|
+
openedMerchantIdRef.current = null;
|
|
84
|
+
setDetailLoading(false);
|
|
85
|
+
setOverlay({ kind: 'closed' });
|
|
86
|
+
setSheetData(null);
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
const openDetail = useCallback((merchant: Merchant) => {
|
|
90
|
+
fetchControllerRef.current?.abort();
|
|
91
|
+
const controller = new AbortController();
|
|
92
|
+
fetchControllerRef.current = controller;
|
|
93
|
+
|
|
94
|
+
// 1. 立即用列表数据开 Sheet,给用户即时反馈
|
|
95
|
+
openedMerchantIdRef.current = merchant.merchantId;
|
|
96
|
+
setSheetData(projectSheetDataFromItem(merchant));
|
|
97
|
+
setOverlay({ kind: 'detail', merchant });
|
|
98
|
+
|
|
99
|
+
// 2. 后台请求完整 detail,补全描述/电话/coupons 等字段
|
|
100
|
+
const { mallId, miniAppId } = data;
|
|
101
|
+
if (!mallId || !miniAppId) {
|
|
102
|
+
setDetailLoading(false);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
setDetailLoading(true);
|
|
106
|
+
|
|
107
|
+
const url = `/api/m/shopping-guide/shop-detail?shopId=${encodeURIComponent(merchant.merchantId)}&mallId=${encodeURIComponent(mallId)}&miniAppId=${encodeURIComponent(miniAppId)}`;
|
|
108
|
+
httpGet<{ data: ShopDetailCardData }>(url, { signal: controller.signal })
|
|
109
|
+
.then(({ data: payload }) => {
|
|
110
|
+
// 只更新当前仍然打开的那张 Sheet(防止多次快速切换时旧请求覆盖)
|
|
111
|
+
if (openedMerchantIdRef.current === merchant.merchantId && fetchControllerRef.current === controller) {
|
|
112
|
+
if (payload) setSheetData(projectSheetDataFromDetail(payload.data));
|
|
113
|
+
setDetailLoading(false);
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
.catch(() => {
|
|
117
|
+
// 请求失败静默降级,Sheet 维持列表数据继续展示
|
|
118
|
+
if (openedMerchantIdRef.current === merchant.merchantId && fetchControllerRef.current === controller) {
|
|
119
|
+
setDetailLoading(false);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}, [data]);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<>
|
|
126
|
+
<section className="sg-card sg-recommend-merchants sg-shop-list">
|
|
127
|
+
<ShopGuideHeader subtitle={data.summary ?? '按品类快速找到想逛的门店'} />
|
|
128
|
+
|
|
129
|
+
{allTabs.length > 0 && (
|
|
130
|
+
<div className="sg-rm-tabs" aria-label="按门店品类筛选">
|
|
131
|
+
{/* 「全部」承载「未筛选」这个本就存在的状态——此前它只能靠再点一次已选中的 tab
|
|
132
|
+
回到,而 tab 形态下「点选中项取消」并不直观。与浮层的分类导航同一套语义。 */}
|
|
133
|
+
<button
|
|
134
|
+
type="button"
|
|
135
|
+
aria-pressed={!activeTabCode}
|
|
136
|
+
className={`sg-rm-tab${!activeTabCode ? ' sg-rm-tab--active' : ''}`}
|
|
137
|
+
onClick={() => setActiveTabCode('')}
|
|
138
|
+
>
|
|
139
|
+
<span>全部</span>
|
|
140
|
+
</button>
|
|
141
|
+
{allTabs.map((tab) => {
|
|
142
|
+
const isActive = tab.code === activeTabCode;
|
|
143
|
+
return (
|
|
144
|
+
<button
|
|
145
|
+
key={tab.code}
|
|
146
|
+
type="button"
|
|
147
|
+
aria-pressed={isActive}
|
|
148
|
+
className={`sg-rm-tab${isActive ? ' sg-rm-tab--active' : ''}`}
|
|
149
|
+
onClick={() => setActiveTabCode(tab.code)}
|
|
150
|
+
>
|
|
151
|
+
<span>{tab.name}</span>
|
|
152
|
+
</button>
|
|
153
|
+
);
|
|
154
|
+
})}
|
|
155
|
+
</div>
|
|
156
|
+
)}
|
|
157
|
+
|
|
158
|
+
{filteredItems.length === 0 ? (
|
|
159
|
+
<div className="sg-empty">{data.noResultsReason ?? '暂时没有符合条件的门店'}</div>
|
|
160
|
+
) : (
|
|
161
|
+
<>
|
|
162
|
+
<ShopGuideSectionLabel />
|
|
163
|
+
<ul className="sg-rm-list">
|
|
164
|
+
{previewItems.map((item) => (
|
|
165
|
+
<li key={item.merchantId} className="sg-rm-item">
|
|
166
|
+
{/* 历史卡保留只读浏览:门店行可下钻详情(与 recommend-merchants 同口径)。 */}
|
|
167
|
+
<MerchantRow merchant={item} onSelect={() => openDetail(item)} />
|
|
168
|
+
</li>
|
|
169
|
+
))}
|
|
170
|
+
</ul>
|
|
171
|
+
{/* 与推荐卡同口径:按当前筛选后的条数判断还有没有「更多」可看,
|
|
172
|
+
而不是拿全量比——否则筛到只剩一家时仍会提示「查看全部门店」。 */}
|
|
173
|
+
{filteredItems.length > PREVIEW_ITEM_COUNT && (
|
|
174
|
+
<button
|
|
175
|
+
type="button"
|
|
176
|
+
className="sg-rm-view-all"
|
|
177
|
+
onClick={() => setOverlay({ kind: 'list' })}
|
|
178
|
+
>
|
|
179
|
+
查看全部门店
|
|
180
|
+
<CaretRight size={17} />
|
|
181
|
+
</button>
|
|
182
|
+
)}
|
|
183
|
+
</>
|
|
184
|
+
)}
|
|
185
|
+
|
|
186
|
+
</section>
|
|
187
|
+
|
|
188
|
+
<ShopListSheet
|
|
189
|
+
open={overlay.kind === 'list'}
|
|
190
|
+
items={data.items}
|
|
191
|
+
categoryTabs={allTabs}
|
|
192
|
+
activeTabCode={activeTabCode}
|
|
193
|
+
isHistory={isHistory}
|
|
194
|
+
onSelect={openDetail}
|
|
195
|
+
onClose={closeOverlay}
|
|
196
|
+
/>
|
|
197
|
+
|
|
198
|
+
<ShopDetailSheet
|
|
199
|
+
open={overlay.kind === 'detail'}
|
|
200
|
+
data={sheetData}
|
|
201
|
+
loading={detailLoading}
|
|
202
|
+
cardId={cardId}
|
|
203
|
+
isHistory={isHistory}
|
|
204
|
+
actionTokens={actionTokens}
|
|
205
|
+
claimActionId="promotion.acquire-from-shop-list"
|
|
206
|
+
onClose={closeOverlay}
|
|
207
|
+
/>
|
|
208
|
+
</>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 富卡范式(0.3.2 D10):shop-list 卡本体不渲染默认动作条——领取按钮只存在于
|
|
213
|
+
// 下钻门店详情浮层的券条目里(卡级注册的 promotion.acquire-from-shop-list 仅用于
|
|
214
|
+
// 给下钻浮层签发 contextToken,不在卡面出现)。
|
|
215
|
+
markSelfRendering(ShopListCard);
|
|
216
|
+
export default ShopListCard;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* shopping-guide 展示纯函数(0.4.0 D6:view.ts 只做纯映射/推导,可单测)。
|
|
3
|
+
*/
|
|
4
|
+
import type { ActionDraft, LocationHandoffCardData } from '@tbox.cn/app-contracts-mall';
|
|
5
|
+
|
|
6
|
+
/** 距离展示:<1km → 米整数;否则 x.x km;缺省 '—' */
|
|
7
|
+
export function formatDistance(distanceKm?: number): string {
|
|
8
|
+
if (distanceKm === undefined || distanceKm < 0) return '—';
|
|
9
|
+
if (distanceKm < 1) return `${Math.round(distanceKm * 1000)}m`;
|
|
10
|
+
return `${distanceKm.toFixed(1)} km`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type LocationLevel = 'unavailable' | 'location_only' | 'route_available';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 位置移交三级降级(POC location-handoff 语义):
|
|
17
|
+
* - route_available:可发起导航(itemActions 含 link 类动作);
|
|
18
|
+
* - location_only:仅展示地址(location 完整但无导航动作);
|
|
19
|
+
* - unavailable:地址信息不完整,无任何动作。
|
|
20
|
+
*/
|
|
21
|
+
export function deriveLocationLevel(data: Pick<LocationHandoffCardData, 'location' | 'itemActions'>): LocationLevel {
|
|
22
|
+
const { location, itemActions } = data;
|
|
23
|
+
const hasRoute = itemActions.some((a: ActionDraft) => a.kind === 'link');
|
|
24
|
+
if (hasRoute) return 'route_available';
|
|
25
|
+
const locationComplete = Boolean(location.displayText);
|
|
26
|
+
return locationComplete ? 'location_only' : 'unavailable';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 业态分类图标(支持英文 key 和中文名称关键词匹配;未知类别回退 🏬) */
|
|
30
|
+
const CATEGORY_ICONS: Record<string, string> = {
|
|
31
|
+
// 英文 key
|
|
32
|
+
food: '🍜',
|
|
33
|
+
restaurant: '🍜',
|
|
34
|
+
dining: '🍜',
|
|
35
|
+
drinks: '🥤',
|
|
36
|
+
beverage: '🥤',
|
|
37
|
+
fashion: '👗',
|
|
38
|
+
clothing: '👗',
|
|
39
|
+
apparel: '👗',
|
|
40
|
+
beauty: '💄',
|
|
41
|
+
cosmetics: '💄',
|
|
42
|
+
supermarket: '🛒',
|
|
43
|
+
groceries: '🛒',
|
|
44
|
+
cinema: '🎬',
|
|
45
|
+
entertainment: '🎮',
|
|
46
|
+
kids: '🧸',
|
|
47
|
+
children: '🧸',
|
|
48
|
+
parent_child: '🧸',
|
|
49
|
+
sports: '🏃',
|
|
50
|
+
fitness: '💪',
|
|
51
|
+
electronics: '📱',
|
|
52
|
+
digital: '📱',
|
|
53
|
+
home: '🛋️',
|
|
54
|
+
furniture: '🛋️',
|
|
55
|
+
jewelry: '💍',
|
|
56
|
+
gold: '💍',
|
|
57
|
+
watch: '⌚',
|
|
58
|
+
eyewear: '👓',
|
|
59
|
+
books: '📚',
|
|
60
|
+
education: '📖',
|
|
61
|
+
hotel: '🏨',
|
|
62
|
+
travel: '🧳',
|
|
63
|
+
service: '🧾',
|
|
64
|
+
lifestyle: '🧾',
|
|
65
|
+
parking: '🅿️',
|
|
66
|
+
car: '🚗',
|
|
67
|
+
pharmacy: '💊',
|
|
68
|
+
healthcare: '💊',
|
|
69
|
+
flower: '💐',
|
|
70
|
+
pet: '🐾',
|
|
71
|
+
exhibition: '🖼️',
|
|
72
|
+
office: '🏢',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** 中文业态关键词 → 图标(厂商 CommercialTypeName 直映射) */
|
|
76
|
+
const CATEGORY_ICONS_ZH: Array<[string, string]> = [
|
|
77
|
+
['餐饮', '🍜'],
|
|
78
|
+
['美食', '🍜'],
|
|
79
|
+
['咖啡', '☕'],
|
|
80
|
+
['茶饮', '🧋'],
|
|
81
|
+
['奶茶', '🧋'],
|
|
82
|
+
['饮品', '🥤'],
|
|
83
|
+
['零售', '🛍️'],
|
|
84
|
+
['时尚', '👗'],
|
|
85
|
+
['服装', '👗'],
|
|
86
|
+
['女装', '👗'],
|
|
87
|
+
['男装', '🧥'],
|
|
88
|
+
['运动', '🏃'],
|
|
89
|
+
['健身', '💪'],
|
|
90
|
+
['美妆', '💄'],
|
|
91
|
+
['护肤', '🧴'],
|
|
92
|
+
['美容', '💆'],
|
|
93
|
+
['母婴', '🧸'],
|
|
94
|
+
['儿童', '🧸'],
|
|
95
|
+
['亲子', '🧸'],
|
|
96
|
+
['超市', '🛒'],
|
|
97
|
+
['便利', '🛒'],
|
|
98
|
+
['生鲜', '🥦'],
|
|
99
|
+
['数码', '📱'],
|
|
100
|
+
['电子', '📱'],
|
|
101
|
+
['家居', '🛋️'],
|
|
102
|
+
['家电', '🔌'],
|
|
103
|
+
['珠宝', '💍'],
|
|
104
|
+
['黄金', '🏅'],
|
|
105
|
+
['手表', '⌚'],
|
|
106
|
+
['眼镜', '👓'],
|
|
107
|
+
['书店', '📚'],
|
|
108
|
+
['文具', '✏️'],
|
|
109
|
+
['教育', '📖'],
|
|
110
|
+
['培训', '📖'],
|
|
111
|
+
['影院', '🎬'],
|
|
112
|
+
['电影', '🎬'],
|
|
113
|
+
['娱乐', '🎮'],
|
|
114
|
+
['游戏', '🎮'],
|
|
115
|
+
['文体', '🎭'],
|
|
116
|
+
['文化', '🎨'],
|
|
117
|
+
['艺术', '🎨'],
|
|
118
|
+
['宠物', '🐾'],
|
|
119
|
+
['鲜花', '💐'],
|
|
120
|
+
['医疗', '💊'],
|
|
121
|
+
['药店', '💊'],
|
|
122
|
+
['健康', '🏥'],
|
|
123
|
+
['酒店', '🏨'],
|
|
124
|
+
['旅行', '🧳'],
|
|
125
|
+
['停车', '🅿️'],
|
|
126
|
+
['汽车', '🚗'],
|
|
127
|
+
['服务', '🧾'],
|
|
128
|
+
['生活', '🧾'],
|
|
129
|
+
['银行', '🏦'],
|
|
130
|
+
['金融', '💳'],
|
|
131
|
+
['未归类', '🏪'],
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
export function categoryIcon(code: string): string {
|
|
135
|
+
const key = code.toLowerCase();
|
|
136
|
+
// 英文 key 精确匹配
|
|
137
|
+
if (CATEGORY_ICONS[key]) return CATEGORY_ICONS[key];
|
|
138
|
+
// 英文 key 前缀匹配(如 food_and_beverage)
|
|
139
|
+
for (const [k, icon] of Object.entries(CATEGORY_ICONS)) {
|
|
140
|
+
if (key.startsWith(k)) return icon;
|
|
141
|
+
}
|
|
142
|
+
// 中文名称关键词包含匹配(provider C 端返回中文业态名)
|
|
143
|
+
for (const [keyword, icon] of CATEGORY_ICONS_ZH) {
|
|
144
|
+
if (code.includes(keyword)) return icon;
|
|
145
|
+
}
|
|
146
|
+
return '🏪';
|
|
147
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 品类清单的唯一一份来源:契约给的 `categoryTabs` 打底,再从门店实际的 `businessCategories`
|
|
3
|
+
* 补上契约没列到的。
|
|
4
|
+
*
|
|
5
|
+
* 抽出来是因为两处曾各算各的——半屏做了派生补充,卡片只用 `categoryTabs`。结果同一张卡
|
|
6
|
+
* 卡内看到 5 个品类、点进半屏变成 7 个(多出来的「亲子」「娱乐」正是派生来的),
|
|
7
|
+
* 用户会以为分类口径变了。
|
|
8
|
+
*
|
|
9
|
+
* 派生项的 `code` 带 `derived-` 前缀只为避免与契约 code 撞车;筛选一律按 `name` 匹配
|
|
10
|
+
* `businessCategories`,所以派生项与契约项在筛选上等价。
|
|
11
|
+
*/
|
|
12
|
+
export interface MerchantCategoryTab {
|
|
13
|
+
readonly code: string;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function resolveCategoryTabs(
|
|
18
|
+
categoryTabs: readonly MerchantCategoryTab[] | undefined,
|
|
19
|
+
items: readonly { readonly businessCategories: readonly string[] }[],
|
|
20
|
+
): MerchantCategoryTab[] {
|
|
21
|
+
const result: MerchantCategoryTab[] = [];
|
|
22
|
+
const seenNames = new Set<string>();
|
|
23
|
+
for (const tab of categoryTabs ?? []) {
|
|
24
|
+
const name = tab.name.trim();
|
|
25
|
+
if (!name || seenNames.has(name)) continue;
|
|
26
|
+
seenNames.add(name);
|
|
27
|
+
result.push({ code: tab.code, name });
|
|
28
|
+
}
|
|
29
|
+
for (const item of items) {
|
|
30
|
+
for (const category of item.businessCategories) {
|
|
31
|
+
const name = category.trim();
|
|
32
|
+
if (!name || seenNames.has(name)) continue;
|
|
33
|
+
seenNames.add(name);
|
|
34
|
+
result.push({ code: `derived-${name}`, name });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图片 + 加载失败占位(0.4.0 D6:模块自持 ~20 行,禁跨模块依赖/基元封顶不破)。
|
|
3
|
+
* 源:POC shopping-guide 占位语义。src 缺省或加载失败 → 图标占位。
|
|
4
|
+
*/
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { ImageSquare } from '@phosphor-icons/react';
|
|
7
|
+
|
|
8
|
+
export function ImageWithFallback(props: {
|
|
9
|
+
src?: string;
|
|
10
|
+
alt: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
/** 占位区尺寸(px,图标随比例缩小) */
|
|
13
|
+
size?: number;
|
|
14
|
+
}) {
|
|
15
|
+
const { src, alt, className, size = 40 } = props;
|
|
16
|
+
const [failed, setFailed] = useState(false);
|
|
17
|
+
if (!src || failed) {
|
|
18
|
+
return (
|
|
19
|
+
<div className={`img-fallback ${className ?? ''}`.trim()} aria-label={alt} role="img">
|
|
20
|
+
<ImageSquare weight="duotone" size={Math.round(size * 0.45)} />
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return (
|
|
25
|
+
<img
|
|
26
|
+
className={className}
|
|
27
|
+
src={src}
|
|
28
|
+
alt={alt}
|
|
29
|
+
loading="lazy"
|
|
30
|
+
referrerPolicy="no-referrer"
|
|
31
|
+
onError={() => setFailed(true)}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 门店行:门店导览的三处列表(推荐卡、列表卡、门店列表半屏)共用的唯一一份行结构。
|
|
3
|
+
*
|
|
4
|
+
* 抽出来是因为三处曾各写各的——同一家店在推荐卡上是「名称+状态 / 评分+人均 / 业态+位置 /
|
|
5
|
+
* 营业时间」四行,在半屏里却是「名称+人均 / 位置 / 业态标签+状态」三行,字段与层次都对不上。
|
|
6
|
+
* 靠人工同步两份 JSX 迟早再次分叉,故收成一个组件:**要改行长什么样,只有这一个地方可改。**
|
|
7
|
+
* 现行结构:名称 / 评分+人均(可选)/ 业态标签 / 位置。status 与 operatingStatus 字段保留在
|
|
8
|
+
* 数据契约上但行内不渲染(详情半屏使用)。
|
|
9
|
+
*
|
|
10
|
+
* 样式钩子是 `sg-merchant-row`,不依赖任何外层容器类——原先的尺寸与配色挂在
|
|
11
|
+
* `.sg-recommend-merchants` 下,半屏拿不到,这正是两边长歪的起点。
|
|
12
|
+
* 外层容器各自的视觉(半屏的白底卡片、卡片里的分隔线)由调用方经 `className` 追加。
|
|
13
|
+
*/
|
|
14
|
+
import { MapPin, Star } from '@phosphor-icons/react';
|
|
15
|
+
import { ImageWithFallback } from './ImageWithFallback';
|
|
16
|
+
|
|
17
|
+
export interface MerchantRowData {
|
|
18
|
+
readonly merchantId: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly logoUrl?: string;
|
|
21
|
+
readonly businessCategories: readonly string[];
|
|
22
|
+
readonly location: { readonly displayText: string };
|
|
23
|
+
readonly status: { readonly code: 'enabled' | 'disabled' | 'unknown'; readonly label: string };
|
|
24
|
+
readonly rating?: string;
|
|
25
|
+
readonly avgSpend?: string;
|
|
26
|
+
readonly operatingStatus?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function MerchantRow(props: {
|
|
30
|
+
readonly merchant: MerchantRowData;
|
|
31
|
+
readonly disabled?: boolean;
|
|
32
|
+
readonly className?: string;
|
|
33
|
+
readonly onSelect: () => void;
|
|
34
|
+
}) {
|
|
35
|
+
const { merchant, disabled = false, className, onSelect } = props;
|
|
36
|
+
return (
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
className={['sg-rm-item-head', 'sg-merchant-row', className].filter(Boolean).join(' ')}
|
|
40
|
+
aria-label={`查看${merchant.name}详情`}
|
|
41
|
+
disabled={disabled}
|
|
42
|
+
onClick={onSelect}
|
|
43
|
+
>
|
|
44
|
+
<ImageWithFallback src={merchant.logoUrl} alt="" className="sg-rm-item-image" size={96} />
|
|
45
|
+
<div className="sg-rm-item-meta">
|
|
46
|
+
{/* 名称独占一行:状态胶囊原先钉在右侧,长店名会被挤到省略号
|
|
47
|
+
(「跃动运动集合空间旗舰体验店」只显示得出前八个字)。 */}
|
|
48
|
+
<div className="sg-rm-item-name-row">
|
|
49
|
+
<span className="sg-rm-item-name">{merchant.name}</span>
|
|
50
|
+
</div>
|
|
51
|
+
{(merchant.rating || merchant.avgSpend) && (
|
|
52
|
+
<div className="sg-rm-item-stats">
|
|
53
|
+
{merchant.rating && (
|
|
54
|
+
<span className="sg-rm-item-rating">
|
|
55
|
+
<Star size={14} weight="fill" />
|
|
56
|
+
{merchant.rating}
|
|
57
|
+
</span>
|
|
58
|
+
)}
|
|
59
|
+
{merchant.avgSpend && <span className="sg-rm-item-avg-spend">人均 {merchant.avgSpend}</span>}
|
|
60
|
+
</div>
|
|
61
|
+
)}
|
|
62
|
+
{merchant.businessCategories.length > 0 && (
|
|
63
|
+
<div className="sg-rm-item-tags" aria-label="门店业态">
|
|
64
|
+
{merchant.businessCategories.map((category) => (
|
|
65
|
+
<span key={category} className="sg-rm-item-tag">{category}</span>
|
|
66
|
+
))}
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
{/* 营业状态与营业时间不进行内(2026-09-02):线上厂商数据拿不到真实营业状态,
|
|
70
|
+
恒为「营业状态以现场为准」,展示等于噪音;详情半屏仍显示状态字段。 */}
|
|
71
|
+
<div className="sg-rm-item-location">
|
|
72
|
+
<MapPin size={13} weight="fill" />
|
|
73
|
+
<span>{merchant.location.displayText}</span>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</button>
|
|
77
|
+
);
|
|
78
|
+
}
|