202509090937
加入全場開關動作
This commit is contained in:
parent
d70da24a75
commit
feb008dfeb
@ -5,33 +5,95 @@ namespace App\Livewire\Grids;
|
||||
use App\Models\Room;
|
||||
use App\Models\Branch;
|
||||
use App\Enums\RoomType;
|
||||
|
||||
use App\Services\TcpSocketClient;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use WireUi\Traits\WireUiActions;
|
||||
|
||||
|
||||
|
||||
class RoomGrid extends Component
|
||||
{
|
||||
use WireUiActions;
|
||||
|
||||
public $branch ;
|
||||
public $branchName="";
|
||||
protected $listeners = [
|
||||
'fireAlarm', 'shutdownAll',
|
||||
'muteAll', 'pauseAll',
|
||||
];
|
||||
public array $roomTypes;
|
||||
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->branch = Branch::first();
|
||||
$this->branchName = $this->branch->name ?? '';
|
||||
$this->roomTypes = ['all' => '全部'] + collect(RoomType::cases())->mapWithKeys(fn($e) => [$e->value => $e->labels()])->toArray();
|
||||
}
|
||||
public function fireAlarm()
|
||||
{
|
||||
$this->send('F');
|
||||
$this->notification()->send([
|
||||
'icon' => 'success',
|
||||
'title' => '成功',
|
||||
'description' => '命令已成功發送:🔥 火災警報!',
|
||||
]);
|
||||
}
|
||||
|
||||
public function shutdownAll()
|
||||
{
|
||||
$this->send('X');
|
||||
$this->notification()->send([
|
||||
'icon' => 'success',
|
||||
'title' => '成功',
|
||||
'description' => '命令已成功發送:⏻ 已送出全館關台!' ,
|
||||
]);
|
||||
}
|
||||
|
||||
public function muteAll()
|
||||
{
|
||||
$this->send('mute');
|
||||
$this->notification()->send([
|
||||
'icon' => 'success',
|
||||
'title' => '成功',
|
||||
'description' => '命令已成功發送:🔇 全館靜音中!' ,
|
||||
]);
|
||||
}
|
||||
|
||||
public function pauseAll()
|
||||
{
|
||||
$this->send('pause');
|
||||
$this->notification()->send([
|
||||
'icon' => 'success',
|
||||
'title' => '成功',
|
||||
'description' => '命令已成功發送:⏸ 已暫停全館播放!' ,
|
||||
]);
|
||||
}
|
||||
public function send(string $action)
|
||||
{
|
||||
$rooms=Room::where([['is_online',true],['branch_id',$this->branch->id]])->get();
|
||||
foreach($rooms as $room){
|
||||
$client = new TcpSocketClient($room->internal_ip, $room->port);
|
||||
try {
|
||||
$response = $client->send($room->name . "," . $action);
|
||||
} catch (\Throwable $e) {
|
||||
logger()->error('❌ TCP 傳送失敗: ' . $e->getMessage(), [
|
||||
'room_id' => $room->id,
|
||||
'ip' => $room->internal_ip,
|
||||
'port' => $room->port,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$branch = Branch::first();
|
||||
$this->branchName = $branch->name ?? '';
|
||||
|
||||
{
|
||||
$rooms = collect(); // 預設為空集合
|
||||
$floors = [];
|
||||
|
||||
if ($branch) {
|
||||
$rooms = Room::where('branch_id', $branch->id)->orderBy('name', 'asc')->get();
|
||||
if ($this->branch) {
|
||||
$rooms = Room::where('branch_id', $this->branch->id)->orderBy('name', 'asc')->get();
|
||||
$floors = $rooms->pluck('floor')->unique()->sort()->values()->toArray();
|
||||
array_unshift($floors, 'all');
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace App\Livewire\Pages;
|
||||
|
||||
use App\Models\RoomSession;
|
||||
use Livewire\Component;
|
||||
use App\Services\ApiClient;
|
||||
use WireUi\Traits\WireUiActions;
|
||||
use App\Services\TcpSocketClient;
|
||||
|
||||
|
@ -1,4 +1,27 @@
|
||||
<x-card title="{{ $branchName }} - 包廂設定" shadow="none">
|
||||
{{-- 全域控制按鈕 --}}
|
||||
<div class="flex gap-4 mb-6">
|
||||
<x-button
|
||||
label="🔥 火災"
|
||||
class="bg-red-600 text-white hover:bg-red-700"
|
||||
wire:click="fireAlarm"
|
||||
/>
|
||||
<x-button
|
||||
label="⏻ 關台"
|
||||
class="bg-gray-800 text-white hover:bg-black"
|
||||
wire:click="shutdownAll"
|
||||
/>
|
||||
<x-button
|
||||
label="🔇 靜音"
|
||||
class="bg-yellow-600 text-white hover:bg-yellow-700"
|
||||
wire:click="muteAll"
|
||||
/>
|
||||
<x-button
|
||||
label="⏸ 暫停"
|
||||
class="bg-blue-600 text-white hover:bg-blue-700"
|
||||
wire:click="pauseAll"
|
||||
/>
|
||||
</div>
|
||||
<div x-data="{ floor: '{{ $floors[0] ?? 1 }}', type: 'all' }">
|
||||
{{-- 樓層 Tab --}}
|
||||
<div class="flex gap-2 mb-2">
|
||||
|
Loading…
x
Reference in New Issue
Block a user