feat: multi diagrams

This commit is contained in:
2026-04-06 16:35:11 +08:00
parent 42a879e961
commit d19b770ef4
8 changed files with 98 additions and 16 deletions

View File

@@ -101,12 +101,27 @@ class TerminalResource extends Resource
Forms\Components\Section::make('组态配置')
->schema([
Forms\Components\TextInput::make('diagram_url')
Forms\Components\Repeater::make('diagram_urls')
->label('组态界面地址')
->url()
->maxLength(500)
->placeholder('https://example.com/diagram.png')
->helperText('组态界面的访问地址'),
->schema([
Forms\Components\TextInput::make('title')
->label('标题')
->required()
->maxLength(100)
->placeholder('例如: 主组态'),
Forms\Components\TextInput::make('url')
->label('地址')
->required()
->url()
->maxLength(500)
->placeholder('https://example.com/diagram.html'),
])
->columns(2)
->defaultItems(0)
->addActionLabel('添加组态地址')
->itemLabel(fn (array $state): ?string => $state['title'] ?? null)
->collapsible()
->reorderable(),
]),
Forms\Components\Section::make('网关配置')

View File

@@ -45,12 +45,19 @@ class ViewTerminal extends ViewRecord
Infolists\Components\Section::make('组态配置')
->schema([
Infolists\Components\TextEntry::make('diagram_url')
Infolists\Components\RepeatableEntry::make('diagram_urls')
->label('组态界面地址')
->copyable()
->placeholder('未设置')
->url(fn($state) => $state)
->openUrlInNewTab(),
->schema([
Infolists\Components\TextEntry::make('title')
->label('标题'),
Infolists\Components\TextEntry::make('url')
->label('地址')
->copyable()
->url(fn ($state) => $state)
->openUrlInNewTab(),
])
->columns(2)
->placeholder('未设置'),
]),
Infolists\Components\Section::make('AI提示词配置')

View File

@@ -37,7 +37,10 @@ class TerminalApiController extends Controller
'terminal_name' => $terminal->name,
'terminal_code' => $terminal->code,
'station_name' => $terminal->station?->name,
'diagram_url' => $terminal->diagram_url,
'diagram_urls' => collect($terminal->diagram_urls ?? [])->values()->map(fn ($item) => [
'title' => $item['title'] ?? '',
'url' => $item['url'] ?? '',
])->all(),
'scada_data_url' => $terminal->scada_data_url,
'scada_tags_url' => $terminal->scada_tags_url,
'voice_wakeup_enabled' => $terminal->voice_wakeup_enabled,

View File

@@ -23,7 +23,7 @@ class Terminal extends Model
'ip_address',
'mac_address',
'station_id',
'diagram_url',
'diagram_urls',
'scada_data_url',
'scada_tags_url',
'voice_wakeup_enabled',
@@ -40,6 +40,7 @@ class Terminal extends Model
protected function casts(): array
{
return [
'diagram_urls' => 'array',
'voice_wakeup_enabled' => 'boolean',
'is_online' => 'boolean',
'last_online_at' => 'datetime',
@@ -74,7 +75,7 @@ class Terminal extends Model
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly(['name', 'code', 'station_id', 'diagram_url'])
->logOnly(['name', 'code', 'station_id', 'diagram_urls'])
->logOnlyDirty()
->setDescriptionForEvent(fn(string $eventName) => "终端已{$eventName}");
}

View File

@@ -29,7 +29,7 @@ class TerminalFactory extends Factory
'code' => 'TERM-' . fake()->unique()->numerify('####'),
'ip_address' => fake()->localIpv4(),
'station_id' => null,
'diagram_url' => fake()->imageUrl(1920, 1080, 'diagram', true),
'diagram_urls' => [['title' => '组态', 'url' => fake()->url()]],
'voice_wakeup_enabled' => false,
'voice_wakeup_word' => null,
'is_online' => fake()->boolean(70), // 70%概率在线

View File

@@ -0,0 +1,53 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('terminals', function (Blueprint $table) {
$table->renameColumn('diagram_url', 'diagram_urls');
});
// Migrate existing string URLs to JSON array format
DB::table('terminals')->whereNotNull('diagram_urls')->orderBy('id')->each(function ($terminal) {
$decoded = json_decode($terminal->diagram_urls, true);
if (is_array($decoded)) {
return; // Already JSON, skip
}
DB::table('terminals')->where('id', $terminal->id)->update([
'diagram_urls' => json_encode([['title' => '默认组态', 'url' => $terminal->diagram_urls]]),
]);
});
Schema::table('terminals', function (Blueprint $table) {
$table->json('diagram_urls')->nullable()->comment('组态界面地址')->change();
});
}
public function down(): void
{
// Extract first URL back to string
DB::table('terminals')->whereNotNull('diagram_urls')->orderBy('id')->each(function ($terminal) {
$decoded = json_decode($terminal->diagram_urls, true);
$url = is_array($decoded) ? ($decoded[0]['url'] ?? null) : $terminal->diagram_urls;
DB::table('terminals')->where('id', $terminal->id)->update([
'diagram_urls' => $url,
]);
});
Schema::table('terminals', function (Blueprint $table) {
$table->string('diagram_urls', 500)->nullable()->comment('组态界面地址')->change();
});
Schema::table('terminals', function (Blueprint $table) {
$table->renameColumn('diagram_urls', 'diagram_url');
});
}
};

View File

@@ -53,7 +53,10 @@ PROMPT;
'code' => "SCREEN-{$beamline}",
'ip_address' => $ipAddress,
'station_id' => $station->id,
'diagram_url' => 'https://ssrf.9z.work/scada/demo.html',
'diagram_urls' => [
['title' => 'BL16U1', 'url' => 'https://ssrf.9z.work/scada/BL16U1.svg'],
['title' => 'BL16U1前端布局图', 'url' => 'https://ssrf.9z.work/scada/BL16U1-1.svg']
],
'is_online' => in_array($beamline, ['BL02U1', 'BL07U', 'BL08U', 'BL13U', 'BL15U']),
'last_online_at' => in_array($beamline, ['BL02U1', 'BL07U', 'BL08U', 'BL13U', 'BL15U'])
? now()

View File

@@ -65,7 +65,7 @@ class TerminalResourceTest extends TestCase
'code' => 'TEST-0001',
'ip_address' => '192.168.1.100',
'station_id' => $station->id,
'diagram_url' => 'https://example.com/diagram.html',
'diagram_urls' => [['title' => '测试组态', 'url' => 'https://example.com/diagram.html']],
];
Livewire::test(CreateTerminal::class)