Skip to content

Commit

Permalink
fix:修复接口
Browse files Browse the repository at this point in the history
  • Loading branch information
galaxy-s10 committed Mar 23, 2022
1 parent 5af43b2 commit 1c3b99e
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 139 deletions.
32 changes: 13 additions & 19 deletions src/components/songCover/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import React, { memo } from 'react'


import { SongsCoverWrapper } from './style';
import React, { memo } from "react";

import { SongsCoverWrapper } from "./style";

export default memo(function SongCover(props) {
const { info } = props;
const { info } = props;

return (
<SongsCoverWrapper>
<div className="cover-top">
<img src={info.picUrl} width="140" alt="" />
</div>
<div className="cover-bottom text-nowrap">
{info.name}
</div>
<div className="cover-source text-nowrap">
by {info.copywriter || info.creator.nickname}
</div>
</SongsCoverWrapper>
)
})
return (
<SongsCoverWrapper>
<div className="cover-top">
<img src={info.picUrl} width="140" alt="" />
</div>
<div className="cover-bottom text-nowrap">{info.name}</div>
<div className="cover-source text-nowrap">by {info.copywriter}</div>
</SongsCoverWrapper>
);
});
6 changes: 3 additions & 3 deletions src/page/discover/c-pages/recommend/c-page/ranking/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export default memo(function Ranking() {
<RankingWrapper>
<RecommendHeader title="榜单"></RecommendHeader>
<div className="tops">
{upRanking && <RankingCover info={upRanking}></RankingCover>}
{newRanking && <RankingCover info={newRanking}></RankingCover>}
{originRanking && <RankingCover info={originRanking}></RankingCover>}
<RankingCover info={upRanking}></RankingCover>
<RankingCover info={newRanking}></RankingCover>
<RankingCover info={originRanking}></RankingCover>
</div>
</RankingWrapper>
);
Expand Down
31 changes: 17 additions & 14 deletions src/page/discover/c-pages/recommend/store/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getHotRecommend,
getAlbum,
getRanking,
getToplist,
} from "@/servies/recommend";

