feat(音频播放器): 添加音频播放器组件及功能
新增音频播放器组件,支持播放控制、进度条调节、音量控制、播放列表等功能。添加了FontAwesome图标库依赖,并更新了相关路由和页面配置。
Showing
10 changed files
with
192 additions
and
28 deletions
| ... | @@ -8,6 +8,9 @@ | ... | @@ -8,6 +8,9 @@ |
| 8 | "name": "vue-vite", | 8 | "name": "vue-vite", |
| 9 | "version": "0.0.0", | 9 | "version": "0.0.0", |
| 10 | "dependencies": { | 10 | "dependencies": { |
| 11 | + "@fortawesome/fontawesome-svg-core": "^6.5.1", | ||
| 12 | + "@fortawesome/free-solid-svg-icons": "^6.5.1", | ||
| 13 | + "@fortawesome/vue-fontawesome": "^3.0.5", | ||
| 11 | "@heroicons/vue": "^2.2.0", | 14 | "@heroicons/vue": "^2.2.0", |
| 12 | "@vant/touch-emulator": "^1.4.0", | 15 | "@vant/touch-emulator": "^1.4.0", |
| 13 | "@vant/use": "^1.6.0", | 16 | "@vant/use": "^1.6.0", |
| ... | @@ -830,6 +833,48 @@ | ... | @@ -830,6 +833,48 @@ |
| 830 | "node": ">=18" | 833 | "node": ">=18" |
| 831 | } | 834 | } |
| 832 | }, | 835 | }, |
| 836 | + "node_modules/@fortawesome/fontawesome-common-types": { | ||
| 837 | + "version": "6.5.1", | ||
| 838 | + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-6.5.1.tgz", | ||
| 839 | + "integrity": "sha512-GkWzv+L6d2bI5f/Vk6ikJ9xtl7dfXtoRu3YGE6nq0p/FFqA1ebMOAWg3XgRyb0I6LYyYkiAo+3/KrwuBp8xG7A==", | ||
| 840 | + "hasInstallScript": true, | ||
| 841 | + "engines": { | ||
| 842 | + "node": ">=6" | ||
| 843 | + } | ||
| 844 | + }, | ||
| 845 | + "node_modules/@fortawesome/fontawesome-svg-core": { | ||
| 846 | + "version": "6.5.1", | ||
| 847 | + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-6.5.1.tgz", | ||
| 848 | + "integrity": "sha512-MfRCYlQPXoLlpem+egxjfkEuP9UQswTrlCOsknus/NcMoblTH2g0jPrapbcIb04KGA7E2GZxbAccGZfWoYgsrQ==", | ||
| 849 | + "hasInstallScript": true, | ||
| 850 | + "dependencies": { | ||
| 851 | + "@fortawesome/fontawesome-common-types": "6.5.1" | ||
| 852 | + }, | ||
| 853 | + "engines": { | ||
| 854 | + "node": ">=6" | ||
| 855 | + } | ||
| 856 | + }, | ||
| 857 | + "node_modules/@fortawesome/free-solid-svg-icons": { | ||
| 858 | + "version": "6.5.1", | ||
| 859 | + "resolved": "https://registry.npmjs.org/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-6.5.1.tgz", | ||
| 860 | + "integrity": "sha512-S1PPfU3mIJa59biTtXJz1oI0+KAXW6bkAb31XKhxdxtuXDiUIFsih4JR1v5BbxY7hVHsD1RKq+jRkVRaf773NQ==", | ||
| 861 | + "hasInstallScript": true, | ||
| 862 | + "dependencies": { | ||
| 863 | + "@fortawesome/fontawesome-common-types": "6.5.1" | ||
| 864 | + }, | ||
| 865 | + "engines": { | ||
| 866 | + "node": ">=6" | ||
| 867 | + } | ||
| 868 | + }, | ||
| 869 | + "node_modules/@fortawesome/vue-fontawesome": { | ||
| 870 | + "version": "3.0.5", | ||
| 871 | + "resolved": "https://registry.npmjs.org/@fortawesome/vue-fontawesome/-/vue-fontawesome-3.0.5.tgz", | ||
| 872 | + "integrity": "sha512-isZZ4+utQH9qg9cWxWYHQ9GwI3r5FeO7GnmzKYV+gbjxcptQhh+F99iZXi1Y9AvFUEgy8kRpAdvDlbb3drWFrw==", | ||
| 873 | + "peerDependencies": { | ||
| 874 | + "@fortawesome/fontawesome-svg-core": "~1 || ~6", | ||
| 875 | + "vue": ">= 3.0.0 < 4" | ||
| 876 | + } | ||
| 877 | + }, | ||
| 833 | "node_modules/@heroicons/vue": { | 878 | "node_modules/@heroicons/vue": { |
| 834 | "version": "2.2.0", | 879 | "version": "2.2.0", |
| 835 | "resolved": "https://registry.npmjs.org/@heroicons/vue/-/vue-2.2.0.tgz", | 880 | "resolved": "https://registry.npmjs.org/@heroicons/vue/-/vue-2.2.0.tgz", | ... | ... |
| ... | @@ -15,6 +15,9 @@ | ... | @@ -15,6 +15,9 @@ |
| 15 | "dev_upload": "npm run build_tar && npm run scp-dev && npm run dec-dev && npm run remove_tar" | 15 | "dev_upload": "npm run build_tar && npm run scp-dev && npm run dec-dev && npm run remove_tar" |
| 16 | }, | 16 | }, |
| 17 | "dependencies": { | 17 | "dependencies": { |
| 18 | + "@fortawesome/fontawesome-svg-core": "^6.5.1", | ||
| 19 | + "@fortawesome/free-solid-svg-icons": "^6.5.1", | ||
| 20 | + "@fortawesome/vue-fontawesome": "^3.0.5", | ||
| 18 | "@heroicons/vue": "^2.2.0", | 21 | "@heroicons/vue": "^2.2.0", |
| 19 | "@vant/touch-emulator": "^1.4.0", | 22 | "@vant/touch-emulator": "^1.4.0", |
| 20 | "@vant/use": "^1.6.0", | 23 | "@vant/use": "^1.6.0", | ... | ... |
| ... | @@ -10,6 +10,7 @@ declare module 'vue' { | ... | @@ -10,6 +10,7 @@ declare module 'vue' { |
| 10 | export interface GlobalComponents { | 10 | export interface GlobalComponents { |
| 11 | ActivityCard: typeof import('./components/ui/ActivityCard.vue')['default'] | 11 | ActivityCard: typeof import('./components/ui/ActivityCard.vue')['default'] |
| 12 | AppLayout: typeof import('./components/layout/AppLayout.vue')['default'] | 12 | AppLayout: typeof import('./components/layout/AppLayout.vue')['default'] |
| 13 | + AudioPlayer: typeof import('./components/ui/AudioPlayer.vue')['default'] | ||
| 13 | BottomNav: typeof import('./components/layout/BottomNav.vue')['default'] | 14 | BottomNav: typeof import('./components/layout/BottomNav.vue')['default'] |
| 14 | CheckInDialog: typeof import('./components/ui/CheckInDialog.vue')['default'] | 15 | CheckInDialog: typeof import('./components/ui/CheckInDialog.vue')['default'] |
| 15 | ConfirmDialog: typeof import('./components/ui/ConfirmDialog.vue')['default'] | 16 | ConfirmDialog: typeof import('./components/ui/ConfirmDialog.vue')['default'] | ... | ... |
src/components/ui/AudioPlayer.vue
0 → 100644
This diff is collapsed. Click to expand it.
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-03-20 20:36:36 | 2 | * @Date: 2025-03-20 20:36:36 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-24 23:32:16 | 4 | + * @LastEditTime: 2025-04-07 14:24:50 |
| 5 | * @FilePath: /mlaj/src/main.js | 5 | * @FilePath: /mlaj/src/main.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -13,10 +13,21 @@ import axios from '@/utils/axios'; | ... | @@ -13,10 +13,21 @@ import axios from '@/utils/axios'; |
| 13 | import 'vant/lib/index.css' | 13 | import 'vant/lib/index.css' |
| 14 | import '@vant/touch-emulator'; | 14 | import '@vant/touch-emulator'; |
| 15 | 15 | ||
| 16 | +/* import the fontawesome core */ | ||
| 17 | +import { library } from '@fortawesome/fontawesome-svg-core' | ||
| 18 | +/* import font awesome icon component */ | ||
| 19 | +import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' | ||
| 20 | +/* import specific icons */ | ||
| 21 | +import { faCirclePause, faCirclePlay, faPlay, faPause, faBackwardStep, faForwardStep, faVolumeUp, faRedo, faRepeat, faList, faChevronDown, faVolumeOff, faXmark } from '@fortawesome/free-solid-svg-icons' | ||
| 22 | + | ||
| 23 | +/* add icons to the library */ | ||
| 24 | +library.add(faCirclePause, faCirclePlay, faPlay, faPause, faBackwardStep, faForwardStep, faVolumeUp, faRedo, faRepeat, faList, faChevronDown, faVolumeOff, faXmark) | ||
| 25 | + | ||
| 16 | const app = createApp(App) | 26 | const app = createApp(App) |
| 17 | // 屏蔽警告信息 | 27 | // 屏蔽警告信息 |
| 18 | app.config.warnHandler = () => null; | 28 | app.config.warnHandler = () => null; |
| 19 | 29 | ||
| 20 | app.config.globalProperties.$http = axios; // 关键语句 | 30 | app.config.globalProperties.$http = axios; // 关键语句 |
| 31 | +app.component('font-awesome-icon', FontAwesomeIcon) | ||
| 21 | app.use(router) | 32 | app.use(router) |
| 22 | app.mount('#app') | 33 | app.mount('#app') | ... | ... |
| ... | @@ -163,6 +163,12 @@ export const routes = [ | ... | @@ -163,6 +163,12 @@ export const routes = [ |
| 163 | meta: { title: '修改密码' }, | 163 | meta: { title: '修改密码' }, |
| 164 | }, | 164 | }, |
| 165 | { | 165 | { |
| 166 | + path: '/profile/settings/audio', | ||
| 167 | + name: 'AudioPlayer', | ||
| 168 | + component: () => import('../views/profile/settings/AudioPlayerPage.vue'), | ||
| 169 | + meta: { title: '音频播放' }, | ||
| 170 | + }, | ||
| 171 | + { | ||
| 166 | path: '/profile/learning-records', | 172 | path: '/profile/learning-records', |
| 167 | name: 'LearningRecords', | 173 | name: 'LearningRecords', |
| 168 | component: () => import('../views/profile/LearningRecordsPage.vue'), | 174 | component: () => import('../views/profile/LearningRecordsPage.vue'), | ... | ... |
src/utils/time.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2025-04-07 12:41:59 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-04-07 12:42:05 | ||
| 5 | + * @FilePath: /mlaj/src/utils/time.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +/** | ||
| 9 | + * 格式化时间戳为 mm:ss 或 hh:mm:ss 格式 | ||
| 10 | + * @param {number} seconds - 总秒数(支持小数) | ||
| 11 | + * @returns {string} 格式化后的时间字符串 | ||
| 12 | + */ | ||
| 13 | +export function formatTime(seconds) { | ||
| 14 | + if (isNaN(seconds) || seconds < 0) return '0:00' | ||
| 15 | + | ||
| 16 | + const hours = Math.floor(seconds / 3600) | ||
| 17 | + seconds %= 3600 | ||
| 18 | + const minutes = Math.floor(seconds / 60) | ||
| 19 | + seconds = Math.floor(seconds % 60) | ||
| 20 | + | ||
| 21 | + const pad = (n) => n.toString().padStart(2, '0') | ||
| 22 | + if (hours > 0) { | ||
| 23 | + return `${hours}:${pad(minutes)}:${pad(seconds)}` | ||
| 24 | + } | ||
| 25 | + return `${minutes}:${pad(seconds)}` | ||
| 26 | +} |
| ... | @@ -64,6 +64,17 @@ | ... | @@ -64,6 +64,17 @@ |
| 64 | <ChevronRightIcon class="w-5 h-5 text-gray-400" /> | 64 | <ChevronRightIcon class="w-5 h-5 text-gray-400" /> |
| 65 | </div> | 65 | </div> |
| 66 | </div> | 66 | </div> |
| 67 | + | ||
| 68 | + <!-- 音频播放 --> | ||
| 69 | + <div class="p-4" @click="router.push('/profile/settings/audio')"> | ||
| 70 | + <div class="flex items-center justify-between"> | ||
| 71 | + <div> | ||
| 72 | + <h3 class="text-base font-medium text-gray-900">音频播放</h3> | ||
| 73 | + <p class="text-sm text-gray-500">播放音频文件</p> | ||
| 74 | + </div> | ||
| 75 | + <ChevronRightIcon class="w-5 h-5 text-gray-400" /> | ||
| 76 | + </div> | ||
| 77 | + </div> | ||
| 67 | </div> | 78 | </div> |
| 68 | </FrostedGlass> | 79 | </FrostedGlass> |
| 69 | </div> | 80 | </div> | ... | ... |
| 1 | +<!-- | ||
| 2 | + * @Date: 2025-03-24 13:04:21 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-04-07 14:06:35 | ||
| 5 | + * @FilePath: /mlaj/src/views/profile/settings/AudioPlayerPage.vue | ||
| 6 | + * @Description: 音频播放页面 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <AppLayout> | ||
| 10 | + <div class="bg-gradient-to-br from-green-50 via-green-100/30 to-blue-50/30 min-h-screen"> | ||
| 11 | + <div class="px-4 py-6"> | ||
| 12 | + <FrostedGlass class="rounded-xl overflow-hidden"> | ||
| 13 | + <AudioPlayer :songs="audioList" /> | ||
| 14 | + </FrostedGlass> | ||
| 15 | + </div> | ||
| 16 | + </div> | ||
| 17 | + </AppLayout> | ||
| 18 | +</template> | ||
| 19 | + | ||
| 20 | +<script setup> | ||
| 21 | +import { ref } from 'vue'; | ||
| 22 | +import AppLayout from '@/components/layout/AppLayout.vue'; | ||
| 23 | +import FrostedGlass from '@/components/ui/FrostedGlass.vue'; | ||
| 24 | +import AudioPlayer from '@/components/ui/AudioPlayer.vue'; | ||
| 25 | + | ||
| 26 | +// 测试音频数据 | ||
| 27 | +const audioList = ref([ | ||
| 28 | + { | ||
| 29 | + id: 1, | ||
| 30 | + title: '示例音频 1', | ||
| 31 | + artist: '演唱者 1', | ||
| 32 | + cover: 'https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg', | ||
| 33 | + url: 'https://img.tukuppt.com/newpreview_music/09/03/95/5c8af46b01eb138909.mp3' | ||
| 34 | + }, | ||
| 35 | + { | ||
| 36 | + id: 2, | ||
| 37 | + title: '示例音频 2', | ||
| 38 | + artist: '演唱者 2', | ||
| 39 | + cover: 'https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg', | ||
| 40 | + url: 'https://img.tukuppt.com/newpreview_music/09/03/72/5c8ad96fbf47328809.mp3' | ||
| 41 | + }, | ||
| 42 | + { | ||
| 43 | + id: 3, | ||
| 44 | + title: '示例音频 3', | ||
| 45 | + artist: '演唱者 3', | ||
| 46 | + cover: 'https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg', | ||
| 47 | + url: 'https://img.tukuppt.com/newpreview_music/09/03/95/5c8af46b01eb138909.mp3' | ||
| 48 | + }, | ||
| 49 | + { | ||
| 50 | + id: 4, | ||
| 51 | + title: '示例音频 4', | ||
| 52 | + artist: '演唱者 4', | ||
| 53 | + cover: 'https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg', | ||
| 54 | + url: 'https://img.tukuppt.com/newpreview_music/09/03/72/5c8ad96fbf47328809.mp3' | ||
| 55 | + }, | ||
| 56 | + { | ||
| 57 | + id: 5, | ||
| 58 | + title: '示例音频 5', | ||
| 59 | + artist: '演唱者 5', | ||
| 60 | + cover: 'https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg', | ||
| 61 | + url: 'https://img.tukuppt.com/newpreview_music/09/03/95/5c8af46b01eb138909.mp3' | ||
| 62 | + }, | ||
| 63 | + { | ||
| 64 | + id: 6, | ||
| 65 | + title: '示例音频 6', | ||
| 66 | + artist: '演唱者 6', | ||
| 67 | + cover: 'https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg', | ||
| 68 | + url: 'https://img.tukuppt.com/newpreview_music/09/03/72/5c8ad96fbf47328809.mp3' | ||
| 69 | + }, | ||
| 70 | + { | ||
| 71 | + id: 7, | ||
| 72 | + title: '示例音频 7', | ||
| 73 | + artist: '演唱者 7', | ||
| 74 | + cover: 'https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg', | ||
| 75 | + url: 'https://img.tukuppt.com/newpreview_music/09/03/95/5c8af46b01eb138909.mp3' | ||
| 76 | + }, | ||
| 77 | + { | ||
| 78 | + id: 8, | ||
| 79 | + title: '示例音频 8', | ||
| 80 | + artist: '演唱者 8', | ||
| 81 | + cover: 'https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg', | ||
| 82 | + url: 'https://img.tukuppt.com/newpreview_music/09/03/72/5c8ad96fbf47328809.mp3' | ||
| 83 | + }, | ||
| 84 | +]); | ||
| 85 | +</script> |
| 1 | <!-- | 1 | <!-- |
| 2 | - * @Date: 2025-03-20 19:53:12 | 2 | + * @Date: 2025-03-21 13:12:37 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-20 23:56:05 | 4 | + * @LastEditTime: 2025-04-07 12:57:28 |
| 5 | - * @FilePath: /mlaj/src/App.vue | 5 | + * @FilePath: /mlaj/src/views/test.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| 8 | -<script setup> | ||
| 9 | -const arr = []; | ||
| 10 | -arr.push({ a: '1' }); | ||
| 11 | -arr.push({ a: '2', b: 'random1' }); | ||
| 12 | -arr.push({ a: '3', b: 'random2', c: true }); | ||
| 13 | -arr.push({ a: '4', b: 'random3', d: 123 }); | ||
| 14 | -arr.push({ a: '5', b: 'random4', e: new Date() }); | ||
| 15 | - | ||
| 16 | -const arr2 = arr.map(item => { | ||
| 17 | - return { | ||
| 18 | - ...item, | ||
| 19 | - b: 'random5' | ||
| 20 | - } | ||
| 21 | -}) | ||
| 22 | - | ||
| 23 | -console.warn(arr2); | ||
| 24 | -</script> | ||
| 25 | - | ||
| 26 | -<template> | ||
| 27 | -</template> | ||
| 28 | - | ||
| 29 | -<style> | ||
| 30 | - | ||
| 31 | -</style> | ... | ... |
-
Please register or login to post a comment