diff --git a/src-tauri/src/service/asset.rs b/src-tauri/src/service/asset.rs index ca1446cdb..b4302af2a 100644 --- a/src-tauri/src/service/asset.rs +++ b/src-tauri/src/service/asset.rs @@ -104,11 +104,15 @@ impl AssetService { info!("Cookie: {}", self.cookie_header); info!("query: {:?}", self.query); - let (r#type, category) = match self.query.get_category() { - Category::Linux => (Some(Category::Linux), None), - Category::Windows => (Some(Category::Windows), None), - Category::Database => (None, Some(Category::Database)), - Category::Device => (None, Some(Category::Device)), + let (r#type, category) = if favorite { + (None, None) + } else { + match self.query.get_category() { + Category::Linux => (Some(Category::Linux), None), + Category::Windows => (Some(Category::Windows), None), + Category::Database => (None, Some(Category::Database)), + Category::Device => (None, Some(Category::Device)), + } }; let query = AssetQuery { diff --git a/ui/components/AssetContextMenu/contextMenu.vue b/ui/components/AssetContextMenu/contextMenu.vue index da7ed3372..4a9c72afe 100644 --- a/ui/components/AssetContextMenu/contextMenu.vue +++ b/ui/components/AssetContextMenu/contextMenu.vue @@ -56,7 +56,7 @@ const menuItems = computed((): MenuItem[] => { }, { label: isFavorited.value ? t("ContextMenu.Unfavorite") : t("ContextMenu.Favorite"), - icon: isFavorited.value ? "lucide:star-off" : "i-lucide-star", + icon: isFavorited.value ? "lucide:star-off" : "lucide:star", onClick: () => (isFavorited.value ? handleUnfavorite() : handleFavorite()) } ]; diff --git a/ui/components/Card/TableCard/tableCard.vue b/ui/components/Card/TableCard/tableCard.vue index e3bd4f838..37310fcce 100644 --- a/ui/components/Card/TableCard/tableCard.vue +++ b/ui/components/Card/TableCard/tableCard.vue @@ -44,65 +44,63 @@ const contextMenuAsset = ref(null); const renameInputEl = ref(null); const actionMenuOpen = reactive>({}); -/** - * @description 下拉菜单选项 - * @param asset - */ -const buildMenuItems = (asset: AssetItem): MenuItem[] => { - const protocols = (asset.permedProtocols || []).map((p: any) => p.name); - const uniqueProtocols = Array.from(new Set(protocols)); +const buildMenuItems = computed(() => { + return (asset: AssetItem): MenuItem[] => { + const protocols = (asset.permedProtocols || []).map((p: any) => p.name); + const uniqueProtocols = Array.from(new Set(protocols)); - const items: MenuItem[] = [ - { - value: "connect", - label: t("ContextMenu.Connect"), - icon: "i-lucide-plug", - onClick: () => emits("connectTrigger", asset) - }, - { - label: t("ContextMenu.Edit"), - icon: "solar:pen-new-square-linear", - onClick: () => emits("editTrigger", asset) - }, - { - label: t("ContextMenu.Rename"), - icon: "i-lucide-pencil", - onClick: () => handleRenameTrigger(asset) - }, - { - label: asset.isFavorite ? t("ContextMenu.Unfavorite") : t("ContextMenu.Favorite"), - icon: "i-lucide-star", - onClick: () => (asset.isFavorite ? handleAssetUnfavorite(asset.id) : handleAssetFavorite(asset.id)) - } - ]; + const items: MenuItem[] = [ + { + value: "connect", + label: t("ContextMenu.Connect"), + icon: "i-lucide-plug", + onClick: () => emits("connectTrigger", asset) + }, + { + label: t("ContextMenu.Edit"), + icon: "solar:pen-new-square-linear", + onClick: () => emits("editTrigger", asset) + }, + { + label: t("ContextMenu.Rename"), + icon: "i-lucide-pencil", + onClick: () => handleRenameTrigger(asset) + }, + { + label: asset.isFavorite ? t("ContextMenu.Unfavorite") : t("ContextMenu.Favorite"), + icon: asset.isFavorite ? "lucide:star-off" : "lucide:star", + onClick: () => (asset.isFavorite ? handleUnfavorite(asset) : handleFavorite(asset)) + } + ]; - if (uniqueProtocols.length > 1) { - const protocolItems: MenuItem[] = uniqueProtocols.map((name: string) => ({ - label: `${t("ContextMenu.Use")} ${name.toUpperCase()}`, - icon: "i-lucide-plug", - onClick: () => - handleAssetConnection( - displayUser(asset.id, asset.permedAccounts!), - asset.id, - displayProtocol(asset.id, asset.permedProtocols!), - asset.permedAccounts!, - name - ) - })); + if (uniqueProtocols.length > 1) { + const protocolItems: MenuItem[] = uniqueProtocols.map((name: string) => ({ + label: `${t("ContextMenu.Use")} ${name.toUpperCase()}`, + icon: "i-lucide-plug", + onClick: () => + handleAssetConnection( + displayUser(asset.id, asset.permedAccounts!), + asset.id, + displayProtocol(asset.id, asset.permedProtocols!), + asset.permedAccounts!, + name + ) + })); - const moreConnect: MenuItem = { - value: "moreConnect", - label: t("ContextMenu.MoreConnect"), - icon: "i-lucide-ellipsis", - onClick: () => void 0, - children: protocolItems - }; + const moreConnect: MenuItem = { + value: "moreConnect", + label: t("ContextMenu.MoreConnect"), + icon: "i-lucide-ellipsis", + onClick: () => void 0, + children: protocolItems + }; - items.splice(1, 0, moreConnect); - } + items.splice(1, 0, moreConnect); + } - return items; -}; + return items; + }; +}); /** * @description 处理上下文事件 @@ -111,6 +109,22 @@ const handleContextTrigger = (asset: AssetItem) => { emits("contextTrigger", asset); }; +const emitFavoriteChanged = (assetId: string, favorite: boolean) => { + try { + useEventBus().emit("favoriteChanged", { assetId, favorite }); + } catch {} +}; + +const handleFavorite = (asset: AssetItem) => { + handleAssetFavorite(asset.id); + emitFavoriteChanged(asset.id, true); +}; + +const handleUnfavorite = (asset: AssetItem) => { + handleAssetUnfavorite(asset.id); + emitFavoriteChanged(asset.id, false); +}; + /** * @description 触发重命名 */ @@ -229,7 +243,7 @@ const columns: TableColumn[] = [ id: "actions", header: () => t("AssetCard.Actions"), cell: ({ row }) => { - const menuItems = buildMenuItems(row.original); + const menuItems = buildMenuItems.value(row.original); return h( UFieldGroup, diff --git a/ui/composables/useAssetFetcher.ts b/ui/composables/useAssetFetcher.ts index 6474c2556..9d4159403 100644 --- a/ui/composables/useAssetFetcher.ts +++ b/ui/composables/useAssetFetcher.ts @@ -104,7 +104,7 @@ export const useAssetFetcher = (assetType: string, scrollRef?: Ref { if (!hasMore.value || isLoading.value) return; - // 元素内容的总高度 - 元素内容被卷起(向上滚动)的距离 - 元素可视区域的高度 + // 元素内容的总高度 - 元素内容被卷起(向上滚动)的距离 - 元素可视区域的高度 const distanceToBottom = el.scrollHeight - el.scrollTop - el.clientHeight; if (distanceToBottom <= 50) {