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();
$branch = Branch::where('name',$validated['branch_name'])->first();
$room = Room::where([
['branch_id', $branch->id],
['name', $validated['room_name']],
])->first();
$roomType = null;
$roomName = null;
// 從 room_name例如 PC101, SVR01中擷取 type 與 name
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) {
return ApiResponse::error('房間不存在');

View File

@ -20,13 +20,14 @@ class RoomDetailModal extends Component
'openAccountNotify','closeAccountNotify'
];
public $room;
public $room_name;
public $branch;
public bool $showModal = false;
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->showModal = true;
}
@ -69,7 +70,7 @@ class RoomDetailModal extends Component
return [
'branch_name' => $this->branch->name ?? '',
'room_name' => $this->room->name ?? '',
'room_name' => $this->room_name ?? '',
'command' => $command,
'started_at' => $startedAt ? $startedAt->toDateTimeString() : null,
'ended_at' => $endedAt ? $endedAt->toDateTimeString() : null,