|
|
|
@ -17,6 +17,53 @@ export enum FormType { |
|
|
|
VoiceCallForm = 4 |
|
|
|
} |
|
|
|
|
|
|
|
// 基础表单数据类型
|
|
|
|
interface BaseFormData { |
|
|
|
nodeId: string; |
|
|
|
} |
|
|
|
|
|
|
|
// 设备注册表单数据类型
|
|
|
|
interface DeviceRegistrationFormData extends BaseFormData { |
|
|
|
isDualSim: boolean; |
|
|
|
sim1Plmn: string; |
|
|
|
sim1CellId: string; |
|
|
|
sim1RegistrationWaitTime: number; |
|
|
|
sim2Plmn: string; |
|
|
|
sim2CellId: string; |
|
|
|
sim2RegistrationWaitTime: number; |
|
|
|
} |
|
|
|
|
|
|
|
// 网络连通性表单数据类型
|
|
|
|
interface NetworkConnectivityFormData extends BaseFormData { |
|
|
|
targetHost: string; |
|
|
|
pingCount: number; |
|
|
|
timeout: number; |
|
|
|
packetSize: number; |
|
|
|
interval: number; |
|
|
|
} |
|
|
|
|
|
|
|
// 网络性能表单数据类型
|
|
|
|
interface NetworkPerformanceFormData extends BaseFormData { |
|
|
|
serverHost: string; |
|
|
|
serverPort: number; |
|
|
|
testDuration: number; |
|
|
|
bandwidth: number; |
|
|
|
protocol: string; |
|
|
|
parallel: number; |
|
|
|
} |
|
|
|
|
|
|
|
// 语音通话表单数据类型
|
|
|
|
interface VoiceCallFormData extends BaseFormData { |
|
|
|
phoneNumber: string; |
|
|
|
callDuration: number; |
|
|
|
callType: string; |
|
|
|
waitTime: number; |
|
|
|
hangupDelay: number; |
|
|
|
} |
|
|
|
|
|
|
|
// 联合类型定义所有可能的表单数据
|
|
|
|
type FormData = BaseFormData | DeviceRegistrationFormData | NetworkConnectivityFormData | NetworkPerformanceFormData | VoiceCallFormData; |
|
|
|
|
|
|
|
interface FormTypeDrawerProps { |
|
|
|
open: boolean; |
|
|
|
onOpenChange: (open: boolean) => void; |
|
|
|
@ -36,7 +83,7 @@ export default function FormTypeDrawer({ |
|
|
|
loading = false, |
|
|
|
initialData |
|
|
|
}: FormTypeDrawerProps) { |
|
|
|
const [formData, setFormData] = useState<any>({}); |
|
|
|
const [formData, setFormData] = useState<FormData>({ nodeId }); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (open) { |
|
|
|
@ -48,7 +95,7 @@ export default function FormTypeDrawer({ |
|
|
|
} |
|
|
|
}, [open, initialData, nodeId, formType]); |
|
|
|
|
|
|
|
const getDefaultFormData = (formType: number, nodeId: string) => { |
|
|
|
const getDefaultFormData = (formType: number, nodeId: string): FormData => { |
|
|
|
switch (formType) { |
|
|
|
case FormType.DeviceRegistrationForm: |
|
|
|
return { |
|
|
|
@ -60,7 +107,7 @@ export default function FormTypeDrawer({ |
|
|
|
sim2Plmn: '', |
|
|
|
sim2CellId: '', |
|
|
|
sim2RegistrationWaitTime: 5000 |
|
|
|
}; |
|
|
|
} as DeviceRegistrationFormData; |
|
|
|
case FormType.NetworkConnectivityForm: |
|
|
|
return { |
|
|
|
nodeId, |
|
|
|
@ -69,7 +116,7 @@ export default function FormTypeDrawer({ |
|
|
|
timeout: 5000, |
|
|
|
packetSize: 64, |
|
|
|
interval: 1000 |
|
|
|
}; |
|
|
|
} as NetworkConnectivityFormData; |
|
|
|
case FormType.NetworkPerformanceForm: |
|
|
|
return { |
|
|
|
nodeId, |
|
|
|
@ -79,7 +126,7 @@ export default function FormTypeDrawer({ |
|
|
|
bandwidth: 1000, |
|
|
|
protocol: 'tcp', |
|
|
|
parallel: 1 |
|
|
|
}; |
|
|
|
} as NetworkPerformanceFormData; |
|
|
|
case FormType.VoiceCallForm: |
|
|
|
return { |
|
|
|
nodeId, |
|
|
|
@ -88,7 +135,7 @@ export default function FormTypeDrawer({ |
|
|
|
callType: 'mo', |
|
|
|
waitTime: 5000, |
|
|
|
hangupDelay: 2000 |
|
|
|
}; |
|
|
|
} as VoiceCallFormData; |
|
|
|
default: |
|
|
|
return { nodeId }; |
|
|
|
} |
|
|
|
@ -139,9 +186,9 @@ export default function FormTypeDrawer({ |
|
|
|
<div className="flex items-center space-x-2"> |
|
|
|
<Checkbox |
|
|
|
id="isDualSim" |
|
|
|
checked={formData.isDualSim || false} |
|
|
|
checked={(formData as DeviceRegistrationFormData).isDualSim || false} |
|
|
|
onCheckedChange={(checked) => { |
|
|
|
setFormData(prev => ({ |
|
|
|
setFormData((prev: FormData) => ({ |
|
|
|
...prev, |
|
|
|
isDualSim: checked, |
|
|
|
...(checked ? {} : { |
|
|
|
@ -149,7 +196,7 @@ export default function FormTypeDrawer({ |
|
|
|
sim2CellId: '', |
|
|
|
sim2RegistrationWaitTime: 5000 |
|
|
|
}) |
|
|
|
})); |
|
|
|
} as DeviceRegistrationFormData)); |
|
|
|
}} |
|
|
|
/> |
|
|
|
<Label htmlFor="isDualSim">双卡模式</Label> |
|
|
|
@ -164,8 +211,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Label htmlFor="sim1Plmn">PLMN *</Label> |
|
|
|
<Input |
|
|
|
id="sim1Plmn" |
|
|
|
value={formData.sim1Plmn || ''} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, sim1Plmn: e.target.value }))} |
|
|
|
value={(formData as DeviceRegistrationFormData).sim1Plmn || ''} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, sim1Plmn: e.target.value } as DeviceRegistrationFormData))} |
|
|
|
placeholder="例如: 46001" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
@ -173,8 +220,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Label htmlFor="sim1CellId">小区ID</Label> |
|
|
|
<Input |
|
|
|
id="sim1CellId" |
|
|
|
value={formData.sim1CellId || ''} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, sim1CellId: e.target.value }))} |
|
|
|
value={(formData as DeviceRegistrationFormData).sim1CellId || ''} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, sim1CellId: e.target.value } as DeviceRegistrationFormData))} |
|
|
|
placeholder="例如: 12345" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
@ -183,8 +230,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Input |
|
|
|
id="sim1RegistrationWaitTime" |
|
|
|
type="number" |
|
|
|
value={formData.sim1RegistrationWaitTime || 5000} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, sim1RegistrationWaitTime: parseInt(e.target.value) }))} |
|
|
|
value={(formData as DeviceRegistrationFormData).sim1RegistrationWaitTime || 5000} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, sim1RegistrationWaitTime: parseInt(e.target.value) } as DeviceRegistrationFormData))} |
|
|
|
min="1000" |
|
|
|
max="30000" |
|
|
|
/> |
|
|
|
@ -192,7 +239,7 @@ export default function FormTypeDrawer({ |
|
|
|
</CardContent> |
|
|
|
</Card> |
|
|
|
|
|
|
|
{formData.isDualSim && ( |
|
|
|
{(formData as DeviceRegistrationFormData).isDualSim && ( |
|
|
|
<Card> |
|
|
|
<CardHeader> |
|
|
|
<CardTitle className="text-sm">SIM卡2配置</CardTitle> |
|
|
|
@ -202,8 +249,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Label htmlFor="sim2Plmn">PLMN *</Label> |
|
|
|
<Input |
|
|
|
id="sim2Plmn" |
|
|
|
value={formData.sim2Plmn || ''} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, sim2Plmn: e.target.value }))} |
|
|
|
value={(formData as DeviceRegistrationFormData).sim2Plmn || ''} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, sim2Plmn: e.target.value } as DeviceRegistrationFormData))} |
|
|
|
placeholder="例如: 46002" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
@ -211,8 +258,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Label htmlFor="sim2CellId">小区ID</Label> |
|
|
|
<Input |
|
|
|
id="sim2CellId" |
|
|
|
value={formData.sim2CellId || ''} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, sim2CellId: e.target.value }))} |
|
|
|
value={(formData as DeviceRegistrationFormData).sim2CellId || ''} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, sim2CellId: e.target.value } as DeviceRegistrationFormData))} |
|
|
|
placeholder="例如: 12346" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
@ -221,8 +268,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Input |
|
|
|
id="sim2RegistrationWaitTime" |
|
|
|
type="number" |
|
|
|
value={formData.sim2RegistrationWaitTime || 5000} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, sim2RegistrationWaitTime: parseInt(e.target.value) }))} |
|
|
|
value={(formData as DeviceRegistrationFormData).sim2RegistrationWaitTime || 5000} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, sim2RegistrationWaitTime: parseInt(e.target.value) } as DeviceRegistrationFormData))} |
|
|
|
min="1000" |
|
|
|
max="30000" |
|
|
|
/> |
|
|
|
@ -239,8 +286,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Label htmlFor="targetHost">目标主机地址 *</Label> |
|
|
|
<Input |
|
|
|
id="targetHost" |
|
|
|
value={formData.targetHost || ''} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, targetHost: e.target.value }))} |
|
|
|
value={(formData as NetworkConnectivityFormData).targetHost || ''} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, targetHost: e.target.value } as NetworkConnectivityFormData))} |
|
|
|
placeholder="例如: 8.8.8.8" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
@ -250,8 +297,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Input |
|
|
|
id="pingCount" |
|
|
|
type="number" |
|
|
|
value={formData.pingCount || 4} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, pingCount: parseInt(e.target.value) }))} |
|
|
|
value={(formData as NetworkConnectivityFormData).pingCount || 4} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, pingCount: parseInt(e.target.value) } as NetworkConnectivityFormData))} |
|
|
|
min="1" |
|
|
|
max="10" |
|
|
|
/> |
|
|
|
@ -261,8 +308,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Input |
|
|
|
id="timeout" |
|
|
|
type="number" |
|
|
|
value={formData.timeout || 5000} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, timeout: parseInt(e.target.value) }))} |
|
|
|
value={(formData as NetworkConnectivityFormData).timeout || 5000} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, timeout: parseInt(e.target.value) } as NetworkConnectivityFormData))} |
|
|
|
min="1000" |
|
|
|
max="30000" |
|
|
|
/> |
|
|
|
@ -277,8 +324,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Label htmlFor="serverHost">服务器地址 *</Label> |
|
|
|
<Input |
|
|
|
id="serverHost" |
|
|
|
value={formData.serverHost || ''} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, serverHost: e.target.value }))} |
|
|
|
value={(formData as NetworkPerformanceFormData).serverHost || ''} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, serverHost: e.target.value } as NetworkPerformanceFormData))} |
|
|
|
placeholder="例如: localhost" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
@ -288,8 +335,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Input |
|
|
|
id="serverPort" |
|
|
|
type="number" |
|
|
|
value={formData.serverPort || 5201} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, serverPort: parseInt(e.target.value) }))} |
|
|
|
value={(formData as NetworkPerformanceFormData).serverPort || 5201} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, serverPort: parseInt(e.target.value) } as NetworkPerformanceFormData))} |
|
|
|
min="1" |
|
|
|
max="65535" |
|
|
|
/> |
|
|
|
@ -299,8 +346,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Input |
|
|
|
id="testDuration" |
|
|
|
type="number" |
|
|
|
value={formData.testDuration || 10} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, testDuration: parseInt(e.target.value) }))} |
|
|
|
value={(formData as NetworkPerformanceFormData).testDuration || 10} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, testDuration: parseInt(e.target.value) } as NetworkPerformanceFormData))} |
|
|
|
min="1" |
|
|
|
max="3600" |
|
|
|
/> |
|
|
|
@ -315,16 +362,16 @@ export default function FormTypeDrawer({ |
|
|
|
<Label htmlFor="phoneNumber">电话号码 *</Label> |
|
|
|
<Input |
|
|
|
id="phoneNumber" |
|
|
|
value={formData.phoneNumber || ''} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, phoneNumber: e.target.value }))} |
|
|
|
value={(formData as VoiceCallFormData).phoneNumber || ''} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, phoneNumber: e.target.value } as VoiceCallFormData))} |
|
|
|
placeholder="例如: 13800138000" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
<div> |
|
|
|
<Label htmlFor="callType">通话类型</Label> |
|
|
|
<Select |
|
|
|
value={formData.callType || 'mo'} |
|
|
|
onValueChange={(value) => setFormData(prev => ({ ...prev, callType: value }))} |
|
|
|
value={(formData as VoiceCallFormData).callType || 'mo'} |
|
|
|
onValueChange={(value) => setFormData((prev: FormData) => ({ ...prev, callType: value } as VoiceCallFormData))} |
|
|
|
> |
|
|
|
<SelectTrigger> |
|
|
|
<SelectValue /> |
|
|
|
@ -340,8 +387,8 @@ export default function FormTypeDrawer({ |
|
|
|
<Input |
|
|
|
id="callDuration" |
|
|
|
type="number" |
|
|
|
value={formData.callDuration || 30} |
|
|
|
onChange={(e) => setFormData(prev => ({ ...prev, callDuration: parseInt(e.target.value) }))} |
|
|
|
value={(formData as VoiceCallFormData).callDuration || 30} |
|
|
|
onChange={(e) => setFormData((prev: FormData) => ({ ...prev, callDuration: parseInt(e.target.value) } as VoiceCallFormData))} |
|
|
|
min="5" |
|
|
|
max="300" |
|
|
|
/> |
|
|
|
|