fix: 完善菜单和应用验证
All checks were successful
continuous-integration/drone/push Build is passing

- 侧边栏菜单增加「应用管理」和「企微应用」
- 租户订阅页面应用选择增加前端验证
- 后端增加 app_code 存在性验证
This commit is contained in:
111
2026-01-24 10:10:56 +08:00
parent 6a93e05ec3
commit 0a799ee276
3 changed files with 21 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ from sqlalchemy.orm import Session
from ..database import get_db from ..database import get_db
from ..models.tenant_app import TenantApp from ..models.tenant_app import TenantApp
from ..models.app import App
from .auth import get_current_user, require_operator from .auth import get_current_user, require_operator
from ..models.user import User from ..models.user import User
@@ -86,6 +87,11 @@ async def create_tenant_app(
db: Session = Depends(get_db) 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( exists = db.query(TenantApp).filter(
TenantApp.tenant_id == data.tenant_id, TenantApp.tenant_id == data.tenant_id,

View File

@@ -13,7 +13,9 @@ const menuItems = computed(() => {
const items = [ const items = [
{ path: '/dashboard', title: '仪表盘', icon: 'Odometer' }, { path: '/dashboard', title: '仪表盘', icon: 'Odometer' },
{ path: '/tenants', title: '租户管理', icon: 'OfficeBuilding' }, { 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: '/stats', title: '统计分析', icon: 'TrendCharts' },
{ path: '/logs', title: '日志查看', icon: 'Document' } { path: '/logs', title: '日志查看', icon: 'Document' }
] ]

View File

@@ -41,9 +41,20 @@ const currentAppRequireJssdk = computed(() => {
return appRequireJssdk.value[form.app_code] || false 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 = { const rules = {
tenant_id: [{ required: true, message: '请输入租户ID', trigger: 'blur' }], tenant_id: [{ required: true, message: '请输入租户ID', trigger: 'blur' }],
app_code: [{ required: true, message: '请选择应用', trigger: 'change' }] app_code: [{ required: true, validator: validateAppCode, trigger: 'change' }]
} }
// 查看 Token 对话框 // 查看 Token 对话框