refactor: 移除收藏功能及相关代码
删除用户收藏表及相关SQL定义 移除前端收藏按钮及JavaScript逻辑 清理API中收藏相关接口 更新README文档移除收藏功能说明
This commit is contained in:
@@ -213,7 +213,7 @@ php -S localhost:8000
|
||||
"endpoints": {
|
||||
"/api?action=list": "获取应用列表,支持search、platform、age_rating、tag、page、limit参数。search:搜索关键词;platform:平台;age_rating:年龄分级;tag:标签;page:页码;limit:每页数量",
|
||||
"/api?action=app&id=1": "获取指定ID的应用详情,需传入app_id参数。包含应用基础信息、版本、图片、评价和标签信息",
|
||||
"/api?action=favorite": "收藏应用(POST方法,需app_id和user_id参数)"
|
||||
|
||||
},
|
||||
"example": "GET /api?action=list&search=游戏&limit=10"
|
||||
}
|
||||
|
||||
38
api.php
38
api.php
@@ -15,7 +15,7 @@ if (!isset($_GET['action']) || $_GET['action'] === '') {
|
||||
'endpoints' => [
|
||||
'/api?action=list' => '获取应用列表,支持search、platform、age_rating、tag、page、limit参数。search:搜索关键词;platform:平台;age_rating:年龄分级;tag:标签;page:页码;limit:每页数量',
|
||||
'/api?action=app&id=1' => '获取指定ID的应用详情,需传入app_id参数。包含应用基础信息、版本、图片、评价和标签信息',
|
||||
'/api?action=favorite' => '收藏应用(POST方法,需app_id和user_id参数)'
|
||||
|
||||
],
|
||||
'example' => 'GET /api?action=list&search=游戏&limit=10'
|
||||
]);
|
||||
@@ -218,42 +218,6 @@ if (isset($_GET['action'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// 处理用户收藏应用
|
||||
elseif ($action === 'favorite' && isset($_GET['app_id']) && is_numeric($_GET['app_id']) && isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $requestMethod === 'POST') {
|
||||
$appId = $_GET['app_id'];
|
||||
$userId = $_GET['user_id'];
|
||||
|
||||
$stmt = $conn->prepare("INSERT IGNORE INTO user_favorites (user_id, app_id) VALUES (?, ?)");
|
||||
$stmt->bind_param("ii", $userId, $appId);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(['status' => 'success', 'message' => 'App added to favorites']);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Failed to add to favorites']);
|
||||
}
|
||||
$stmt->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取用户收藏列表
|
||||
elseif ($action === 'favorites' && isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $requestMethod === 'GET') {
|
||||
$userId = $_GET['user_id'];
|
||||
|
||||
$sql = "SELECT apps.* FROM user_favorites JOIN apps ON user_favorites.app_id = apps.id WHERE user_favorites.user_id = $userId";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
$favorites = [];
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$favorites[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($favorites);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 获取所有标签
|
||||
elseif ($action === 'tags' && $requestMethod === 'GET') {
|
||||
$sql = "SELECT id, name FROM tags ORDER BY name";
|
||||
|
||||
@@ -160,16 +160,7 @@ CREATE TABLE IF NOT EXISTS download_history (
|
||||
FOREIGN KEY (version_id) REFERENCES app_versions(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 创建用户收藏表
|
||||
CREATE TABLE IF NOT EXISTS user_favorites (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
app_id INT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY unique_favorite (user_id, app_id),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (app_id) REFERENCES apps(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
-- 创建公告表
|
||||
CREATE TABLE IF NOT EXISTS announcements (
|
||||
|
||||
@@ -189,7 +189,7 @@ $resultApps = $conn->query($sqlApps);
|
||||
</small>
|
||||
</p>
|
||||
<a href="app.php?id=<?php echo $app['id']; ?>" class="btn btn-primary">查看详情</a>
|
||||
<button class="btn btn-outline-secondary mt-2" onclick="toggleFavorite(<?php echo $app['id']; ?>, '<?php echo addslashes(htmlspecialchars($app['name'])); ?>')">收藏</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -309,7 +309,7 @@ $announcement = $announcementResult && $announcementResult->num_rows > 0 ? $anno
|
||||
echo '<p class="card-text">平台: '. implode(', ', $platforms) . '</p>';
|
||||
echo '<p class="card-text">评分: '. round($row['avg_rating'] ?? 0, 1) . '/5</p>';
|
||||
echo '<a href="app.php?id='. $row['id'] . '" class="btn btn-primary">查看详情</a>';
|
||||
echo '<button class="btn btn-outline-secondary mt-2" onclick="toggleFavorite('. $row['id'] . ', \''. htmlspecialchars($row['name']) . '\')">收藏</button>';
|
||||
|
||||
echo '</div></div></div>';
|
||||
}
|
||||
} else {
|
||||
|
||||
2
remove_favorite_feature.sql
Normal file
2
remove_favorite_feature.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- 删除收藏功能相关表
|
||||
DROP TABLE IF EXISTS user_favorites;
|
||||
@@ -139,7 +139,7 @@ while ($row = $result->fetch_assoc()) {
|
||||
<h5 class="card-title">版本 <?php echo htmlspecialchars($version['version']); ?></h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">发布日期: <?php echo date('Y-m-d', strtotime($version['created_at'])); ?></h6>
|
||||
<p class="card-text"><?php echo nl2br(htmlspecialchars($version['changelog'])); ?></p>
|
||||
<button class="btn btn-outline-secondary mt-2" onclick="toggleFavorite(<?php echo $appId; ?>, '<?php echo addslashes(htmlspecialchars($app['name'])); ?>')">收藏</button>
|
||||
|
||||
</div>
|
||||
<div class="card-footer bg-transparent d-flex justify-content-between align-items-center">
|
||||
<?php
|
||||
@@ -193,22 +193,7 @@ $sizeText = formatFileSize($fileSize);
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- 收藏功能逻辑 -->
|
||||
<script>
|
||||
function toggleFavorite(appId, appName) {
|
||||
let favorites = JSON.parse(localStorage.getItem('appFavorites')) || {};
|
||||
|
||||
if (favorites[appId]) {
|
||||
delete favorites[appId];
|
||||
alert('已取消收藏 ' + appName);
|
||||
} else {
|
||||
favorites[appId] = appName;
|
||||
alert('已收藏 ' + appName);
|
||||
}
|
||||
|
||||
localStorage.setItem('appFavorites', JSON.stringify(favorites));
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<!-- Bootstrap JS Bundle with Popper -->
|
||||
<script src="/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user