diff --git a/src/app.tsx b/src/app.tsx index 065af38..9caf5af 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -30,8 +30,8 @@ class App extends Component { config: Config = { pages: [ 'pages/my/index', - 'pages/search/index', 'pages/searchResult/index', + 'pages/search/index', // 'pages/search/index', 'pages/index/index', 'pages/songDetail/index', diff --git a/src/base.scss b/src/base.scss index 875fc9d..010ce46 100644 --- a/src/base.scss +++ b/src/base.scss @@ -1 +1,8 @@ -$primary-color: #d43c33; \ No newline at end of file +$primary-color: #d43c33; +@mixin text-ellipsis { + overflow: hidden; + /*文本不会换行*/ + white-space: nowrap; + /*当文本溢出包含元素时,以省略号表示超出的文本*/ + text-overflow: ellipsis; +} \ No newline at end of file diff --git a/src/pages/searchResult/index.scss b/src/pages/searchResult/index.scss index 31f1d0c..e544b60 100644 --- a/src/pages/searchResult/index.scss +++ b/src/pages/searchResult/index.scss @@ -1,22 +1,41 @@ -.seaechResult_container { +@import '../../base.scss'; +.searchResult_container { &.hasMusicBox { padding-bottom: 120px; } - .seaechResult__music { - padding: 10px 30px; + .search_content { + padding: 108px 36px 24px 36px; + height: 100%; + box-sizing: border-box; + .search_content__title { + font-size: 38px; + font-weight: 700; + padding: 20px 0; + } + .search_content__more { + text-align: center; + font-size: 24px; + line-height: 50px; + padding: 15px 0; + color: #888888; + } + } + .searchResult__music { + padding: 10px 30px 10px 0; display: flex; align-items: center; width: 100%; box-sizing: border-box; - .seaechResult__music__info { + border-bottom: 1px solid #eeeeee; + .searchResult__music__info { flex: 1; overflow: hidden; - .seaechResult__music__info__name { + .searchResult__music__info__name { font-size: 34px; overflow: hidden; text-overflow: ellipsis; } - .seaechResult__music__info__desc { + .searchResult__music__info__desc { font-size: 24px; color: #888888; margin-top: 10px; @@ -24,10 +43,39 @@ text-overflow: ellipsis; } } - .seaechResult__music__icon { + .searchResult__music__icon { font-size: 30px; color: #dddddd; padding: 40px 0 40px 80px; } } + .search_content__playList__item { + display: flex; + align-items: center; + margin-bottom: 15px; + .search_content__playList__item__cover { + width: 150px; + height: 150px; + border-radius: 10px; + margin-right: 20px; + display: block; + } + .search_content__playList__item__info { + flex: 1; + .search_content__playList__item__info__title { + width: 95%; + @include text-ellipsis; + margin-bottom: 10px; + font-size: 30px; + } + .search_content__playList__item__info__desc { + font-size: 20px; + color: #bbbbbb; + display: flex; + } + .search_content__playList__item__info__desc__nickname { + margin: 0 10px; + } + } + } } diff --git a/src/pages/searchResult/index.tsx b/src/pages/searchResult/index.tsx index 9a2e51c..a1c769f 100644 --- a/src/pages/searchResult/index.tsx +++ b/src/pages/searchResult/index.tsx @@ -1,6 +1,7 @@ import { ComponentClass } from 'react' import Taro, { Component, Config } from '@tarojs/taro' -import { View } from '@tarojs/components' +import { View, Image, Text } from '@tarojs/components' +import { AtSearchBar, AtTabs, AtTabsPane, AtIcon } from 'taro-ui' import classnames from 'classnames' import CLoading from '../../components/CLoading' import { connect } from '@tarojs/redux' @@ -25,6 +26,7 @@ type IProps = PageStateProps & PageDispatchProps type PageState = { keywords: string, + activeTab: number, songList: Array<{ id: number, name: string, @@ -35,6 +37,85 @@ type PageState = { artists: Array<{ name: string }> + }>, + tabList: Array<{ + title: string + }>, + albumInfo: { // 专辑 + albums: Array<{ + name: string, + id: number + }>, + more: boolean, + moreText: string + }, + artistInfo: { // 歌手 + artists: Array<{ + name: string, + id: number, + picUrl: string + }>, + more: boolean, + moreText: string + }, + djRadioInfo: { // 电台 + djRadios: Array<{ + name: string, + id: number, + picUrl: string + }>, + more: boolean, + moreText: string + }, + playListInfo: { // 歌单 + playLists: Array<{ + name: string, + id: number, + coverImgUrl: string, + trackCount: number, + playCount: number, + creator: { + nickname: string + } + }>, + more: boolean, + moreText: string + }, + videoInfo: { // 视频 + videos: Array<{ + name: string, + id: number, + picUrl: string + }>, + more: boolean, + moreText: string + }, + userListInfo: { // 用户 + users: Array<{ + name: string, + id: number, + picUrl: string + }>, + more: boolean, + moreText: string + }, + songInfo: { // 单曲 + songs: Array<{ + id: number, + name: string, + al: { + id: number, + name: string + }, + ar: Array<{ + name: string + }> + }>, + more: boolean, + moreText: string + }, + sim_query: Array<{ + keyword: string, }> } @@ -72,7 +153,66 @@ class Page extends Component { const { keywords } = this.$router.params this.state = { keywords, - songList: [] + songList: [], + activeTab: 0, + tabList: [ + { + title: '综合' + }, + { + title: '单曲' + }, + { + title: '视频' + },{ + title: '歌手' + }, + { + title: '专辑' + }, + { + title: '主播电台' + }, + { + title: '用户' + } + ], + userListInfo: { + users: [], + more: false, + moreText: '' + }, + videoInfo: { + videos: [], + more: false, + moreText: '' + }, + playListInfo: { + playLists: [], + more: false, + moreText: '' + }, + songInfo: { + songs: [], + more: false, + moreText: '' + }, + albumInfo: { + albums: [], + more: false, + moreText: '' + }, + djRadioInfo: { + djRadios: [], + more: false, + moreText: '' + }, + artistInfo: { + artists: [], + more: false, + moreText: '' + }, + sim_query: [] } } @@ -98,20 +238,55 @@ class Page extends Component { getResult(keywords) { api.get('/search', { keywords, - type: 1 + type: 1018 }).then((res) => { console.log('res', res) - if (res.data && res.data.result) { - this.setState({ - songList: res.data.result.songs - }) - res.data.result.songs = res.data.result.songs.map((item) => { - item.ar = item.artists - return item - }) - this.props.updateCanplayList({ - canPlayList: res.data.result.songs - }) + const result = res.data.result + if (result) { + if (result.album) { + this.setState({ + albumInfo: result.album + }) + } + if (result.artist) { + this.setState({ + artistInfo: result.artist + }) + } + if (result.djRadio) { + this.setState({ + djRadioInfo: result.djRadio + }) + } + if (result.playList) { + this.setState({ + playListInfo: result.playList + }) + } + if (result.song) { + this.setState({ + songInfo: result.song + }) + } + if (result.user) { + this.setState({ + userListInfo: result.user + }) + } + if (result.video) { + this.setState({ + videoInfo: result.video + }) + } + if (result.sim_query && result.sim_query.sim_querys) { + this.setState({ + sim_query: result.sim_query.sim_querys + }) + } + + // this.props.updateCanplayList({ + // canPlayList: res.data.result.songs + // }) } }) } @@ -133,6 +308,12 @@ class Page extends Component { }) } + goPlayListDetail(item) { + Taro.navigateTo({ + url: `/pages/playListDetail/index?id=${item.id}&name=${item.name}` + }) + } + showMore() { Taro.showToast({ title: '暂未实现,敬请期待', @@ -140,37 +321,152 @@ class Page extends Component { }) } + searchTextChange(val) { + this.setState({ + keywords: val + }) + } + + searchResult() { + + } + + switchTab(activeTab) { + if (activeTab !== 0) { + Taro.showToast({ + title: '正在开发,敬请期待', + icon: 'none' + }) + return + } + this.setState({ + activeTab + }) + } + render () { - const { songList } = this.state + const { songList, keywords, activeTab, tabList, songInfo, playListInfo } = this.state return ( - + + + + + { + songInfo.songs.length === 0 ? : + + + + 单曲 + + { + songInfo.songs.map((item, index) => ( + + + + {item.name} + + + {`${item.ar[0] ? item.ar[0].name : ''} - ${item.al.name}`} + + + + + )) + } + + {songInfo.moreText} + + + + + 歌单 + + + { + playListInfo.playLists.map((item, index) => ( + + + + + + + {item.name} + + + + {item.trackCount}首音乐 + + + by {item.creator.nickname} + + + {item.playCount}次 + + + + + )) + } + + {playListInfo.moreText} + + + + + } + + + 标签页二的内容 + + + 标签页三的内容 + + + 标签页四的内容 + + + 标签页五的内容 + + + 标签页六的内容 + + { songList.map((item, index) => ( - - - - {item.name} + + + + {item.name} - + {`${item.artists[0] ? item.artists[0].name : ''} - ${item.album.name}`} - + )) } - { - songList.length === 0 ? : '' - } ) }