feat: add Yuheng ticket bind, trial SMS off, shared bindings

Ship ticket-exchange and bind/policy for Z13, keep trial binds SMS-free, allow shared company bindings, and align SyncPage plus sync docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whm
2026-08-05 15:09:49 +08:00
parent f90245db9c
commit d195aa4804
19 changed files with 957 additions and 96 deletions

View File

@@ -25,6 +25,7 @@ import {
} from "@ant-design/icons";
import {
AgentAccount,
BindCode,
Session,
SyncBinding,
SyncChannel,
@@ -38,6 +39,9 @@ import {
listApps,
listSyncBindings,
listSyncChannels,
listBindCodes,
createBindCode,
revokeBindCode,
previewSyncTable,
reconcileSyncChannel,
startSyncChannel,
@@ -163,6 +167,7 @@ export function SyncPage(props: {
const { message } = AntApp.useApp();
const [items, setItems] = useState<SyncChannel[]>([]);
const [bindings, setBindings] = useState<SyncBinding[]>([]);
const [bindCodes, setBindCodes] = useState<BindCode[]>([]);
const [agents, setAgents] = useState<AgentAccount[]>([]);
const [appOptions, setAppOptions] = useState<{ value: string; label: string }[]>([]);
const [loading, setLoading] = useState(false);
@@ -190,15 +195,17 @@ export function SyncPage(props: {
async function refresh() {
setLoading(true);
try {
const [ch, bind, ag, apps] = await Promise.all([
const [ch, bind, ag, apps, codes] = await Promise.all([
listSyncChannels(session),
listSyncBindings(session).catch(() => ({ items: [] as SyncBinding[] })),
listAgents(session).catch(() => ({ items: [] as AgentAccount[] })),
listApps(session).catch(() => ({ items: [] as { slug: string; name: string; status: string }[] })),
listBindCodes(session).catch(() => ({ items: [] as BindCode[] })),
]);
setItems(ch.items || []);
setBindings(bind.items || []);
setAgents(ag.items || []);
setBindCodes(codes.items || []);
setAppOptions(
(apps.items || [])
.filter((a) => a.status === "published" || !a.status)
@@ -581,6 +588,101 @@ export function SyncPage(props: {
]}
/>
<Typography.Title level={5} style={{ marginTop: 28 }}>
</Typography.Title>
<Typography.Paragraph type="secondary" style={{ marginTop: 0 }}>
<Typography.Text code>POST /auth/bind-code/redeem</Typography.Text>{" "}
<Typography.Text code>13531041944</Typography.Text>
</Typography.Paragraph>
<Space style={{ marginBottom: 12 }}>
<Button
type="primary"
disabled={busy}
onClick={async () => {
setBusy(true);
try {
const bc = await createBindCode(session, { max_uses: 1, expires_hours: 168 });
message.success(`已生成绑定码 ${bc.code}`);
setInfo(`绑定码 ${bc.code}(可复制发给用户)`);
await refresh();
} catch (e: any) {
message.error(e.message || String(e));
} finally {
setBusy(false);
}
}}
>
</Button>
</Space>
<Table
rowKey="code"
loading={loading}
dataSource={bindCodes}
pagination={false}
locale={{ emptyText: "暂无绑定码" }}
columns={[
{
title: "绑定码",
dataIndex: "code",
render: (c: string) => <Typography.Text copyable code>{c}</Typography.Text>,
},
{
title: "通道",
dataIndex: "channel_id",
render: (id: string) =>
id ? <Typography.Text copyable={{ text: id }}>{id.slice(0, 8)}</Typography.Text> : "—",
},
{
title: "次数",
render: (_: unknown, r: BindCode) => `${r.used_count}/${r.max_uses}`,
width: 80,
},
{
title: "过期",
dataIndex: "expires_at",
render: (t: string) => (t ? new Date(t).toLocaleString() : "—"),
},
{
title: "状态",
width: 90,
render: (_: unknown, r: BindCode) => {
if (r.revoked) return <Tag color="default"></Tag>;
if (r.used_count >= r.max_uses) return <Tag></Tag>;
if (r.expires_at && new Date(r.expires_at).getTime() < Date.now())
return <Tag color="warning"></Tag>;
return <Tag color="success"></Tag>;
},
},
{
title: "操作",
width: 90,
render: (_: unknown, r: BindCode) => (
<Button
size="small"
danger
disabled={!!r.revoked || busy}
onClick={async () => {
setBusy(true);
try {
await revokeBindCode(session, r.code);
setInfo(`已撤销 ${r.code}`);
await refresh();
} catch (e: any) {
message.error(e.message || String(e));
} finally {
setBusy(false);
}
}}
>
</Button>
),
},
]}
/>
<Typography.Title level={5} style={{ marginTop: 28 }}>
线
</Typography.Title>
@@ -677,6 +779,12 @@ export function SyncPage(props: {
},
},
{ title: "备注", dataIndex: "note", ellipsis: true },
{
title: "共享",
width: 70,
render: (_: unknown, b: SyncBinding) =>
b.shared ? <Tag color="blue"></Tag> : <Typography.Text type="secondary"></Typography.Text>,
},
]}
/>
@@ -684,6 +792,7 @@ export function SyncPage(props: {
LWW 5
= agent push
线 push Binding
Binding <Typography.Text code>shared=true</Typography.Text>
</Typography.Paragraph>
<Modal

View File

@@ -1143,6 +1143,7 @@ export async function ensureSyncBinding(
display_name?: string;
note?: string;
user_id?: number;
shared?: boolean;
}
) {
const res = await apiFetch(`/api/v1/admin/sync/bindings`, {
@@ -1167,11 +1168,70 @@ export type SyncBinding = {
channel_id?: string;
database_name?: string;
display_name?: string;
shared?: boolean;
note?: string;
created_at?: string;
updated_at?: string;
};
export type BindCode = {
code: string;
tenant_id: number;
channel_id?: string;
online_db_id?: string;
database_name?: string;
max_uses: number;
used_count: number;
revoked?: boolean;
expires_at?: string;
created_by?: number;
created_at?: string;
note?: string;
};
export async function listBindCodes(session: Session) {
const res = await apiFetch(`/api/v1/admin/bind-codes`, {
headers: { Authorization: `Bearer ${session.accessToken}` },
});
const data = await readJson(res);
throwIfBad(res, data, "list bind codes failed");
return data as { items: BindCode[] };
}
export async function createBindCode(
session: Session,
body?: {
channel_id?: string;
online_db_id?: string;
database_name?: string;
max_uses?: number;
expires_hours?: number;
note?: string;
}
) {
const res = await apiFetch(`/api/v1/admin/bind-codes`, {
method: "POST",
headers: {
Authorization: `Bearer ${session.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body || {}),
});
const data = await readJson(res);
throwIfBad(res, data, "create bind code failed");
return data as BindCode;
}
export async function revokeBindCode(session: Session, code: string) {
const res = await apiFetch(`/api/v1/admin/bind-codes/${encodeURIComponent(code)}`, {
method: "DELETE",
headers: { Authorization: `Bearer ${session.accessToken}` },
});
const data = await readJson(res);
throwIfBad(res, data, "revoke bind code failed");
return data as { ok: boolean };
}
export async function listSyncBindings(session: Session, localDatabaseId?: string) {
const q = localDatabaseId
? `?local_database_id=${encodeURIComponent(localDatabaseId)}`