feat(收藏功能): 为应用和版本添加收藏功能

- 在应用列表、详情页和版本列表中添加收藏按钮
- 使用localStorage存储用户收藏的应用数据
- 添加收藏/取消收藏的交互提示
- 统一调整搜索按钮的样式尺寸
This commit is contained in:
2025-07-08 09:31:27 +08:00
parent 51d6fdc6ee
commit 06c8f549d3
4 changed files with 22 additions and 2 deletions

View File

@@ -121,6 +121,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"> <a href="<?php echo htmlspecialchars($version['file_path']); ?>" class="btn btn-primary" download>下载</a> <small class="text-muted">文件大小: <?php echo $fileSize; ?></small> </div>
</div>
@@ -130,6 +131,23 @@ while ($row = $result->fetch_assoc()) {
<?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="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>