diff --git a/src/views/api/Music.vue b/src/views/api/Music.vue
index 96ad225..044dd31 100644
--- a/src/views/api/Music.vue
+++ b/src/views/api/Music.vue
@@ -24,6 +24,7 @@
播放
上传音乐
+
歌单管理
搜索
重置
@@ -85,7 +86,7 @@
-
+
@@ -139,6 +140,31 @@
+
+ 添加歌单
+
+
+
+
+ {{ scope.row.name }}
+
+
+
+
+
+ {{ scope.row.path }}
+
+
+
+
+
+ 保存
+ 取消
+ 删除
+
+
+
+
@@ -190,6 +216,10 @@ const currentMusic = ref
()
const lyricForm = ref()
const musicUpload = ref()
const player = ref()
+const lyricLoading = ref(false)
+const libDrawerVisible = ref(false)
+const libTableData = ref<(MusicLibModel & { _isNew?: boolean })[]>([])
+const libSaving = ref(false)
const lyricRuleValidate = {
cloudId: [
@@ -266,13 +296,17 @@ function remove(row: MusicModel) {
}
async function updateLyric(row: MusicModel) {
currentRow.value = { ...row }
+ lyricFormData.value = {}
modifyLyricModal.value = true
if (row.lyricId) {
- const data = (await http.get('/api/v2/music/lyric/get', {params: {lyricId: row.lyricId}}))
- data.cloudId = data.cloudId ? data.cloudId.toString() : null
- lyricFormData.value = data
- } else {
- lyricFormData.value = {}
+ lyricLoading.value = true
+ try {
+ const data = await http.get('/api/v2/music/lyric/get', {params: {lyricId: row.lyricId}})
+ data.cloudId = data.cloudId ? data.cloudId.toString() : null
+ lyricFormData.value = data
+ } finally {
+ lyricLoading.value = false
+ }
}
}
async function saveLyric() {
@@ -350,9 +384,43 @@ function musicPlay() {
})
}
+function loadLibs() {
+ return http.get('/api/v2/music/lib/list').then(data => {
+ musicLibs.value = data
+ libTableData.value = data.map((item: MusicLibModel) => ({ ...item }))
+ })
+}
+function addLibRow() {
+ if (libTableData.value.some(item => (item as any)._isNew)) return
+ libTableData.value.unshift({ _id: '', name: '', path: '', musicCount: 0, _isNew: true })
+}
+function cancelAddLib() {
+ libTableData.value = libTableData.value.filter(item => !(item as any)._isNew)
+}
+async function saveLib(row: MusicLibModel & { _isNew?: boolean }) {
+ if (!row.name || !row.path) {
+ ElMessage.warning('请输入歌单名称和路径')
+ return
+ }
+ libSaving.value = true
+ try {
+ await http.post('/api/v2/music/lib/add', { name: row.name, path: row.path })
+ ElMessage.success('歌单创建成功')
+ await loadLibs()
+ } finally {
+ libSaving.value = false
+ }
+}
+function removeLib(row: MusicLibModel) {
+ ElMessageBox.confirm(`是否确认删除歌单「${row.name}」?`, '确认删除', { type: 'warning' }).then(async () => {
+ await http.delete('/api/v2/music/lib/delete', { params: { id: row._id } })
+ ElMessage.success('歌单删除成功')
+ await loadLibs()
+ }).catch(() => {})
+}
+
// created
-http.get('/api/v2/music/lib/list').then(data => {
- musicLibs.value = data
+loadLibs().then(() => {
loadData()
})
http.get('/api/v2/music/listExts').then(data => {