list item template

This commit is contained in:
DIYgod 2018-03-16 14:17:50 +08:00
parent 72d569e08b
commit ddcf4612c2
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
5 changed files with 23 additions and 23 deletions

View File

@ -27,8 +27,8 @@ export default (options) => {
}
options.audio.map((item) => {
item.name = item.name || item.title;
item.artist = item.artist || item.author;
item.name = item.name || item.title || 'Audio name';
item.artist = item.artist || item.author || 'Audio artist';
item.cover = item.cover || item.pic;
item.type = item.type || 'normal';
return item;

View File

@ -10,6 +10,7 @@ import Lrc from './lrc';
import Controller from './controller';
import Timer from './timer';
import Events from './events';
import tplListItem from '../template/list-item.art';
const instances = [];
@ -449,23 +450,16 @@ class APlayer {
this.events.trigger('addaudio', newMusic);
const wasSingle = !this.isMultiple();
this.options.audio = this.options.audio.concat(newMusic);
this.template.listOl.innerHTML += tplListItem({
theme: this.options.theme,
audio: newMusic,
index: this.options.audio.length + 1
});
let newItemHTML = ``;
for (let i = 0; i < newMusic.length; i++) {
newItemHTML += `
<li>
<span class="aplayer-list-cur" style="background: ${newMusic[i].theme || this.options.theme};"></span>
<span class="aplayer-list-index">${this.options.audio.length - newMusic.length + i + 1}</span>
<span class="aplayer-list-title">${newMusic[i].name}</span>
<span class="aplayer-list-author">${newMusic[i].artist}</span>
</li>`;
}
this.template.listOl.innerHTML += newItemHTML;
this.options.audio = this.options.audio.concat(newMusic);
if (wasSingle && this.isMultiple()) {
this.container.classList.add('aplayer-withlist');
this.audio.loop = false;
}
this.template.list.style.height = this.options.audio.length * 33 - 1 + 'px';
this.template.listOl.style.height = this.options.audio.length * 33 - 1 + 'px';

View File

@ -22,6 +22,7 @@ class Template {
options: this.options,
icons: Icons,
cover: cover,
getObject: (obj) => obj,
});
this.lrc = this.container.querySelector('.aplayer-lrc-contents');

View File

@ -0,0 +1,8 @@
{{each audio}}
<li>
<span class="aplayer-list-cur" style="background-color: {{ $value.theme || theme }};"></span>
<span class="aplayer-list-index">{{ $index + index }}</span>
<span class="aplayer-list-title">{{ $value.name }}</span>
<span class="aplayer-list-author">{{ $value.artist }}</span>
</li>
{{/each}}

View File

@ -53,13 +53,10 @@
</div>
<div class="aplayer-list{{ if options.listFolded }} aplayer-list-hide{{ /if }}"{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
<ol{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
{{each options.audio}}
<li>
<span class="aplayer-list-cur" style="background-color: {{ $value.theme || options.theme }};"></span>
<span class="aplayer-list-index">{{ $index + 1 }}</span>
<span class="aplayer-list-title">{{ $value.name }}</span>
<span class="aplayer-list-author">{{ $value.artist }}</span>
</li>
{{/each}}
{{ include './list-item.art' getObject({
theme: options.theme,
audio: options.audio,
index: 1
}) }}
</ol>
</div>