Skip to content

feat: 支持按照文件名排序#838

Open
kyv001 wants to merge 5 commits intoimsyy:devfrom
kyv001:feature/sort-by-filename
Open

feat: 支持按照文件名排序#838
kyv001 wants to merge 5 commits intoimsyy:devfrom
kyv001:feature/sort-by-filename

Conversation

@kyv001
Copy link
Contributor

@kyv001 kyv001 commented Feb 7, 2026

支持按照文件名排序本地文件,以便对

Some Album/
  01 - Track 01.wav
  02 - Track 02.wav
  03 - Track 03.wav
  ...

这样的本地专辑保持正确顺序。

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kyv001, 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!

此拉取请求引入了一项新功能,允许用户根据文件的名称对本地文件进行排序。这对于那些希望按照文件名(例如,"01 - Track 01.wav")来组织和播放本地专辑的用户来说,能够确保歌曲以正确的顺序呈现,从而显著提升了本地音乐库的管理体验。

Highlights

  • 新增文件名排序功能: 为本地文件列表添加了按文件名排序的功能,确保本地专辑的正确顺序。
  • 更新排序逻辑: 在 SongList.vue 中实现了根据文件路径提取文件名并进行排序的逻辑。
  • 类型定义扩展: 在 main.ts 中扩展了 SortField 类型,包含了新的 filename 选项。
  • UI选项更新: 在 meta.ts 中为文件名排序添加了对应的显示名称 "文件名"。
Changelog
  • src/components/List/SongList.vue
    • 在计算属性 listData 的排序逻辑中,新增了 filename 排序选项。
    • 实现了从文件路径中提取文件名的辅助函数 getFileName
    • 使用 localeCompare 对提取出的文件名进行本地化比较排序。
  • src/types/main.ts
    • SortField 类型定义中,新增了 filename 字符串字面量,以支持新的排序字段。
  • src/utils/meta.ts
    • sortFieldOptions 对象中,新增了 filename 属性,并为其设置了显示名称 "文件名",以便在用户界面中显示。
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
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 添加了按文件名排序的功能,这对于管理本地音乐文件非常有用。代码实现整体不错,我在 SongList.vue 中发现一个可以优化性能的地方,通过移除在 sort 回调中重复定义的函数来避免不必要的性能开销。具体建议请看我的评论。继续加油!

Comment on lines 311 to 317
// 从路径中提取文件名
const getFileName = (path?: string) => {
if (!path) return "";
return path.split(/[\\/]/).pop() || "";
};
const fileNameA = getFileName(a.path);
const fileNameB = getFileName(b.path);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

为了提升性能和简化代码,建议直接提取文件名进行比较,而不是在每次比较时都重新声明 getFileName 函数。在 sort 的回调中重复定义函数会带来不必要的性能开销,尤其是在处理大型列表时。

        const fileNameA = a.path?.split(/[\\/]/).pop() || "";
        const fileNameB = b.path?.split(/[\\/]/).pop() || "";

@kyv001
Copy link
Contributor Author

kyv001 commented Feb 7, 2026

现已支持按照曲目序号排序(虽然超出了PR的范围)

case "filename": {
const fileNameA = a.path?.split(/[\\/]/).pop() || "";
const fileNameB = b.path?.split(/[\\/]/).pop() || "";
result = fileNameA.localeCompare(fileNameB, "zh-CN");
Copy link
Collaborator

Choose a reason for hiding this comment

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

localeCompare 默认不仅行数字敏感排序,如果文件名为 1.mp3, 10.mp3, 2.mp3,默认排序结果可能是 1, 10, 2。建议加上 numeric: true

Copy link
Collaborator

Choose a reason for hiding this comment

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

实际上,从 localeCompare 改成 Intl.Collator 来排序可能更好,在 sort 循环中反复调用 localeCompare 性能比较糟糕。不过只是非阻塞性建议,可采纳可不采纳吧

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