应用市场列表页和详情页更新为即时查询已安装app,删除使用缓存的逻辑
This commit is contained in:
parent
e8c2bf23da
commit
5ffbecefd2
@ -12,11 +12,17 @@
|
|||||||
</template>
|
</template>
|
||||||
{{ t('Back') }}
|
{{ t('Back') }}
|
||||||
</n-button>
|
</n-button>
|
||||||
<n-button type="primary" @click="installApp" size="medium">
|
<n-button
|
||||||
|
:type="isCurrentAppInstalled ? 'warning' : 'primary'"
|
||||||
|
@click="installApp"
|
||||||
|
size="medium"
|
||||||
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon><Icon icon="tabler:download" /></n-icon>
|
<n-icon>
|
||||||
|
<Icon :icon="isCurrentAppInstalled ? 'tabler:refresh' : 'tabler:download'" />
|
||||||
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
{{ t('Install') }}
|
{{ isCurrentAppInstalled ? t('Update') : t('Install') }}
|
||||||
</n-button>
|
</n-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -151,8 +157,18 @@ const installMessage = ref('')
|
|||||||
const installStatus = ref<'success' | 'error' | 'info'>('info')
|
const installStatus = ref<'success' | 'error' | 'info'>('info')
|
||||||
const showProgressModal = ref(false)
|
const showProgressModal = ref(false)
|
||||||
|
|
||||||
|
// 已安装应用集合
|
||||||
|
const installedAppNames = ref<Set<string>>(new Set())
|
||||||
|
|
||||||
const appName = computed(() => route.params.name as string)
|
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() {
|
async function loadAppDetail() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
error.value = ''
|
error.value = ''
|
||||||
@ -261,6 +277,9 @@ async function performInstall() {
|
|||||||
installMessage.value = t('应用安装成功!')
|
installMessage.value = t('应用安装成功!')
|
||||||
message.success(t('应用安装成功'))
|
message.success(t('应用安装成功'))
|
||||||
|
|
||||||
|
// 刷新已安装应用列表
|
||||||
|
loadInstalledApps()
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
showProgressModal.value = false
|
showProgressModal.value = false
|
||||||
}, 2000)
|
}, 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(() => {
|
onMounted(() => {
|
||||||
loadAppDetail()
|
loadAppDetail()
|
||||||
|
loadInstalledApps()
|
||||||
|
|
||||||
|
// 监听全局事件
|
||||||
|
window.addEventListener('installedAppsUpdated', () => {
|
||||||
|
loadInstalledApps()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -361,23 +361,10 @@ function truncateText(text: string, maxLength: number): string {
|
|||||||
// 加载已安装应用列表
|
// 加载已安装应用列表
|
||||||
async function loadInstalledApps() {
|
async function loadInstalledApps() {
|
||||||
try {
|
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')
|
const response = await axios.get('/jingrow/installed-app-names')
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
const apps = response.data.apps || []
|
const apps = response.data.apps || []
|
||||||
installedAppNames.value = new Set(apps)
|
installedAppNames.value = new Set(apps)
|
||||||
sessionStorage.setItem('installed_apps_names', JSON.stringify({
|
|
||||||
apps,
|
|
||||||
timestamp: Date.now()
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Load installed apps error:', error)
|
console.error('Load installed apps error:', error)
|
||||||
@ -393,6 +380,11 @@ function isAppInstalled(appName: string): boolean {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadApps()
|
loadApps()
|
||||||
loadInstalledApps()
|
loadInstalledApps()
|
||||||
|
|
||||||
|
// 监听全局事件
|
||||||
|
window.addEventListener('installedAppsUpdated', () => {
|
||||||
|
loadInstalledApps()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听搜索和排序变化
|
// 监听搜索和排序变化
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user