export const changeBannerAction = (res) => ({
Expand Down Expand Up @@ -52,20 +53,22 @@ export const getAlbumAction = (limit) => {
};
export const getRankingAction = (idx) => {
return (dispatch) => {
// 0:飙升 2:新歌 3:原创
getRanking(idx).then((res) => {
switch (idx) {
case 0:
dispatch(changeUpRankingAction(res.playlists));
break;
case 2:
dispatch(changeNewRankingAction(res.playlists));
break;
case 3:
dispatch(changeOriginRankingAction(res.playlists));
break;
default:
}
getToplist().then((toplistRes) => {
// 0:飙升 2:新歌 3:原创
getRanking(toplistRes.list[idx].id).then((res) => {
switch (idx) {
case 0:
dispatch(changeUpRankingAction(res.playlist));
break;
case 2:
dispatch(changeNewRankingAction(res.playlist));
break;
case 3:
dispatch(changeOriginRankingAction(res.playlist));
break;
default:
}
});
});
};
};
184 changes: 90 additions & 94 deletions src/page/player/store/actionCreators.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,102 @@
import { getSongDetail, getLyric } from '@/servies/player';
import { getSongDetail, getLyric } from "@/servies/player";
import { parseLyric } from "../../../untils/lrc-parse";

const changeCurrentSongAction = currentSong => ({
type: "changeCurrentSong",
currentSong,
})
const changeCurrentSongIndexAction = currentSongIndex => ({
type: "changeCurrentSongIndex",
currentSongIndex,
})
const changePlayListAction = playList => ({
type: "changePlayList",
playList,
})
const changeCurrentSongAction = (currentSong) => ({
type: "changeCurrentSong",
currentSong,
});
const changeCurrentSongIndexAction = (currentSongIndex) => ({
type: "changeCurrentSongIndex",
currentSongIndex,
});
const changePlayListAction = (playList) => ({
type: "changePlayList",
playList,
});

export const changeSequenceAction = sequence => ({
type: "changeSequence",
sequence,
})
export const changeLyricListAction = lyricList => ({
type: "changeLyricList",
lyricList,
})
export const changeLyricListIndexAction = currentLyricIndex => ({
type: "changeCurrentLyricIndex",
currentLyricIndex,
})
export const changeSequenceAction = (sequence) => ({
type: "changeSequence",
sequence,
});
export const changeLyricListAction = (lyricList) => ({
type: "changeLyricList",
lyricList,
});
export const changeLyricListIndexAction = (currentLyricIndex) => ({
type: "changeCurrentLyricIndex",
currentLyricIndex,
});

export const changePlaySongAction = (tag) => {
return (dispatch, getState) => {
let playList = getState().getIn(["player", "playList"])
let sequence = getState().getIn(["player", "sequence"])
let currentSongIndex = getState().getIn(["player", "currentSongIndex"])
switch (sequence) {
case 1:
let random = Math.floor(Math.random() * playList.length)
while (random === currentSongIndex) {
random = Math.floor(Math.random() * playList.length)
}
currentSongIndex = random;
break;
default:
if (tag === -1) {
// 上一首
currentSongIndex = currentSongIndex == 0 ? playList.length - 1 : currentSongIndex - 1
} else {
// 下一首
currentSongIndex = currentSongIndex == playList.length - 1 ? 0 : currentSongIndex + 1
}
return (dispatch, getState) => {
let playList = getState().getIn(["player", "playList"]);
let sequence = getState().getIn(["player", "sequence"]);
let currentSongIndex = getState().getIn(["player", "currentSongIndex"]);
switch (sequence) {
case 1:
let random = Math.floor(Math.random() * playList.length);
while (random === currentSongIndex) {
random = Math.floor(Math.random() * playList.length);
}
const currentSong = playList[currentSongIndex];
dispatch(changeCurrentSongAction(playList[currentSongIndex]))
dispatch(changeCurrentSongIndexAction(currentSongIndex))

dispatch(getLyricAction(currentSong.id))

}
}

export const getSongDetailAction = ids => {
console.log('object')
return (dispatch, getState) => {
const playList = getState().getIn(["player", "playList"])
const currentIndex = playList.findIndex(song => song.id == ids)

if (currentIndex !== -1) {
console.log('找到歌曲')
// 在播放列表里找到歌曲
dispatch(changeCurrentSongIndexAction(currentIndex))
const currentSong = playList[currentIndex]
dispatch(changeCurrentSongAction(currentSong))
currentSongIndex = random;
break;
default:
if (tag === -1) {
// 上一首
currentSongIndex =
currentSongIndex == 0 ? playList.length - 1 : currentSongIndex - 1;
} else {
console.log('没有找到歌曲')
// 在播放列表里没有找到歌曲
getSongDetail(ids).then(res => {
const song = res.songs && res.songs[0]
if (!song) return
const newPlayList = [...playList]
newPlayList.push(song)
dispatch(changePlayListAction(newPlayList))
dispatch(changeCurrentSongIndexAction(newPlayList.length - 1))
dispatch(changeCurrentSongAction(song))
})
// 下一首
currentSongIndex =
currentSongIndex == playList.length - 1 ? 0 : currentSongIndex + 1;
}
}
const currentSong = playList[currentSongIndex];
dispatch(changeCurrentSongAction(playList[currentSongIndex]));
dispatch(changeCurrentSongIndexAction(currentSongIndex));

// 获取当前的歌词,并且解析
dispatch(getLyricAction(ids))
// getLyric(ids).then(res => {
// const lrcString = res.lrc.lyric;
// const lyrics = parseLyric(lrcString);
// dispatch(changeLyricsAction(lyrics));
// });
dispatch(getLyricAction(currentSong.id));
};
};

}
}
export const getSongDetailAction = (ids) => {
return (dispatch, getState) => {
const playList = getState().getIn(["player", "playList"]);
const currentIndex = playList.findIndex((song) => song.id == ids);

export const getLyricAction = ids => {
console.log(ids, 'index')
return (dispatch, getState) => {
getLyric(ids).then(res => {
const lrcList = parseLyric(res.lrc.lyric)
dispatch(changeLyricListAction(lrcList))
})
if (currentIndex !== -1) {
// 在播放列表里找到歌曲
dispatch(changeCurrentSongIndexAction(currentIndex));
const currentSong = playList[currentIndex];
dispatch(changeCurrentSongAction(currentSong));
} else {
// 在播放列表里没有找到歌曲
getSongDetail(ids).then((res) => {
const song = res.songs && res.songs[0];
if (!song) return;
const newPlayList = [...playList];
newPlayList.push(song);
dispatch(changePlayListAction(newPlayList));
dispatch(changeCurrentSongIndexAction(newPlayList.length - 1));
dispatch(changeCurrentSongAction(song));
});
}
}

// 获取当前的歌词,并且解析
dispatch(getLyricAction(ids));
// getLyric(ids).then(res => {
// const lrcString = res.lrc.lyric;
// const lyrics = parseLyric(lrcString);
// dispatch(changeLyricsAction(lyrics));
// });
};
};

export const getLyricAction = (ids) => {
return (dispatch, getState) => {
getLyric(ids).then((res) => {
const lrcList = parseLyric(res.lrc.lyric);
dispatch(changeLyricListAction(lrcList));
});
};
};
8 changes: 7 additions & 1 deletion src/servies/recommend.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ export function getAlbum(limit) {
},
});
}
export function getToplist() {
return request({
url: "/toplist",
});
}

export function getRanking(id) {
return request({
url: "/top/playlist",
url: "/playlist/detail",
params: {
id,
},
Expand Down
8 changes: 0 additions & 8 deletions src/servies/request.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import axios from "axios";
import { BASE_URL, TIMEOUT } from "./config";
// axios.get("https://www.hsslive.cn/article/typelist").then((res) => {
// //跨域
// console.log(res, 111);
// });
// axios.get("https://www.hsslive.cn/api/type/pagelist").then((res) => {
// //不跨域
// console.log(res, 22);
// });

const instance = axios.create({
baseURL: BASE_URL,
Expand Down

0 comments on commit 1c3b99e

Please sign in to comment.