Commit 0efc7c8430336dabf286634c089f756e28c7417c
1 parent
28dc84a3
feat: add unbind and delete device actions to admin portal
Showing
1 changed file
with
41 additions
and
0 deletions
| ... | ... | @@ -63,6 +63,28 @@ if ($pdo && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && |
| 63 | 63 | $message = "<div style='color: red;'>Operation Failed: " . $e->getMessage() . "</div>"; |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | +} elseif ($pdo && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'unbind') { | |
| 67 | + // 处理解绑 | |
| 68 | + $id = $_POST['id']; | |
| 69 | + try { | |
| 70 | + $stmt = $pdo->prepare("DELETE FROM user_device_bindings WHERE id = ?"); | |
| 71 | + $stmt->execute([$id]); | |
| 72 | + $message = "<div style='color: green; margin-bottom: 20px; background: #e6fffa; padding: 10px; border-radius: 4px;'>✅ 解绑成功</div>"; | |
| 73 | + } catch (Exception $e) { | |
| 74 | + $message = "<div style='color: red;'>Unbind Failed: " . $e->getMessage() . "</div>"; | |
| 75 | + } | |
| 76 | +} elseif ($pdo && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_device') { | |
| 77 | + // 处理删除设备 | |
| 78 | + $deviceId = $_POST['device_id']; | |
| 79 | + try { | |
| 80 | + // 先删除相关绑定 | |
| 81 | + $pdo->prepare("DELETE FROM user_device_bindings WHERE device_id = ?")->execute([$deviceId]); | |
| 82 | + // 再删除设备 | |
| 83 | + $pdo->prepare("DELETE FROM devices WHERE id = ?")->execute([$deviceId]); | |
| 84 | + $message = "<div style='color: green; margin-bottom: 20px; background: #e6fffa; padding: 10px; border-radius: 4px;'>🗑️ 设备 <b>$deviceId</b> 已彻底删除</div>"; | |
| 85 | + } catch (Exception $e) { | |
| 86 | + $message = "<div style='color: red;'>Delete Failed: " . $e->getMessage() . "</div>"; | |
| 87 | + } | |
| 66 | 88 | } |
| 67 | 89 | |
| 68 | 90 | // 获取所有设备列表 (含绑定信息) |
| ... | ... | @@ -201,6 +223,16 @@ if ($pdo) { |
| 201 | 223 | <?php if (!$dev['bound_phone']): ?> |
| 202 | 224 | <button onclick="fillBind('<?php echo htmlspecialchars($dev['id']); ?>')" |
| 203 | 225 | style="cursor: pointer; background: #007bff; color: white; border: none; padding: 4px 8px; border-radius: 4px; font-size: 12px;">选择绑定</button> |
| 226 | + | |
| 227 | + <form method="POST" action="" | |
| 228 | + onsubmit="return confirm('确定要彻底删除设备 <?php echo htmlspecialchars($dev['id']); ?> 吗?');" | |
| 229 | + style="display:inline; margin-left: 5px;"> | |
| 230 | + <input type="hidden" name="action" value="delete_device"> | |
| 231 | + <input type="hidden" name="device_id" | |
| 232 | + value="<?php echo htmlspecialchars($dev['id']); ?>"> | |
| 233 | + <button type="submit" | |
| 234 | + style="cursor: pointer; background: #dc3545; color: white; border: none; padding: 4px 8px; border-radius: 4px; font-size: 12px;">删除</button> | |
| 235 | + </form> | |
| 204 | 236 | <?php else: ?> |
| 205 | 237 | <button disabled |
| 206 | 238 | style="background: #eee; color: #999; border: none; padding: 4px 8px; border-radius: 4px; font-size: 12px;">已占用</button> |
| ... | ... | @@ -231,6 +263,7 @@ if ($pdo) { |
| 231 | 263 | <th>手机号</th> |
| 232 | 264 | <th>设备 ID</th> |
| 233 | 265 | <th>绑定时间</th> |
| 266 | + <th>操作</th> | |
| 234 | 267 | </tr> |
| 235 | 268 | </thead> |
| 236 | 269 | <tbody> |
| ... | ... | @@ -240,6 +273,14 @@ if ($pdo) { |
| 240 | 273 | <td><?php echo htmlspecialchars($row['phone']); ?></td> |
| 241 | 274 | <td><?php echo htmlspecialchars($row['device_id']); ?></td> |
| 242 | 275 | <td><?php echo $row['bound_at']; ?></td> |
| 276 | + <td> | |
| 277 | + <form method="POST" action="" onsubmit="return confirm('确定要解绑吗?');"> | |
| 278 | + <input type="hidden" name="action" value="unbind"> | |
| 279 | + <input type="hidden" name="id" value="<?php echo $row['id']; ?>"> | |
| 280 | + <button type="submit" | |
| 281 | + style="color: red; font-size: 12px; background: none; border: none; cursor: pointer; text-decoration: underline;">解绑</button> | |
| 282 | + </form> | |
| 283 | + </td> | |
| 243 | 284 | </tr> |
| 244 | 285 | <?php endforeach; ?> |
| 245 | 286 | </tbody> | ... | ... |
Please
register
or
login
to post a comment