diff --git a/.umirc.ts b/.umirc.ts index f1e3452..e3a62b4 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -2,14 +2,19 @@ import { defineConfig } from 'umi'; export default defineConfig({ title: '李志 BB 音乐作品播放器', - nodeModulesTransform: { - type: 'none', - }, - favicon: '/favico.png', + favicons: ['/favico.png'], hash: true, history: { type: 'hash', }, + routes: [ + { path: '/', component: 'index' }, + { path: '/about', component: 'about' }, + { path: '/download', component: 'download' }, + { path: '/star', component: 'star' }, + { path: '/video', component: 'video' }, + { path: '/album/:id', component: 'album/index' }, + ], metas: [ { name: 'keywords', @@ -20,6 +25,7 @@ export default defineConfig({ content: '全网最好用的李志(逼哥)音乐作品专属播放器', }, ], + analytics: { baidu: '023e4ef604935de6708edb9e61f17191', }, @@ -46,5 +52,7 @@ export default defineConfig({ })); `, ], - fastRefresh: {}, + + fastRefresh: true, + tailwindcss: {}, }); diff --git a/package.json b/package.json index 3ca1562..fb9331f 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,10 @@ }, "license": "MIT", "scripts": { - "start": "umi dev", - "build": "umi build", + "start": "max dev", + "build": "max build", "tw": "npx tailwindcss -i ./src/input.css -o ./public/tailwind.css --watch", - "postinstall": "umi generate tmp", + "postinstall": "max setup", "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'", "test": "umi-test", "test:coverage": "umi-test --coverage" @@ -43,19 +43,19 @@ "@ant-design/pro-layout": "^6.5.0", "hls.js": "^1.2.9", "react": "17.x", - "react-cmdk": "^1.3.6", + "react-cmdk": "^1.3.9", "react-dom": "17.x", "react-jinke-music-player": "^4.24.2", - "umi": "^3.5.21" + "react-svg": "^16.1.34" }, "devDependencies": { "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", - "@umijs/preset-react": "1.x", + "@umijs/max": "^4.0.0", "@umijs/test": "^3.5.21", "lint-staged": "^10.0.7", "prettier": "^2.2.0", - "tailwindcss": "^3.1.8", + "tailwindcss": "^3", "typescript": "^4.1.2", "yorkie": "^2.0.0" } diff --git a/src/assets/albumInfo.json b/src/assets/albumInfo.json new file mode 100644 index 0000000..7fd7d1f --- /dev/null +++ b/src/assets/albumInfo.json @@ -0,0 +1,146 @@ +[ + { + "name": "梵高先生", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/梵高先生/cover.png", + "year": 2005, + "publisher": "口袋唱片" + }, + { + "name": "被禁忌的游戏", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/被禁忌的游戏/cover.png", + "year": 2006, + "publisher": "口袋唱片" + }, + { + "name": "这个世界会好吗", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/这个世界会好吗/cover.png", + "year": 2006, + "publisher": "独立发行" + }, + { + "name": "工体东路没有人", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/工体东路没有人/cover.png", + "year": 2009, + "publisher": "独立发行" + }, + { + "name": "你好,郑州", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/你好,郑州/cover.png", + "year": 2010, + "publisher": "独立发行" + }, + { + "name": "我爱南京", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/我爱南京/cover.png", + "year": 2010, + "publisher": "独立发行" + }, + { + "name": "F", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/F/cover.png", + "year": 2011, + "publisher": "独立发行" + }, + { + "name": "Imagine-2011", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/Imagine-2011/cover.png", + "year": 2011, + "publisher": "独立发行" + }, + { + "name": "108个关键词", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/108个关键词/cover.png", + "year": 2012, + "publisher": "独立发行" + }, + { + "name": "勾三搭四", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/勾三搭四/cover.png", + "year": 2013, + "publisher": "独立发行" + }, + { + "name": "1701", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/1701/cover.png", + "year": 2014, + "publisher": "独立发行" + }, + { + "name": "看见", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/看见/cover.png", + "year": 2015, + "publisher": "独立发行" + }, + { + "name": "io", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/io/cover.png", + "year": 2015, + "publisher": "独立发行" + }, + { + "name": "北京不插电", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/北京不插电/cover.png", + "year": 2016, + "publisher": "独立发行" + }, + { + "name": "8", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/8/cover.png", + "year": 2016, + "publisher": "独立发行" + }, + { + "name": "在每一条伤心的应天大街上", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/在每一条伤心的应天大街上/cover.png", + "year": 2016, + "publisher": "独立发行" + }, + { + "name": "动静", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/动静/cover.png", + "year": 2016, + "publisher": "独立发行" + }, + { + "name": "家", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/家/cover.png", + "year": 2016, + "publisher": "独立发行" + }, + { + "name": "电声与管弦乐", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/电声与管弦乐/cover.png", + "year": 2017, + "publisher": "独立发行" + }, + { + "name": "电声与管弦乐II", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/电声与管弦乐II/cover.png", + "year": 2017, + "publisher": "独立发行" + }, + { + "name": "广场合集", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/广场合集/cover.png", + "year": null, + "publisher": "" + }, + { + "name": "我们也爱南京", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/我们也爱南京/cover.png", + "year": null, + "publisher": "" + }, + { + "name": "二零零九年十月十六日事件", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/二零零九年十月十六日事件/cover.png", + "year": null, + "publisher": "" + }, + { + "name": "零碎", + "cover": "https://testingcf.jsdelivr.net/gh/nj-lizhi/song@master/audio/零碎/cover.png", + "year": null, + "publisher": "" + } +] diff --git a/src/assets/back.svg b/src/assets/back.svg new file mode 100644 index 0000000..e1f895c --- /dev/null +++ b/src/assets/back.svg @@ -0,0 +1,14 @@ + + + diff --git a/src/assets/download.svg b/src/assets/download.svg new file mode 100644 index 0000000..3bde7cf --- /dev/null +++ b/src/assets/download.svg @@ -0,0 +1,13 @@ + + + diff --git a/src/assets/linux.svg b/src/assets/linux.svg new file mode 100644 index 0000000..5b33fd9 --- /dev/null +++ b/src/assets/linux.svg @@ -0,0 +1,16 @@ + + + diff --git a/src/assets/loading.svg b/src/assets/loading.svg new file mode 100644 index 0000000..a66aa3d --- /dev/null +++ b/src/assets/loading.svg @@ -0,0 +1,21 @@ + + + + + diff --git a/src/assets/mac.svg b/src/assets/mac.svg new file mode 100644 index 0000000..ba95926 --- /dev/null +++ b/src/assets/mac.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + diff --git a/src/assets/play-large.svg b/src/assets/play-large.svg new file mode 100644 index 0000000..c644583 --- /dev/null +++ b/src/assets/play-large.svg @@ -0,0 +1,13 @@ + + + diff --git a/src/assets/play.svg b/src/assets/play.svg new file mode 100644 index 0000000..eb37962 --- /dev/null +++ b/src/assets/play.svg @@ -0,0 +1,11 @@ + + + diff --git a/src/assets/windows.svg b/src/assets/windows.svg new file mode 100644 index 0000000..de5701c --- /dev/null +++ b/src/assets/windows.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/src/components/back.tsx b/src/components/back.tsx new file mode 100644 index 0000000..8bd082f --- /dev/null +++ b/src/components/back.tsx @@ -0,0 +1,25 @@ +import { ReactSVG } from 'react-svg'; +import { Link } from 'umi'; + +import BackIcon from '@/assets/back.svg'; + +interface BackButtonProps { + to: string; +} + +function Back(props: BackButtonProps) { + return ( + + + 返回 + + ); +} + +export default Back; diff --git a/src/components/downloadButton.tsx b/src/components/downloadButton.tsx new file mode 100644 index 0000000..2033fe7 --- /dev/null +++ b/src/components/downloadButton.tsx @@ -0,0 +1,30 @@ +import LinuxIcon from '@/assets/linux.svg'; +import MacOSIcon from '@/assets/mac.svg'; +import WindowsIcon from '@/assets/windows.svg'; +import type { ReactElement } from 'react'; +import { ReactSVG } from 'react-svg'; + +const platformMap: Map = new Map([ + ['MacOS', ], + ['Windows', ], + ['Linux', ], +]); + +interface DownloadButtonProps { + platform: 'MacOS' | 'Windows' | 'Linux'; + url: string; +} + +function DownloadButton(props: DownloadButtonProps) { + return ( + + {platformMap.get(props.platform)} +
{props.platform}
+
+ ); +} + +export default DownloadButton; diff --git a/src/components/githubLink.tsx b/src/components/githubLink.tsx new file mode 100644 index 0000000..e04b3f6 --- /dev/null +++ b/src/components/githubLink.tsx @@ -0,0 +1,34 @@ +function GithubLink() { + return ( + + + + ); +} + +export default GithubLink; diff --git a/src/components/sidebarItem.tsx b/src/components/sidebarItem.tsx new file mode 100644 index 0000000..06cb841 --- /dev/null +++ b/src/components/sidebarItem.tsx @@ -0,0 +1,27 @@ +import { Link, useLocation } from 'umi'; + +interface SidebarItemProps { + emoji: string; + text: string; + to: string; +} + +function SidebarItem(props: SidebarItemProps) { + const location = useLocation(); + + return ( + + {props.emoji} + {props.text} + + ); +} + +export default SidebarItem; diff --git a/src/contexts/playerContext.ts b/src/contexts/playerContext.ts new file mode 100644 index 0000000..c2ba8c8 --- /dev/null +++ b/src/contexts/playerContext.ts @@ -0,0 +1,12 @@ +import type { SongList } from '@/types'; +import React from 'react'; +import type { ReactJkMusicPlayerInstance } from 'react-jinke-music-player'; + +interface PlayerContextType { + player: ReactJkMusicPlayerInstance | null; + songList: SongList; +} + +const PlayerContext = React.createContext(undefined!); + +export default PlayerContext; diff --git a/src/layouts/index.css b/src/layouts/index.css index ef62746..164f935 100644 --- a/src/layouts/index.css +++ b/src/layouts/index.css @@ -29,4 +29,4 @@ body ::-webkit-scrollbar, .audio-lists-panel-content .audio-item:active, .audio-lists-panel-content .audio-item:hover { background-color: rgba(255, 255, 255, 0.2); -} \ No newline at end of file +} diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 4caa201..c99c29c 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -1,16 +1,28 @@ -import { useEffect, useState } from 'react'; -import ReactJkMusicPlayer from 'react-jinke-music-player'; +import GithubLink from '@/components/githubLink'; +import SidebarItem from '@/components/sidebarItem'; +import PlayerContext from '@/contexts/playerContext'; +import type { SongList } from '@/types'; +import { useEffect, useRef, useState } from 'react'; +import 'react-cmdk/dist/cmdk.css'; import CommandPalette, { filterItems, getItemIndex, useHandleOpenCommandPalette, -} from 'react-cmdk'; -import { Link } from 'umi'; +} from 'react-cmdk/src/index'; +import ReactJkMusicPlayer, { + type ReactJkMusicPlayerAudioListProps, + type ReactJkMusicPlayerInstance, + type ReactJkMusicPlayerProps, +} from 'react-jinke-music-player'; import 'react-jinke-music-player/assets/index.css'; +import { useLocation, useOutlet } from 'umi'; import './index.css'; -import 'react-cmdk/dist/cmdk.css'; -const audioLists = window.list?.map((v) => { +import ZhuangB from '@/assets/lizhi.png'; + +const songList = (window as unknown as { list: SongList }).list || []; + +const audioLists: ReactJkMusicPlayerAudioListProps[] = songList.map((v) => { return { name: `${v.name} · ${v.artist}`.replace('专辑-', ''), musicSrc: v.url, @@ -19,7 +31,7 @@ const audioLists = window.list?.map((v) => { }; }); -const options = { +const options: ReactJkMusicPlayerProps = { audioLists, theme: 'dark', locale: 'zh_CN', @@ -33,19 +45,24 @@ const options = { showDownload: !window.location.href.includes('from=pake'), }; -export default function Layout({ children, location }) { +export default function Layout() { const [active, setActive] = useState('all'); const [page, setPage] = useState<'root' | 'albums'>('root'); const [open, setOpen] = useState(false); const [search, setSearch] = useState(''); + const playerInstance = useRef(null); + const location = useLocation(); + const outlet = useOutlet(); useHandleOpenCommandPalette(setOpen); useEffect(() => { + // @ts-ignore document .querySelector('.music-player-panel') .classList.add('backdrop-blur-md'); + // @ts-ignore document .querySelector('.audio-lists-panel') .classList.add('backdrop-blur-md'); @@ -111,7 +128,7 @@ export default function Layout({ children, location }) {
setOpen(true)} - className="bg-gray-900 relative pointer-events-auto cursor-pointer" + className="bg-gray-900 mb-4 relative pointer-events-auto cursor-pointer" >
- - 💿专辑 - - - 🔥Live - - - 🧑自传 - - setActive('download')} - > - 📦APP - - setActive('star')} - > - 🌟赞助 - + + + + +
{/*

友情赞助

- setActive('star')} - > - 🧡好物 - +
*/}
- +
+
- {children} + + {outlet} +
- - { + playerInstance.current = instance; }} - href="https://github.com/turkyden/lizhi-app" - title="Follow me on GitHub" - aria-label="Follow me on GitHub" - rel="noopener" - target="_blank" - > - - + /> + + - - + <> + + +
+ +
+ ); } diff --git a/src/pages/album/[id].tsx b/src/pages/album/[id].tsx deleted file mode 100644 index 41254c9..0000000 --- a/src/pages/album/[id].tsx +++ /dev/null @@ -1,267 +0,0 @@ -import { Link } from 'umi'; -import { message } from 'antd'; -import { useState } from 'react'; - -const ALBUM = [ - { - title: '被禁忌的游戏', - }, - { - title: '这个世界会好吗', - }, - { - title: '梵高先生', - }, - { - title: '我爱南京', - }, - { - title: '你好,郑州', - }, - { - title: '1701', - }, - { - title: 'F', - }, - { - title: '这个世界会好吗', - }, - { - title: '8', - }, - { - title: '在每一条伤心的应天大街上', - }, -]; - -interface ISong { - artist: string; - cover: string; - name: string; - url: string; -} - -interface ISongList extends Array {} - -export default function (props) { - const [currDownloadingName, setcurrDownloadingName] = useState(''); - const artist = props.match.params.id; - - const albumList = window.list.filter((v) => v.artist === artist); - - const onClick = (name: string) => { - const array = document.querySelectorAll('.audio-item'); - for (let index = 0; index < array.length; index++) { - const element = array[index]; - const target = element.querySelector('.player-name'); - if (target?.title.includes(name)) { - target.click(); - } - } - }; - - const handleDownload = async ({ name, url }: ISong) => { - setcurrDownloadingName(name); - try { - let res = await fetch(url); - let blob = await res.blob(); - const a = document.createElement('a'); - document.body.appendChild(a); - a.style.display = 'none'; - // 使用获取到的blob对象创建的url - const targetUrl = window.URL.createObjectURL(blob); - a.href = targetUrl; - // 指定下载的文件名 - a.download = name; - a.click(); - document.body.removeChild(a); - // 移除blob对象的url - window.URL.revokeObjectURL(url); - } catch (e) { - alert(`下载音乐: "${name}" 失败`); - } - setcurrDownloadingName(''); - }; - return ( - <> - - - - - Back - -
- cover -
-

{artist.replace('专辑-', '')}

-
李志
-
- 2007-11-12 - 麦田音乐 - 发行 -
- -
-
onClick(albumList[0].name)} - className="transition hover:text-white text-center py-2 px-6 rounded-full bg-green-500 text-white cursor-pointer hover:opacity-90 shadow-lg shadow-green-500/50 flex items-center" - > - - - - 播放全部 -
-
message.info('开发中!')} - className="hidden hover:text-white text-center tracking-widest py-2 px-6 rounded-full border border-solid border-gray-500 hover:bg-gray-800 cursor-pointer flex items-center" - > - - - - 收藏 -
-
-
-
- -
-
- 歌曲 {albumList.length} -
-
message.info('开发中!')} - > - 专辑信息 -
-
message.info('开发中!')} - > - 评论 -
-
- -
- {albumList.map((a, i) => ( -
-
onClick(a.name)} - > - {i + 1 > 9 ? i + 1 : '0' + (i + 1)} - {a.name} -
-
李志
-
- onClick(a.name)} - > - - - - - handleDownload(a)} - > - {currDownloadingName && currDownloadingName === a.name ? ( - - - - - - ) : ( - - - - )} - -
-
- ))} -
- -
-
- - ); -} diff --git a/src/pages/album/index.tsx b/src/pages/album/index.tsx new file mode 100644 index 0000000..2cf93d2 --- /dev/null +++ b/src/pages/album/index.tsx @@ -0,0 +1,194 @@ +import albumInfoList from '@/assets/albumInfo.json'; +import Back from '@/components/back'; +import PlayerContext from '@/contexts/playerContext'; +import type { AlbumInfo, SongInfo, SongList } from '@/types'; +import { useContext, useMemo, useState } from 'react'; +import { ReactSVG } from 'react-svg'; +import { useParams } from 'umi'; + +import DownloadIcon from '@/assets/download.svg'; +import LoadingIcon from '@/assets/loading.svg'; +import LargePlayIcon from '@/assets/play-large.svg'; +import PlayIcon from '@/assets/play.svg'; + +function getAlbumInfo(name: string): AlbumInfo | null { + for (let i = 0; i < albumInfoList.length; i++) { + if (albumInfoList[i].name === name) { + return albumInfoList[i]; + } + } + return null; +} + +interface ISong { + artist: string; + cover: string; + name: string; + url: string; +} + +export default function () { + const [currDownloadingName, setcurrDownloadingName] = useState(''); + const { player, songList } = useContext(PlayerContext); + const params = useParams(); + const artist = params.id as string; + const albumInfo = useMemo( + () => getAlbumInfo(artist.replace('专辑-', '')), + [artist], + ); + + const albumList = (window as unknown as { list: SongList }).list?.filter( + (v) => v.artist === artist, + ); + + if (!albumList) return <>; + + const onClick = (info: SongInfo) => { + if (!player || !player.playByIndex) return; + + for (let i = 0; i < songList.length; i++) { + if (songList[i].url === info.url) { + player.playByIndex(i); + return; + } + } + }; + + const handleDownload = async ({ name, url }: ISong) => { + setcurrDownloadingName(name); + try { + let res = await fetch(url); + let blob = await res.blob(); + const a = document.createElement('a'); + document.body.appendChild(a); + a.style.display = 'none'; + // 使用获取到的blob对象创建的url + const targetUrl = window.URL.createObjectURL(blob); + a.href = targetUrl; + // 指定下载的文件名 + a.download = name; + a.click(); + document.body.removeChild(a); + // 移除blob对象的url + window.URL.revokeObjectURL(url); + } catch (e) { + alert(`下载音乐: "${name}" 失败`); + } + setcurrDownloadingName(''); + }; + return ( + <> + + +
+ cover +
+

+ {artist.replace('专辑-', '')} +

+
李志
+
+ {albumInfo?.year || '未知年份'} + {albumInfo?.publisher} +
+ +
+
onClick(albumList[0])} + className="transition hover:text-white text-center py-2 px-6 rounded-full bg-green-500 text-white cursor-pointer hover:opacity-90 shadow-lg shadow-green-500/50 flex items-center" + > + + 播放全部 +
+ {/*
message.info('开发中!')} + className="hidden hover:text-white text-center tracking-widest py-2 px-6 rounded-full border border-solid border-gray-500 hover:bg-gray-800 cursor-pointer items-center" + > + + + + 收藏 +
*/} +
+
+
+ +
+
+ 歌曲 {albumList.length} +
+ {/*
message.info('开发中!')} + > + 专辑信息 +
+
message.info('开发中!')} + > + 评论 +
*/} +
+ +
+ {albumList.map((a, i) => ( +
+
onClick(a)} + > + + {i + 1 > 9 ? i + 1 : '0' + (i + 1)} + + {a.name} +
+
李志
+
+ onClick(a)} + > + + + handleDownload(a)} + > + {currDownloadingName && currDownloadingName === a.name ? ( + + ) : ( + + )} + +
+
+ ))} +
+ +
+
+ + ); +} diff --git a/src/pages/download.tsx b/src/pages/download.tsx index 86738f9..80d7c2e 100644 --- a/src/pages/download.tsx +++ b/src/pages/download.tsx @@ -1,92 +1,21 @@ -import React from 'react'; +import DownloadButton from '@/components/downloadButton'; function Download() { return (
diff --git a/src/pages/index.tsx b/src/pages/index.tsx index af4a4ae..5fe44d0 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,4 +1,3 @@ -import { useEffect, useState } from 'react'; import { Link } from 'umi'; const LIVE = [ @@ -28,15 +27,6 @@ interface IAlbum { interface IAlbumList extends Array {} -interface ISong { - artist: string; - cover: string; - name: string; - url: string; -} - -interface ISongList extends Array {} - export default function IndexPage() { return ( <> @@ -57,7 +47,7 @@ export default function IndexPage() {
我们不能失去信仰 · 李志
- {(window.album as IAlbumList).map((v, i) => ( + {((window as any).album as IAlbumList).map((v, i) => ( diff --git a/src/pages/video.tsx b/src/pages/video.tsx index 9b1b774..dca389d 100644 --- a/src/pages/video.tsx +++ b/src/pages/video.tsx @@ -1,6 +1,7 @@ -import { useEffect, useRef, useState } from 'react'; -import { Link } from 'umi'; +import Back from '@/components/back'; +import PlayerContext from '@/contexts/playerContext'; import Hls from 'hls.js'; +import { useContext, useEffect, useRef, useState } from 'react'; const videoList = [ { @@ -22,16 +23,19 @@ const videoList = [ ]; function Video() { - const ref = useRef(); - - const hls = useRef(null); + const videoRef = useRef(null); + const hls = useRef(null); + const { player } = useContext(PlayerContext); const [index, setIndex] = useState(2); useEffect(() => { - document.querySelector('.music-player-audio')?.pause(); - const video = ref.current; + if (!videoRef.current) return; + + player?.pause(); + const video = videoRef.current; const videoSrc = videoList[index].url; + if (Hls.isSupported()) { hls.current = new Hls(); hls.current.loadSource(videoSrc); @@ -41,44 +45,23 @@ function Video() { } }, []); - const handleSelect = (index) => { + const handleSelect = (index: number) => { + if (!hls.current || !videoRef.current) return; + setIndex(index); hls.current.loadSource(videoList[index].url); - hls.current.attachMedia(ref.current); + hls.current.attachMedia(videoRef.current); }; return ( <> - - - - - Back - + +
{/*
Live 现场
*/}
- +
{videoList.map((v, k) => ( diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..e201843 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,16 @@ +export interface SongInfo { + name: string; + artist: string; + url: string; + cover: string; +} + +/** @see https://github.com/nj-lizhi/song/blob/main/audio/list-v2.js */ +export type SongList = SongInfo[]; + +export interface AlbumInfo { + name: string; + cover: string; + year: number | null; + publisher: string; +} diff --git a/tailwind.config.js b/tailwind.config.js index f43c0b9..9cfd53f 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,8 +1,7 @@ -/** @type {import('tailwindcss').Config} */ module.exports = { - content: ['./src/**/*.{html,ejs,js,tsx,ts}'], - theme: { - extend: {}, - }, - plugins: [], + content: [ + './src/pages/**/*.tsx', + './src/components/**/*.tsx', + './src/layouts/**/*.tsx', + ], }; diff --git a/src/input.css b/tailwind.css similarity index 64% rename from src/input.css rename to tailwind.css index bd6213e..b5c61c9 100644 --- a/src/input.css +++ b/tailwind.css @@ -1,3 +1,3 @@ @tailwind base; @tailwind components; -@tailwind utilities; \ No newline at end of file +@tailwind utilities;