schema([ TextInput::make('name') ->label('名称') ->required() ->maxLength(255), TextInput::make('help') ->label('帮助') ->maxLength(255), Section::make('节点 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('标识符类型') ->required() ->reactive(), // 确保当选择的值变化时触发其他字段的重新渲染 TextInput::make('namespace_index') ->label('命名空间') ->required(), // 数值型标识符字段 TextInput::make('numeric_id') ->label('数值 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') ->label('名称'), TextColumn::make('nodeid') ->label('节点 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') ->label('帮助') ]) ->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'), ]; } }