|
|
@@ -122,6 +122,7 @@ import {
|
|
|
HdsVisualComponentAttribute,
|
|
|
} from '@kit.UIDesignKit';
|
|
|
import { GlobalAlphabetIndexerModifier } from '../Styels/GlobalStyles'
|
|
|
+import { getFirstLetter } from '../Constants';
|
|
|
|
|
|
const TAG = 'LocalMusic';
|
|
|
|
|
|
@@ -3447,10 +3448,14 @@ export struct LocalMusic {
|
|
|
let targetIndex = -1;
|
|
|
for (let i = 0; i < songs.length; i++) {
|
|
|
let song = songs[i]
|
|
|
- let text = song.name
|
|
|
- const pyStr = song.pyStr
|
|
|
- if(pyStr){
|
|
|
- let firstPinyin = pyStr[0]
|
|
|
+ let text = this.isShowFileName?song.fileName:song.name
|
|
|
+ if(this.sortType === 0||this.sortType==1){
|
|
|
+ text = song.artist
|
|
|
+ }else if(this.sortType === 2||this.sortType==3){
|
|
|
+ text = song.album
|
|
|
+ }
|
|
|
+ if(text){
|
|
|
+ let firstPinyin = getFirstLetter(text)
|
|
|
if (firstPinyin&&firstPinyin === letter) {
|
|
|
targetIndex = i;
|
|
|
break;
|
|
|
@@ -3464,17 +3469,14 @@ export struct LocalMusic {
|
|
|
}
|
|
|
// 找到对应字母表的索引
|
|
|
findAlphaBetIndex(song: VideoItem):number{
|
|
|
- let text = song.name
|
|
|
- // if(this.sortMode === SortMode.ByArtist){
|
|
|
- // text = song.artist
|
|
|
- // }else if(this.sortMode === SortMode.ByTitle){
|
|
|
- // text = song.title
|
|
|
- // }else if(this.sortMode === SortMode.ByRoot){
|
|
|
- // text = song.webFilePath.replace('/','')
|
|
|
- // }
|
|
|
- const pyStr = song.pyStr
|
|
|
- if(pyStr){
|
|
|
- let firstLetter = pyStr[0]
|
|
|
+ let text = this.isShowFileName?song.fileName:song.name
|
|
|
+ if(this.sortType === 0||this.sortType==1){
|
|
|
+ text = song.artist
|
|
|
+ }else if(this.sortType === 2||this.sortType==3){
|
|
|
+ text = song.album
|
|
|
+ }
|
|
|
+ if(text){
|
|
|
+ let firstLetter = getFirstLetter(text)
|
|
|
for(let i=0;i<this.alphaBet.length;i++){
|
|
|
if(this.alphaBet[i] === firstLetter){
|
|
|
return i
|
|
|
@@ -3496,29 +3498,33 @@ export struct LocalMusic {
|
|
|
}
|
|
|
let alphabetSet = new Set<string>();
|
|
|
for (let song of songs) {
|
|
|
- let text = song.name
|
|
|
- // if(this.sortMode === SortMode.ByArtist){
|
|
|
- // text = song.artist
|
|
|
- // }else if(this.sortMode === SortMode.ByTitle){
|
|
|
- // text = song.title
|
|
|
- // }else if(this.sortMode === SortMode.ByRoot){
|
|
|
- // text = song.webFilePath.replace('/','')
|
|
|
- // }
|
|
|
- const pyStr = song.pyStr
|
|
|
- if(pyStr){
|
|
|
- if(!alphabetSet.has(pyStr)){
|
|
|
- alphabetSet.add(pyStr)
|
|
|
+ let text = this.isShowFileName?song.fileName:song.name
|
|
|
+ if(this.sortType === 0||this.sortType==1){
|
|
|
+ text = song.artist
|
|
|
+ }else if(this.sortType === 2||this.sortType==3){
|
|
|
+ text = song.album
|
|
|
+ }
|
|
|
+ if(text){
|
|
|
+ let firstPinyin = getFirstLetter(text)
|
|
|
+ if(!alphabetSet.has(firstPinyin)){
|
|
|
+ alphabetSet.add(firstPinyin)
|
|
|
}
|
|
|
}
|
|
|
+ // const pyStr = song.pyStr
|
|
|
+ // if(pyStr){
|
|
|
+ // if(!alphabetSet.has(pyStr)){
|
|
|
+ // alphabetSet.add(pyStr)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
}
|
|
|
- // this.alphaBet = Array.from(alphabetSet).sort((a,b)=>{
|
|
|
- // if(this.upOrDown === SortModeUpOrDown.Down){
|
|
|
- // return b.localeCompare(a)
|
|
|
- // }else{
|
|
|
- // return a.localeCompare(b)
|
|
|
- // }
|
|
|
- // })
|
|
|
+ this.alphaBet = Array.from(alphabetSet).sort((a,b)=>{
|
|
|
+ if(this.sortType ===4||this.sortType==0||this.sortType==2||this.sortType==6){
|
|
|
+ return a.localeCompare(b)
|
|
|
+ }else{
|
|
|
+ return b.localeCompare(a)
|
|
|
+ }
|
|
|
+ })
|
|
|
if(this.videoLocalList.length > 0){
|
|
|
this.listScroller.scrollToIndex(0)
|
|
|
this.selectAlphaBetIndex = 0
|