[增添]添加了ManageDataSource管理页面

This commit is contained in:
makotocc0107
2024-08-27 10:34:38 +08:00
parent 72eb990970
commit fae4b62663
5 changed files with 645 additions and 160 deletions

View File

@@ -0,0 +1,129 @@
<?php
namespace App\Filament\Pages;
use App\Services\EtcdService;
use App\Settings\DataSourceSettings;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Pages\SettingsPage;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Actions\Action;
class ManageDataSource extends SettingsPage
{
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
protected static string $settings = DataSourceSettings::class;
public function form(Form $form): Form
{
return $form
->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'])),
]);
}
}

View File

@@ -0,0 +1,94 @@
<?php
return [
/*
* Each settings class used in your application must be registered, you can
* put them (manually) here.
*/
'settings' => [
],
/*
* The path where the settings classes will be created.
*/
'setting_class_path' => app_path('Settings'),
/*
* In these directories settings migrations will be stored and ran when migrating. A settings
* migration created via the make:settings-migration command will be stored in the first path or
* a custom defined path when running the command.
*/
'migrations_paths' => [
database_path('settings'),
],
/*
* When no repository was set for a settings class the following repository
* will be used for loading and saving settings.
*/
'default_repository' => 'database',
/*
* Settings will be stored and loaded from these repositories.
*/
'repositories' => [
'database' => [
'type' => Spatie\LaravelSettings\SettingsRepositories\DatabaseSettingsRepository::class,
'model' => null,
'table' => null,
'connection' => null,
],
'redis' => [
'type' => Spatie\LaravelSettings\SettingsRepositories\RedisSettingsRepository::class,
'connection' => null,
'prefix' => null,
],
],
/*
* The encoder and decoder will determine how settings are stored and
* retrieved in the database. By default, `json_encode` and `json_decode`
* are used.
*/
'encoder' => null,
'decoder' => null,
/*
* The contents of settings classes can be cached through your application,
* settings will be stored within a provided Laravel store and can have an
* additional prefix.
*/
'cache' => [
'enabled' => env('SETTINGS_CACHE_ENABLED', false),
'store' => null,
'prefix' => null,
'ttl' => null,
],
/*
* These global casts will be automatically used whenever a property within
* your settings class isn't a default PHP type.
*/
'global_casts' => [
DateTimeInterface::class => Spatie\LaravelSettings\SettingsCasts\DateTimeInterfaceCast::class,
DateTimeZone::class => Spatie\LaravelSettings\SettingsCasts\DateTimeZoneCast::class,
// Spatie\DataTransferObject\DataTransferObject::class => Spatie\LaravelSettings\SettingsCasts\DtoCast::class,
Spatie\LaravelData\Data::class => Spatie\LaravelSettings\SettingsCasts\DataCast::class,
],
/*
* The package will look for settings in these paths and automatically
* register them.
*/
'auto_discover_settings' => [
app_path('Settings'),
],
/*
* Automatically discovered settings classes can be cached, so they don't
* need to be searched each time the application boots up.
*/
'discovered_settings_cache_path' => base_path('bootstrap/cache'),
];

View File

@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('settings', function (Blueprint $table): void {
$table->id();
$table->string('group');
$table->string('name');
$table->boolean('locked')->default(false);
$table->json('payload');
$table->timestamps();
$table->unique(['group', 'name']);
});
}
};