11import { weapiRequest } from "../utils/request"
22import { songMark } from "../utils/constant"
3- import { getAlbumTextInSongDetail , getArtistTextInSongDetail } from "../utils/descHelper"
3+ import { getAlbumTextInSongDetail , getArtistTextInSongDetail } from "../utils/descHelper"
44import { downloadSongBatch } from "./downloadSongBatch"
55import { uploadSongBatch } from "./uploadSongBatch"
66class AlbumDetail {
@@ -10,6 +10,10 @@ class AlbumDetail {
1010 this . flag = true
1111 this . albumSongList = [ ]
1212 this . albumRes = null
13+ this . albumDiscList = [ ]
14+ const params = new URLSearchParams ( unsafeWindow . location . search )
15+ this . playlistId = Number ( params . get ( 'id' ) )
16+ this . _hash = params . get ( '_hash' )
1317 } ;
1418 fetchAlbumData ( albumId ) {
1519 this . albumId = albumId
@@ -26,14 +30,27 @@ class AlbumDetail {
2630 privilege : content . songs [ i ] . privilege ,
2731 }
2832 this . albumSongList . push ( songItem )
33+ const discInfos = content . songs [ i ] . cd ? content . songs [ i ] . cd . split ( ' ' ) : [ ]
34+ if ( discInfos . length > 0 ) {
35+ const discIndex = parseInt ( discInfos [ 0 ] )
36+ while ( this . albumDiscList . length < discIndex ) {
37+ this . albumDiscList . push ( null )
38+ }
39+ if ( this . albumDiscList [ discIndex - 1 ] === null ) {
40+ let discTitle = `Disc ${ discIndex } `
41+ if ( discInfos . length > 1 ) discTitle += ' ' + discInfos . slice ( 1 ) . join ( ' ' )
42+ this . albumDiscList [ discIndex - 1 ] = { title : discTitle , songs : [ ] }
43+ }
44+ this . albumDiscList [ discIndex - 1 ] . songs . push ( songItem )
45+ }
2946 }
3047 this . dataFetched = true
3148 this . checkStartCreateDom ( )
3249 }
3350 } )
3451 }
3552 onDomReady ( ) {
36- this . domReady = true
53+ this . domReady = true
3754 this . descriptionArea = document . querySelector ( '.topblk' )
3855 this . operationArea = document . querySelector ( '#content-operation' )
3956 this . checkStartCreateDom ( )
@@ -43,6 +60,7 @@ class AlbumDetail {
4360 this . flag = false
4461 this . AppendInfos ( )
4562 this . AppendBtns ( )
63+ if ( this . albumDiscList . length > 1 ) this . createDiscTable ( )
4664 }
4765 }
4866 AppendInfos ( ) {
@@ -54,9 +72,47 @@ class AlbumDetail {
5472 this . descriptionArea . innerHTML += `<p class="intr"><a class="s-fc7" href="${ this . albumRes . album . blurPicUrl } " target="_blank">专辑封面原图</a></p>`
5573 }
5674 }
57- AppendBtns ( ) {
75+ AppendBtns ( ) {
5876 downloadSongBatch ( this . albumId , this . operationArea )
5977 uploadSongBatch ( this . albumId , this . operationArea )
6078 }
79+ createDiscTable ( ) {
80+ const tableRows = document . querySelectorAll ( '.m-table-album tr' )
81+ const tableParent = document . querySelector ( 'div:has(> .m-table-album)' )
82+ let isTableCreated = false
83+ this . albumDiscList . forEach ( ( disc , index ) => {
84+ if ( disc === null ) return
85+ isTableCreated = true
86+ tableParent . innerHTML += `
87+ <div class="u-title u-title-1 f-cb" style="margin-top: 10px"><h3><span class="f-ff2">${ disc . title } </span></h3><span class="sub s-fc3">${ disc . songs . length } 首歌</span></div>
88+ <table class="m-table m-table-album">
89+ <thead><tr><th class="first w1"><div class="wp"> </div></th><th><div class="wp">歌曲标题</div></th><th class="w2-1"><div class="wp">时长</div></th><th class="w4"><div class="wp">歌手</div></th></tr></thead>
90+ <tbody id="ncmextend-disc-${ index } "></tbody>
91+ </table>
92+ `
93+ let tbody = tableParent . querySelector ( `#ncmextend-disc-${ index } ` )
94+ disc . songs . forEach ( ( songItem , songIndex ) => {
95+ tableRows . forEach ( tableRow => {
96+ if ( Number ( tableRow . id . slice ( 0 , - 13 ) ) === songItem . id ) {
97+ tableRow . querySelector ( '.num' ) . innerHTML = songItem . song . no
98+ tableRow . className = songIndex % 2 == 0 ? "even " : ""
99+ if ( songItem . privilege . st < 0 ) tableRow . className += 'js-dis'
100+ tbody . appendChild ( tableRow )
101+ }
102+ } )
103+ } )
104+ } )
105+ if ( isTableCreated ) {
106+ const originTitle = document . querySelector ( '.n-songtb .u-title' )
107+ originTitle . parentNode . removeChild ( originTitle )
108+ tableParent . removeChild ( tableParent . firstChild )
109+ }
110+ //定位到url中的目标歌曲
111+ if ( / ^ s o n g l i s t - ( \d + ) $ / . test ( this . _hash ) && tableRows . length > 0 ) {
112+ const timestamp = document . querySelector ( '.m-table > tbody > tr' ) . id . slice ( - 13 )
113+ const tr = document . querySelector ( `[id="${ this . _hash . slice ( 9 ) } ${ timestamp } "]` )
114+ if ( tr ) tr . scrollIntoView ( ) ;
115+ }
116+ }
61117}
62118export let albumDetailObj = new AlbumDetail ( )
0 commit comments