Skip to content

feat: 在播放界面、评论区、专辑等页面添加具体评论数量#942

Merged
imsyy merged 5 commits into
SPlayer-Dev:devfrom
WorldSansha:feat-new-work
Feb 28, 2026
Merged

feat: 在播放界面、评论区、专辑等页面添加具体评论数量#942
imsyy merged 5 commits into
SPlayer-Dev:devfrom
WorldSansha:feat-new-work

Conversation

@WorldSansha
Copy link
Copy Markdown
Contributor

@WorldSansha WorldSansha commented Feb 26, 2026

概述
在全屏播放器的评论按钮右上角显示当前歌曲的评论数量角标,并在评论面板的"全部评论"标题旁显示具体评论数。

改动内容

  • 评论数量角标
  • 全屏播放器评论按钮右上角新增评论数量角标,样式参考播放列表数量角标
  • 歌曲切换时自动通过 /comment/new 接口轻量获取评论总数(pageSize=1)
  • 数量格式化:1236 → 1.2K+,133145 → 13.3W+

评论面板

  • "全部评论"标题右侧显示完整评论数量

设置项

  • 新增「显示评论数量」设置(外观设置 → 界面布局)

三种模式:

  • 关闭:不显示角标,不发起额外 API 请求
  • 缩减(默认):超过 999 自动缩写(K+ / W+)
  • 完整:显示原始数字
image image

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @WorldSansha, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此PR通过在播放界面和评论区集成评论数量显示,显著提升了用户体验。它引入了一个可配置的评论数量展示功能,允许用户一目了然地查看评论活动,无论是作为播放器控制上的紧凑型角标,还是评论面板内的完整计数,并提供了自定义其可见性和格式的选项。

Highlights

  • 评论数量角标: 在全屏播放器评论按钮右上角新增评论数量角标,并支持数量格式化(如1.2K+,13.3W+)。
  • 评论面板显示: 在评论面板的“全部评论”标题旁显示当前歌曲的完整评论数量。
  • 新增设置项: 引入“显示评论数量”设置,用户可在“外观设置”中选择“关闭”、“缩减”(默认)或“完整”模式。
  • 优化API请求: 在歌曲切换时,通过轻量级API请求(pageSize=1)自动获取当前歌曲的评论总数。
Changelog
  • src/components/Player/PlayerComment.vue
    • 在评论面板的“全部评论”标题旁添加了评论数量的显示。
    • 更新了 getAllComment 函数,以将获取到的评论总数存储到状态管理中。
    • 在歌曲切换时,将当前歌曲的评论数量重置为0。
    • 为评论数量显示添加了新的CSS样式。
  • src/components/Player/PlayerControl.vue
    • 在播放器评论按钮上集成了 n-badge 组件,用于显示格式化后的评论数量角标。
    • 引入了 getComment API。
    • 新增了 formatCommentCount 计算属性,用于根据设置格式化评论数量(缩减或完整)。
    • 添加了 fetchCommentCount 函数,用于异步获取歌曲评论数量。
    • 实现了 watch 监听 musicStore.playSong.id 变化,以便在歌曲切换时更新评论数量。
    • 在组件挂载时,如果当前有歌曲且不是本地文件,则获取评论数量。
    • 为 n-badge 组件的角标部分添加了自定义样式。
  • src/components/Setting/config/appearance.ts
    • 在外观设置中新增了名为“显示评论数量”的配置项,允许用户选择“关闭”、“缩减”或“完整”显示模式。
  • src/stores/setting.ts
    • 在 SettingState 接口中定义了 showCommentCount 属性,类型为 "off" | "compact" | "full"。
    • 在设置存储的默认状态中,将 showCommentCount 初始化为 "compact"。
  • src/stores/status.ts
    • 在 StatusState 接口中定义了 songCommentCount 属性,类型为 number。
    • 在状态存储的默认状态中,将 songCommentCount 初始化为 0。
Activity
  • 此拉取请求自创建以来,尚未有评论、审查或进展更新。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

此拉取请求成功地在播放界面和评论区内添加了评论数量显示功能。实现细节考虑周全,包括评论数量的格式化(如 K+ 和 W+)、在歌曲切换时重置并重新获取评论数,以及在设置中提供了三种显示模式(关闭、缩减、完整)。代码结构清晰,逻辑合理,对 API 的调用也进行了优化,只在需要时轻量级地获取评论总数。这是一个高质量的改进,提升了用户体验。

@WorldSansha WorldSansha changed the title feat: 在播放界面和评论区内添加评论数量 feat: 在播放界面、评论区、专辑等页面添加具体评论数量 Feb 26, 2026
@WorldSansha
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 实现了在多个界面显示评论数量的功能,包括全屏播放器、评论面板和专辑页面,并添加了相应的设置项。整体实现思路清晰,代码结构良好。

我提出了一些关于代码优化的建议:

  • PlayerControl.vue 中,存在冗余的 CSS 样式,可以进行简化。
  • album.vue 中,对评论数量的缓存处理逻辑可以优化,以避免不必要的网络请求和修复一个潜在的竞态条件。

请查看具体的评论以了解详细信息。

Comment thread src/views/List/album.vue
Comment on lines +198 to +199
// 获取专辑评论数量(专辑API不返回commentCount)
fetchAlbumCommentCount(id);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

从缓存加载数据时,可以先检查缓存中是否已存在 commentCount,如果不存在再调用 fetchAlbumCommentCount。这样可以避免在已有数据的情况下发起不必要的网络请求。

      // 若缓存中无评论数,则主动获取
      if (cached.detail.commentCount == null) {
        fetchAlbumCommentCount(id);
      }

