sendSwitch 問題 改用 room_name = PC101

This commit is contained in:
allen.yan 2025-06-04 16:11:45 +08:00
parent 53eb40dc68
commit ae6742575d
2 changed files with 15 additions and 7 deletions

View File

@ -258,10 +258,17 @@ class RoomControlController extends Controller
{ {
$validated = $request->validated(); $validated = $request->validated();
$branch = Branch::where('name',$validated['branch_name'])->first(); $branch = Branch::where('name',$validated['branch_name'])->first();
$room = Room::where([ $roomType = null;
['branch_id', $branch->id], $roomName = null;
['name', $validated['room_name']], // 從 room_name例如 PC101, SVR01中擷取 type 與 name
])->first(); if (preg_match('/^([A-Za-z]+)(\d+)$/', $validated['room_name'], $matches)) {
$roomType = strtolower($matches[1]); // 'PC' → 'pc'
$roomName = $matches[2]; // '101'
}
$room = Room::where('branch_id', $branch->id)
->where('name', $roomName)
->where('type', $roomType)
->first();
if (!$room) { if (!$room) {
return ApiResponse::error('房間不存在'); return ApiResponse::error('房間不存在');

View File

@ -20,13 +20,14 @@ class RoomDetailModal extends Component
'openAccountNotify','closeAccountNotify' 'openAccountNotify','closeAccountNotify'
]; ];
public $room; public $room_name;
public $branch; public $branch;
public bool $showModal = false; public bool $showModal = false;
public function openModal($roomId) public function openModal($roomId)
{ {
$this->room = Room::find($roomId); $room = Room::find($roomId);
$this->room_name=$room->type->value . $room->name;
$this->branch = Branch::find($this->room->branch_id); $this->branch = Branch::find($this->room->branch_id);
$this->showModal = true; $this->showModal = true;
} }
@ -69,7 +70,7 @@ class RoomDetailModal extends Component
return [ return [
'branch_name' => $this->branch->name ?? '', 'branch_name' => $this->branch->name ?? '',
'room_name' => $this->room->name ?? '', 'room_name' => $this->room_name ?? '',
'command' => $command, 'command' => $command,
'started_at' => $startedAt ? $startedAt->toDateTimeString() : null, 'started_at' => $startedAt ? $startedAt->toDateTimeString() : null,
'ended_at' => $endedAt ? $endedAt->toDateTimeString() : null, 'ended_at' => $endedAt ? $endedAt->toDateTimeString() : null,