Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions src/components/Modal/CopyLyrics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
</n-list>
</n-checkbox-group>
</n-scrollbar>
<n-collapse-transition :show="displaySuffix !== ''">
<n-divider />
<n-flex justify="end">
<n-text> {{ displaySuffix }} </n-text>
</n-flex>
</n-collapse-transition>
<n-divider />
<n-flex vertical size="small" class="footer">
<n-text depth="2" class="footer-title">要复制的内容</n-text>
Expand Down Expand Up @@ -73,6 +79,27 @@ const displayLyrics = computed(() => {
});
});

const displaySuffix = computed(() => {
const showSongName = selectedFilters.value.includes("songName");
const showArtist = selectedFilters.value.includes("artist");

if (!showSongName && !showArtist) return "";

const songName = musicStore.playSong.name;
const artistName = Array.isArray(musicStore.playSong.artists)
? musicStore.playSong.artists.map((ar) => ar.name).join("/")
: musicStore.playSong.artists;

if (showSongName && showArtist) {
return `——《${songName}》 - ${artistName}`;
} else if (showSongName) {
return `——《${songName}》`;
} else if (showArtist) {
return `—— ${artistName}`;
}
return "";
Comment on lines +97 to +100
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

这里的 else if (showArtist) 条件是多余的,并且最后的 return "" 是无法访问到的代码。因为函数开头已经判断了 showSongNameshowArtist 都为 false 的情况并提前返回,所以如果代码能执行到这里,showArtist 必定为 true。你可以用一个 else 语句来简化这部分逻辑,这样代码更简洁,也移除了无法访问到的代码。

  } else {
    return `—— ${artistName}`;
  }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

原有逻辑,未改动

});

const showTranslation = computed(() => selectedFilters.value.includes("translation"));
const showRomaji = computed(() => selectedFilters.value.includes("romaji"));

Expand All @@ -92,6 +119,8 @@ const selectAll = () => {
* 复制歌词
*/
const handleCopy = async () => {
const lineSeparator = selectedFilters.value.includes("emptyLine") ? "\n\n" : "\n";

let linesToCopy = displayLyrics.value
.filter((l) => selectedLines.value.includes(l.index))
.map((l) => {
Expand All @@ -102,27 +131,9 @@ const handleCopy = async () => {
return parts.join("\n");
})
.filter((s) => s)
.join(selectedFilters.value.includes("emptyLine") ? "\n\n" : "\n");
.join(lineSeparator);

const showSongName = selectedFilters.value.includes("songName");
const showArtist = selectedFilters.value.includes("artist");

if (showSongName || showArtist) {
const songName = musicStore.playSong.name;
const artistName = Array.isArray(musicStore.playSong.artists)
? musicStore.playSong.artists.map((ar) => ar.name).join("/")
: musicStore.playSong.artists;

let suffix = "\n\n——";
if (showSongName && showArtist) {
suffix += `《${songName}》 - ${artistName}`;
} else if (showSongName) {
suffix += `《${songName}》`;
} else if (showArtist) {
suffix += ` ${artistName}`;
}
linesToCopy += suffix;
}
if (displaySuffix.value) linesToCopy += `${lineSeparator}${displaySuffix.value}`;

if (linesToCopy) {
await copyData(linesToCopy);
Expand Down