feat: 添加功能开关控制页面实现
实现功能开关控制页面,包含数据库连接、状态切换和日志记录功能 页面展示功能列表并提供启用/禁用操作按钮
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// 连接SQL Server数据库
|
||||
$serverName = "localhost";
|
||||
$connectionOptions = array(
|
||||
"Database" => "your_database",
|
||||
"Uid" => "your_username",
|
||||
"PWD" => "your_password"
|
||||
);
|
||||
// 检查 sqlsrv 扩展是否已加载
|
||||
if (!extension_loaded('sqlsrv')) {
|
||||
die('SQLSRV 扩展未加载,请检查 PHP 配置。');
|
||||
}
|
||||
$conn = sqlsrv_connect($serverName, $connectionOptions);
|
||||
|
||||
if (!$conn) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
// 处理开关操作
|
||||
if (isset($_GET['action']) && isset($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
$status = $_GET['action'] == 'enable' ? 1 : 0;
|
||||
|
||||
// 更新状态
|
||||
$sql = "UPDATE features SET status = ? WHERE id = ?";
|
||||
$params = array($status, $id);
|
||||
$stmt = sqlsrv_query($conn, $sql, $params);
|
||||
|
||||
// 记录日志
|
||||
$logSql = "INSERT INTO operation_logs (feature_id, action, operation_time) VALUES (?, ?, GETDATE())";
|
||||
$logParams = array($id, $_GET['action']);
|
||||
sqlsrv_query($conn, $logSql, $logParams);
|
||||
}
|
||||
|
||||
// 查询功能列表
|
||||
$sql = "SELECT id, name, description, status FROM features";
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
|
||||
// 微信HTML5页面
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>功能开关控制</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 0; padding: 15px; }
|
||||
.feature { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #eee; }
|
||||
.feature-info { flex: 1; }
|
||||
.feature-name { font-weight: bold; margin-bottom: 5px; }
|
||||
.feature-desc { color: #666; font-size: 14px; }
|
||||
.toggle-btn { padding: 5px 10px; border-radius: 4px; border: none; color: white; cursor: pointer; }
|
||||
.enable { background-color: #4CAF50; }
|
||||
.disable { background-color: #f44336; }
|
||||
.status { margin-left: 10px; font-size: 14px; color: #666; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>功能开关控制</h2>
|
||||
<?php while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)): ?>
|
||||
<div class="feature">
|
||||
<div class="feature-info">
|
||||
<div class="feature-name"><?php echo $row['name']; ?></div>
|
||||
<div class="feature-desc"><?php echo $row['description']; ?></div>
|
||||
</div>
|
||||
<div>
|
||||
<?php if ($row['status']): ?>
|
||||
<a href="?action=disable&id=<?php echo $row['id']; ?>" class="toggle-btn disable">关闭</a>
|
||||
<span class="status">(已启用)</span>
|
||||
<?php else: ?>
|
||||
<a href="?action=enable&id=<?php echo $row['id']; ?>" class="toggle-btn enable">开启</a>
|
||||
<span class="status">(已禁用)</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
sqlsrv_close($conn);
|
||||
?>
|
||||
Reference in New Issue
Block a user