feat: card music

This commit is contained in:
zzc
2026-02-12 08:31:54 +08:00
parent a787280e6f
commit 1aef7f1c7c

View File

@@ -540,6 +540,7 @@ const titleState = ref({
}); });
const bgms = ref([]); const bgms = ref([]);
const curBgm = ref(null);
const currentBgmIndex = ref(0); const currentBgmIndex = ref(0);
const isBgmPlaying = ref(false); const isBgmPlaying = ref(false);
const innerAudioContext = uni.createInnerAudioContext(); const innerAudioContext = uni.createInnerAudioContext();
@@ -566,6 +567,7 @@ const selectBgm = (index) => {
// 这里用户可能想重播,或者什么都不做。暂时什么都不做 // 这里用户可能想重播,或者什么都不做。暂时什么都不做
return; return;
} }
curBgm.value = bgms.value[index];
playBgm(index); playBgm(index);
closeBgmList(); closeBgmList();
}; };
@@ -573,6 +575,7 @@ const selectBgm = (index) => {
const turnOffBgm = () => { const turnOffBgm = () => {
stopBgm(); stopBgm();
currentBgmIndex.value = -1; // -1 表示关闭 currentBgmIndex.value = -1; // -1 表示关闭
curBgm.value = null;
closeBgmList(); closeBgmList();
uni.showToast({ title: "已关闭音乐", icon: "none" }); uni.showToast({ title: "已关闭音乐", icon: "none" });
}; };
@@ -1033,9 +1036,24 @@ const getTemplateList = async (isLoadMore = false) => {
}; };
const getMusicList = async () => { const getMusicList = async () => {
try {
const res = await getCardMusicList(); const res = await getCardMusicList();
bgms.value = res || []; 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(); initBgm();
}
} catch (error) {
console.error("加载音乐列表失败:", error);
}
}; };
const getTemplateTitleList = async (isLoadMore = false) => { const getTemplateTitleList = async (isLoadMore = false) => {
@@ -1298,6 +1316,7 @@ const shareOrSave = async (id) => {
blessingFrom: signatureName.value, blessingFrom: signatureName.value,
templateId: currentTemplate.value?.id || "", templateId: currentTemplate.value?.id || "",
titleId: currentTitle?.value?.id || "", titleId: currentTitle?.value?.id || "",
musicId: curBgm.value?.id || "",
}); });
}; };