修复应用市场列表页和详情页已安装应用或扩展包无法显示更新按钮的问题
This commit is contained in:
parent
b42ca46218
commit
46aac3eaf4
@ -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,17 @@ 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
|
||||
return isAppInstalled(app.value.app_name || app.value.name || '')
|
||||
})
|
||||
|
||||
async function loadAppDetail() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
@ -289,6 +304,9 @@ async function performInstall() {
|
||||
installMessage.value = t('应用安装成功!')
|
||||
message.success(t('应用安装成功'))
|
||||
|
||||
// 刷新已安装应用列表
|
||||
loadInstalledApps()
|
||||
|
||||
setTimeout(() => {
|
||||
showProgressModal.value = false
|
||||
}, 2000)
|
||||
@ -308,8 +326,33 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
// 检查应用是否已安装
|
||||
function isAppInstalled(appName: string): boolean {
|
||||
if (!appName) return false
|
||||
return installedAppNames.value.has(appName.toLowerCase())
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadAppDetail()
|
||||
loadInstalledApps()
|
||||
|
||||
// 监听全局事件
|
||||
window.addEventListener('installedAppsUpdated', () => {
|
||||
loadInstalledApps()
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@ -389,23 +389,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)
|
||||
@ -421,6 +408,11 @@ function isAppInstalled(appName: string): boolean {
|
||||
onMounted(() => {
|
||||
loadApps()
|
||||
loadInstalledApps()
|
||||
|
||||
// 监听全局事件
|
||||
window.addEventListener('installedAppsUpdated', () => {
|
||||
loadInstalledApps()
|
||||
})
|
||||
})
|
||||
|
||||
// 监听搜索和排序变化
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user