schema([ Select::make('data_source_type') ->options([ 'opcua' => 'Opcua', ]) ->default('opcua') ->label('数据源类型') ->columns(1) ->required() ->reactive(), Fieldset::make() ->schema([ TextInput::make('name') ->label('名称') ->required(), Textarea::make('description') ->label('描述') ->autosize() ->nullable(), TextInput::make('opcua_service_address') ->label('opcua服务地址') ->prefix('opc.tcp://') ->required(), ]) ->visible(fn($get) => in_array($get('data_source_type'), ['opcua'])), Fieldset::make() ->schema([ Select::make('security_mode') ->label('安全模式') ->required() ->options([ 'Anonymous' => '匿名模式', 'UsernamePassword' => '用户名密码模式', 'Certificate' => '证书/密钥模式', 'CertificateAndUsernamePassword' => '证书/密码 + 用户名密码模式', 'OpensslMbedtls' => 'Openssl/mbedtls模式', ]) ->reactive(), // Triggers reactivity for the dependsOn method TextInput::make('security_policy_address') ->label('安全策略地址') ->nullable(), // Certificate + UsernamePassword mode: Shows 'username', 'password', 'key_authentication_file', 'certificate_authentication_file', 'trusted_list' TextInput::make('username') ->label('用户名') ->nullable() ->visible(fn($get) => in_array($get('security_mode'), ['UsernamePassword', 'CertificateAndUsernamePassword'])), TextInput::make('password') ->label('密码') ->password() ->revealable() ->nullable() ->visible(fn($get) => in_array($get('security_mode'), ['UsernamePassword', 'CertificateAndUsernamePassword'])), TextInput::make('key_authentication_file') ->label('密钥文件') ->visible(fn($get) => in_array($get('security_mode'), ['Certificate', 'CertificateAndUsernamePassword'])), TextInput::make('certificate_authentication_file') ->label('证书文件') ->visible(fn($get) => in_array($get('security_mode'), ['Certificate', 'CertificateAndUsernamePassword'])), TextInput::make('trusted_list') ->label('信任列表') ->nullable() ->visible(fn($get) => in_array($get('security_mode'), ['Certificate', 'CertificateAndUsernamePassword'])), // Openssl/Mbedtls mode: Shows 'certificate_identity_file', 'key_identity_file' TextInput::make('certificate_identity_file') ->label('证书身份验证文件') ->visible(fn($get) => $get('security_mode') === 'OpensslMbedtls'), TextInput::make('key_identity_file') ->label('密钥身份验证文件') ->visible(fn($get) => $get('security_mode') === 'OpensslMbedtls'), // Anonymous mode: Shows 'measurement_point_address' and 'interface_address' TextInput::make('measurement_point_address') ->label('测点地址') ->required() ->visible(fn($get) => in_array($get('security_mode'), ['Anonymous', 'Certificate', 'UsernamePassword', 'CertificateAndUsernamePassword', 'OpensslMbedtls'])), TextInput::make('interface_address') ->label('接口地址') ->required() ->visible(fn($get) => in_array($get('security_mode'), ['Anonymous', 'Certificate', 'UsernamePassword', 'CertificateAndUsernamePassword', 'OpensslMbedtls'])), Toggle::make('state') ->label('启用') ->onColor('success'), ]) ->visible(fn($get) => in_array($get('data_source_type'), ['opcua'])), ]); } }