[增添]增加了网络配置服务,自动读取网络接口及对应信息
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Services\NetworkService;
|
||||
use App\Settings\NetworkSettings;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
@@ -19,10 +20,53 @@ class ManageNetwork extends SettingsPage
|
||||
protected static ?string $navigationLabel = '网络连接配置管理';
|
||||
|
||||
protected static ?string $title = '网络连接配置管理';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
// 获取当前网络接口
|
||||
$interfaces = NetworkService::getNetworkInterfaces();
|
||||
|
||||
return $form
|
||||
->schema([
|
||||
// 添加网络接口选择框
|
||||
Select::make('network_interface')
|
||||
->label('选择网络接口')
|
||||
->options(array_combine(array_keys($interfaces), array_keys($interfaces)))
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set) use ($interfaces) {
|
||||
// 调试输出:检查当前选择的接口
|
||||
error_log("选择的接口: " . $state);
|
||||
|
||||
// 当选择框的值更新时,自动填充对应的网络信息
|
||||
if (isset($interfaces[$state])) {
|
||||
$set('ip', $interfaces[$state]['ip'] ?? '无IP地址');
|
||||
$set('mask', $interfaces[$state]['mask'] ?? '无子网掩码');
|
||||
// 假设我们通过其他方式获取网关(如手动输入或自动获取)
|
||||
// $set('gateway', '自动获取或手动输入的值');
|
||||
error_log("ip " . $interfaces[$state]['ip']);
|
||||
error_log("mask " . $interfaces[$state]['mask']);
|
||||
}
|
||||
else{
|
||||
error_log("未找到接口:" . $state);
|
||||
}
|
||||
}),
|
||||
|
||||
// 动态显示端口信息
|
||||
Fieldset::make('端口信息')
|
||||
->schema([
|
||||
TextInput::make('ip')
|
||||
->label("IP地址")
|
||||
->readOnly() // 禁用以表示这是自动填充的字段
|
||||
->reactive(),
|
||||
TextInput::make('mask')
|
||||
->label('子网掩码')
|
||||
->readOnly()
|
||||
->reactive(),
|
||||
])
|
||||
->visible(fn($get) => !is_null($get('network_interface'))) // 检查是否有选择的接口
|
||||
->reactive(),
|
||||
|
||||
// DHCP选项
|
||||
Select::make('dhcp_enabled')
|
||||
->options([
|
||||
true => "是",
|
||||
@@ -33,7 +77,8 @@ class ManageNetwork extends SettingsPage
|
||||
->required()
|
||||
->reactive(),
|
||||
|
||||
Fieldset::make()
|
||||
// 动态显示的网络信息字段
|
||||
Fieldset::make('网络配置')
|
||||
->schema([
|
||||
TextInput::make('ip_address')
|
||||
->label("IP地址")
|
||||
|
||||
Reference in New Issue
Block a user