From 1aef7f1c7c6b4381c3bbb2370a0f77b912a022a7 Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Thu, 12 Feb 2026 08:31:54 +0800 Subject: [PATCH] feat: card music --- pages/make/index.vue | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pages/make/index.vue b/pages/make/index.vue index 19e6832..50a5d41 100644 --- a/pages/make/index.vue +++ b/pages/make/index.vue @@ -540,6 +540,7 @@ const titleState = ref({ }); const bgms = ref([]); +const curBgm = ref(null); const currentBgmIndex = ref(0); const isBgmPlaying = ref(false); const innerAudioContext = uni.createInnerAudioContext(); @@ -566,6 +567,7 @@ const selectBgm = (index) => { // 这里用户可能想重播,或者什么都不做。暂时什么都不做 return; } + curBgm.value = bgms.value[index]; playBgm(index); closeBgmList(); }; @@ -573,6 +575,7 @@ const selectBgm = (index) => { const turnOffBgm = () => { stopBgm(); currentBgmIndex.value = -1; // -1 表示关闭 + curBgm.value = null; closeBgmList(); uni.showToast({ title: "已关闭音乐", icon: "none" }); }; @@ -1033,9 +1036,24 @@ const getTemplateList = async (isLoadMore = false) => { }; const getMusicList = async () => { - const res = await getCardMusicList(); - bgms.value = res || []; - initBgm(); + try { + const res = await getCardMusicList(); + if (res && res.length > 0) { + bgms.value = res.map((item) => ({ + id: item.id, + name: item.name, + musicUrl: item.musicUrl, + // 兼容旧逻辑 + url: item.musicUrl, + })); + if (bgms.value.length > 0) { + curBgm.value = bgms.value[0]; + } + initBgm(); + } + } catch (error) { + console.error("加载音乐列表失败:", error); + } }; const getTemplateTitleList = async (isLoadMore = false) => { @@ -1298,6 +1316,7 @@ const shareOrSave = async (id) => { blessingFrom: signatureName.value, templateId: currentTemplate.value?.id || "", titleId: currentTitle?.value?.id || "", + musicId: curBgm.value?.id || "", }); };