bgm.service.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.bgmService = exports.BgmService = void 0;
  4. class BgmService {
  5. // 背景音乐数据
  6. bgmList = [
  7. { id: 1, name: '轻柔钢琴', url: 'https://example.com/bgm/light-piano.mp3', mood: '轻柔', duration: 180, size: 2400000 },
  8. { id: 2, name: '温暖弦乐', url: 'https://example.com/bgm/warm-strings.mp3', mood: '温暖', duration: 240, size: 3200000 },
  9. { id: 3, name: '自然雨声', url: 'https://example.com/bgm/rain-nature.mp3', mood: '自然', duration: 300, size: 4000000 },
  10. { id: 4, name: '咖啡馆氛围', url: 'https://example.com/bgm/cafe-ambient.mp3', mood: '氛围', duration: 200, size: 2600000 },
  11. { id: 5, name: '企业配乐', url: 'https://example.com/bgm/corporate.mp3', mood: '商务', duration: 150, size: 2000000 },
  12. { id: 6, name: '欢快节拍', url: 'https://example.com/bgm/upbeat.mp3', mood: '欢快', duration: 180, size: 2400000 },
  13. { id: 7, name: '抒情慢歌', url: 'https://example.com/bgm/ballad.mp3', mood: '抒情', duration: 220, size: 2900000 },
  14. { id: 8, name: '古风配乐', url: 'https://example.com/bgm/ancient-chinese.mp3', mood: '古风', duration: 260, size: 3400000 },
  15. { id: 9, name: '科技感', url: 'https://example.com/bgm/tech.mp3', mood: '科技', duration: 190, size: 2500000 },
  16. { id: 10, name: '儿童音乐', url: 'https://example.com/bgm/children.mp3', mood: '童趣', duration: 160, size: 2100000 },
  17. ];
  18. // 风格分类
  19. moods = ['轻柔', '温暖', '自然', '氛围', '商务', '欢快', '抒情', '古风', '科技', '童趣'];
  20. /**
  21. * 获取所有背景音乐
  22. */
  23. getBgmList() {
  24. return this.bgmList;
  25. }
  26. /**
  27. * 按风格筛选背景音乐
  28. */
  29. getBgmByMood(mood) {
  30. if (!mood)
  31. return this.bgmList;
  32. return this.bgmList.filter(bgm => bgm.mood === mood);
  33. }
  34. /**
  35. * 获取单个背景音乐
  36. */
  37. getBgmById(id) {
  38. return this.bgmList.find(bgm => bgm.id === id);
  39. }
  40. /**
  41. * 获取所有风格
  42. */
  43. getMoods() {
  44. return this.moods;
  45. }
  46. /**
  47. * 添加背景音乐
  48. */
  49. addBgm(data) {
  50. const newBgm = {
  51. id: this.bgmList.length + 1,
  52. ...data,
  53. };
  54. this.bgmList.push(newBgm);
  55. return newBgm;
  56. }
  57. /**
  58. * 更新背景音乐
  59. */
  60. updateBgm(id, data) {
  61. const index = this.bgmList.findIndex(bgm => bgm.id === id);
  62. if (index === -1)
  63. return null;
  64. this.bgmList[index] = { ...this.bgmList[index], ...data };
  65. return this.bgmList[index];
  66. }
  67. /**
  68. * 删除背景音乐
  69. */
  70. deleteBgm(id) {
  71. const index = this.bgmList.findIndex(bgm => bgm.id === id);
  72. if (index === -1)
  73. return false;
  74. this.bgmList.splice(index, 1);
  75. return true;
  76. }
  77. }
  78. exports.BgmService = BgmService;
  79. exports.bgmService = new BgmService();