已安装的应用显示更新按钮

This commit is contained in:
jingrow 2025-10-27 02:55:55 +08:00
parent 2567b75dfb
commit e8c2bf23da
2 changed files with 82 additions and 1 deletions

View File

@ -94,7 +94,18 @@
<n-button type="default" @click="viewAppDetail(app)">
{{ t('View Details') }}
</n-button>
<n-button type="primary" @click="installApp(app)">
<n-button
v-if="isAppInstalled(app.app_name || app.name)"
type="warning"
@click="installApp(app)"
>
{{ t('Update') }}
</n-button>
<n-button
v-else
type="primary"
@click="installApp(app)"
>
{{ t('Install') }}
</n-button>
</div>
@ -171,6 +182,9 @@ const installMessage = ref('')
const installStatus = ref<'success' | 'error' | 'info'>('info')
const showProgressModal = ref(false)
//
const installedAppNames = ref<Set<string>>(new Set())
//
const sortOptions = computed(() => [
{ label: t('Latest'), value: 'creation desc' },
@ -300,6 +314,9 @@ async function performInstall(app: any) {
installMessage.value = t('应用安装成功!')
message.success(t('应用安装成功'))
//
loadInstalledApps()
setTimeout(() => {
showProgressModal.value = false
}, 2000)
@ -341,8 +358,41 @@ function truncateText(text: string, maxLength: number): string {
return text.substring(0, maxLength) + '...'
}
//
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)
}
}
//
function isAppInstalled(appName: string): boolean {
if (!appName) return false
return installedAppNames.value.has(appName.toLowerCase())
}
onMounted(() => {
loadApps()
loadInstalledApps()
})
//

View File

@ -220,6 +220,37 @@ async def check_app_exists(app_name: str):
return {'exists': False, 'installed': False, 'error': str(e)}
@router.get("/jingrow/installed-app-names")
async def get_installed_app_names():
"""获取所有已安装的应用名称列表"""
try:
from jingrow.utils.jingrow_api import get_single_pagetype, get_record_list
installed = set()
# 从 Local Installed Apps 获取应用列表
result = get_single_pagetype("Local Installed Apps")
if result.get('success'):
config = result.get('config', {})
local_installed_apps = config.get('local_installed_apps', [])
for app in local_installed_apps:
app_name = app.get('app_name', '')
if app_name:
installed.add(app_name.lower())
# 从 Package PageType 获取扩展包列表
package_result = get_record_list("Package", fields=["name"], limit=1000)
if package_result.get('success') and package_result.get('data'):
for pkg in package_result.get('data', []):
pkg_name = pkg.get('name', '')
if pkg_name:
installed.add(pkg_name.lower())
return {'success': True, 'apps': list(installed)}
except Exception as e:
return {'success': False, 'error': str(e), 'apps': []}
@router.get("/jingrow/local-apps")
async def get_local_apps(request: Request):
"""扫描本地未安装的App"""