feat(收藏功能): 为应用和版本添加收藏功能
- 在应用列表、详情页和版本列表中添加收藏按钮 - 使用localStorage存储用户收藏的应用数据 - 添加收藏/取消收藏的交互提示 - 统一调整搜索按钮的样式尺寸
This commit is contained in:
@@ -119,6 +119,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>
|
||||
|
||||
@@ -120,7 +120,7 @@ if (!isset($conn) || !$conn instanceof mysqli) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button class="btn btn-primary w-100" type="submit">搜索</button>
|
||||
<button class="btn btn-primary w-100" style="width: calc(3.5rem + calc(var(--bs-border-width) * 2)); height: calc(3.5rem + calc(var(--bs-border-width) * 2))" type="submit">搜索</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -201,6 +201,7 @@ if (!isset($conn) || !$conn instanceof mysqli) {
|
||||
echo '<p class="card-text">'. substr(htmlspecialchars($row['description']), 0, 100) . '...</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
tags.php
2
tags.php
@@ -129,7 +129,7 @@ $tagResult = $conn->query("SELECT id, name FROM tags ORDER BY name");
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button class="btn btn-primary w-100" type="submit">搜索</button>
|
||||
<button class="btn btn-primary w-100" style="width: calc(3.5rem + calc(var(--bs-border-width) * 2)); height: calc(3.5rem + calc(var(--bs-border-width) * 2))" type="submit">搜索</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user