11<template >
22 <div >
3- <CardWithHeader
4- :header =" $t('app.app')"
5- class =" card-interval"
6- v-loading =" loading"
7- @mouseenter =" refreshLauncherOnHover"
8- >
3+ <CardWithHeader :header =" $t('app.app')" class =" card-interval" v-loading =" loading" >
94 <template #header-r >
10- <el-button class =" h-button-setting" link icon =" Refresh" @click =" refreshLauncher" />
115 <el-popover placement =" left" :width =" 226" trigger =" click" >
126 <el-input size =" small" v-model =" filter" clearable @input =" loadOption()" />
137 <el-table :show-header =" false" :data =" options" max-height =" 150px" >
@@ -191,41 +185,25 @@ import { changeLauncherStatus, loadAppLauncher, loadAppLauncherOption } from '@/
191185import i18n from ' @/lang' ;
192186import { GlobalStore } from ' @/store' ;
193187import { MsgSuccess } from ' @/utils/message' ;
194- import { ref , computed } from ' vue' ;
188+ import { ref } from ' vue' ;
195189import { useRouter } from ' vue-router' ;
196190import { jumpToPath } from ' @/utils/util' ;
197191import { jumpToInstall } from ' @/utils/app' ;
198192import { routerToFileWithPath , routerToNameWithQuery } from ' @/utils/router' ;
199- import { clearDashboardCacheByPrefix , getDashboardCache , setDashboardCache } from ' @/utils/dashboardCache' ;
200193
201194const router = useRouter ();
202195const globalStore = GlobalStore ();
203196
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-
214197let loading = ref (false );
215198let apps = ref ([]);
216199const options = ref ([]);
217200const filter = ref ();
218- const launcherFromCache = ref (false );
219- const launcherOptionFromCache = ref (false );
220- const systemIPFromCache = ref (false );
221- const hasRefreshedLauncherOnHover = ref (false );
222201const mobile = computed (() => {
223202 return globalStore .isMobile ();
224203});
225204const defaultLink = ref (' ' );
226205
227206const acceptParams = (): void => {
228- hasRefreshedLauncherOnHover .value = false ;
229207 search ();
230208 loadOption ();
231209 getConfig ();
@@ -237,31 +215,17 @@ const goInstall = (key: string, type: string) => {
237215 }
238216};
239217
240- const search = async (force ? : boolean ) => {
218+ const search = async () => {
241219 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- }
254220 await loadAppLauncher ()
255221 .then ((res ) => {
256222 loading .value = false ;
257223 apps .value = res .data ;
258- launcherFromCache .value = false ;
259224 for (const item of apps .value ) {
260225 if (item .detail && item .detail .length !== 0 ) {
261226 item .currentRow = item .detail [0 ];
262227 }
263228 }
264- setDashboardCache (' appLauncher' , apps .value , DASHBOARD_CACHE_TTL .launcher );
265229 })
266230 .finally (() => {
267231 loading .value = false ;
@@ -274,9 +238,7 @@ const onChangeStatus = async (row: any) => {
274238 .then (() => {
275239 loading .value = false ;
276240 MsgSuccess (i18n .global .t (' commons.msg.operationSuccess' ));
277- clearLauncherCache ();
278241 search ();
279- loadOption ();
280242 })
281243 .catch (() => {
282244 loading .value = false ;
@@ -287,18 +249,12 @@ const toLink = (link: string) => {
287249 window .open (link , ' _blank' );
288250};
289251
290- const getConfig = async (force ? : boolean ) => {
252+ const getConfig = async () => {
291253 try {
292- const cache = force ? null : getDashboardCache (' systemIP' );
293- if (cache !== null ) {
294- defaultLink .value = cache ;
295- systemIPFromCache .value = true ;
296- return ;
297- }
298254 const res = await getAgentSettingByKey (' SystemIP' );
299- defaultLink . value = res .data || ' ' ;
300- systemIPFromCache .value = false ;
301- setDashboardCache ( ' systemIP ' , defaultLink . value , DASHBOARD_CACHE_TTL . systemIP );
255+ if ( res .data != ' ' ) {
256+ defaultLink .value = res . data ;
257+ }
302258 } catch (error ) {}
303259};
304260
@@ -330,33 +286,9 @@ const onOperate = async (operation: string, row: any) => {
330286 });
331287};
332288
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- }
289+ const loadOption = async () => {
341290 const res = await loadAppLauncherOption (filter .value || ' ' );
342291 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 );
360292};
361293
362294defineExpose ({
0 commit comments