From 7499298a8ba34f9bdcfa04ae58444f787fe5d0f1 Mon Sep 17 00:00:00 2001 From: Megghy Date: Mon, 25 Nov 2024 08:57:34 +0800 Subject: [PATCH] fix song adding --- src/components/SongList.vue | 486 ++++++++++-------------- src/views/manage/SongListManageView.vue | 5 + 2 files changed, 215 insertions(+), 276 deletions(-) diff --git a/src/components/SongList.vue b/src/components/SongList.vue index 9270618..d9bfab5 100644 --- a/src/components/SongList.vue +++ b/src/components/SongList.vue @@ -85,6 +85,7 @@ const batchUpdate_Option = ref() const playingSong = ref() const isLrcLoading = ref() +const isLoading = ref(false) const formRef = ref(null) const updateSongRules: FormRules = { @@ -104,27 +105,31 @@ const updateSongRules: FormRules = { const songSelectOption = [ { label: '中文', - value: SongLanguage.Chinese, + value: '中文', }, { label: '日语', - value: SongLanguage.Japanese, + value: '日语', }, { label: '英语', - value: SongLanguage.English, + value: '英语', + }, + { + label: '韩语', + value: '韩语', }, { label: '法语', - value: SongLanguage.French, + value: '法语', }, { label: '西语', - value: SongLanguage.Spanish, + value: '西语', }, { label: '其他', - value: SongLanguage.Other, + value: '其他', }, ] const languageSelectOption = computed(() => { @@ -221,8 +226,8 @@ function createColumns(): DataTableColumns { render(data) { return (data.language?.length ?? 0) > 0 ? h(NSpace, { size: 5 }, () => - data.language?.map((a) => h(NTag, { bordered: false, size: 'small' }, () => a)), - ) + data.language?.map((a) => h(NTag, { bordered: false, size: 'small' }, () => a)), + ) : null }, }, @@ -241,41 +246,41 @@ function createColumns(): DataTableColumns { render(data) { return data.options ? h(NSpace, {}, () => [ - data.options?.needJianzhang - ? h( - NTag, - { color: { textColor: 'white', color: GetGuardColor(3), borderColor: 'white' }, size: 'small' }, - () => '舰长', - ) - : null, - data.options?.needTidu - ? h( - NTag, - { color: { textColor: 'white', color: GetGuardColor(2), borderColor: 'white' }, size: 'small' }, - () => '提督', - ) - : null, - data.options?.needZongdu - ? h( - NTag, - { color: { textColor: 'white', color: GetGuardColor(1), borderColor: 'white' }, size: 'small' }, - () => '总督', - ) - : null, - data.options?.scMinPrice - ? h( - NTag, - { - color: { textColor: 'white', color: GetSCColor(data.options.scMinPrice), borderColor: 'white' }, - size: 'small', - }, - () => 'SC | ' + data.options?.scMinPrice, - ) - : null, - data.options?.fanMedalMinLevel - ? h(NTag, { type: 'info', size: 'small' }, () => '粉丝牌 | ' + data.options?.fanMedalMinLevel) - : null, - ]) + data.options?.needJianzhang + ? h( + NTag, + { color: { textColor: 'white', color: GetGuardColor(3), borderColor: 'white' }, size: 'small' }, + () => '舰长', + ) + : null, + data.options?.needTidu + ? h( + NTag, + { color: { textColor: 'white', color: GetGuardColor(2), borderColor: 'white' }, size: 'small' }, + () => '提督', + ) + : null, + data.options?.needZongdu + ? h( + NTag, + { color: { textColor: 'white', color: GetGuardColor(1), borderColor: 'white' }, size: 'small' }, + () => '总督', + ) + : null, + data.options?.scMinPrice + ? h( + NTag, + { + color: { textColor: 'white', color: GetSCColor(data.options.scMinPrice), borderColor: 'white' }, + size: 'small', + }, + () => 'SC | ' + data.options?.scMinPrice, + ) + : null, + data.options?.fanMedalMinLevel + ? h(NTag, { type: 'info', size: 'small' }, () => '粉丝牌 | ' + data.options?.fanMedalMinLevel) + : null, + ]) : null }, }, @@ -308,77 +313,77 @@ function createColumns(): DataTableColumns { () => [ GetPlayButton(data), data.url?.endsWith('mp3') || - data.url?.endsWith('flac') || - data.url?.endsWith('ogg') || - data.url?.endsWith('wav') || - data.url?.endsWith('m4a') + data.url?.endsWith('flac') || + data.url?.endsWith('ogg') || + data.url?.endsWith('wav') || + data.url?.endsWith('m4a') ? h(NTooltip, null, { + trigger: () => + h( + NButton, + { + type: 'primary', + size: 'small', + circle: true, + loading: isLrcLoading.value == data.key, + onClick: () => { + playingSong.value = data + }, + }, + { + icon: () => h(NIcon, { component: Play24Filled }), + }, + ), + default: () => '试听', + }) + : null, + props.isSelf + ? [ + h(NTooltip, null, { trigger: () => h( NButton, { - type: 'primary', size: 'small', circle: true, - loading: isLrcLoading.value == data.key, + secondary: true, onClick: () => { - playingSong.value = data + updateSongModel.value = JSON.parse(JSON.stringify(data)) + showModal.value = true }, }, { - icon: () => h(NIcon, { component: Play24Filled }), + icon: () => h(NIcon, { component: NotepadEdit20Filled }), }, ), - default: () => '试听', - }) - : null, - props.isSelf - ? [ - h(NTooltip, null, { - trigger: () => - h( - NButton, - { - size: 'small', - circle: true, - secondary: true, - onClick: () => { - updateSongModel.value = JSON.parse(JSON.stringify(data)) - showModal.value = true - }, - }, - { - icon: () => h(NIcon, { component: NotepadEdit20Filled }), - }, - ), - default: () => '修改', - }), - h(NTooltip, null, { - trigger: () => - h( - NPopconfirm, - { - onPositiveClick: () => delSong(data), - }, - { - trigger: () => - h( - NButton, - { - type: 'error', - size: 'small', - circle: true, - }, - { - icon: () => h(NIcon, { component: Delete24Filled }), - }, - ), - default: () => '确认删除该歌曲?', - }, - ), - default: () => '删除', - }), - ] + default: () => '修改', + }), + h(NTooltip, null, { + trigger: () => + h( + NPopconfirm, + { + onPositiveClick: () => delSong(data), + }, + { + trigger: () => + h( + NButton, + { + type: 'error', + size: 'small', + circle: true, + }, + { + icon: () => h(NIcon, { component: Delete24Filled }), + }, + ), + default: () => '确认删除该歌曲?', + }, + ), + default: () => '删除', + }), + ] : null, props.extraButton?.(data), ], @@ -434,23 +439,23 @@ function GetPlayButton(song: SongsInfo) { case SongFrom.Custom: return song.url ? h(NTooltip, null, { - trigger: () => - h( - NButton, - { - size: 'small', - color: '#6b95bd', - ghost: true, - onClick: () => { - window.open(song.url) - }, + trigger: () => + h( + NButton, + { + size: 'small', + color: '#6b95bd', + ghost: true, + onClick: () => { + window.open(song.url) }, - { - icon: () => h(NIcon, { component: SquareArrowForward24Filled }), - }, - ), - default: () => '打开链接', - }) + }, + { + icon: () => h(NIcon, { component: SquareArrowForward24Filled }), + }, + ), + default: () => '打开链接', + }) : null } } @@ -462,6 +467,11 @@ function renderCell(value: string | number) { } async function updateSong() { + if (props.songs.some((s) => s.name == updateSongModel.value.name)) { + message.error('已存在相同名称的歌曲') + return + } + isLoading.value = true await QueryPostAPI(SONG_API_URL + 'update', { key: updateSongModel.value.key, song: updateSongModel.value, @@ -473,6 +483,8 @@ async function updateSong() { } else { message.error('未能更新歌曲信息: ' + data.message) } + }).finally(() => { + isLoading.value = false }) } async function delSong(song: SongsInfo) { @@ -489,6 +501,7 @@ async function delSong(song: SongsInfo) { } async function delBatchSong() { const ids = selectedColumn.value.map((s) => s.toString()) + isLoading.value = true await QueryPostAPI(SONG_API_URL + 'del-batch', ids).then((data) => { if (data.code == 200) { songsInternal.value = songsInternal.value.filter((s) => !ids.includes(s.key)) @@ -498,6 +511,8 @@ async function delBatchSong() { } else { message.error('未能删除歌曲: ' + data.message) } + }).finally(() => { + isLoading.value = false }) } function GetSCColor(price: number): string { @@ -532,6 +547,7 @@ function batchUpdateAuthor() { message.error('请先选择歌曲') return } + isLoading.value = true QueryPostAPI(SONG_API_URL + 'update-batch-author', { ids: selectedColumn.value.map((s) => s.toString()), data: batchUpdate_Author.value, @@ -551,6 +567,8 @@ function batchUpdateAuthor() { }) .catch((err) => { message.error('未能更新歌曲: ' + err) + }).finally(() => { + isLoading.value = false }) } function batchUpdateTag() { @@ -558,6 +576,7 @@ function batchUpdateTag() { message.error('请先选择歌曲') return } + isLoading.value = true QueryPostAPI(SONG_API_URL + 'update-batch-tag', { ids: selectedColumn.value.map((s) => s.toString()), data: batchUpdate_Tag.value, @@ -577,6 +596,8 @@ function batchUpdateTag() { }) .catch((err) => { message.error('未能更新歌曲: ' + err) + }).finally(() => { + isLoading.value = false }) } function batchUpdateLanguage() { @@ -584,6 +605,7 @@ function batchUpdateLanguage() { message.error('请先选择歌曲') return } + isLoading.value = true QueryPostAPI(SONG_API_URL + 'update-batch-language', { ids: selectedColumn.value.map((s) => s.toString()), data: batchUpdate_Language.value, @@ -603,6 +625,8 @@ function batchUpdateLanguage() { }) .catch((err) => { message.error('未能更新歌曲: ' + err) + }).finally(() => { + isLoading.value = false }) } function batchUpdateOption() { @@ -610,6 +634,7 @@ function batchUpdateOption() { message.error('请先选择歌曲') return } + isLoading.value = true QueryPostAPI(SONG_API_URL + 'update-batch-option', { ids: selectedColumn.value.map((s) => s.toString()), data: batchUpdate_Option.value ? batchUpdate_Option.value : null, @@ -629,6 +654,8 @@ function batchUpdateOption() { }) .catch((err) => { message.error('未能更新歌曲: ' + err) + }).finally(() => { + isLoading.value = false }) } @@ -644,21 +671,10 @@ onMounted(() => { - - + + 清除歌手选择 @@ -674,19 +690,14 @@ onMounted(() => { 批量编辑 - + }" /> @@ -694,47 +705,20 @@ onMounted(() => { - + - + - + - + - + 是否启用