完善&优化
This commit is contained in:
parent
a526c7e1cf
commit
948016e562
@ -225,3 +225,23 @@ export const arrPushByPosition = <T>(list: T[], newList: T[], position: number)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
|
||||
// https://stackoverflow.com/a/2450976
|
||||
export const arrShuffle = <T>(array: T[]) => {
|
||||
let currentIndex = array.length
|
||||
let randomIndex
|
||||
|
||||
// While there remain elements to shuffle.
|
||||
while (currentIndex != 0) {
|
||||
// Pick a remaining element.
|
||||
randomIndex = Math.floor(Math.random() * currentIndex)
|
||||
currentIndex--;
|
||||
|
||||
// And swap it with the current element.
|
||||
[array[currentIndex], array[randomIndex]] = [
|
||||
array[randomIndex], array[currentIndex]]
|
||||
}
|
||||
|
||||
return array
|
||||
}
|
||||
|
||||
@ -125,6 +125,7 @@
|
||||
"list_sort_modal_by_down": "Descending",
|
||||
"list_sort_modal_by_field": "Sort field",
|
||||
"list_sort_modal_by_name": "Song name",
|
||||
"list_sort_modal_by_random": "Random",
|
||||
"list_sort_modal_by_singer": "Singer name",
|
||||
"list_sort_modal_by_source": "Song source",
|
||||
"list_sort_modal_by_time": "Duration",
|
||||
|
||||
@ -125,12 +125,12 @@
|
||||
"list_sort_modal_by_down": "降序",
|
||||
"list_sort_modal_by_field": "排序字段",
|
||||
"list_sort_modal_by_name": "歌曲名",
|
||||
"list_sort_modal_by_random": "随机乱序",
|
||||
"list_sort_modal_by_singer": "歌手名",
|
||||
"list_sort_modal_by_source": "歌曲源",
|
||||
"list_sort_modal_by_time": "时长",
|
||||
"list_sort_modal_by_type": "排序类别",
|
||||
"list_sort_modal_by_up": "升序",
|
||||
"list_sort_modal_by_disorder": "随机乱序",
|
||||
"list_sort_modal_tip_confirm": "你确定要这么做吗?",
|
||||
"list_update_modal__auto_update": "自动更新",
|
||||
"list_update_modal__tips": "💡 每次启动软件时将会自动更新已勾选“自动更新”的列表",
|
||||
|
||||
@ -125,6 +125,7 @@
|
||||
"list_sort_modal_by_down": "降序",
|
||||
"list_sort_modal_by_field": "排序字段",
|
||||
"list_sort_modal_by_name": "歌曲名",
|
||||
"list_sort_modal_by_random": "隨機亂序",
|
||||
"list_sort_modal_by_singer": "歌手名",
|
||||
"list_sort_modal_by_source": "歌曲源",
|
||||
"list_sort_modal_by_time": "時長",
|
||||
|
||||
@ -10,31 +10,31 @@
|
||||
<li :class="$style.listItem">
|
||||
<base-checkbox
|
||||
id="list_sort_modal_field_name" v-model="sortField" name="list_sort_modal_field" :aria-label="$t('list_sort_modal_by_name')"
|
||||
need="need" value="name" :label="$t('list_sort_modal_by_name')"
|
||||
need="need" value="name" :disabled="disabledSortFislds" :label="$t('list_sort_modal_by_name')"
|
||||
/>
|
||||
</li>
|
||||
<li :class="$style.listItem">
|
||||
<base-checkbox
|
||||
id="list_sort_modal_field_singer" v-model="sortField" name="list_sort_modal_field"
|
||||
need="need" value="singer" :label="$t('list_sort_modal_by_singer')"
|
||||
need="need" value="singer" :disabled="disabledSortFislds" :label="$t('list_sort_modal_by_singer')"
|
||||
/>
|
||||
</li>
|
||||
<li :class="$style.listItem">
|
||||
<base-checkbox
|
||||
id="list_sort_modal_field_album" v-model="sortField" name="list_sort_modal_field"
|
||||
need="need" value="albumName" :label="$t('list_sort_modal_by_album')"
|
||||
need="need" value="albumName" :disabled="disabledSortFislds" :label="$t('list_sort_modal_by_album')"
|
||||
/>
|
||||
</li>
|
||||
<li :class="$style.listItem">
|
||||
<base-checkbox
|
||||
id="list_sort_modal_field_time" v-model="sortField" name="list_sort_modal_field"
|
||||
need="need" value="interval" :label="$t('list_sort_modal_by_time')"
|
||||
need="need" value="interval" :disabled="disabledSortFislds" :label="$t('list_sort_modal_by_time')"
|
||||
/>
|
||||
</li>
|
||||
<li :class="$style.listItem">
|
||||
<base-checkbox
|
||||
id="list_sort_modal_field_source" v-model="sortField" name="list_sort_modal_field"
|
||||
need="need" value="source" :label="$t('list_sort_modal_by_source')"
|
||||
need="need" value="source" :disabled="disabledSortFislds" :label="$t('list_sort_modal_by_source')"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
@ -56,8 +56,8 @@
|
||||
</li>
|
||||
<li :class="$style.listItem">
|
||||
<base-checkbox
|
||||
id="list_sort_modal_type_disorder" v-model="sortType" name="list_sort_modal_type"
|
||||
need="need" value="disorder" :label="$t('list_sort_modal_by_disorder')"
|
||||
id="list_sort_modal_type_random" v-model="sortType" name="list_sort_modal_type"
|
||||
need="need" value="random" :label="$t('list_sort_modal_by_random')"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
@ -102,7 +102,7 @@ export default {
|
||||
sortType.value = ''
|
||||
}
|
||||
const verify = () => {
|
||||
return !!sortField.value && !!sortType.value
|
||||
return !!sortType.value && (!!sortField.value || sortType.value == 'random')
|
||||
}
|
||||
const handleSort = async() => {
|
||||
if (!verify()) return
|
||||
@ -131,9 +131,14 @@ export default {
|
||||
}
|
||||
})
|
||||
|
||||
const disabledSortFislds = computed(() => {
|
||||
return sortType.value == 'random'
|
||||
})
|
||||
|
||||
return {
|
||||
sortField,
|
||||
sortType,
|
||||
disabledSortFislds,
|
||||
closeModal,
|
||||
handleSort,
|
||||
handleAfterLeave,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// import { throttle } from '@common/utils'
|
||||
|
||||
import { filterFileName, sortInsert, similar, arrPushByPosition } from '@common/utils/common'
|
||||
import { filterFileName, sortInsert, similar, arrPushByPosition, arrShuffle } from '@common/utils/common'
|
||||
import { joinPath, saveStrToFile } from '@common/utils/nodejs'
|
||||
import { createLocalMusicInfo } from '@renderer/utils/music'
|
||||
|
||||
@ -79,45 +79,14 @@ const getIntv = (musicInfo: LX.Music.MusicInfo) => {
|
||||
* @param localeId 排序语言
|
||||
* @returns
|
||||
*/
|
||||
export const sortListMusicInfo = async(list: LX.Music.MusicInfo[], sortType: 'up' | 'down' | 'disorder', fieldName: 'name' | 'singer' | 'albumName' | 'interval' | 'source', localeId: string) => {
|
||||
export const sortListMusicInfo = async(list: LX.Music.MusicInfo[], sortType: 'up' | 'down' | 'random', fieldName: 'name' | 'singer' | 'albumName' | 'interval' | 'source', localeId: string) => {
|
||||
// console.log(sortType, fieldName, localeId)
|
||||
// const locale = new Intl.Locale(localeId)
|
||||
if (sortType == 'disorder' && (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') {
|
||||
switch (sortType) {
|
||||
case 'random':
|
||||
arrShuffle(list)
|
||||
break
|
||||
case 'up':
|
||||
if (fieldName == 'interval') {
|
||||
list.sort((a, b) => {
|
||||
if (a.interval == null) {
|
||||
@ -144,7 +113,8 @@ export const sortListMusicInfo = async(list: LX.Music.MusicInfo[], sortType: 'up
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break
|
||||
case 'down':
|
||||
if (fieldName == 'interval') {
|
||||
list.sort((a, b) => {
|
||||
if (a.interval == null) {
|
||||
@ -171,11 +141,9 @@ export const sortListMusicInfo = async(list: LX.Music.MusicInfo[], sortType: 'up
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const variantRxp = /(\(|().+(\)|))/g
|
||||
|
||||
Loading…
Reference in New Issue
Block a user