mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-08-28 03:26:56 +08:00
🐛 Fix: file sort order will not changed after force refresh now
This commit is contained in:
@@ -26,6 +26,8 @@ import { ref, onBeforeMount } from 'vue'
|
|||||||
import { getFileIconPath } from '@/manage/utils/common'
|
import { getFileIconPath } from '@/manage/utils/common'
|
||||||
import { Loading } from '@element-plus/icons-vue'
|
import { Loading } from '@element-plus/icons-vue'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
|
import mime from 'mime-types'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
const base64Image = ref('')
|
const base64Image = ref('')
|
||||||
const props = defineProps(
|
const props = defineProps(
|
||||||
@@ -46,11 +48,16 @@ const props = defineProps(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const createBase64Image = async () => {
|
const createBase64Image = async () => {
|
||||||
const base64 = await fs.readFile(props.localPath, 'base64')
|
const filePath = path.normalize(props.localPath)
|
||||||
base64Image.value = `data:image/png;base64,${base64}`
|
const base64 = await fs.readFile(filePath, 'base64')
|
||||||
|
base64Image.value = `data:${mime.lookup(filePath) || 'image/png'};base64,${base64}`
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
onBeforeMount(async () => {
|
||||||
await createBase64Image()
|
try {
|
||||||
|
await createBase64Image()
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -497,7 +497,7 @@ https://www.baidu.com/img/bd_logo1.png"
|
|||||||
shadow="hover"
|
shadow="hover"
|
||||||
>
|
>
|
||||||
<el-image
|
<el-image
|
||||||
v-if="!item.isDir && currentPicBedName !== 'webdavplist'"
|
v-if="!item.isDir && currentPicBedName !== 'webdavplist' && currentPicBedName !== 'local'"
|
||||||
:src="isShowThumbnail && item.isImage ?
|
:src="isShowThumbnail && item.isImage ?
|
||||||
item.url
|
item.url
|
||||||
: require(`./assets/icons/${getFileIconPath(item.fileName ?? '')}`)"
|
: require(`./assets/icons/${getFileIconPath(item.fileName ?? '')}`)"
|
||||||
@@ -526,6 +526,13 @@ https://www.baidu.com/img/bd_logo1.png"
|
|||||||
:url="item.url"
|
:url="item.url"
|
||||||
@click="handleClickFile(item)"
|
@click="handleClickFile(item)"
|
||||||
/>
|
/>
|
||||||
|
<ImageLocal
|
||||||
|
v-else-if="!item.isDir && currentPicBedName === 'local'"
|
||||||
|
:is-show-thumbnail="isShowThumbnail"
|
||||||
|
:item="item"
|
||||||
|
:local-path="item.key"
|
||||||
|
@click="handleClickFile(item)"
|
||||||
|
/>
|
||||||
<el-image
|
<el-image
|
||||||
v-else
|
v-else
|
||||||
:src="require('./assets/icons/folder.webp')"
|
:src="require('./assets/icons/folder.webp')"
|
||||||
@@ -1485,6 +1492,7 @@ import { videoExt } from '../utils/videofile'
|
|||||||
|
|
||||||
// 组件
|
// 组件
|
||||||
import ImageWebdav from '@/components/ImageWebdav.vue'
|
import ImageWebdav from '@/components/ImageWebdav.vue'
|
||||||
|
import ImageLocal from '@/components/ImageLocal.vue'
|
||||||
|
|
||||||
// 国际化函数
|
// 国际化函数
|
||||||
import { T as $T } from '@/i18n'
|
import { T as $T } from '@/i18n'
|
||||||
@@ -2134,6 +2142,10 @@ async function resetParam (force: boolean = false) {
|
|||||||
isShowFileInfo.value = false
|
isShowFileInfo.value = false
|
||||||
lastChoosed.value = -1
|
lastChoosed.value = -1
|
||||||
layoutStyle.value = await getConfig('settings.isShowList') ? 'list' : 'grid'
|
layoutStyle.value = await getConfig('settings.isShowList') ? 'list' : 'grid'
|
||||||
|
fileSortExtReverse.value = false
|
||||||
|
fileSortNameReverse.value = false
|
||||||
|
fileSortSizeReverse.value = false
|
||||||
|
fileSortTimeReverse.value = false
|
||||||
if (!isAutoRefresh.value && !force && !paging.value) {
|
if (!isAutoRefresh.value && !force && !paging.value) {
|
||||||
const cachedData = await searchExistFileList()
|
const cachedData = await searchExistFileList()
|
||||||
if (cachedData.length > 0) {
|
if (cachedData.length > 0) {
|
||||||
@@ -2150,13 +2162,7 @@ async function resetParam (force: boolean = false) {
|
|||||||
const res = await getBucketFileList() as IStringKeyMap
|
const res = await getBucketFileList() as IStringKeyMap
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
res.fullList.sort((a: any, b: any) => {
|
res.fullList.sort((a: any, b: any) => {
|
||||||
if (a.isDir && !b.isDir) {
|
return b.isDir - a.isDir || a.fileName.localeCompare(b.fileName)
|
||||||
return -1
|
|
||||||
} else if (!a.isDir && b.isDir) {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return a.fileName.localeCompare(b.fileName)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
currentPageFilesInfo.push(...res.fullList)
|
currentPageFilesInfo.push(...res.fullList)
|
||||||
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
|
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
|
||||||
@@ -2229,88 +2235,57 @@ watch(currentPageNumber, () => {
|
|||||||
const changePage = async (cur: number | undefined, prev: number | undefined) => {
|
const changePage = async (cur: number | undefined, prev: number | undefined) => {
|
||||||
if (!cur || !prev) {
|
if (!cur || !prev) {
|
||||||
currentPageNumber.value = 1
|
currentPageNumber.value = 1
|
||||||
} else {
|
return
|
||||||
if (cur > prev) {
|
}
|
||||||
isShowLoadingPage.value = true
|
const isForwardNavigation = cur > prev
|
||||||
currentPageNumber.value = prev + 1
|
const newPageNumber = isForwardNavigation ? prev + 1 : prev - 1
|
||||||
currentPageFilesInfo.length = 0
|
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
|
||||||
selectedItems.length = 0
|
|
||||||
searchText.value = ''
|
isShowLoadingPage.value = true
|
||||||
urlToUpload.value = ''
|
currentPageNumber.value = newPageNumber
|
||||||
dialogVisible.value = false
|
currentPageFilesInfo.length = 0
|
||||||
const res = await getBucketFileList() as IStringKeyMap
|
selectedItems.length = 0
|
||||||
isShowLoadingPage.value = false
|
searchText.value = ''
|
||||||
if (res.success) {
|
urlToUpload.value = ''
|
||||||
res.fullList.sort((a: any) => {
|
dialogVisible.value = false
|
||||||
return a.isDir ? -1 : 1
|
|
||||||
})
|
if (!isForwardNavigation) {
|
||||||
currentPageFilesInfo.push(...res.fullList)
|
pagingMarker.value = pagingMarkerStack[pagingMarkerStack.length - 2]
|
||||||
const sortType = localStorage.getItem('sortType') as 'name' | 'size' | 'time' | 'ext' | 'check' | 'init' || ''
|
pagingMarkerStack.pop()
|
||||||
if (['name', 'time', 'size', 'ext'].includes(sortType as string)) {
|
pagingMarkerStack.pop()
|
||||||
sortFile(sortType)
|
}
|
||||||
}
|
|
||||||
if (res.isTruncated) {
|
const res = await getBucketFileList() as IStringKeyMap
|
||||||
pagingMarkerStack.push(pagingMarker.value)
|
isShowLoadingPage.value = false
|
||||||
pagingMarker.value = res.nextMarker
|
|
||||||
} else {
|
if (!res.success) {
|
||||||
ElNotification({
|
ElNotification({
|
||||||
title: $T('MANAGE_BUCKET_GET_LIST_FAIL_TITLE'),
|
title: $T('MANAGE_BUCKET_GET_LIST_FAIL_TITLE'),
|
||||||
message: $T('MANAGE_BUCKET_LAST_PAGE_MSG'),
|
message: $T('MANAGE_BUCKET_GET_LIST_FAIL_MSG'),
|
||||||
type: 'success',
|
type: 'error',
|
||||||
duration: 1000
|
duration: 1000
|
||||||
})
|
})
|
||||||
}
|
return
|
||||||
} else {
|
}
|
||||||
ElNotification({
|
|
||||||
title: $T('MANAGE_BUCKET_GET_LIST_FAIL_TITLE'),
|
res.fullList.sort((a: any) => (a.isDir ? -1 : 1))
|
||||||
message: $T('MANAGE_BUCKET_GET_LIST_FAIL_MSG'),
|
currentPageFilesInfo.push(...res.fullList)
|
||||||
type: 'error',
|
|
||||||
duration: 1000
|
if (['name', 'time', 'size', 'ext'].includes(sortType as string)) {
|
||||||
})
|
sortFile(sortType)
|
||||||
}
|
}
|
||||||
} else if (cur < prev) {
|
|
||||||
isShowLoadingPage.value = true
|
if (!(cur < prev && !paging.value)) {
|
||||||
currentPageNumber.value = prev - 1
|
if (res.isTruncated) {
|
||||||
currentPageFilesInfo.length = 0
|
pagingMarkerStack.push(pagingMarker.value)
|
||||||
selectedItems.length = 0
|
pagingMarker.value = res.nextMarker
|
||||||
searchText.value = ''
|
} else {
|
||||||
urlToUpload.value = ''
|
ElNotification({
|
||||||
dialogVisible.value = false
|
title: $T('MANAGE_BUCKET_GET_LIST_FAIL_TITLE'),
|
||||||
pagingMarker.value = pagingMarkerStack[pagingMarkerStack.length - 2]
|
message: $T('MANAGE_BUCKET_LAST_PAGE_MSG'),
|
||||||
pagingMarkerStack.pop()
|
type: 'success',
|
||||||
pagingMarkerStack.pop()
|
duration: 1000
|
||||||
const res = await getBucketFileList() as IStringKeyMap
|
})
|
||||||
isShowLoadingPage.value = false
|
|
||||||
if (res.success) {
|
|
||||||
res.fullList.sort((a: any) => {
|
|
||||||
return a.isDir ? -1 : 1
|
|
||||||
})
|
|
||||||
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 (res.isTruncated) {
|
|
||||||
pagingMarkerStack.push(pagingMarker.value)
|
|
||||||
pagingMarker.value = res.nextMarker
|
|
||||||
} else {
|
|
||||||
ElNotification({
|
|
||||||
title: $T('MANAGE_BUCKET_GET_LIST_FAIL_TITLE'),
|
|
||||||
message: $T('MANAGE_BUCKET_LAST_PAGE_MSG'),
|
|
||||||
type: 'success',
|
|
||||||
duration: 1000
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ElNotification({
|
|
||||||
title: $T('MANAGE_BUCKET_GET_LIST_FAIL_TITLE'),
|
|
||||||
message: $T('MANAGE_BUCKET_GET_LIST_FAIL_MSG'),
|
|
||||||
type: 'error',
|
|
||||||
duration: 1000
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2404,13 +2379,7 @@ function sortFile (type: 'name' | 'size' | 'time' | 'ext' | 'check' | 'init') {
|
|||||||
break
|
break
|
||||||
case 'init':
|
case 'init':
|
||||||
currentPageFilesInfo.sort((a: any, b: any) => {
|
currentPageFilesInfo.sort((a: any, b: any) => {
|
||||||
if (a.isDir && !b.isDir) {
|
return b.isDir - a.isDir || a.fileName.localeCompare(b.fileName)
|
||||||
return -1
|
|
||||||
} else if (!a.isDir && b.isDir) {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return a.fileName.localeCompare(b.fileName)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2879,13 +2848,7 @@ async function getBucketFileListBackStage () {
|
|||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
const currentFileList = fileTransferStore.getFileTransferList()
|
const currentFileList = fileTransferStore.getFileTransferList()
|
||||||
currentFileList.sort((a: any, b: any) => {
|
currentFileList.sort((a: any, b: any) => {
|
||||||
if (a.isDir && !b.isDir) {
|
return b.isDir - a.isDir || a.fileName.localeCompare(b.fileName)
|
||||||
return -1
|
|
||||||
} else if (!a.isDir && b.isDir) {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return a.fileName.localeCompare(b.fileName)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
currentPageFilesInfo.length = 0
|
currentPageFilesInfo.length = 0
|
||||||
currentPageFilesInfo.push(...currentFileList)
|
currentPageFilesInfo.push(...currentFileList)
|
||||||
|
|||||||
@@ -454,7 +454,8 @@ function handleSelectMenu (bucketName: string) {
|
|||||||
const transformedConfig = JSON.parse(currentPicBedConfig.transformedConfig ?? '{}')
|
const transformedConfig = JSON.parse(currentPicBedConfig.transformedConfig ?? '{}')
|
||||||
|
|
||||||
let prefix = transformedConfig[bucketName]?.baseDir || '/'
|
let prefix = transformedConfig[bucketName]?.baseDir || '/'
|
||||||
if (currentPicBedConfig.picBedName ?? currentPicBedName.value === 'local') {
|
const cpicBedName = currentPicBedConfig.picBedName ?? currentPicBedName.value
|
||||||
|
if (cpicBedName === 'local') {
|
||||||
prefix = `/${transPathToUnix(prefix)}/`
|
prefix = `/${transPathToUnix(prefix)}/`
|
||||||
} else {
|
} else {
|
||||||
prefix = prefix.startsWith('/') ? prefix : `/${prefix}`
|
prefix = prefix.startsWith('/') ? prefix : `/${prefix}`
|
||||||
@@ -465,7 +466,7 @@ function handleSelectMenu (bucketName: string) {
|
|||||||
prefix,
|
prefix,
|
||||||
bucketName,
|
bucketName,
|
||||||
customUrl: transformedConfig[bucketName]?.customUrl ?? '',
|
customUrl: transformedConfig[bucketName]?.customUrl ?? '',
|
||||||
picBedName: currentPicBedConfig.picBedName ?? currentPicBedName.value,
|
picBedName: cpicBedName,
|
||||||
alias: currentAlias.value,
|
alias: currentAlias.value,
|
||||||
bucketConfig: bucketList.value[bucketName],
|
bucketConfig: bucketList.value[bucketName],
|
||||||
cdnUrl: currentPicBedConfig.customUrl,
|
cdnUrl: currentPicBedConfig.customUrl,
|
||||||
|
|||||||
Reference in New Issue
Block a user