mantur-components 0.1.13-beta.0 → 0.1.13-beta.2

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 CHANGED
@@ -42,7 +42,13 @@ export function Header({
42
42
  }: {
43
43
  userInfo: { username?: string; nickname?: string; avatar?: string } | null;
44
44
  }) {
45
- return <ManturHeader user={userInfo} />;
45
+ return (
46
+ <ManturHeader
47
+ user={userInfo}
48
+ appName={import.meta.env.VITE_APP_NAME}
49
+ mainPrefix={import.meta.env.VITE_MAIN_PREFIX}
50
+ />
51
+ );
46
52
  }
47
53
  ```
48
54
 
@@ -62,6 +68,8 @@ export function Header({
62
68
  <ManturHeader
63
69
  user={userInfo}
64
70
  disabled={disabled}
71
+ appName={import.meta.env.VITE_APP_NAME}
72
+ mainPrefix={import.meta.env.VITE_MAIN_PREFIX}
65
73
  brandSlot={<span className="text-lg font-bold">自定义品牌</span>}
66
74
  >
67
75
  <div className="px-4">自定义中间内容</div>
@@ -80,6 +88,8 @@ interface ManturHeaderProps {
80
88
  children?: React.ReactNode;
81
89
  onTenantContextChange?: (detail: ManturTenantContextDetail) => void;
82
90
  rechargePaymentMethod?: "card" | "alipay" | "wechat_pay";
91
+ appName?: string;
92
+ mainPrefix?: string;
83
93
  stripePublishableKey?: string;
84
94
  stripePaymentWindowFeatures?: string;
85
95
  }
@@ -97,6 +107,10 @@ interface ManturHeaderProps {
97
107
 
98
108
  `rechargePaymentMethod`:兼容旧版本的支付方式参数。当前充值创建订单不再主动提交支付方式,支付方式由 Stripe Checkout Session 内部选择。
99
109
 
110
+ `appName`:当前宿主应用名,建议宿主在调用 Header 时传 `appName={import.meta.env.VITE_APP_NAME}`。充值创建订单时会优先使用该值作为请求体 `app`,不传时才回退到 `window.__MANTUR_APP_NAME__`、组件库构建环境或本地开发端口推断。
111
+
112
+ `mainPrefix`:主应用域名前缀,建议宿主传 `mainPrefix={import.meta.env.VITE_MAIN_PREFIX}`。Header logo hover 时展示“主页/Home”,点击会跳回主应用首页;本地开发环境(`localhost`/`127.0.0.1`)固定跳到 `:80`,测试和生产环境按 `mainPrefix` 替换当前子域名。
113
+
100
114
  `stripePublishableKey`:Stripe publishable key。订单返回 Checkout Session `clientSecret`(字段名为 `clientSecret`,值以 `cs_` 开头)时,组件库会在自己的支付弹窗中挂载 Stripe Checkout Elements。
101
115
 
102
116
  `stripePaymentWindowFeatures`:兼容旧版本的窗口配置参数。当前支付不再打开新窗口,不读取该参数。
@@ -153,7 +167,7 @@ import {
153
167
  } from "mantur-components";
154
168
  ```
155
169
 
