Update list.ts

This commit is contained in:
brstlig 2023-06-23 09:00:54 +08:00 committed by GitHub
parent ea5e8b56dd
commit 48900711c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,6 +82,42 @@ const getIntv = (musicInfo: LX.Music.MusicInfo) => {
export const sortListMusicInfo = async(list: LX.Music.MusicInfo[], sortType: 'up' | 'down', fieldName: 'name' | 'singer' | 'albumName' | 'interval' | 'source', localeId: string) => {
// console.log(sortType, fieldName, localeId)
// const locale = new Intl.Locale(localeId)
if (sortType == 'unorder' && (fieldName =='name' || fieldName == 'singer' || fieldName =='albumName' || fieldName =='interval' || fieldName =='source')){
let change_num:number[]=[]
for(let i:number = 0;i<list.length;i++){
if(change_num.length == 0){
let r_num:number = Math.floor(Math.random()*list.length)
change_num.push(r_num)
}
else{
let sign:boolean = false
do{
let r_num:number = Math.floor(Math.random()*list.length)
for(let j:number = 0 ; j<change_num.length; j++){
if(change_num[j] == r_num){
break;
}
if (j == change_num.length-1){
change_num.push(r_num)
sign = true
}
}
}while(!sign)
}
}
let list2:LX.Music.MusicInfo[]=[]
for(let k:number = 0;k<change_num.length;k++){
list2.push(list[change_num[k]])
}
return list2
}
else{
if (sortType == 'up') {
if (fieldName == 'interval') {
list.sort((a, b) => {
@ -138,6 +174,9 @@ export const sortListMusicInfo = async(list: LX.Music.MusicInfo[], sortType: 'up
}
}
return list
}
}
const variantRxp = /(\(|).+(\)|)/g