feat: card music
This commit is contained in:
@@ -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 () => {
|
||||
try {
|
||||
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();
|
||||
}
|
||||
} 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 || "",
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user