156
- 充值面板打开时会调用 `getManturBillingPackages()` 拉取 `/billing/packages`;点击支付时会调用 `createManturRechargeOrder()` 创建 `/billing/recharge/orders`,请求体传 `packageId` 或 `customAmount`,并固定传 `uiMode: "elements"`。请求体还会补齐 `app` 和 `redirect`:`app` `window.__MANTUR_APP_NAME__` `VITE_APP_NAME`;本地开发若没有这些配置,会用当前端口兜底识别应用(`:82` creative-agent、`:83` production-agent、`:81` traffic-engine、`:84` distribution-matrix)。`redirect` 与路由拦截器一致,只取当前页面的 `pathname + search + hash`,不拼接协议、域名或开发端口。订单创建成功后会触发浏览器事件 `mantur-recharge-order-created`,`detail` 为后端返回的订单信息。
170
+ 充值面板打开时会调用 `getManturBillingPackages()` 拉取 `/billing/packages`;点击支付时会调用 `createManturRechargeOrder()` 创建 `/billing/recharge/orders`,请求体传 `packageId` 或 `customAmount`,并固定传 `uiMode: "elements"`。请求体还会补齐 `app` 和 `redirect`:`app` 优先取 `ManturHeader` 的 `appName` prop,建议宿主传 `import.meta.env.VITE_APP_NAME`;未传时回退到 `window.__MANTUR_APP_NAME__` 或组件库内可读取的 `VITE_APP_NAME`;本地开发若没有这些配置,会用当前端口兜底识别应用(`:82` creative-agent、`:83` production-agent、`:81` traffic-engine、`:84` distribution-matrix)。`redirect` 与路由拦截器一致,只取当前页面的 `pathname + search + hash`,不拼接协议、域名或开发端口。订单创建成功后会触发浏览器事件 `mantur-recharge-order-created`,`detail` 为后端返回的订单信息。
157
171
 
158
172
  积分明细弹窗打开后会调用 `getManturBillingLedger()` 拉取 `/billing/accounts/me/ledger`,并根据“获得/消耗”、来源和日期范围筛选传递 `directions`、`bizTypes`、`fromTime`、`toTime`,分页总数使用接口返回的 `total`。
159
173
 
@@ -183,7 +197,14 @@ function applyTenantContext(detail: ManturTenantContextDetail) {
183
197
  }
184
198
 
185
199
  function Header({ userInfo }: { userInfo: UserInfo | null }) {
186
- return <ManturHeader user={userInfo} onTenantContextChange={applyTenantContext} />;
200
+ return (
201
+ <ManturHeader
202
+ user={userInfo}
203
+ appName={import.meta.env.VITE_APP_NAME}
204
+ mainPrefix={import.meta.env.VITE_MAIN_PREFIX}
205
+ onTenantContextChange={applyTenantContext}
206
+ />
207
+ );
187
208
  }
188
209
  ```
189
210
 
@@ -239,12 +260,13 @@ formatDateByLang("2026-05-19T12:00:00Z", "datetime", "en-US");
239
260
 
240
261
  ## 主应用跳转工具
241
262
 
242
- 组件库导出 `redirectToManturMain`,用于从当前子应用跳转到主应用入口:
263
+ 组件库导出 `redirectToManturMain` 和 `redirectToManturMainHome`,用于从当前子应用跳转到主应用:
243
264
 
244
265
  ```ts
245
- import { redirectToManturMain } from "mantur-components";
266
+ import { redirectToManturMain, redirectToManturMainHome } from "mantur-components";
246
267
 
247
268
  redirectToManturMain(import.meta.env.VITE_MAIN_PREFIX, import.meta.env.VITE_APP_NAME);
269
+ redirectToManturMainHome(import.meta.env.VITE_MAIN_PREFIX);
248
270
  ```
249
271
 
250
272
  行为说明:
@@ -252,12 +274,19 @@ redirectToManturMain(import.meta.env.VITE_MAIN_PREFIX, import.meta.env.VITE_APP_
252
274
  - `VITE_MAIN_PREFIX` 为空时保留当前域名并移除端口。
253
275
  - `VITE_MAIN_PREFIX` 存在时,将当前 URL 的子域名替换为 `VITE_MAIN_PREFIX`。
254
276
  - 非 dev 跳转会追加 `appName=VITE_APP_NAME` 和 `redirect=当前路由地址` 参数。
277
+ - `redirectToManturMainHome` 只跳主应用首页;本地开发固定跳 `localhost:80`。
255
278
  - 需要只生成 URL 不跳转时,可传 `{ navigate: false }`。
256
279
 
257
280
  ## 公共导出
258
281
 
259
282
  ```ts
