@tbox.cn/app-module-activity-play 1.0.0-alpha.17 → 1.0.0-alpha.19
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/README.md +3 -2
- package/dist/{chunk-OFPXH7OI.js → chunk-3JWG2EQT.js} +6 -23
- package/dist/{chunk-YH6HTRSS.js → chunk-ZT6G6NZQ.js} +3 -81
- package/dist/client/index.js +1 -1
- package/dist/index.js +2 -2
- package/dist/server/index.js +1 -1
- package/package.json +6 -6
- package/src/client/cards/activity-play/ActivityDetailSheet.tsx +6 -4
- package/src/client/cards/activity-play/ActivityPlayCard.tsx +2 -24
- package/src/server/cards/activity-play/meta.ts +1 -1
- package/src/server/cards/activity-play/samples.ts +3 -92
- package/tests/activity-card.test.tsx +59 -3
- package/tests/samples.test.ts +4 -0
package/README.md
CHANGED
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
已随远端活动改造(2026-11-17)退场——参与跳转由前端构造动态插件公开页链接并经宿主 `my.navigateTo` 处理;
|
|
10
10
|
详情只服务展示。本人奖品恒按当前可信用户查询(主体检查先于供给调用——缺用户 LOGIN_REQUIRED
|
|
11
11
|
零奖品 API 调用;领取/核销归供应商)。活动与奖品列表采用门店导览式标题区、图文行和状态标签,图片缺失或加载失败时展示中立图标。
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
活动列表将进行中项置顶,同组保持返回顺序;排序作用于本次已返回条目,不改变供应商查询或截断范围。两类列表默认展示前 3 条,点击底部查看全部在卡片内展开本次已返回条目,不额外查询;奖品截断提示保留。
|
|
13
|
+
活动卡的 list/detail 共用初始态的标题区、图文行与状态标签样式;card-preview 仅保留初始态、列表多状态、列表空态、详情进行中。活动列表“去参与”重新查询活动详情并打开统一 BottomSheet,展示详情主图、标题简介、状态时间、玩法规则和奖品设置;缺少规则或奖品时隐藏对应区块;弹层底部“立即参与”才构造 `dynamic-plugin://2021007119624628/activity?activityId=<编码后的活动ID>` 并经 `callJsapi('navigateTo', {url})` 交给宿主(详情非 active 时禁用);奖品查看详情重新查询本人记录并通过模板 kit 的统一 BottomSheet 打开半屏弹层。
|
|
14
14
|
历史卡禁用参与和奖品详情查询,查看全部仅展开已有快照。宿主需关联动态插件并允许 `my.navigateTo`。
|
|
15
|
+
参与导航失败时,容器标记或支付宝桥能力在场提示“跳转异常,请稍后重试”;非壳提示“电脑端不支持参与,请扫右下角「支付宝小程序」二维码体验”。
|
|
15
16
|
接入语义见 [INTEGRATION.md](INTEGRATION.md)。
|
|
16
17
|
|
|
17
18
|
本文描述当前代码契约。远端活动、直接宿主导航及奖品卡片的目标调整见 [实施计划](../../docs/plans/activity-play-plugin/implementation-plan.md);文档方案不表示本包已完成改造。
|
|
@@ -63,7 +63,7 @@ import { markSelfRendering } from "@tbox.cn/app-agent-sdk-client";
|
|
|
63
63
|
import { useEffect, useRef, useState } from "react";
|
|
64
64
|
import { toast } from "@tbox.cn/app-agent-ui-kit/toast";
|
|
65
65
|
import { BottomSheet } from "@tbox.cn/app-agent-ui-kit/bottom-sheet";
|
|
66
|
-
import { callJsapi, httpGet } from "@tbox.cn/app-agent-sdk-client";
|
|
66
|
+
import { callJsapi, hasAlipayBridge, httpGet, isInAlipayShell } from "@tbox.cn/app-agent-sdk-client";
|
|
67
67
|
import { activityPlayActivitySchema } from "@tbox.cn/app-contracts-mall";
|
|
68
68
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
69
69
|
var ACTIVITY_PLAY_PLUGIN_URL = "dynamic-plugin://2021007119624628/activity";
|
|
@@ -108,13 +108,13 @@ function ActivityDetailSheet({ mallId, activityId, onClose }) {
|
|
|
108
108
|
try {
|
|
109
109
|
await callJsapi("navigateTo", { url: buildActivityPlayPluginUrl(detail.activityId) });
|
|
110
110
|
} catch {
|
|
111
|
-
void toast("\
|
|
111
|
+
void toast(isInAlipayShell() || hasAlipayBridge() ? "\u8DF3\u8F6C\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5" : "\u7535\u8111\u7AEF\u4E0D\u652F\u6301\u53C2\u4E0E\uFF0C\u8BF7\u626B\u53F3\u4E0B\u89D2\u300C\u652F\u4ED8\u5B9D\u5C0F\u7A0B\u5E8F\u300D\u4E8C\u7EF4\u7801\u4F53\u9A8C");
|
|
112
112
|
} finally {
|
|
113
113
|
navigating.current = false;
|
|
114
114
|
setOpening(false);
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
-
return /* @__PURE__ */ jsx(BottomSheet, { open: true, title: "\u6D3B\u52A8\u8BE6\u60C5", onClose, className: "ap-activity-sheet", children: error ? /* @__PURE__ */ jsx("p", { role: "alert", children: error }) : detail ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
117
|
+
return /* @__PURE__ */ jsx(BottomSheet, { open: true, title: "\u6D3B\u52A8\u8BE6\u60C5", onClose, size: "large", className: "ap-activity-sheet", children: error ? /* @__PURE__ */ jsx("p", { role: "alert", children: error }) : detail ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
118
118
|
/* @__PURE__ */ jsxs("section", { className: "ap-card ap-card--detail flex flex-col gap-2 bg-transparent p-0", children: [
|
|
119
119
|
(detail.detailCoverUrl || detail.imageUrl) && /* @__PURE__ */ jsx(
|
|
120
120
|
"img",
|
|
@@ -171,7 +171,7 @@ function ActivityDetailSheet({ mallId, activityId, onClose }) {
|
|
|
171
171
|
] }, index)) })
|
|
172
172
|
] })
|
|
173
173
|
] }),
|
|
174
|
-
/* @__PURE__ */ jsx("footer", { className: "ap-activity-sheet__footer
|
|
174
|
+
/* @__PURE__ */ jsx("footer", { className: "ap-activity-sheet__footer mt-3.5 bg-card pt-2.5 [&>button]:min-h-10 [&>button]:w-full", children: /* @__PURE__ */ jsx(
|
|
175
175
|
"button",
|
|
176
176
|
{
|
|
177
177
|
type: "button",
|
|
@@ -266,25 +266,8 @@ function ActivityRow({ item, mallId, isHistory }) {
|
|
|
266
266
|
function ActivityPlayCard(props) {
|
|
267
267
|
const { data, isHistory = false } = props;
|
|
268
268
|
const [expanded, setExpanded] = useState3(false);
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
const item = data.items[0];
|
|
272
|
-
if (!item) return null;
|
|
273
|
-
const range = [formatActivityPlayTime(item.startsAt), formatActivityPlayTime(item.endsAt)].filter(Boolean).join(" \u2014 ");
|
|
274
|
-
return /* @__PURE__ */ jsxs3("section", { className: "ap-card ap-card--detail flex flex-col gap-2 bg-transparent p-0", children: [
|
|
275
|
-
/* @__PURE__ */ jsx3("span", { className: "ap-card__eyebrow text-xs leading-4.5 text-muted-foreground", children: "\u6D3B\u52A8\u73A9\u6CD5" }),
|
|
276
|
-
/* @__PURE__ */ jsxs3("div", { className: "ap-card__detail-head flex flex-wrap items-center gap-2 [&>strong]:text-base [&>strong]:leading-5.5", children: [
|
|
277
|
-
/* @__PURE__ */ jsx3("strong", { children: item.title }),
|
|
278
|
-
/* @__PURE__ */ jsx3("span", { className: `max-w-full shrink-0 rounded-[3.5px] px-1.5 py-px text-[11px] leading-4 [overflow-wrap:anywhere] ap-badge ap-badge--${activityPlayStatusTone(item.status)} ${activityPlayBadgeClass(item.status)}`, children: activityPlayStatusText(item.status) })
|
|
279
|
-
] }),
|
|
280
|
-
item.description && /* @__PURE__ */ jsx3("p", { className: "ap-card__detail-desc m-0 whitespace-pre-wrap text-[13px] leading-[19px] text-secondary-foreground [overflow-wrap:anywhere]", children: item.description }),
|
|
281
|
-
item.imageUrl && /* @__PURE__ */ jsx3("img", { className: "ap-card__cover max-h-45 w-full rounded-md object-cover", src: item.imageUrl, alt: `${item.title}\u5C01\u9762`, loading: "lazy" }),
|
|
282
|
-
range && /* @__PURE__ */ jsxs3("p", { className: "ap-card__meta m-0 text-xs leading-4.5 text-muted-foreground [overflow-wrap:anywhere]", children: [
|
|
283
|
-
"\u6D3B\u52A8\u65F6\u95F4\uFF1A",
|
|
284
|
-
range
|
|
285
|
-
] })
|
|
286
|
-
] });
|
|
287
|
-
}
|
|
269
|
+
const sortedItems = [...data.items].sort((a, b) => Number(b.status === "active") - Number(a.status === "active"));
|
|
270
|
+
const visibleItems = expanded ? sortedItems : sortedItems.slice(0, LIST_PREVIEW_COUNT);
|
|
288
271
|
return /* @__PURE__ */ jsxs3("section", { className: "ap-card ap-card--list flex flex-col gap-0 bg-card px-3.5", children: [
|
|
289
272
|
/* @__PURE__ */ jsx3(ListHeader, { title: "\u5546\u5708\u6D3B\u52A8\u4E00\u89C8", subtitle: "\u8FD1\u671F\u6D3B\u52A8 \u4E00\u952E\u53C2\u4E0E", kind: "activity" }),
|
|
290
273
|
data.items.length === 0 ? /* @__PURE__ */ jsx3("p", { className: "ap-card__empty m-0 px-1.5 py-5 text-center text-xs leading-4.5 text-secondary-foreground", children: "\u6682\u65E0\u5339\u914D\u7684\u6D3B\u52A8\u73A9\u6CD5" }) : /* @__PURE__ */ jsx3("ul", { className: "ap-card__list m-0 flex list-none flex-col p-0", children: visibleItems.map((item) => /* @__PURE__ */ jsx3(ActivityRow, { item, mallId: data.mallId, isHistory }, item.activityId)) }),
|
|
@@ -776,32 +776,9 @@ var activityPlayCardSamples = [
|
|
|
776
776
|
items: [
|
|
777
777
|
{ activityId: "demo-wheel", title: "\u5E78\u8FD0\u5927\u8F6C\u76D8", description: "\u8FDB\u5165\u6D3B\u52A8\u9875\u9762\u67E5\u770B\u53C2\u4E0E\u89C4\u5219", status: "active" },
|
|
778
778
|
{ activityId: "demo-points", title: "\u79EF\u5206\u7FFB\u500D", startsAt: "2026-12-01T10:00:00+08:00", endsAt: "2026-12-31T22:00:00+08:00", status: "not_started" },
|
|
779
|
-
{ activityId: "demo-ended", title: "\u5468\u5E74\u5E86\u62BD\u5956", description: "\u6D3B\u52A8\u5DF2\u7ED3\u675F", endsAt: "2026-10-31T22:00:00+08:00", status: "ended" }
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
label: "\u5217\u8868\xB7\u5E26\u5C01\u9762",
|
|
785
|
-
group: "\u6D3B\u52A8\u73A9\u6CD5\xB7\u5217\u8868",
|
|
786
|
-
note: "\u53EF\u9009 imageUrl \u5B57\u6BB5\u5728\u573A\uFF08HTTPS \u5360\u4F4D\u2014\u2014\u7F3A\u7701\u56FE\u515C\u5E95\u5206\u652F\u7684\u7B49\u4EF7\u793A\u8303\uFF09",
|
|
787
|
-
data: {
|
|
788
|
-
mallId: "mall-demo",
|
|
789
|
-
mode: "list",
|
|
790
|
-
items: [
|
|
791
|
-
{ activityId: "demo-wheel", title: "\u5E78\u8FD0\u5927\u8F6C\u76D8", imageUrl: "https://example.com/wheel.png", status: "active" }
|
|
792
|
-
]
|
|
793
|
-
}
|
|
794
|
-
},
|
|
795
|
-
{
|
|
796
|
-
label: "\u5217\u8868\xB7\u6570\u5B57\u5F62\u6001 ID",
|
|
797
|
-
group: "\u6D3B\u52A8\u73A9\u6CD5\xB7\u5217\u8868",
|
|
798
|
-
note: 'activityId \u6309\u539F\u5B57\u7B26\u4E32\u5904\u7406\u2014\u2014"001" \u4E0E "1" \u662F\u4E0D\u540C\u6D3B\u52A8\uFF08\u4F9B\u5E94\u5546\u5B9A\u4E49\u6807\u8BC6\u7A7A\u95F4\uFF09',
|
|
799
|
-
data: {
|
|
800
|
-
mallId: "mall-demo",
|
|
801
|
-
mode: "list",
|
|
802
|
-
items: [
|
|
803
|
-
{ activityId: "001", title: "\u96F6\u4E00\u6D3B\u52A8", status: "active" },
|
|
804
|
-
{ activityId: "1", title: "\u58F9\u53F7\u6D3B\u52A8", status: "active" }
|
|
779
|
+
{ activityId: "demo-ended", title: "\u5468\u5E74\u5E86\u62BD\u5956", description: "\u6D3B\u52A8\u5DF2\u7ED3\u675F", endsAt: "2026-10-31T22:00:00+08:00", status: "ended" },
|
|
780
|
+
{ activityId: "demo-paused", title: "\u6682\u505C\u4E2D\u7684\u6D3B\u52A8", status: "disabled" },
|
|
781
|
+
{ activityId: "demo-weird", title: "\u795E\u79D8\u65B0\u73A9\u6CD5", status: "unknown" }
|
|
805
782
|
]
|
|
806
783
|
}
|
|
807
784
|
},
|
|
@@ -834,61 +811,6 @@ var activityPlayCardSamples = [
|
|
|
834
811
|
}
|
|
835
812
|
]
|
|
836
813
|
}
|
|
837
|
-
},
|
|
838
|
-
{
|
|
839
|
-
label: "\u8BE6\u60C5\xB7\u672A\u5F00\u59CB",
|
|
840
|
-
group: "\u6D3B\u52A8\u73A9\u6CD5\xB7\u8BE6\u60C5",
|
|
841
|
-
note: "\u65F6\u95F4\u4E0E\u72B6\u6001\u5E76\u5B58\uFF08\u56DE\u590D\u300C\u4EC0\u4E48\u65F6\u5019\u5F00\u59CB\u300D\u7684\u5C55\u793A\u5206\u652F\uFF09",
|
|
842
|
-
data: {
|
|
843
|
-
mallId: "mall-demo",
|
|
844
|
-
mode: "detail",
|
|
845
|
-
items: [
|
|
846
|
-
{
|
|
847
|
-
activityId: "demo-points",
|
|
848
|
-
title: "\u79EF\u5206\u7FFB\u500D",
|
|
849
|
-
description: "\u6D3B\u52A8\u671F\u95F4\u6D88\u8D39\u79EF\u5206\u53CC\u500D",
|
|
850
|
-
startsAt: "2026-12-01T10:00:00+08:00",
|
|
851
|
-
endsAt: "2026-12-31T22:00:00+08:00",
|
|
852
|
-
status: "not_started"
|
|
853
|
-
}
|
|
854
|
-
]
|
|
855
|
-
}
|
|
856
|
-
},
|
|
857
|
-
{
|
|
858
|
-
label: "\u8BE6\u60C5\xB7\u72B6\u6001\u672A\u77E5",
|
|
859
|
-
group: "\u6D3B\u52A8\u73A9\u6CD5\xB7\u8BE6\u60C5",
|
|
860
|
-
note: "unknown \u4FDD\u5B88\u5C55\u793A\uFF08\u4E0A\u6E38\u672A\u77E5\u679A\u4E3E\u2014\u2014\u4E0D\u63A8\u65AD\u4E3A\u8FDB\u884C\u4E2D\uFF0C\u4E0D\u5F15\u5BFC\u53C2\u4E0E\u52A8\u4F5C\uFF09",
|
|
861
|
-
data: {
|
|
862
|
-
mallId: "mall-demo",
|
|
863
|
-
mode: "detail",
|
|
864
|
-
items: [
|
|
865
|
-
{ activityId: "demo-weird", title: "\u795E\u79D8\u65B0\u73A9\u6CD5", status: "unknown" }
|
|
866
|
-
]
|
|
867
|
-
}
|
|
868
|
-
},
|
|
869
|
-
{
|
|
870
|
-
label: "\u8BE6\u60C5\xB7\u5DF2\u4E0B\u7EBF",
|
|
871
|
-
group: "\u6D3B\u52A8\u73A9\u6CD5\xB7\u8BE6\u60C5",
|
|
872
|
-
note: "\u8BE6\u60C5\u5141\u8BB8\u8FD4\u56DE disabled\uFF08\u4F9B\u5E94\u5546\u5DF2\u505C\u7528\u2014\u2014\u8BF4\u660E\u72B6\u6001\uFF0C\u4E0D\u7B49\u4E8E\u4E0D\u5B58\u5728\uFF09",
|
|
873
|
-
data: {
|
|
874
|
-
mallId: "mall-demo",
|
|
875
|
-
mode: "detail",
|
|
876
|
-
items: [
|
|
877
|
-
{ activityId: "demo-paused", title: "\u6682\u505C\u4E2D\u7684\u6D3B\u52A8", status: "disabled" }
|
|
878
|
-
]
|
|
879
|
-
}
|
|
880
|
-
},
|
|
881
|
-
{
|
|
882
|
-
label: "\u8BE6\u60C5\xB7\u5DF2\u7ED3\u675F",
|
|
883
|
-
group: "\u6D3B\u52A8\u73A9\u6CD5\xB7\u8BE6\u60C5",
|
|
884
|
-
note: "ended \u6001\uFF08\u5386\u53F2\u8BF4\u660E\u7528\uFF09",
|
|
885
|
-
data: {
|
|
886
|
-
mallId: "mall-demo",
|
|
887
|
-
mode: "detail",
|
|
888
|
-
items: [
|
|
889
|
-
{ activityId: "demo-ended", title: "\u5468\u5E74\u5E86\u62BD\u5956", description: "\u6D3B\u52A8\u5DF2\u7ED3\u675F", endsAt: "2026-10-31T22:00:00+08:00", status: "ended" }
|
|
890
|
-
]
|
|
891
|
-
}
|
|
892
814
|
}
|
|
893
815
|
];
|
|
894
816
|
|
package/dist/client/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -31,10 +31,10 @@ import {
|
|
|
31
31
|
toActivityPlayPrizeError,
|
|
32
32
|
toPrizeDetailCardData,
|
|
33
33
|
toPrizeListCardData
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-ZT6G6NZQ.js";
|
|
35
35
|
import {
|
|
36
36
|
clientModule
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-3JWG2EQT.js";
|
|
38
38
|
export {
|
|
39
39
|
ACTIVITY_PLAY_CARD_TYPE,
|
|
40
40
|
ACTIVITY_PLAY_LIMIT_DEFAULT,
|
package/dist/server/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-module-activity-play",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "活动玩法业务模块:供应商活动查询(HTTP/工具/出卡)",
|
|
6
6
|
"exports": {
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@tbox.cn/app-contracts": "1.0.0-alpha.
|
|
23
|
-
"@tbox.cn/app-
|
|
24
|
-
"@tbox.cn/app-
|
|
25
|
-
"@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.
|
|
22
|
+
"@tbox.cn/app-contracts": "1.0.0-alpha.19",
|
|
23
|
+
"@tbox.cn/app-contracts-mall": "1.0.0-alpha.19",
|
|
24
|
+
"@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.19",
|
|
25
|
+
"@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.19"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"zod": "3.25.76",
|
|
29
29
|
"react": "18.3.1",
|
|
30
|
-
"@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.
|
|
30
|
+
"@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.19"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/express": "4.17.25",
|
|
@@ -2,7 +2,7 @@ import { activityPlayBadgeClass } from '../view';
|
|
|
2
2
|
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { toast } from '@tbox.cn/app-agent-ui-kit/toast';
|
|
4
4
|
import { BottomSheet } from '@tbox.cn/app-agent-ui-kit/bottom-sheet';
|
|
5
|
-
import { callJsapi, httpGet } from '@tbox.cn/app-agent-sdk-client';
|
|
5
|
+
import { callJsapi, hasAlipayBridge, httpGet, isInAlipayShell } from '@tbox.cn/app-agent-sdk-client';
|
|
6
6
|
import { activityPlayActivitySchema } from '@tbox.cn/app-contracts-mall';
|
|
7
7
|
import type { ActivityPlayActivity } from '@tbox.cn/app-contracts-mall';
|
|
8
8
|
import { activityPlayStatusText, activityPlayStatusTone, formatActivityPlayTime } from '../view';
|
|
@@ -57,7 +57,9 @@ export function ActivityDetailSheet({ mallId, activityId, onClose }: {
|
|
|
57
57
|
try {
|
|
58
58
|
await callJsapi('navigateTo', { url: buildActivityPlayPluginUrl(detail.activityId) });
|
|
59
59
|
} catch {
|
|
60
|
-
void toast(
|
|
60
|
+
void toast(isInAlipayShell() || hasAlipayBridge()
|
|
61
|
+
? '跳转异常,请稍后重试'
|
|
62
|
+
: '电脑端不支持参与,请扫右下角「支付宝小程序」二维码体验');
|
|
61
63
|
} finally {
|
|
62
64
|
navigating.current = false;
|
|
63
65
|
setOpening(false);
|
|
@@ -65,7 +67,7 @@ export function ActivityDetailSheet({ mallId, activityId, onClose }: {
|
|
|
65
67
|
};
|
|
66
68
|
|
|
67
69
|
return (
|
|
68
|
-
<BottomSheet open title="活动详情" onClose={onClose} className="ap-activity-sheet">
|
|
70
|
+
<BottomSheet open title="活动详情" onClose={onClose} size="large" className="ap-activity-sheet">
|
|
69
71
|
{error ? <p role="alert">{error}</p> : detail ? (
|
|
70
72
|
<>
|
|
71
73
|
<section className="ap-card ap-card--detail flex flex-col gap-2 bg-transparent p-0">
|
|
@@ -130,7 +132,7 @@ export function ActivityDetailSheet({ mallId, activityId, onClose }: {
|
|
|
130
132
|
</section>
|
|
131
133
|
)}
|
|
132
134
|
</section>
|
|
133
|
-
<footer className="ap-activity-sheet__footer
|
|
135
|
+
<footer className="ap-activity-sheet__footer mt-3.5 bg-card pt-2.5 [&>button]:min-h-10 [&>button]:w-full">
|
|
134
136
|
<button type="button" className="ap-list__action shrink-0 cursor-pointer rounded-full border-0 bg-primary px-3 py-1 text-xs font-semibold leading-4.5 text-white disabled:cursor-default disabled:opacity-45" disabled={opening || detail.status !== 'active'}
|
|
135
137
|
onClick={() => { void participate(); }}>
|
|
136
138
|
{opening ? '打开中' : detail.status === 'active' ? '立即参与' : activityPlayStatusText(detail.status)}
|
|
@@ -50,30 +50,8 @@ function ActivityRow({ item, mallId, isHistory }: {
|
|
|
50
50
|
export function ActivityPlayCard(props: { data: ActivityPlayCardData; isHistory?: boolean }) {
|
|
51
51
|
const { data, isHistory = false } = props;
|
|
52
52
|
const [expanded, setExpanded] = useState(false);
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const item = data.items[0];
|
|
56
|
-
if (!item) return null; // 契约保证 detail 恰 1 项;防御性渲染
|
|
57
|
-
const range = [formatActivityPlayTime(item.startsAt), formatActivityPlayTime(item.endsAt)]
|
|
58
|
-
.filter(Boolean)
|
|
59
|
-
.join(' — ');
|
|
60
|
-
return (
|
|
61
|
-
<section className="ap-card ap-card--detail flex flex-col gap-2 bg-transparent p-0">
|
|
62
|
-
<span className="ap-card__eyebrow text-xs leading-4.5 text-muted-foreground">活动玩法</span>
|
|
63
|
-
<div className="ap-card__detail-head flex flex-wrap items-center gap-2 [&>strong]:text-base [&>strong]:leading-5.5">
|
|
64
|
-
<strong>{item.title}</strong>
|
|
65
|
-
<span className={`max-w-full shrink-0 rounded-[3.5px] px-1.5 py-px text-[11px] leading-4 [overflow-wrap:anywhere] ap-badge ap-badge--${activityPlayStatusTone(item.status)} ${activityPlayBadgeClass(item.status)}`}>
|
|
66
|
-
{activityPlayStatusText(item.status)}
|
|
67
|
-
</span>
|
|
68
|
-
</div>
|
|
69
|
-
{item.description && <p className="ap-card__detail-desc m-0 whitespace-pre-wrap text-[13px] leading-[19px] text-secondary-foreground [overflow-wrap:anywhere]">{item.description}</p>}
|
|
70
|
-
{item.imageUrl && (
|
|
71
|
-
<img className="ap-card__cover max-h-45 w-full rounded-md object-cover" src={item.imageUrl} alt={`${item.title}封面`} loading="lazy" />
|
|
72
|
-
)}
|
|
73
|
-
{range && <p className="ap-card__meta m-0 text-xs leading-4.5 text-muted-foreground [overflow-wrap:anywhere]">活动时间:{range}</p>}
|
|
74
|
-
</section>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
53
|
+
const sortedItems = [...data.items].sort((a, b) => Number(b.status === 'active') - Number(a.status === 'active'));
|
|
54
|
+
const visibleItems = expanded ? sortedItems : sortedItems.slice(0, LIST_PREVIEW_COUNT);
|
|
77
55
|
return (
|
|
78
56
|
<section className="ap-card ap-card--list flex flex-col gap-0 bg-card px-3.5">
|
|
79
57
|
<ListHeader title="商圈活动一览" subtitle="近期活动 一键参与" kind="activity" />
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* activity-play 卡元数据(单一稳定传输卡型;mode 区分列表/详情——视觉由前端渲染器组织)。
|
|
3
3
|
* 数据契约单源 = contracts-mall activityPlayCardDataSchema(条目复用供应商活动对象
|
|
4
4
|
* activityPlayActivitySchema——不含本地目录/入口配置字段)。信封字段(ID/时间戳/历史
|
|
5
|
-
* 标记)由 SDK 生成。unknown
|
|
5
|
+
* 标记)由 SDK 生成。unknown 状态由列表多状态样本覆盖。
|
|
6
6
|
*/
|
|
7
7
|
import type { CardMeta } from '@tbox.cn/app-contracts';
|
|
8
8
|
import { activityPlayCardDataSchema } from '@tbox.cn/app-contracts-mall';
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* activity-play 卡附加预览样本(远端活动改造 2026-11-17——覆盖列表/详情/空态/
|
|
3
|
-
* 四种已知状态与 unknown/可空字段缺席)。
|
|
4
|
-
*
|
|
5
|
-
* 方法论(对齐 member/parking 画廊沉淀约定):
|
|
6
|
-
* - 样本即契约:全样本 data 必须 activityPlayCardDataSchema 校验通过且无 shape 外键
|
|
7
|
-
* (module tests/samples.test.ts 双断言);
|
|
8
|
-
* - mallId 恒用 demo 商圈标识(卡片 data 的 mallId 来自执行上下文——样本仅预览展示位);
|
|
9
|
-
* - activityId 用字符形态多样的假值('001' 引用形态示例——原字符串语义示范);
|
|
10
|
-
* - imageUrl 只用 example.com 占位(缺省图兜底分支的等价示范);
|
|
11
|
-
* - 可选字段(说明/图片/起止时间)缺席样本在场(外部缺事实不编造)。
|
|
12
|
-
*/
|
|
1
|
+
/** 活动玩法附加预览:列表多状态、列表空态、详情进行中;初始态由 meta.sampleData 提供。 */
|
|
13
2
|
import type { CardSample } from '@tbox.cn/app-contracts';
|
|
14
3
|
import type { ActivityPlayCardData } from '@tbox.cn/app-contracts-mall';
|
|
15
4
|
|
|
@@ -25,31 +14,8 @@ export const activityPlayCardSamples: CardSample<ActivityPlayCardData>[] = [
|
|
|
25
14
|
{ activityId: 'demo-wheel', title: '幸运大转盘', description: '进入活动页面查看参与规则', status: 'active' },
|
|
26
15
|
{ activityId: 'demo-points', title: '积分翻倍', startsAt: '2026-12-01T10:00:00+08:00', endsAt: '2026-12-31T22:00:00+08:00', status: 'not_started' },
|
|
27
16
|
{ activityId: 'demo-ended', title: '周年庆抽奖', description: '活动已结束', endsAt: '2026-10-31T22:00:00+08:00', status: 'ended' },
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
label: '列表·带封面',
|
|
33
|
-
group: '活动玩法·列表',
|
|
34
|
-
note: '可选 imageUrl 字段在场(HTTPS 占位——缺省图兜底分支的等价示范)',
|
|
35
|
-
data: {
|
|
36
|
-
mallId: 'mall-demo',
|
|
37
|
-
mode: 'list',
|
|
38
|
-
items: [
|
|
39
|
-
{ activityId: 'demo-wheel', title: '幸运大转盘', imageUrl: 'https://example.com/wheel.png', status: 'active' },
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
label: '列表·数字形态 ID',
|
|
45
|
-
group: '活动玩法·列表',
|
|
46
|
-
note: 'activityId 按原字符串处理——"001" 与 "1" 是不同活动(供应商定义标识空间)',
|
|
47
|
-
data: {
|
|
48
|
-
mallId: 'mall-demo',
|
|
49
|
-
mode: 'list',
|
|
50
|
-
items: [
|
|
51
|
-
{ activityId: '001', title: '零一活动', status: 'active' },
|
|
52
|
-
{ activityId: '1', title: '壹号活动', status: 'active' },
|
|
17
|
+
{ activityId: 'demo-paused', title: '暂停中的活动', status: 'disabled' },
|
|
18
|
+
{ activityId: 'demo-weird', title: '神秘新玩法', status: 'unknown' },
|
|
53
19
|
],
|
|
54
20
|
},
|
|
55
21
|
},
|
|
@@ -83,59 +49,4 @@ export const activityPlayCardSamples: CardSample<ActivityPlayCardData>[] = [
|
|
|
83
49
|
],
|
|
84
50
|
},
|
|
85
51
|
},
|
|
86
|
-
{
|
|
87
|
-
label: '详情·未开始',
|
|
88
|
-
group: '活动玩法·详情',
|
|
89
|
-
note: '时间与状态并存(回复「什么时候开始」的展示分支)',
|
|
90
|
-
data: {
|
|
91
|
-
mallId: 'mall-demo',
|
|
92
|
-
mode: 'detail',
|
|
93
|
-
items: [
|
|
94
|
-
{
|
|
95
|
-
activityId: 'demo-points',
|
|
96
|
-
title: '积分翻倍',
|
|
97
|
-
description: '活动期间消费积分双倍',
|
|
98
|
-
startsAt: '2026-12-01T10:00:00+08:00',
|
|
99
|
-
endsAt: '2026-12-31T22:00:00+08:00',
|
|
100
|
-
status: 'not_started',
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
label: '详情·状态未知',
|
|
107
|
-
group: '活动玩法·详情',
|
|
108
|
-
note: 'unknown 保守展示(上游未知枚举——不推断为进行中,不引导参与动作)',
|
|
109
|
-
data: {
|
|
110
|
-
mallId: 'mall-demo',
|
|
111
|
-
mode: 'detail',
|
|
112
|
-
items: [
|
|
113
|
-
{ activityId: 'demo-weird', title: '神秘新玩法', status: 'unknown' },
|
|
114
|
-
],
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
label: '详情·已下线',
|
|
119
|
-
group: '活动玩法·详情',
|
|
120
|
-
note: '详情允许返回 disabled(供应商已停用——说明状态,不等于不存在)',
|
|
121
|
-
data: {
|
|
122
|
-
mallId: 'mall-demo',
|
|
123
|
-
mode: 'detail',
|
|
124
|
-
items: [
|
|
125
|
-
{ activityId: 'demo-paused', title: '暂停中的活动', status: 'disabled' },
|
|
126
|
-
],
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
label: '详情·已结束',
|
|
131
|
-
group: '活动玩法·详情',
|
|
132
|
-
note: 'ended 态(历史说明用)',
|
|
133
|
-
data: {
|
|
134
|
-
mallId: 'mall-demo',
|
|
135
|
-
mode: 'detail',
|
|
136
|
-
items: [
|
|
137
|
-
{ activityId: 'demo-ended', title: '周年庆抽奖', description: '活动已结束', endsAt: '2026-10-31T22:00:00+08:00', status: 'ended' },
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
52
|
];
|
|
@@ -6,10 +6,13 @@ import type { Root } from 'react-dom/client';
|
|
|
6
6
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
7
|
import { ActivityPlayPrizeListCard } from '../src/client/cards/activity-play-prize/ActivityPlayPrizeListCard';
|
|
8
8
|
import { ActivityPlayCard } from '../src/client/cards/activity-play/ActivityPlayCard';
|
|
9
|
+
import activityMeta from '../src/server/cards/activity-play/meta';
|
|
9
10
|
|
|
10
|
-
const { httpGet, callJsapi, toast } = vi.hoisted(() => ({
|
|
11
|
+
const { httpGet, callJsapi, toast, isInAlipayShell, hasAlipayBridge } = vi.hoisted(() => ({
|
|
12
|
+
httpGet: vi.fn(), callJsapi: vi.fn(), toast: vi.fn(), isInAlipayShell: vi.fn(), hasAlipayBridge: vi.fn(),
|
|
13
|
+
}));
|
|
11
14
|
vi.mock('@tbox.cn/app-agent-ui-kit/toast', () => ({ toast }));
|
|
12
|
-
vi.mock('@tbox.cn/app-agent-sdk-client', () => ({ httpGet, callJsapi, markSelfRendering: vi.fn() }));
|
|
15
|
+
vi.mock('@tbox.cn/app-agent-sdk-client', () => ({ httpGet, callJsapi, isInAlipayShell, hasAlipayBridge, markSelfRendering: vi.fn() }));
|
|
13
16
|
// 业务交互测试;通用弹层的 portal、焦点、遮罩由 kit 测试覆盖。
|
|
14
17
|
vi.mock('@tbox.cn/app-agent-ui-kit/bottom-sheet', () => ({
|
|
15
18
|
BottomSheet: ({ children, onClose }: { children: ReactNode; onClose: () => void }) => (
|
|
@@ -20,6 +23,8 @@ const item = { activityId: 'act_001', title: '列表活动', status: 'active' as
|
|
|
20
23
|
let root: Root;
|
|
21
24
|
beforeEach(() => {
|
|
22
25
|
vi.clearAllMocks();
|
|
26
|
+
isInAlipayShell.mockReturnValue(true);
|
|
27
|
+
hasAlipayBridge.mockReturnValue(false);
|
|
23
28
|
const container = document.createElement('div');
|
|
24
29
|
document.body.append(container);
|
|
25
30
|
root = createRoot(container);
|
|
@@ -39,6 +44,43 @@ async function click(label: string) {
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
describe('活动列表参与交互', () => {
|
|
47
|
+
it('四种预览状态共用初始态卡壳、标题区与图文行样式', async () => {
|
|
48
|
+
let initialShellClass: string | undefined;
|
|
49
|
+
let initialRowClass: string | undefined;
|
|
50
|
+
for (const data of [activityMeta.sampleData!, ...(activityMeta.samples ?? []).map((sample) => sample.data)]) {
|
|
51
|
+
await act(async () => root.render(<ActivityPlayCard data={data} />));
|
|
52
|
+
const shell = document.querySelector('.ap-card')!;
|
|
53
|
+
initialShellClass ??= shell.className;
|
|
54
|
+
expect(shell.className).toBe(initialShellClass);
|
|
55
|
+
expect(shell.textContent).toContain('商圈活动一览');
|
|
56
|
+
expect(shell.querySelector('.ap-card--detail')).toBeNull();
|
|
57
|
+
const row = shell.querySelector('.ap-card__row');
|
|
58
|
+
if (row) {
|
|
59
|
+
initialRowClass ??= row.className;
|
|
60
|
+
expect(row.className).toBe(initialRowClass);
|
|
61
|
+
} else {
|
|
62
|
+
expect(shell.textContent).toContain('暂无匹配的活动玩法');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('进行中活动稳定置顶,预览与展开保持一致且不修改卡片快照', async () => {
|
|
68
|
+
const items = [
|
|
69
|
+
{ ...item, activityId: 'ended', title: '已结束', status: 'ended' as const },
|
|
70
|
+
{ ...item, activityId: 'active-1', title: '进行中一' },
|
|
71
|
+
{ ...item, activityId: 'pending', title: '未开始', status: 'not_started' as const },
|
|
72
|
+
{ ...item, activityId: 'active-2', title: '进行中二' },
|
|
73
|
+
{ ...item, activityId: 'unknown', title: '未知', status: 'unknown' as const },
|
|
74
|
+
];
|
|
75
|
+
const originalIds = items.map((entry) => entry.activityId);
|
|
76
|
+
await act(async () => root.render(<ActivityPlayCard data={{ mallId: 'mall-a', mode: 'list', items }} />));
|
|
77
|
+
const titles = () => [...document.querySelectorAll('.ap-card__row-title strong')].map((node) => node.textContent);
|
|
78
|
+
expect(titles()).toEqual(['进行中一', '进行中二', '已结束']);
|
|
79
|
+
await click('查看全部活动');
|
|
80
|
+
expect(titles()).toEqual(['进行中一', '进行中二', '已结束', '未开始', '未知']);
|
|
81
|
+
expect(items.map((entry) => entry.activityId)).toEqual(originalIds);
|
|
82
|
+
});
|
|
83
|
+
|
|
42
84
|
it('列表按钮只查详情并打开弹层;立即参与才经宿主导航打开插件,重复点击只导航一次', async () => {
|
|
43
85
|
await render();
|
|
44
86
|
await click('去参与');
|
|
@@ -96,10 +138,24 @@ describe('活动列表参与交互', () => {
|
|
|
96
138
|
await click('去参与');
|
|
97
139
|
expect(httpGet).toHaveBeenCalledTimes(2);
|
|
98
140
|
await click('立即参与');
|
|
99
|
-
expect(toast).toHaveBeenCalledWith('
|
|
141
|
+
expect(toast).toHaveBeenCalledWith('跳转异常,请稍后重试');
|
|
100
142
|
expect(document.querySelector('[role="alert"]')).toBeNull();
|
|
101
143
|
});
|
|
102
144
|
|
|
145
|
+
it.each([
|
|
146
|
+
{ shell: false, bridge: false, message: '电脑端不支持参与,请扫右下角「支付宝小程序」二维码体验' },
|
|
147
|
+
{ shell: true, bridge: false, message: '跳转异常,请稍后重试' },
|
|
148
|
+
{ shell: false, bridge: true, message: '跳转异常,请稍后重试' },
|
|
149
|
+
])('导航失败提示按容器与实际桥能力区分:$shell/$bridge', async ({ shell, bridge, message }) => {
|
|
150
|
+
isInAlipayShell.mockReturnValue(shell);
|
|
151
|
+
hasAlipayBridge.mockReturnValue(bridge);
|
|
152
|
+
callJsapi.mockRejectedValueOnce({ code: 'BRIDGE_UNAVAILABLE' });
|
|
153
|
+
await render();
|
|
154
|
+
await click('去参与');
|
|
155
|
+
await click('立即参与');
|
|
156
|
+
expect(toast).toHaveBeenCalledWith(message);
|
|
157
|
+
});
|
|
158
|
+
|
|
103
159
|
it('详情按接口展示主图、规则及奖品档位,空字段不显示对应区块', async () => {
|
|
104
160
|
await render();
|
|
105
161
|
httpGet.mockResolvedValueOnce({ status: 200, data: { data: {
|
package/tests/samples.test.ts
CHANGED
|
@@ -15,6 +15,10 @@ const sampledStatuses = new Set(
|
|
|
15
15
|
);
|
|
16
16
|
|
|
17
17
|
describe('activity-play 样本即契约(T02-05)', () => {
|
|
18
|
+
it('预览仅保留初始态及三个指定附加状态', () => {
|
|
19
|
+
expect(meta.samples?.map((sample) => sample.label)).toEqual(['列表·多状态', '列表·空态', '详情·进行中']);
|
|
20
|
+
});
|
|
21
|
+
|
|
18
22
|
it('sampleData 与全附加样本过 dataSchema + shape 无越界键', () => {
|
|
19
23
|
expect(activityPlayCardDataSchema.safeParse(meta.sampleData).success).toBe(true);
|
|
20
24
|
expect(findSampleShapeViolations(meta).violations).toEqual([]);
|