11<template >
22 <div >
3- <CardWithHeader :header =" $t('app.app')" class =" card-interval" v-loading =" loading" >
3+ <CardWithHeader
4+ :header =" $t('app.app')"
5+ class =" card-interval"
6+ v-loading =" loading"
7+ @mouseenter =" refreshLauncherOnHover"
8+ >
49 <template #header-r >
10+ <el-button class =" h-button-setting" link icon =" Refresh" @click =" refreshLauncher" />
511 <el-popover placement =" left" :width =" 226" trigger =" click" >
612 <el-input size =" small" v-model =" filter" clearable @input =" loadOption()" />
713 <el-table :show-header =" false" :data =" options" max-height =" 150px" >
@@ -185,25 +191,41 @@ import { changeLauncherStatus, loadAppLauncher, loadAppLauncherOption } from '@/
185191import i18n from ' @/lang' ;
186192import { GlobalStore } from ' @/store' ;
187193import { MsgSuccess } from ' @/utils/message' ;
188- import { ref } from ' vue' ;
194+ import { ref , computed } from ' vue' ;
189195import { useRouter } from ' vue-router' ;
190196import { jumpToPath } from ' @/utils/util' ;
191197import { jumpToInstall } from ' @/utils/app' ;
192198import { routerToFileWithPath , routerToNameWithQuery } from ' @/utils/router' ;
199+ import { clearDashboardCacheByPrefix , getDashboardCache , setDashboardCache } from ' @/utils/dashboardCache' ;
193200
194201const router = useRouter ();
195202const globalStore = GlobalStore ();
196203
204+ const DASHBOARD_CACHE_TTL = {
205+ launcherOption: 5 * 60 * 1000 ,
206+ launcher: 10 * 60 * 1000 ,
207+ systemIP: 10 * 60 * 1000 ,
208+ };
209+
210+ const clearLauncherCache = () => {
211+ clearDashboardCacheByPrefix ([' appLauncherOption-' , ' appLauncher' , ' systemIP' ]);
212+ };
213+
197214let loading = ref (false );
198215let apps = ref ([]);
199216const options = ref ([]);
200217const filter = ref ();
218+ const launcherFromCache = ref (false );
219+ const launcherOptionFromCache = ref (false );
220+ const systemIPFromCache = ref (false );
221+ const hasRefreshedLauncherOnHover = ref (false );
201222const mobile = computed (() => {
202223 return globalStore .isMobile ();
203224});
204225const defaultLink = ref (' ' );
205226
206227const acceptParams = (): void => {
228+ hasRefreshedLauncherOnHover .value = false ;
207229 search ();
208230 loadOption ();
209231 getConfig ();
@@ -215,17 +237,31 @@ const goInstall = (key: string, type: string) => {
215237 }
216238};
217239
218- const search = async () => {
240+ const search = async (force ? : boolean ) => {
219241 loading .value = true ;
242+ const cache = force ? null : getDashboardCache (' appLauncher' );
243+ if (cache !== null ) {
244+ apps .value = cache ;
245+ launcherFromCache .value = true ;
246+ for (const item of apps .value ) {
247+ if (item .detail && item .detail .length !== 0 ) {
248+ item .currentRow = item .detail [0 ];
249+ }
250+ }
251+ loading .value = false ;
252+ return ;
253+ }
220254 await loadAppLauncher ()
221255 .then ((res ) => {
222256 loading .value = false ;
223257 apps .value = res .data ;
258+ launcherFromCache .value = false ;
224259 for (const item of apps .value ) {
225260 if (item .detail && item .detail .length !== 0 ) {
226261 item .currentRow = item .detail [0 ];
227262 }
228263 }
264+ setDashboardCache (' appLauncher' , apps .value , DASHBOARD_CACHE_TTL .launcher );
229265 })
230266 .finally (() => {
231267 loading .value = false ;
@@ -238,7 +274,9 @@ const onChangeStatus = async (row: any) => {
238274 .then (() => {
239275 loading .value = false ;
240276 MsgSuccess (i18n .global .t (' commons.msg.operationSuccess' ));
277+ clearLauncherCache ();
241278 search ();
279+ loadOption ();
242280 })
243281 .catch (() => {
244282 loading .value = false ;
@@ -249,12 +287,18 @@ const toLink = (link: string) => {
249287 window .open (link , ' _blank' );
250288};
251289
252- const getConfig = async () => {
290+ const getConfig = async (force ? : boolean ) => {
253291 try {
254- const res = await getAgentSettingByKey (' SystemIP' );
255- if (res .data != ' ' ) {
256- defaultLink .value = res .data ;
292+ const cache = force ? null : getDashboardCache (' systemIP' );
293+ if (cache !== null ) {
294+ defaultLink .value = cache ;
295+ systemIPFromCache .value = true ;
296+ return ;
257297 }
298+ const res = await getAgentSettingByKey (' SystemIP' );
299+ defaultLink .value = res .data || ' ' ;
300+ systemIPFromCache .value = false ;
301+ setDashboardCache (' systemIP' , defaultLink .value , DASHBOARD_CACHE_TTL .systemIP );
258302 } catch (error ) {}
259303};
260304
@@ -286,9 +330,33 @@ const onOperate = async (operation: string, row: any) => {
286330 });
287331};
288332
289- const loadOption = async () => {
333+ const loadOption = async (force ? : boolean ) => {
334+ const cacheKey = ` appLauncherOption-${filter .value || ' ' } ` ;
335+ const cache = force ? null : getDashboardCache (cacheKey );
336+ if (cache !== null ) {
337+ options .value = cache ;
338+ launcherOptionFromCache .value = true ;
339+ return ;
340+ }
290341 const res = await loadAppLauncherOption (filter .value || ' ' );
291342 options .value = res .data || [];
343+ launcherOptionFromCache .value = false ;
344+ setDashboardCache (cacheKey , options .value , DASHBOARD_CACHE_TTL .launcherOption );
345+ };
346+
347+ const refreshLauncher = async () => {
348+ clearLauncherCache ();
349+ hasRefreshedLauncherOnHover .value = false ;
350+ await Promise .allSettled ([loadOption (true ), search (true ), getConfig (true )]);
351+ };
352+
353+ const refreshLauncherOnHover = async () => {
354+ if (hasRefreshedLauncherOnHover .value ) return ;
355+ if (! launcherFromCache .value && ! launcherOptionFromCache .value && ! systemIPFromCache .value ) return ;
356+ hasRefreshedLauncherOnHover .value = true ;
357+ await loadOption (true );
358+ await search (true );
359+ await getConfig (true );
292360};
293361
294362defineExpose ({
0 commit comments