应用市场列表页和详情页更新为即时查询已安装app,删除使用缓存的逻辑

This commit is contained in:
jingrow 2025-10-27 03:41:56 +08:00
parent e8c2bf23da
commit 5ffbecefd2
2 changed files with 46 additions and 16 deletions

View File

@ -12,11 +12,17 @@
</template>
{{ t('Back') }}
</n-button>
<n-button type="primary" @click="installApp" size="medium">
<n-button
:type="isCurrentAppInstalled ? 'warning' : 'primary'"
@click="installApp"
size="medium"
>
<template #icon>
<n-icon><Icon icon="tabler:download" /></n-icon>
<n-icon>
<Icon :icon="isCurrentAppInstalled ? 'tabler:refresh' : 'tabler:download'" />
</n-icon>
</template>
{{ t('Install') }}
{{ isCurrentAppInstalled ? t('Update') : t('Install') }}
</n-button>
</div>
</div>
@ -151,8 +157,18 @@ const installMessage = ref('')
const installStatus = ref<'success' | 'error' | 'info'>('info')
const showProgressModal = ref(false)
//
const installedAppNames = ref<Set<string>>(new Set())
const appName = computed(() => route.params.name as string)
//
const isCurrentAppInstalled = computed(() => {
if (!app.value) return false
const appName = app.value.app_name || app.value.name || ''
return installedAppNames.value.has(appName.toLowerCase())
})
async function loadAppDetail() {
loading.value = true
error.value = ''
@ -261,6 +277,9 @@ async function performInstall() {
installMessage.value = t('应用安装成功!')
message.success(t('应用安装成功'))
//
loadInstalledApps()
setTimeout(() => {
showProgressModal.value = false
}, 2000)
@ -280,8 +299,27 @@ async function performInstall() {
}
}
//
async function loadInstalledApps() {
try {
const response = await axios.get('/jingrow/installed-app-names')
if (response.data.success) {
const apps = response.data.apps || []
installedAppNames.value = new Set(apps)
}
} catch (error) {
console.error('Load installed apps error:', error)
}
}
onMounted(() => {
loadAppDetail()
loadInstalledApps()
//
window.addEventListener('installedAppsUpdated', () => {
loadInstalledApps()
})
})
</script>

View File

@ -361,23 +361,10 @@ function truncateText(text: string, maxLength: number): string {
//
async function loadInstalledApps() {
try {
const cached = sessionStorage.getItem('installed_apps_names')
if (cached) {
const data = JSON.parse(cached)
if (Date.now() - data.timestamp < 30 * 60 * 1000) {
installedAppNames.value = new Set(data.apps || [])
return
}
}
const response = await axios.get('/jingrow/installed-app-names')
if (response.data.success) {
const apps = response.data.apps || []
installedAppNames.value = new Set(apps)
sessionStorage.setItem('installed_apps_names', JSON.stringify({
apps,
timestamp: Date.now()
}))
}
} catch (error) {
console.error('Load installed apps error:', error)
@ -393,6 +380,11 @@ function isAppInstalled(appName: string): boolean {
onMounted(() => {
loadApps()
loadInstalledApps()
//
window.addEventListener('installedAppsUpdated', () => {
loadInstalledApps()
})
})
//