[增添]添加了MetricResource的数据库以及页面元素
This commit is contained in:
20
.idea/workspace.xml
generated
20
.idea/workspace.xml
generated
@@ -4,7 +4,7 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="596fb1a0-d6fb-4db8-a922-13b01593ce79" name="更改" comment="[增添]添加了ManageDataSource管理页面">
|
||||
<list default="true" id="596fb1a0-d6fb-4db8-a922-13b01593ce79" name="更改" comment="[增添]添加了Manage Exposer的默认数据库值以及Page页面">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@@ -26,6 +26,9 @@
|
||||
<option name="RESET_MODE" value="HARD" />
|
||||
<option name="UPDATE_TYPE" value="REBASE" />
|
||||
</component>
|
||||
<component name="PerforceDirect.Settings">
|
||||
<option name="CHARSET" value="无" />
|
||||
</component>
|
||||
<component name="PhpWorkspaceProjectConfiguration" interpreter_name="C:\Users\gmch2\scoop\shims\php.exe">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/vendor/filament/support" />
|
||||
@@ -351,7 +354,7 @@
|
||||
<workItem from="1724721535300" duration="1534000" />
|
||||
<workItem from="1724723119931" duration="37000" />
|
||||
<workItem from="1724723165774" duration="1511000" />
|
||||
<workItem from="1724724784154" duration="1746000" />
|
||||
<workItem from="1724724784154" duration="2759000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="[增添]添加注册">
|
||||
<option name="closed" value="true" />
|
||||
@@ -393,7 +396,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1724726078488</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="6" />
|
||||
<task id="LOCAL-00006" summary="[增添]添加了Manage Exposer的默认数据库值以及Page页面">
|
||||
<option name="closed" value="true" />
|
||||
<created>1724726680511</created>
|
||||
<option name="number" value="00006" />
|
||||
<option name="presentableId" value="LOCAL-00006" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1724726680511</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="7" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -414,6 +425,7 @@
|
||||
<MESSAGE value="[增添]添加注册" />
|
||||
<MESSAGE value="[增添]添加了datasource的setting数据库以及默认值" />
|
||||
<MESSAGE value="[增添]添加了ManageDataSource管理页面" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="[增添]添加了ManageDataSource管理页面" />
|
||||
<MESSAGE value="[增添]添加了Manage Exposer的默认数据库值以及Page页面" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="[增添]添加了Manage Exposer的默认数据库值以及Page页面" />
|
||||
</component>
|
||||
</project>
|
||||
128
management-panel/app/Filament/Resources/MetricResource.php
Normal file
128
management-panel/app/Filament/Resources/MetricResource.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\MetricResource\Pages;
|
||||
use App\Filament\Resources\MetricResource\RelationManagers;
|
||||
use App\Models\Metric;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
|
||||
class MetricResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Metric::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('help')
|
||||
->maxLength(255),
|
||||
|
||||
Section::make('Node ID')
|
||||
->description('节点设置必须唯一')
|
||||
->columns([
|
||||
'default' => 3
|
||||
])
|
||||
->schema([
|
||||
// 1 = Numeric, 2 = String, 3 = GUID
|
||||
Select::make('identifier_type')
|
||||
->options([
|
||||
1 => 'Numeric',
|
||||
2 => 'String',
|
||||
3 => 'GUID',
|
||||
])
|
||||
->default(1)
|
||||
->label('Identifier Type')
|
||||
->required()
|
||||
->reactive(), // 确保当选择的值变化时触发其他字段的重新渲染
|
||||
|
||||
TextInput::make('namespace_index')
|
||||
->label('Namespace')
|
||||
->required(),
|
||||
|
||||
// 数值型标识符字段
|
||||
TextInput::make('numeric_id')
|
||||
->label('Numeric ID')
|
||||
->required()
|
||||
->visible(fn($get) => $get('identifier_type') == Metric::TYPE_NUMERIC),
|
||||
|
||||
// 字符串型标识符字段
|
||||
TextInput::make('string_id')
|
||||
->label('String ID')
|
||||
->required()
|
||||
->visible(fn($get) => $get('identifier_type') == Metric::TYPE_STRING),
|
||||
|
||||
// GUID 型标识符字段
|
||||
TextInput::make('guid_id')
|
||||
->label('GUID ID')
|
||||
->required()
|
||||
->visible(fn($get) => $get('identifier_type') == Metric::TYPE_GUID),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name'),
|
||||
TextColumn::make('nodeid')
|
||||
->label('Node ID')
|
||||
->state(function ($record) {
|
||||
switch ($record->identifier_type) {
|
||||
case 1: // Numeric
|
||||
return 'ns=' . $record->namespace_index . ';i=' . $record->numeric_id;
|
||||
case 2: // String
|
||||
return 'ns=' . $record->namespace_index . ';s=' . $record->string_id;
|
||||
case 3: // GUID
|
||||
return 'ns=' . $record->namespace_index . ';g=' . $record->guid_id;
|
||||
default:
|
||||
return 'Unknown Type';
|
||||
}
|
||||
}),
|
||||
TextColumn::make('help')
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListMetrics::route('/'),
|
||||
'create' => Pages\CreateMetric::route('/create'),
|
||||
'edit' => Pages\EditMetric::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MetricResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MetricResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateMetric extends CreateRecord
|
||||
{
|
||||
protected static string $resource = MetricResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MetricResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MetricResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditMetric extends EditRecord
|
||||
{
|
||||
protected static string $resource = MetricResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MetricResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MetricResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListMetrics extends ListRecords
|
||||
{
|
||||
protected static string $resource = MetricResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
24
management-panel/app/Models/Metric.php
Normal file
24
management-panel/app/Models/Metric.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Metric extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable=[
|
||||
"name",
|
||||
"namespace_index",
|
||||
"identifier_type",
|
||||
"numeric_id",
|
||||
"string_id",
|
||||
"guid_id",
|
||||
"help"
|
||||
];
|
||||
|
||||
const TYPE_NUMERIC = 1;
|
||||
const TYPE_STRING = 2;
|
||||
const TYPE_GUID = 3;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('metrics', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
|
||||
// 命名空间索引
|
||||
$table->integer('namespace_index');
|
||||
|
||||
// 标识符类型,存储为整数
|
||||
// 1 = Numeric, 2 = String, 3 = GUID
|
||||
$table->Integer('identifier_type');
|
||||
|
||||
// 数值型标识符
|
||||
$table->integer('numeric_id')->nullable();
|
||||
|
||||
// 字符串型标识符
|
||||
$table->string('string_id')->nullable();
|
||||
|
||||
// GUID 型标识符
|
||||
$table->char('guid_id', 36)->nullable();
|
||||
|
||||
$table->string('help')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
// 在同一命名空间中,确保唯一标识符唯一
|
||||
$table->unique(['namespace_index', 'numeric_id']);
|
||||
$table->unique(['namespace_index', 'string_id']);
|
||||
$table->unique(['namespace_index', 'guid_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('metrics');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user