diff --git a/backend/app/routers/tenant_apps.py b/backend/app/routers/tenant_apps.py index c41cc7b..81a2c83 100644 --- a/backend/app/routers/tenant_apps.py +++ b/backend/app/routers/tenant_apps.py @@ -8,6 +8,7 @@ from sqlalchemy.orm import Session from ..database import get_db from ..models.tenant_app import TenantApp +from ..models.app import App from .auth import get_current_user, require_operator from ..models.user import User @@ -86,6 +87,11 @@ async def create_tenant_app( db: Session = Depends(get_db) ): """创建应用配置""" + # 验证 app_code 是否存在于应用管理中 + app_exists = db.query(App).filter(App.app_code == data.app_code, App.status == 1).first() + if not app_exists: + raise HTTPException(status_code=400, detail=f"应用 '{data.app_code}' 不存在,请先在应用管理中创建") + # 检查是否重复 exists = db.query(TenantApp).filter( TenantApp.tenant_id == data.tenant_id, diff --git a/frontend/src/components/Layout.vue b/frontend/src/components/Layout.vue index 3efa1c8..ce1b488 100644 --- a/frontend/src/components/Layout.vue +++ b/frontend/src/components/Layout.vue @@ -13,7 +13,9 @@ const menuItems = computed(() => { const items = [ { path: '/dashboard', title: '仪表盘', icon: 'Odometer' }, { path: '/tenants', title: '租户管理', icon: 'OfficeBuilding' }, - { path: '/app-config', title: '应用配置', icon: 'Setting' }, + { path: '/apps', title: '应用管理', icon: 'Grid' }, + { path: '/tenant-wechat-apps', title: '企微应用', icon: 'ChatDotRound' }, + { path: '/app-config', title: '租户订阅', icon: 'Setting' }, { path: '/stats', title: '统计分析', icon: 'TrendCharts' }, { path: '/logs', title: '日志查看', icon: 'Document' } ] diff --git a/frontend/src/views/app-config/index.vue b/frontend/src/views/app-config/index.vue index 93f73ad..a9fe21a 100644 --- a/frontend/src/views/app-config/index.vue +++ b/frontend/src/views/app-config/index.vue @@ -41,9 +41,20 @@ const currentAppRequireJssdk = computed(() => { return appRequireJssdk.value[form.app_code] || false }) +// 验证 app_code 必须是有效的应用 +const validateAppCode = (rule, value, callback) => { + if (!value) { + callback(new Error('请选择应用')) + } else if (!appList.value.find(a => a.app_code === value)) { + callback(new Error('请从列表中选择有效的应用')) + } else { + callback() + } +} + const rules = { tenant_id: [{ required: true, message: '请输入租户ID', trigger: 'blur' }], - app_code: [{ required: true, message: '请选择应用', trigger: 'change' }] + app_code: [{ required: true, validator: validateAppCode, trigger: 'change' }] } // 查看 Token 对话框