-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
376 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react' | ||
import { Icon } from '@blueprintjs/core' | ||
|
||
import Table, { IColumn } from 'components/Table' | ||
import { IMusic, IArtist, IAlbum } from 'apis/types/business' | ||
import { formatTime } from 'helpers/time' | ||
import styles from './style.module.css' | ||
|
||
interface IProps { | ||
data: IMusic[] | ||
} | ||
|
||
const columns: IColumn<IMusic, keyof IMusic>[] = [ | ||
{ | ||
title: '', | ||
key: 'name', | ||
width: '100px', | ||
render: (name: string, record: IMusic, index?: number) => { | ||
return ( | ||
<div className={styles.operations}> | ||
<span className={styles.index}>{(index || 0) + 1}</span> | ||
<Icon icon='heart' iconSize={14} /> | ||
<Icon icon='import' iconSize={14} /> | ||
</div> | ||
) | ||
} | ||
}, | ||
{ | ||
title: '音乐标题', | ||
key: 'name', | ||
width: '45%', | ||
render: (name: string, { alias }: IMusic) => { | ||
return ( | ||
<> | ||
<div>{name}</div> | ||
{alias?.length ? <div className={styles.alias}>{alias.join(' ')}</div> : null} | ||
</> | ||
) | ||
} | ||
}, | ||
{ | ||
title: '歌手', | ||
key: 'artists', | ||
width: '15%', | ||
render: (artists: IArtist[]) => artists?.map(({ name }) => name).join(' / ') | ||
}, | ||
{ | ||
title: '专辑', | ||
key: 'album', | ||
width: '15%', | ||
render: (album: IAlbum) => album?.name | ||
}, | ||
{ | ||
title: '时长', | ||
key: 'duration', | ||
width: '10%', | ||
render: (duration: number) => formatTime(duration / 1000) | ||
} | ||
] | ||
|
||
const MusicList: React.FC<IProps> = ({ data }) => { | ||
return ( | ||
<div> | ||
<Table<IMusic> | ||
columns={columns} | ||
data={data} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default MusicList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@value colors: "~styles/colors.module.css"; | ||
@value tipsColor, tipsHoverColor from colors; | ||
|
||
.alias { | ||
margin-top: 10px; | ||
color: tipsColor; | ||
} | ||
|
||
.operations { | ||
display: flex; | ||
justify-content: space-between; | ||
padding-right: 10px; | ||
color: tipsColor; | ||
|
||
.index { | ||
width: 40px; | ||
margin-right: 6px; | ||
text-align: right; | ||
} | ||
|
||
span:nth-child(2), span:nth-child(3) { | ||
cursor: pointer; | ||
|
||
&:hover { | ||
color: tipsHoverColor; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { ReactElement } from 'react' | ||
|
||
import styles from './style.module.css' | ||
|
||
export interface IColumn<RecordType, Key extends keyof RecordType> { | ||
title?: string, | ||
key: Key, | ||
width?: string, | ||
render: (value: any, record: RecordType, index?: number) => string | ReactElement | ||
} | ||
|
||
interface IProps<RecordType> { | ||
columns: IColumn<RecordType, keyof RecordType>[], | ||
data: RecordType[] | ||
} | ||
|
||
function Table<RecordType extends object = any>({ columns, data }: IProps<RecordType>) { | ||
return ( | ||
<div className={styles.root}> | ||
<div className={styles.header}> | ||
{columns.map(({ title, key, width }, index) => { | ||
return <div key={index} style={{ width }}>{title}</div> | ||
})} | ||
</div> | ||
<div className={styles.content}> | ||
{data?.map((item, index) => { | ||
return <div className={styles.row} key={index}> | ||
{columns.map(({ key, width, render }, idx) => { | ||
return <div key={idx} style={{ width }}>{render(item[key], item, index)}</div> | ||
})} | ||
</div> | ||
})} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@value colors: "~styles/colors.module.css"; | ||
@value tipsHoverColor, bgColor from colors; | ||
|
||
.root { | ||
font-size: 0.9em; | ||
} | ||
|
||
.header { | ||
display: flex; | ||
padding: 10px 0; | ||
color: tipsHoverColor; | ||
} | ||
|
||
.content { | ||
.row { | ||
display: flex; | ||
padding: 10px 0; | ||
} | ||
|
||
.row:nth-child(2n) { | ||
background-color: #fafafa; | ||
} | ||
|
||
.row:hover { | ||
background-color: bgColor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useLocation } from 'react-router-dom' | ||
|
||
const useQuery = () => { | ||
const { search } = useLocation() | ||
const result: IDictionary<string> = {} | ||
|
||
search | ||
.substr(1) | ||
.split('&') | ||
.reduce((prev, curr) => { | ||
const [key, value] = curr.split('=') | ||
prev[key] = decodeURIComponent(value) | ||
return prev | ||
}, result) | ||
|
||
return result | ||
} | ||
|
||
export default useQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
|
||
import MusicListBase from 'components/MusicList' | ||
import { IMusic } from 'apis/types/business' | ||
|
||
interface IProps { | ||
data: IMusic[], | ||
total: number | ||
} | ||
|
||
const MusicList: React.FC<IProps> = ({ data, total }) => { | ||
return ( | ||
<div> | ||
<MusicListBase data={data} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default MusicList |
Oops, something went wrong.