作者 xiaoqiu

完成背景音乐

不能预览此文件类型
不能预览此文件类型
@@ -15,4 +15,12 @@ export const getUseBg = () => { @@ -15,4 +15,12 @@ export const getUseBg = () => {
15 url: '/system/bg/getUsedBg', 15 url: '/system/bg/getUsedBg',
16 method: 'get', 16 method: 'get',
17 }) 17 })
  18 +}
  19 +
  20 +// 获取应用背景
  21 +export const getUseBgMusic = () => {
  22 + return request({
  23 + url: '/system/bgMusic/getUsedBgMusic',
  24 + method: 'get',
  25 + })
18 } 26 }
不能预览此文件类型
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 <!-- 每层的图片 --> 16 <!-- 每层的图片 -->
17 <img 17 <img
18 v-for="(childen, number) in item" 18 v-for="(childen, number) in item"
  19 + :key="number + index"
19 :src="childen" 20 :src="childen"
20 alt="图片" 21 alt="图片"
21 @click.stop="handleClick($event, childen)" 22 @click.stop="handleClick($event, childen)"
@@ -46,9 +47,12 @@ @@ -46,9 +47,12 @@
46 <script setup> 47 <script setup>
47 import { ref, onMounted, onUnmounted } from 'vue' 48 import { ref, onMounted, onUnmounted } from 'vue'
48 import { ElMessage, ElMessageBox } from 'element-plus' 49 import { ElMessage, ElMessageBox } from 'element-plus'
49 -import { getSignatureList, getUseBg } from '@/api/signature' 50 +import { getSignatureList, getUseBg, getUseBgMusic } from '@/api/signature'
50 let imgList = import.meta.glob('../assets/img/*.*', { eager: true }) 51 let imgList = import.meta.glob('../assets/img/*.*', { eager: true })
51 let imgArr = Object.values(imgList).map((item) => item.default) 52 let imgArr = Object.values(imgList).map((item) => item.default)
  53 +// 导入音乐文件
  54 +let musicList = import.meta.glob('../assets/music/*.*', { eager: true })
  55 +let musicArr = Object.values(musicList).map((item) => item.default)
52 let spanBoxList = ref([]) // 图片列表 56 let spanBoxList = ref([]) // 图片列表
53 let aEls = ref([]) // 图片元素 57 let aEls = ref([]) // 图片元素
54 let radius = ref(760) 58 let radius = ref(760)
@@ -201,6 +205,11 @@ onMounted(async () => { @@ -201,6 +205,11 @@ onMounted(async () => {
201 if (!localStorage.getItem('crgx_server')) { 205 if (!localStorage.getItem('crgx_server')) {
202 return openServer(true) 206 return openServer(true)
203 } 207 }
  208 + document.addEventListener('keydown', (e) => {
  209 + if (e.key == 'j') {
  210 + openServer()
  211 + }
  212 + })
204 getImgList() 213 getImgList()
205 const bgRes = await getUseBg() // 获取背景图片 214 const bgRes = await getUseBg() // 获取背景图片
206 bgImgUrl.value = server_base + bgRes.data.path 215 bgImgUrl.value = server_base + bgRes.data.path
@@ -214,21 +223,40 @@ onMounted(async () => { @@ -214,21 +223,40 @@ onMounted(async () => {
214 //鼠标滚动事件 223 //鼠标滚动事件
215 document.addEventListener('mousewheel', handleMouseWheel) 224 document.addEventListener('mousewheel', handleMouseWheel)
216 // 监听键盘按下事件 225 // 监听键盘按下事件
217 - document.addEventListener('keydown', (e) => {  
218 - if (e.key == 'j') {  
219 - openServer()  
220 - }  
221 - })  
222 //暂停开始旋转 226 //暂停开始旋转
223 function playSpin(yes) { 227 function playSpin(yes) {
224 spinDom1.style.animationPlayState = yes ? 'running' : 'paused' 228 spinDom1.style.animationPlayState = yes ? 'running' : 'paused'
225 } 229 }
226 230
  231 + // 音频播放逻辑
  232 + if (musicArr.length > 0) {
  233 + let currentIndex = 0
  234 + const audio = new Audio()
  235 +
  236 + async function playNext() {
  237 + if (currentIndex >= musicArr.length) {
  238 + currentIndex = 0
  239 + }
  240 + audio.src = musicArr[currentIndex]
  241 + const resMusic = await getUseBgMusic()
  242 + if (resMusic.code == 200) {
  243 + audio.src = server_base + resMusic.data.path
  244 + }
  245 + audio.play().catch((err) => {
  246 + console.error('播放失败:', err)
  247 + })
  248 + currentIndex++
  249 + }
  250 +
  251 + audio.addEventListener('ended', playNext)
  252 + playNext()
  253 + }
  254 +
227 //鼠标移动事件 255 //鼠标移动事件
228 document.onpointerdown = function (e) { 256 document.onpointerdown = function (e) {
229 //清除惯性定时器 257 //清除惯性定时器
230 clearInterval(dragBoxDom.value.timer) 258 clearInterval(dragBoxDom.value.timer)
231 - e = e || ewindow.event 259 + e = e || window.event
232 //鼠标点击位置 260 //鼠标点击位置
233 ;(startX.value = e.clientX), (startY.value = e.clientY) 261 ;(startX.value = e.clientX), (startY.value = e.clientY)
234 this.onpointermove = function (e) { 262 this.onpointermove = function (e) {