转换字节数
This commit is contained in:
parent
ff75509353
commit
cbbf007da1
@ -17,7 +17,6 @@ export default class MusicList {
|
||||
//this.audio.addEventListener('timeupdate', () => {
|
||||
// console.log(this.audio.currentTime)
|
||||
//})
|
||||
|
||||
// 本地添加音乐按钮
|
||||
const input = document.createElement('input')
|
||||
input.type = 'file'
|
||||
@ -73,10 +72,18 @@ export default class MusicList {
|
||||
this.EventListeners[name] = callback
|
||||
}
|
||||
add(item) {
|
||||
// 将字节转换为可读的单位
|
||||
const bytesToSize = bytes => {
|
||||
if (bytes === 0) return '0 B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i]
|
||||
}
|
||||
this.list.push(item)
|
||||
this.ul.appendChild(ListItem({
|
||||
id: item.id,
|
||||
innerText: `${item.name} - ${item.size} - ${item.type} - ${item.id}`,
|
||||
innerText: `${item.name} - ${bytesToSize(item.size)}`,
|
||||
children: [
|
||||
Button({
|
||||
innerText: '播放',
|
||||
|
@ -11,11 +11,12 @@ export function List({ children = [] }) {
|
||||
return ul
|
||||
}
|
||||
|
||||
export function ListItem({ innerText, onclick, id, children = [] }) {
|
||||
export function ListItem({ innerText, onclick, id, children = [], dataset }) {
|
||||
const li = document.createElement('li')
|
||||
li.innerText = innerText
|
||||
li.onclick = onclick
|
||||
li.id = id
|
||||
dataset && Object.keys(dataset).forEach(key => li.dataset[key] = dataset[key])
|
||||
children.forEach(child => li.appendChild(child))
|
||||
return li
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user