fix: harden real backend admin workflows and ui

This commit is contained in:
hectorzhao
2026-07-03 19:29:56 +08:00
parent dd09d91c1e
commit 8cca361441
71 changed files with 5111 additions and 4439 deletions
+30 -21
View File
@@ -26,6 +26,7 @@ type SmsChannel = {
corpCode: string;
account: string;
accessNo: string;
passwordCipher?: string;
};
type ChannelModalState = {
@@ -139,6 +140,22 @@ function mapUiStatusToApi(channel: SmsChannel) {
return channel.status === 'stopped' ? 'active' : 'disabled';
}
function buildChannelPayload(channel: SmsChannel, passwordCipher?: string) {
return {
name: channel.name,
carrier: channel.carrier,
sendRegion: channel.sendRegion,
gatewayHost: channel.gatewayHost,
gatewayPort: Number(channel.gatewayPort),
enterpriseCode: channel.corpCode,
account: channel.account,
passwordCipher: passwordCipher || undefined,
srcId: channel.accessNo,
rateLimitPerSecond: 100,
unitPrice: Math.round(channel.unitPrice),
};
}
function RateBlock({ label, rate, count, tone = 'neutral' }: { label: string; rate: number; count: number; tone?: 'success' | 'warning' | 'danger' | 'neutral' }) {
return (
<div className={`sms-channel-rate sms-channel-rate--${tone}`}>
@@ -193,6 +210,7 @@ function ChannelFormModal({
corpCode,
account,
accessNo,
passwordCipher: password || undefined,
});
}
@@ -355,31 +373,22 @@ export function AdminChannelsPage() {
);
async function upsertChannel(nextChannel: SmsChannel) {
if (modal?.mode === 'edit') {
setError('短信通道编辑接口待补,当前不做本地模拟保存');
return;
}
try {
const created = await adminApi.createChannel({
code: `CH-${Date.now()}`,
name: nextChannel.name,
carrier: nextChannel.carrier,
sendRegion: nextChannel.sendRegion,
gatewayHost: nextChannel.gatewayHost,
gatewayPort: Number(nextChannel.gatewayPort),
enterpriseCode: nextChannel.corpCode,
account: nextChannel.account,
passwordCipher: 'secret',
srcId: nextChannel.accessNo,
rateLimitPerSecond: 100,
unitPrice: Math.round(nextChannel.unitPrice),
status: 'active',
});
setChannels((items) => [mapApiChannel(created), ...items]);
if (modal?.mode === 'edit' && modal.channel) {
const updated = await adminApi.updateChannel(modal.channel.id, buildChannelPayload(nextChannel, nextChannel.passwordCipher));
setChannels((items) => items.map((item) => (item.id === updated.id ? mapApiChannel(updated) : item)));
} else {
const created = await adminApi.createChannel({
code: `CH-${Date.now()}`,
...buildChannelPayload(nextChannel, nextChannel.passwordCipher || 'secret'),
status: 'active',
});
setChannels((items) => [mapApiChannel(created), ...items]);
}
setModal(null);
setError('');
} catch (failure) {
setError(failure instanceof Error ? failure.message : '通道创建失败');
setError(failure instanceof Error ? failure.message : '通道保存失败');
}
}