Comment thread src/views/List/album.vue
if (currentRequestId.value !== id) return;
setDetailData(formatCoverList(detail.album)[0]);
// 获取专辑评论数量(专辑API不返回commentCount)
fetchAlbumCommentCount(id);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了确保获取到的 commentCount 能够被正确地保存到缓存中,建议在这里使用 await 等待 fetchAlbumCommentCount 执行完成。
当前实现存在竞态条件:saveCache 可能会在 fetchAlbumCommentCount 更新 detailData.value.commentCount 之前执行,导致评论数未能存入缓存。

  await fetchAlbumCommentCount(id);

Comment thread src/components/Player/PlayerControl.vue Outdated
const { timeDisplay, toggleTimeFormat } = useTimeFormat();

// 格式化评论数量
const formatCommentCount = computed(() => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分计算可以提取到 src\utils\format.ts 工具函数中
然后在这里和歌单页面都能处理一下

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/views/List/album.vue
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不必要多添加请求了,专辑的接口没返回评论数量就不显示了吧

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果就专辑页面没有评论数量的话好像怪怪的(,而且其实也能从别的地方获取

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我后面改下吧

@WorldSansha
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 的主要目标是在多个界面(如播放器、评论区、专辑页)添加评论数量的显示,并提供了相关的设置选项。整体实现得很好,功能点覆盖全面,包括了 API 请求、状态管理、UI 展示和用户设置。

代码层面,我发现几处可以改进的地方:

  • PlayerControl.vuealbum.vue 中,获取评论数的异步请求里有空的 catch 块,建议加入 console.error 日志,以便于调试。
  • format.ts 中的 formatCommentCount 函数逻辑可以简化,使其更具可读性。

除此之外,代码结构清晰,新功能的集成方式也比较合理。这些小调整将有助于提升代码的健壮性和可维护性。

Comment on lines +189 to +191
} catch {
// 忽略错误
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这个 try...catch 块目前会静默地忽略所有错误。虽然对于这个非核心功能,我们可能不希望向用户显示错误消息,但在开发和维护期间,将错误记录到控制台以进行调试是一种很好的做法。这有助于识别与 API 或网络相关的潜在问题。

  } catch (error) {
    console.error("获取评论数量失败:", error);
  }

Comment thread src/utils/format.ts Outdated
Comment on lines +13 to +24
export const formatCommentCount = (count: number, mode: "full" | "compact" = "compact"): string | number => {
if (mode === "full") return count;
if (count >= 10000) {
const val = Math.floor(count / 1000) / 10;
return `${val % 1 === 0 ? val.toFixed(0) : val}W+`;
}
if (count >= 1000) {
const val = Math.floor(count / 100) / 10;
return `${val % 1 === 0 ? val.toFixed(0) : val}K+`;
}
return count;
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

当前格式化评论数量的函数逻辑有些复杂,可以进行简化以提高可读性和可维护性。目前的实现使用了一些虽然巧妙但不太直观的数学运算来截断到一位小数。采用更直接的方法可以使代码意图更清晰。

Suggested change
export const formatCommentCount = (count: number, mode: "full" | "compact" = "compact"): string | number => {
if (mode === "full") return count;
if (count >= 10000) {
const val = Math.floor(count / 1000) / 10;
return `${val % 1 === 0 ? val.toFixed(0) : val}W+`;
}
if (count >= 1000) {
const val = Math.floor(count / 100) / 10;
return `${val % 1 === 0 ? val.toFixed(0) : val}K+`;
}
return count;
};
export const formatCommentCount = (count: number, mode: "full" | "compact" = "compact"): string | number => {
if (mode === "full" || count < 1000) {
return count;
}
if (count >= 10000) {
const num = Math.floor((count / 10000) * 10) / 10;
return `${num}W+`;
}
// count >= 1000
const num = Math.floor((count / 1000) * 10) / 10;
return `${num}K+`;
};

Comment thread src/views/List/album.vue
Comment on lines +273 to +275
} catch {
// 忽略错误
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

与项目中其他部分的代码类似,此处的 try...catch 块会静默地忽略错误。更好的做法是将这些错误记录到控制台。这样可以在获取专辑评论数失败时帮助调试,而不会中断用户体验。

  } catch (error) {
    console.error("获取专辑评论数量失败:", error);
  }

Comment thread src/utils/format.ts Outdated
* @param mode 显示模式("full" 显示完整数值,"compact" 缩减显示)
* @returns 格式化后的评论数量
*/
export const formatCommentCount = (count: number, mode: "full" | "compact" = "compact"): string | number => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用传递 mode
可以直接在方法内使用 const settings = useSettingStore() 来获取

Comment thread src/components/Player/PlayerControl.vue Outdated
// 格式化评论数量
const formattedCommentCount = computed(() => {
const count = statusStore.songCommentCount;
const mode = settingStore.showCommentCount === "full" ? "full" : "compact";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接在方法内使用 settingStore,这里就没必要用 computed 了

Comment thread src/views/List/album.vue
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我后面改下吧

移除 mode 参数,改为在函数内部通过 useSettingStore() 获取显示模式,
简化调用方并移除 PlayerControl 中不再需要的 computed 包装。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@WorldSansha
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

此 PR 新增了在多处显示评论数量的功能,包括全屏播放器、评论区和专辑页面。同时增加了一个新的设置项,用于控制评论数量的显示方式(关闭、缩减、完整)。代码实现很可靠,能够高效地获取评论数并更新 UI。我发现 PlayerControl.vue 中存在一处轻微的 CSS 代码重复,并提出了修改建议。总体而言,这是一次很棒的功能增强。

@imsyy imsyy merged commit 76be3cc into SPlayer-Dev:dev Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants