Feature: remember last time choosed sort type

This commit is contained in:
萌萌哒赫萝 2023-05-06 11:29:34 +08:00
parent 344088f391
commit efd9d54f89
2 changed files with 26 additions and 3 deletions

View File

@ -24,8 +24,7 @@ const configFileNames = [
'data.json', 'data.json',
'data.bak.json', 'data.bak.json',
'manage.json', 'manage.json',
'manage.bak.json', 'manage.bak.json'
'UpDownTaskQueue.json'
] ]
function getOctokit (syncConfig: SyncConfig) { function getOctokit (syncConfig: SyncConfig) {

View File

@ -2052,6 +2052,10 @@ async function resetParam (force: boolean = false) {
const cachedData = await searchExistFileList() const cachedData = await searchExistFileList()
if (cachedData.length > 0) { if (cachedData.length > 0) {
currentPageFilesInfo.push(...cachedData[0].value.fullList) currentPageFilesInfo.push(...cachedData[0].value.fullList)
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
if (['name', 'time', 'size', 'ext'].includes(sortType as string)) {
sortFile(sortType)
}
showLoadingPage.value = false showLoadingPage.value = false
return return
} }
@ -2069,6 +2073,10 @@ async function resetParam (force: boolean = false) {
} }
}) })
currentPageFilesInfo.push(...res.fullList) currentPageFilesInfo.push(...res.fullList)
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
if (['name', 'time', 'size', 'ext'].includes(sortType as string)) {
sortFile(sortType)
}
if (res.isTruncated && paging.value) { if (res.isTruncated && paging.value) {
pagingMarkerStack.push(pagingMarker.value) pagingMarkerStack.push(pagingMarker.value)
pagingMarker.value = res.nextMarker pagingMarker.value = res.nextMarker
@ -2151,6 +2159,10 @@ const changePage = async (cur: number | undefined, prev: number | undefined) =>
return a.isDir ? -1 : 1 return a.isDir ? -1 : 1
}) })
currentPageFilesInfo.push(...res.fullList) currentPageFilesInfo.push(...res.fullList)
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
if (['name', 'time', 'size', 'ext'].includes(sortType as string)) {
sortFile(sortType)
}
if (res.isTruncated) { if (res.isTruncated) {
pagingMarkerStack.push(pagingMarker.value) pagingMarkerStack.push(pagingMarker.value)
pagingMarker.value = res.nextMarker pagingMarker.value = res.nextMarker
@ -2188,6 +2200,10 @@ const changePage = async (cur: number | undefined, prev: number | undefined) =>
return a.isDir ? -1 : 1 return a.isDir ? -1 : 1
}) })
currentPageFilesInfo.push(...res.fullList) currentPageFilesInfo.push(...res.fullList)
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
if (['name', 'time', 'size', 'ext'].includes(sortType as string)) {
sortFile(sortType)
}
if (paging.value) { if (paging.value) {
if (res.isTruncated) { if (res.isTruncated) {
pagingMarkerStack.push(pagingMarker.value) pagingMarkerStack.push(pagingMarker.value)
@ -2245,13 +2261,14 @@ function searchAndSort () {
currentPageFilesInfo.forEach((item: any) => { currentPageFilesInfo.forEach((item: any) => {
item.match = true item.match = true
}) })
sortFile('init') sortFile(localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || 'init')
} }
} }
function sortFile (type: 'name' | 'size' | 'time' | 'ext' | 'check' | 'init') { function sortFile (type: 'name' | 'size' | 'time' | 'ext' | 'check' | 'init') {
switch (type) { switch (type) {
case 'name': case 'name':
localStorage.setItem('sortType', 'name')
fileSortNameReverse.value = !fileSortNameReverse.value fileSortNameReverse.value = !fileSortNameReverse.value
currentPageFilesInfo.sort((a: any, b: any) => { currentPageFilesInfo.sort((a: any, b: any) => {
if (fileSortNameReverse.value) { if (fileSortNameReverse.value) {
@ -2262,6 +2279,7 @@ function sortFile (type: 'name' | 'size' | 'time' | 'ext' | 'check' | 'init') {
}) })
break break
case 'size': case 'size':
localStorage.setItem('sortType', 'size')
fileSortSizeReverse.value = !fileSortSizeReverse.value fileSortSizeReverse.value = !fileSortSizeReverse.value
currentPageFilesInfo.sort((a: any, b: any) => { currentPageFilesInfo.sort((a: any, b: any) => {
if (fileSortSizeReverse.value) { if (fileSortSizeReverse.value) {
@ -2272,6 +2290,7 @@ function sortFile (type: 'name' | 'size' | 'time' | 'ext' | 'check' | 'init') {
}) })
break break
case 'time': case 'time':
localStorage.setItem('sortType', 'time')
fileSortTimeReverse.value = !fileSortTimeReverse.value fileSortTimeReverse.value = !fileSortTimeReverse.value
currentPageFilesInfo.sort((a: any, b: any) => { currentPageFilesInfo.sort((a: any, b: any) => {
if (fileSortTimeReverse.value) { if (fileSortTimeReverse.value) {
@ -2282,6 +2301,7 @@ function sortFile (type: 'name' | 'size' | 'time' | 'ext' | 'check' | 'init') {
}) })
break break
case 'ext': case 'ext':
localStorage.setItem('sortType', 'ext')
fileSortExtReverse.value = !fileSortExtReverse.value fileSortExtReverse.value = !fileSortExtReverse.value
currentPageFilesInfo.sort((a: any, b: any) => { currentPageFilesInfo.sort((a: any, b: any) => {
if (fileSortExtReverse.value) { if (fileSortExtReverse.value) {
@ -2788,6 +2808,10 @@ async function getBucketFileListBackStage () {
}) })
currentPageFilesInfo.length = 0 currentPageFilesInfo.length = 0
currentPageFilesInfo.push(...currentFileList) currentPageFilesInfo.push(...currentFileList)
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
if (['name', 'time', 'size', 'ext'].includes(sortType as string)) {
sortFile(sortType)
}
const table = fileCacheDbInstance.table(currentPicBedName.value) const table = fileCacheDbInstance.table(currentPicBedName.value)
table.put({ table.put({
key: getTableKeyOfDb(), key: getTableKeyOfDb(),