From 04fc33e4c05fc8ae068b6f1c0141e69659a6c24f Mon Sep 17 00:00:00 2001 From: zhaojisen <1301338853@qq.com> Date: Thu, 20 Nov 2025 10:33:01 +0800 Subject: [PATCH] perf: table tooltips and languange --- src-tauri/src/commands/url_watcher.rs | 8 +++- src-tauri/src/service/user.rs | 50 +++------------------- ui/components/Card/TableCard/tableCard.vue | 32 ++++++++++++-- ui/components/SideBar/profile.vue | 4 +- ui/utils/index.ts | 27 ++++++------ 5 files changed, 57 insertions(+), 64 deletions(-) diff --git a/src-tauri/src/commands/url_watcher.rs b/src-tauri/src/commands/url_watcher.rs index a9e3837bb..4e21600e0 100644 --- a/src-tauri/src/commands/url_watcher.rs +++ b/src-tauri/src/commands/url_watcher.rs @@ -122,13 +122,17 @@ pub fn url_watcher(app: AppHandle, name: String, origin: String) { let license_valid = if xpack_message.status == 200 && xpack_message.success { serde_json::from_str::(&xpack_message.data) .ok() - .and_then(|value| value.get("XPACK_LICENSE_IS_VALID").and_then(|v| v.as_bool())) + .and_then(|value| { + value + .get("XPACK_LICENSE_IS_VALID") + .and_then(|v| v.as_bool()) + }) .unwrap_or(false) } else { false }; - let user_data = user_service.init(profile, license_valid).await; + let user_data = user_service.init(profile).await; let _ = app.emit( "login-success-detected", diff --git a/src-tauri/src/service/user.rs b/src-tauri/src/service/user.rs index d6302aa18..59fe459ac 100644 --- a/src-tauri/src/service/user.rs +++ b/src-tauri/src/service/user.rs @@ -51,50 +51,14 @@ impl UserService { get_with_response(&url, &self.cookie_header).await } - pub async fn init(&self, profile: ApiResponse, fetch_orgs: bool) -> UserProfileData { - if fetch_orgs { - let (permission_orgs, current_org) = - tokio::join!(self.get_permission_orgs(), self.get_current_org()); + pub async fn init(&self, profile: ApiResponse) -> UserProfileData { + let (permission_orgs, current_org) = + tokio::join!(self.get_permission_orgs(), self.get_current_org()); - UserProfileData { - profile, - current_org, - permission_orgs, - } - } else { - let permission_orgs = ApiResponse { - status: 200, - data: json!({ - "pam_orgs": [], - "audit_orgs": [], - "console_orgs": [], - "workbench_orgs": [], - "id": "", - "username": "", - }) - .to_string(), - success: true, - }; - - let current_org = ApiResponse { - status: 200, - data: json!({ - "id": "", - "name": "", - "is_root": false, - "is_default": false, - "is_system": false, - "comment": "", - }) - .to_string(), - success: true, - }; - - UserProfileData { - profile, - current_org, - permission_orgs, - } + UserProfileData { + profile, + current_org, + permission_orgs, } } } diff --git a/ui/components/Card/TableCard/tableCard.vue b/ui/components/Card/TableCard/tableCard.vue index 44576025d..89ea4bf4b 100644 --- a/ui/components/Card/TableCard/tableCard.vue +++ b/ui/components/Card/TableCard/tableCard.vue @@ -14,7 +14,10 @@ interface MenuItem { children?: MenuItem[]; } +const ASSET_NAME_TOOLTIP_THRESHOLD = 20; + const UButton = resolveComponent("UButton"); +const UTooltip = resolveComponent("UTooltip"); const UCheckbox = resolveComponent("UCheckbox"); const UFieldGroup = resolveComponent("UFieldGroup"); const UDropdownMenu = resolveComponent("UDropdownMenu"); @@ -183,6 +186,11 @@ function cancelRename() { renamingId.value = null; } +const shouldShowTooltip = (text: string | undefined | null) => { + if (!text) return false; + return text.length > ASSET_NAME_TOOLTIP_THRESHOLD; +}; + const columns: TableColumn[] = [ { id: "select", @@ -222,13 +230,29 @@ const columns: TableColumn[] = [ }); } - return h( + const assetName = row.original.name || "-"; + + const textNode = h( "div", { - class: "truncate", - title: row.original.name + class: "truncate" }, - row.original.name + assetName + ); + + if (!shouldShowTooltip(assetName) || assetName === "-") { + return textNode; + } + + return h( + UTooltip, + { + arrow: true, + text: assetName + }, + { + default: () => textNode + } ); }, meta: { class: { th: "max-w-[300px]", td: "max-w-[300px]" } } diff --git a/ui/components/SideBar/profile.vue b/ui/components/SideBar/profile.vue index b650b61fb..e3d98fb6a 100644 --- a/ui/components/SideBar/profile.vue +++ b/ui/components/SideBar/profile.vue @@ -480,7 +480,7 @@ onMounted(async () => { const resolvedSite = resolved_site || normalizedSite; if (status === "success" && profileData) { - const language = resolveLanguageFromCookies(cookies); + const language = await resolveLanguageFromCookies(); if (vStatus !== "incompatible" && !vMatch) { useEventBus().emit("versionAlert", { type: "noMatch", version: versionMessage[versionMessage.length - 1] }); @@ -500,7 +500,7 @@ onMounted(async () => { org: currentOrgData, system_roles: profileData.system_roles, availableOrgs, - xpackLicenseValid: xpack_license_valid ?? false, + xpackLicenseValid: xpack_license_valid ?? true, language, connectionInfo: { protocol: "", diff --git a/ui/utils/index.ts b/ui/utils/index.ts index 883d006eb..d3eb592c4 100644 --- a/ui/utils/index.ts +++ b/ui/utils/index.ts @@ -33,22 +33,23 @@ export function transformAssetsData(rawDataArray: RawAssetData[]): AssetItem[] { } /** - * @description 处理 cooklies 中的 django_language - * @param cookies + * @description 获取操作系统的语言 */ -export function resolveLanguageFromCookies(cookies: string | undefined | null): "zh" | "en" { - if (!cookies) return "en"; +export async function resolveLanguageFromCookies(): Promise<"zh" | "en"> { + const normalize = (lang: string | null | undefined) => { + if (!lang) return "en" as const; - const langEntry = cookies - .split(";") - .map((chunk) => chunk.trim()) - .find((chunk) => chunk.toLowerCase().startsWith("django_language=")); - - if (!langEntry) return "en"; + const normalized = lang.toLowerCase(); + if (normalized.includes("zh")) return "zh" as const; + return "en" as const; + }; - const value = langEntry.split("=")[1]?.trim().toLowerCase(); + const locale = await useTauriOsLocale(); + if (locale) { + return normalize(locale); + } - if (!value) return "en"; + const fallback = (typeof navigator !== "undefined" && (navigator.language || navigator.languages?.[0])) || ""; - return value === "zh-hans" || value.startsWith("zh") ? "zh" : "en"; + return normalize(fallback); }