定时任务提交(104487f)误删了应用 config_schema 相关代码,现恢复:
- backend/app/models/app.py: 恢复 config_schema 数据库字段
- backend/app/routers/apps.py: 恢复 ConfigSchemaItem、API 路由、格式化函数
- frontend/src/views/apps/index.vue: 恢复配置项编辑 UI
This commit is contained in:
@@ -18,6 +18,11 @@ class App(Base):
|
||||
# [{"code": "brainstorm", "name": "头脑风暴", "path": "/brainstorm"}, ...]
|
||||
tools = Column(Text)
|
||||
|
||||
# 配置项定义(JSON 数组)- 定义租户可配置的参数
|
||||
# [{"key": "industry", "label": "行业类型", "type": "radio", "options": [...], "default": "...", "required": false}, ...]
|
||||
# type: text(文本) | radio(单选) | select(下拉多选) | switch(开关)
|
||||
config_schema = Column(Text)
|
||||
|
||||
# 是否需要企微JS-SDK
|
||||
require_jssdk = Column(SmallInteger, default=0) # 0-不需要 1-需要
|
||||
|
||||
|
||||
@@ -23,6 +23,18 @@ class ToolItem(BaseModel):
|
||||
path: str
|
||||
|
||||
|
||||
class ConfigSchemaItem(BaseModel):
|
||||
"""配置项定义"""
|
||||
key: str # 配置键
|
||||
label: str # 显示标签
|
||||
type: str # text | radio | select | switch
|
||||
options: Optional[List[str]] = None # radio/select 的选项值
|
||||
option_labels: Optional[dict] = None # 选项显示名称 {"value": "显示名"}
|
||||
default: Optional[str] = None # 默认值
|
||||
placeholder: Optional[str] = None # 输入提示(text类型)
|
||||
required: bool = False # 是否必填
|
||||
|
||||
|
||||
class AppCreate(BaseModel):
|
||||
"""创建应用"""
|
||||
app_code: str
|
||||
@@ -30,6 +42,7 @@ class AppCreate(BaseModel):
|
||||
base_url: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
tools: Optional[List[ToolItem]] = None
|
||||
config_schema: Optional[List[ConfigSchemaItem]] = None
|
||||
require_jssdk: bool = False
|
||||
|
||||
|
||||
@@ -39,6 +52,7 @@ class AppUpdate(BaseModel):
|
||||
base_url: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
tools: Optional[List[ToolItem]] = None
|
||||
config_schema: Optional[List[ConfigSchemaItem]] = None
|
||||
require_jssdk: Optional[bool] = None
|
||||
status: Optional[int] = None
|
||||
|
||||
@@ -119,6 +133,7 @@ async def create_app(
|
||||
base_url=data.base_url,
|
||||
description=data.description,
|
||||
tools=json.dumps([t.model_dump() for t in data.tools], ensure_ascii=False) if data.tools else None,
|
||||
config_schema=json.dumps([c.model_dump() for c in data.config_schema], ensure_ascii=False) if data.config_schema else None,
|
||||
require_jssdk=1 if data.require_jssdk else 0,
|
||||
status=1
|
||||
)
|
||||
@@ -150,6 +165,13 @@ async def update_app(
|
||||
else:
|
||||
update_data['tools'] = None
|
||||
|
||||
# 处理 config_schema JSON
|
||||
if 'config_schema' in update_data:
|
||||
if update_data['config_schema']:
|
||||
update_data['config_schema'] = json.dumps([c.model_dump() if hasattr(c, 'model_dump') else c for c in update_data['config_schema']], ensure_ascii=False)
|
||||
else:
|
||||
update_data['config_schema'] = None
|
||||
|
||||
# 处理 require_jssdk
|
||||
if 'require_jssdk' in update_data:
|
||||
update_data['require_jssdk'] = 1 if update_data['require_jssdk'] else 0
|
||||
@@ -259,6 +281,21 @@ async def get_app_tools(
|
||||
return tools
|
||||
|
||||
|
||||
@router.get("/{app_code}/config-schema")
|
||||
async def get_app_config_schema(
|
||||
app_code: str,
|
||||
user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""获取应用的配置项定义(用于租户订阅时渲染表单)"""
|
||||
app = db.query(App).filter(App.app_code == app_code).first()
|
||||
if not app:
|
||||
raise HTTPException(status_code=404, detail="应用不存在")
|
||||
|
||||
config_schema = json.loads(app.config_schema) if app.config_schema else []
|
||||
return config_schema
|
||||
|
||||
|
||||
def format_app(app: App) -> dict:
|
||||
"""格式化应用数据"""
|
||||
return {
|
||||
@@ -268,6 +305,7 @@ def format_app(app: App) -> dict:
|
||||
"base_url": app.base_url,
|
||||
"description": app.description,
|
||||
"tools": json.loads(app.tools) if app.tools else [],
|
||||
"config_schema": json.loads(app.config_schema) if app.config_schema else [],
|
||||
"require_jssdk": bool(app.require_jssdk),
|
||||
"status": app.status,
|
||||
"created_at": app.created_at,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Delete, Plus } from '@element-plus/icons-vue'
|
||||
import api from '@/api'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
@@ -14,6 +15,14 @@ const query = reactive({
|
||||
size: 20
|
||||
})
|
||||
|
||||
// 配置项类型选项
|
||||
const configTypes = [
|
||||
{ value: 'text', label: '文本输入' },
|
||||
{ value: 'radio', label: '单选' },
|
||||
{ value: 'select', label: '下拉选择' },
|
||||
{ value: 'switch', label: '开关' }
|
||||
]
|
||||
|
||||
// 对话框
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
@@ -24,7 +33,8 @@ const form = reactive({
|
||||
app_name: '',
|
||||
base_url: '',
|
||||
description: '',
|
||||
require_jssdk: false
|
||||
require_jssdk: false,
|
||||
config_schema: [] // 配置项定义
|
||||
})
|
||||
|
||||
const rules = {
|
||||
@@ -63,7 +73,8 @@ function handleCreate() {
|
||||
app_name: '',
|
||||
base_url: '',
|
||||
description: '',
|
||||
require_jssdk: false
|
||||
require_jssdk: false,
|
||||
config_schema: []
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
@@ -76,11 +87,55 @@ function handleEdit(row) {
|
||||
app_name: row.app_name,
|
||||
base_url: row.base_url || '',
|
||||
description: row.description || '',
|
||||
require_jssdk: row.require_jssdk || false
|
||||
require_jssdk: row.require_jssdk || false,
|
||||
config_schema: row.config_schema ? row.config_schema.map(c => ({
|
||||
...c,
|
||||
options: c.options || [],
|
||||
option_labels: c.option_labels || {}
|
||||
})) : []
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// 配置项管理
|
||||
function addConfigItem() {
|
||||
form.config_schema.push({
|
||||
key: '',
|
||||
label: '',
|
||||
type: 'text',
|
||||
options: [],
|
||||
option_labels: {},
|
||||
default: '',
|
||||
placeholder: '',
|
||||
required: false
|
||||
})
|
||||
}
|
||||
|
||||
function removeConfigItem(index) {
|
||||
form.config_schema.splice(index, 1)
|
||||
}
|
||||
|
||||
// 选项管理(radio/select 类型)
|
||||
function addOption(config) {
|
||||
const optionKey = `option_${config.options.length + 1}`
|
||||
config.options.push(optionKey)
|
||||
config.option_labels[optionKey] = ''
|
||||
}
|
||||
|
||||
function removeOption(config, index) {
|
||||
const optionKey = config.options[index]
|
||||
config.options.splice(index, 1)
|
||||
delete config.option_labels[optionKey]
|
||||
}
|
||||
|
||||
function updateOptionKey(config, index, newKey) {
|
||||
const oldKey = config.options[index]
|
||||
const oldLabel = config.option_labels[oldKey]
|
||||
delete config.option_labels[oldKey]
|
||||
config.options[index] = newKey
|
||||
config.option_labels[newKey] = oldLabel || ''
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
await formRef.value.validate()
|
||||
|
||||
@@ -154,6 +209,14 @@ onMounted(() => {
|
||||
<el-table-column prop="app_code" label="应用代码" width="150" />
|
||||
<el-table-column prop="app_name" label="应用名称" width="180" />
|
||||
<el-table-column prop="base_url" label="访问地址" min-width="300" show-overflow-tooltip />
|
||||
<el-table-column label="配置项" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.config_schema && row.config_schema.length > 0" type="primary" size="small">
|
||||
{{ row.config_schema.length }} 项
|
||||
</el-tag>
|
||||
<span v-else style="color: #909399; font-size: 12px">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="JS-SDK" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.require_jssdk ? 'warning' : 'info'" size="small">
|
||||
@@ -191,7 +254,7 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<!-- 编辑对话框 -->
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="550px">
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="800px">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="应用代码" prop="app_code">
|
||||
<el-input v-model="form.app_code" :disabled="!!editingId" placeholder="唯一标识,如: brainstorm" />
|
||||
@@ -212,6 +275,69 @@ onMounted(() => {
|
||||
<el-switch v-model="form.require_jssdk" />
|
||||
<span style="margin-left: 12px; color: #909399; font-size: 12px">开启后租户需关联企微应用</span>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 配置项定义 -->
|
||||
<el-divider content-position="left">配置项定义</el-divider>
|
||||
<div class="config-schema-section">
|
||||
<div class="config-schema-tip">
|
||||
定义租户订阅时可配置的参数,如行业类型、提示词等
|
||||
</div>
|
||||
|
||||
<div v-for="(config, index) in form.config_schema" :key="index" class="config-schema-item">
|
||||
<div class="config-header">
|
||||
<span class="config-index">#{{ index + 1 }}</span>
|
||||
<el-button type="danger" :icon="Delete" circle size="small" @click="removeConfigItem(index)" />
|
||||
</div>
|
||||
|
||||
<div class="config-row">
|
||||
<el-input v-model="config.key" placeholder="配置键(如:industry)" style="width: 140px" />
|
||||
<el-input v-model="config.label" placeholder="显示标签(如:行业类型)" style="width: 160px" />
|
||||
<el-select v-model="config.type" placeholder="类型" style="width: 120px">
|
||||
<el-option v-for="t in configTypes" :key="t.value" :label="t.label" :value="t.value" />
|
||||
</el-select>
|
||||
<el-checkbox v-model="config.required">必填</el-checkbox>
|
||||
</div>
|
||||
|
||||
<!-- text 类型:显示 placeholder -->
|
||||
<div v-if="config.type === 'text'" class="config-row" style="margin-top: 8px">
|
||||
<el-input v-model="config.placeholder" placeholder="输入提示文字" style="width: 300px" />
|
||||
<el-input v-model="config.default" placeholder="默认值" style="width: 200px" />
|
||||
</div>
|
||||
|
||||
<!-- switch 类型:显示默认值 -->
|
||||
<div v-if="config.type === 'switch'" class="config-row" style="margin-top: 8px">
|
||||
<span style="color: #606266; margin-right: 8px">默认值:</span>
|
||||
<el-switch v-model="config.default" active-value="true" inactive-value="false" />
|
||||
</div>
|
||||
|
||||
<!-- radio/select 类型:显示选项编辑 -->
|
||||
<div v-if="config.type === 'radio' || config.type === 'select'" class="config-options">
|
||||
<div class="options-label">选项列表:</div>
|
||||
<div v-for="(opt, optIndex) in config.options" :key="optIndex" class="option-row">
|
||||
<el-input
|
||||
:model-value="opt"
|
||||
@update:model-value="v => updateOptionKey(config, optIndex, v)"
|
||||
placeholder="选项值(如:medical)"
|
||||
style="width: 140px"
|
||||
/>
|
||||
<el-input
|
||||
v-model="config.option_labels[opt]"
|
||||
placeholder="显示名(如:医美)"
|
||||
style="width: 140px"
|
||||
/>
|
||||
<el-radio v-model="config.default" :value="opt">默认</el-radio>
|
||||
<el-button type="danger" :icon="Delete" circle size="small" @click="removeOption(config, optIndex)" />
|
||||
</div>
|
||||
<el-button type="primary" plain size="small" @click="addOption(config)">
|
||||
<el-icon><Plus /></el-icon> 添加选项
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-button type="primary" plain @click="addConfigItem" style="margin-top: 12px">
|
||||
<el-icon><Plus /></el-icon> 添加配置项
|
||||
</el-button>
|
||||
</div>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
@@ -225,4 +351,61 @@ onMounted(() => {
|
||||
.page-tip {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
/* 配置项定义样式 */
|
||||
.config-schema-section {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.config-schema-tip {
|
||||
color: #909399;
|
||||
font-size: 13px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.config-schema-item {
|
||||
background: #f5f7fa;
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.config-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.config-index {
|
||||
font-weight: 600;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.config-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.config-options {
|
||||
margin-top: 10px;
|
||||
padding: 10px;
|
||||
background: #fff;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.options-label {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.option-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user