260
- import { ManturHeader, formatDateByLang, redirectToManturMain } from "mantur-components";
283
+ import {
284
+ ManturHeader,
285
+ formatDateByLang,
286
+ redirectToManturMain,
287
+ redirectToManturMainHome,
288
+ resolveManturMainHomeUrl,
289
+ } from "mantur-components";
261
290
  import type {
262
291
  ManturBillingPackageDTO,
263
292
  ManturCreateRechargeOrderResponse,
@@ -277,3 +306,40 @@ import type {
277
306
  ```bash
278
307
  npm run build
279
308
  ```
309
+
310
+ ## 发布
311
+
312
+ 测试包和生产包直接发布到 npm,通过 npm tag 区分:
313
+
314
+ ```bash
315
+ npm run publish:test
316
+ npm run publish:pro
317
+ ```
318
+
319
+ `publish:test` 会使用 `vite build --mode test` 构建,并发布到 `test` tag。测试包版本必须是 prerelease,例如:
320
+
321
+ ```bash
322
+ npm version prerelease --preid beta --no-git-tag-version
323
+ npm run publish:test
324
+ ```
325
+
326
+ 测试项目安装:
327
+
328
+ ```bash
329
+ npm install mantur-components@test
330
+ ```
331
+
332
+ `publish:pro` 会使用 `vite build --mode pro` 构建,并发布到 `latest` tag。生产包版本不能包含 `beta`、`alpha`、`rc` 等 prerelease 标识,例如:
333
+
334
+ ```bash
335
+ npm version 0.1.13 --no-git-tag-version
336
+ npm run publish:pro
337
+ ```
338
+
339
+ 生产项目安装:
340
+
341
+ ```bash
342
+ npm install mantur-components@latest
343
+ ```
344
+
345
+ 环境变量读取遵循 Vite mode 规则:测试包读取 `.env` 和 `.env.test`,生产包读取 `.env` 和 `.env.pro`。发布前需要确认对应环境变量已经写入正确的 `VITE_*` 配置。
@@ -1,2 +1,2 @@
1
1
  import type { ManturHeaderProps } from "../types";
2
- export declare function ManturHeader({ user, disabled, brandSlot, children, onTenantContextChange, stripePublishableKey, }: ManturHeaderProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function ManturHeader({ user, disabled, brandSlot, children, onTenantContextChange, appName, mainPrefix, stripePublishableKey, }: ManturHeaderProps): import("react/jsx-runtime").JSX.Element;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { cancelManturRechargeOrder, createManturRechargeOrder, getManturBillingA
3
3
  export type { ManturBillingAccountDTO, ManturBillingPackageDTO, ManturChargePointWithModelsDTO, ManturCreateRechargeOrderRequest, ManturCreateRechargeOrderResponse, ManturLedgerEntryDTO, ManturLedgerQuery, ManturModelRuleDTO, ManturPageResult, ManturRechargeOrderDTO, } from "./api";
4
4
  export { formatDateByLang } from "./utils/date";
5
5
  export type { ManturDateFormatType, ManturDateInput } from "./utils/date";
6
- export { getManturRechargeRedirectContext, redirectToManturMain } from "./utils/url";
6
+ export { getManturRechargeRedirectContext, redirectToManturMain, redirectToManturMainHome, resolveManturMainHomeUrl, } from "./utils/url";
7
7
  export type { ManturMainRedirectOptions } from "./utils/url";
8
8
  export { isManturStripePaymentWindowMessage, MANTUR_STRIPE_PAYMENT_ROUTE, MANTUR_STRIPE_PAYMENT_WINDOW_MESSAGE_TYPE, postManturStripePaymentWindowMessage, resolveManturRechargePaymentPageUrl, resolveManturStripePaymentPageUrl, } from "./utils/stripe-payment-window";
9
9
  export type { ManturStripePaymentPageUrlOptions, ManturStripePaymentWindowAction, ManturStripePaymentWindowMessage, } from "./utils/stripe-payment-window";