新增:应用配置管理模块,优化文件系统功能
- 新增 ConfigAPI 和 ConfigService 实现配置管理 - 新增 SettingsPanel 和 UpdateNotification 组件 - 文件系统模块化重构,提升代码质量 - 提取公共函数,优化代码结构 - 版本号更新至 0.2.0
This commit is contained in:
@@ -58,6 +58,20 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
return favoriteFiles.value.some(fav => fav.path === path)
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序收藏列表(按创建时间倒序,最新的在上面)
|
||||
*/
|
||||
const sortFavorites = () => {
|
||||
if (!Array.isArray(favoriteFiles.value)) {
|
||||
return
|
||||
}
|
||||
favoriteFiles.value.sort((a, b) => {
|
||||
const timeA = a.created_at || 0
|
||||
const timeB = b.created_at || 0
|
||||
return timeB - timeA // 倒序:最新的在上面
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换收藏状态
|
||||
* @param {Object} item - 文件/目录信息
|
||||
@@ -77,6 +91,7 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
if (index > -1) {
|
||||
// 已收藏,执行取消收藏
|
||||
favoriteFiles.value.splice(index, 1)
|
||||
sortFavorites() // 排序
|
||||
save(favoriteFiles.value)
|
||||
|
||||
onRemove(item)
|
||||
@@ -96,6 +111,7 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
created_at: Date.now(), // 添加时间戳
|
||||
})
|
||||
|
||||
sortFavorites() // 排序
|
||||
save(favoriteFiles.value)
|
||||
|
||||
onAdd(item)
|
||||
@@ -125,6 +141,7 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
const item = favoriteFiles.value[index]
|
||||
favoriteFiles.value.splice(index, 1)
|
||||
|
||||
sortFavorites() // 排序
|
||||
save(favoriteFiles.value)
|
||||
|
||||
onRemove(item)
|
||||
@@ -161,6 +178,7 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
const executeClear = () => {
|
||||
const count = favoriteFiles.value.length
|
||||
favoriteFiles.value = []
|
||||
sortFavorites() // 保持一致性
|
||||
save([])
|
||||
|
||||
Message.success(`已清空 ${count} 个收藏项`)
|
||||
@@ -211,9 +229,10 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
)
|
||||
}
|
||||
|
||||
// 组件挂载时加载数据
|
||||
// 组件挂载时加载数据并排序
|
||||
onMounted(() => {
|
||||
load()
|
||||
sortFavorites() // 确保加载后的数据是排序的
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -228,6 +247,7 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
clearAll,
|
||||
getSortedFavorites,
|
||||
searchFavorites,
|
||||
sortFavorites,
|
||||
load,
|
||||
save,
|
||||
}
|
||||
@@ -235,7 +255,7 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
|
||||
/**
|
||||
* @typedef {Object} UseFavoriteFilesReturn
|
||||
* @property {Ref<Array>} favoriteFiles - 收藏列表
|
||||
* @property {Ref<Array>} favoriteFiles - 收藏列表(自动按时间倒序排列)
|
||||
* @property {Function} isFavorite - 判断是否已收藏
|
||||
* @property {Function} toggleFavorite - 切换收藏状态
|
||||
* @property {Function} removeFavorite - 移除收藏
|
||||
@@ -243,6 +263,7 @@ export function useFavoriteFiles(storageKey, options = {}) {
|
||||
* @property {Function} clearAll - 清空所有收藏
|
||||
* @property {Function} getSortedFavorites - 获取排序后的列表
|
||||
* @property {Function} searchFavorites - 搜索收藏
|
||||
* @property {Function} sortFavorites - 手动排序收藏列表
|
||||
* @property {Function} load - 手动加载数据
|
||||
* @property {Function} save - 手动保存数据
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user