安装app前先检查是否已存在,已存在弹窗提示覆盖安装
This commit is contained in:
parent
8c21e8cd31
commit
2567b75dfb
@ -129,7 +129,7 @@
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { get_session_api_headers } from '@/shared/api/auth'
|
||||
import { NButton, NIcon, NSpin, NEmpty, useMessage } from 'naive-ui'
|
||||
import { NButton, NIcon, NSpin, NEmpty, useMessage, useDialog } from 'naive-ui'
|
||||
import { Icon } from '@iconify/vue'
|
||||
import axios from 'axios'
|
||||
import { t } from '@/shared/i18n'
|
||||
@ -138,6 +138,7 @@ import InstallProgressModal from './InstallProgressModal.vue'
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const message = useMessage()
|
||||
const dialog = useDialog()
|
||||
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
@ -197,6 +198,34 @@ async function installApp() {
|
||||
return
|
||||
}
|
||||
|
||||
// 先检查应用是否已存在
|
||||
try {
|
||||
const appName = app.value.app_name || app.value.name
|
||||
if (appName) {
|
||||
const checkResponse = await axios.get(`/jingrow/check-app/${appName}`)
|
||||
|
||||
if (checkResponse.data.exists) {
|
||||
// 显示确认对话框
|
||||
dialog.warning({
|
||||
title: t('应用已存在'),
|
||||
content: t('应用 "{0}" 已安装,是否覆盖安装?').replace('{0}', appName),
|
||||
positiveText: t('确认覆盖'),
|
||||
negativeText: t('取消'),
|
||||
onPositiveClick: () => {
|
||||
performInstall()
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Check app exists error:', error)
|
||||
}
|
||||
|
||||
performInstall()
|
||||
}
|
||||
|
||||
async function performInstall() {
|
||||
try {
|
||||
installing.value = true
|
||||
installProgress.value = 0
|
||||
|
||||
@ -145,7 +145,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { NInput, NButton, NIcon, NSpin, NEmpty, NSelect, NPagination, useMessage } from 'naive-ui'
|
||||
import { NInput, NButton, NIcon, NSpin, NEmpty, NSelect, NPagination, useMessage, useDialog } from 'naive-ui'
|
||||
import { Icon } from '@iconify/vue'
|
||||
import axios from 'axios'
|
||||
import { t } from '@/shared/i18n'
|
||||
@ -153,6 +153,7 @@ import { get_session_api_headers } from '@/shared/api/auth'
|
||||
import InstallProgressModal from './InstallProgressModal.vue'
|
||||
|
||||
const message = useMessage()
|
||||
const dialog = useDialog()
|
||||
const router = useRouter()
|
||||
|
||||
const searchQuery = ref('')
|
||||
@ -236,6 +237,34 @@ async function installApp(app: any) {
|
||||
return
|
||||
}
|
||||
|
||||
// 先检查应用是否已存在
|
||||
try {
|
||||
const appName = app.app_name || app.name
|
||||
if (appName) {
|
||||
const checkResponse = await axios.get(`/jingrow/check-app/${appName}`)
|
||||
|
||||
if (checkResponse.data.exists) {
|
||||
// 显示确认对话框
|
||||
dialog.warning({
|
||||
title: t('应用已存在'),
|
||||
content: t('应用 "{0}" 已安装,是否覆盖安装?').replace('{0}', appName),
|
||||
positiveText: t('确认覆盖'),
|
||||
negativeText: t('取消'),
|
||||
onPositiveClick: () => {
|
||||
performInstall(app)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Check app exists error:', error)
|
||||
}
|
||||
|
||||
performInstall(app)
|
||||
}
|
||||
|
||||
async function performInstall(app: any) {
|
||||
try {
|
||||
installing.value = true
|
||||
installProgress.value = 0
|
||||
|
||||
@ -190,6 +190,36 @@ async def install_app_from_upload(
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/jingrow/check-app/{app_name}")
|
||||
async def check_app_exists(app_name: str):
|
||||
"""检查应用或扩展包是否已安装"""
|
||||
try:
|
||||
from jingrow.utils.jingrow_api import get_single_pagetype, get_record_list
|
||||
|
||||
# 1. 检查应用是否已安装
|
||||
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:
|
||||
if app.get('app_name', '') == app_name:
|
||||
return {'exists': True, 'installed': True, 'type': 'app'}
|
||||
|
||||
# 2. 检查扩展包是否已安装(通过查询Package PageType)
|
||||
package_result = get_record_list("Package", filters=[["name", "=", app_name]], limit=1)
|
||||
|
||||
if package_result.get('success') and package_result.get('data'):
|
||||
# 如果找到了记录
|
||||
if len(package_result.get('data', [])) > 0:
|
||||
return {'exists': True, 'installed': False, 'type': 'package'}
|
||||
|
||||
return {'exists': False, 'installed': False}
|
||||
except Exception as e:
|
||||
return {'exists': False, 'installed': False, 'error': str(e)}
|
||||
|
||||
|
||||
@router.get("/jingrow/local-apps")
|
||||
async def get_local_apps(request: Request):
|
||||
"""扫描本地未安装的App"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user