- 后端: App 模型添加 config_schema 字段,支持配置项定义 - 后端: apps API 支持 config_schema 的增删改查 - 前端: 应用管理页面支持定义配置项(text/radio/select/switch类型) - 前端: 租户订阅页面根据应用 schema 动态渲染对应表单控件 - 支持设置选项、默认值、必填等属性
This commit is contained in:
@@ -18,6 +18,11 @@ class App(Base):
|
|||||||
# [{"code": "brainstorm", "name": "头脑风暴", "path": "/brainstorm"}, ...]
|
# [{"code": "brainstorm", "name": "头脑风暴", "path": "/brainstorm"}, ...]
|
||||||
tools = Column(Text)
|
tools = Column(Text)
|
||||||
|
|
||||||
|
# 配置项定义(JSON 数组)- 定义租户可配置的参数
|
||||||
|
# [{"key": "industry", "label": "行业类型", "type": "radio", "options": [...], "default": "...", "required": false}, ...]
|
||||||
|
# type: text(文本) | radio(单选) | select(下拉多选) | switch(开关)
|
||||||
|
config_schema = Column(Text)
|
||||||
|
|
||||||
# 是否需要企微JS-SDK
|
# 是否需要企微JS-SDK
|
||||||
require_jssdk = Column(SmallInteger, default=0) # 0-不需要 1-需要
|
require_jssdk = Column(SmallInteger, default=0) # 0-不需要 1-需要
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,18 @@ class ToolItem(BaseModel):
|
|||||||
path: str
|
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):
|
class AppCreate(BaseModel):
|
||||||
"""创建应用"""
|
"""创建应用"""
|
||||||
app_code: str
|
app_code: str
|
||||||
@@ -30,6 +42,7 @@ class AppCreate(BaseModel):
|
|||||||
base_url: Optional[str] = None
|
base_url: Optional[str] = None
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
tools: Optional[List[ToolItem]] = None
|
tools: Optional[List[ToolItem]] = None
|
||||||
|
config_schema: Optional[List[ConfigSchemaItem]] = None
|
||||||
require_jssdk: bool = False
|
require_jssdk: bool = False
|
||||||
|
|
||||||
|
|
||||||
@@ -39,6 +52,7 @@ class AppUpdate(BaseModel):
|
|||||||
base_url: Optional[str] = None
|
base_url: Optional[str] = None
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
tools: Optional[List[ToolItem]] = None
|
tools: Optional[List[ToolItem]] = None
|
||||||
|
config_schema: Optional[List[ConfigSchemaItem]] = None
|
||||||
require_jssdk: Optional[bool] = None
|
require_jssdk: Optional[bool] = None
|
||||||
status: Optional[int] = None
|
status: Optional[int] = None
|
||||||
|
|
||||||
@@ -119,6 +133,7 @@ async def create_app(
|
|||||||
base_url=data.base_url,
|
base_url=data.base_url,
|
||||||
description=data.description,
|
description=data.description,
|
||||||
tools=json.dumps([t.model_dump() for t in data.tools], ensure_ascii=False) if data.tools else None,
|
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,
|
require_jssdk=1 if data.require_jssdk else 0,
|
||||||
status=1
|
status=1
|
||||||
)
|
)
|
||||||
@@ -150,6 +165,13 @@ async def update_app(
|
|||||||
else:
|
else:
|
||||||
update_data['tools'] = None
|
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
|
# 处理 require_jssdk
|
||||||
if 'require_jssdk' in update_data:
|
if 'require_jssdk' in update_data:
|
||||||
update_data['require_jssdk'] = 1 if update_data['require_jssdk'] else 0
|
update_data['require_jssdk'] = 1 if update_data['require_jssdk'] else 0
|
||||||
@@ -259,6 +281,21 @@ async def get_app_tools(
|
|||||||
return 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:
|
def format_app(app: App) -> dict:
|
||||||
"""格式化应用数据"""
|
"""格式化应用数据"""
|
||||||
return {
|
return {
|
||||||
@@ -268,6 +305,7 @@ def format_app(app: App) -> dict:
|
|||||||
"base_url": app.base_url,
|
"base_url": app.base_url,
|
||||||
"description": app.description,
|
"description": app.description,
|
||||||
"tools": json.loads(app.tools) if app.tools else [],
|
"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),
|
"require_jssdk": bool(app.require_jssdk),
|
||||||
"status": app.status,
|
"status": app.status,
|
||||||
"created_at": app.created_at,
|
"created_at": app.created_at,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const tenantList = ref([])
|
|||||||
const appList = ref([])
|
const appList = ref([])
|
||||||
const appRequireJssdk = ref({}) // app_code -> require_jssdk
|
const appRequireJssdk = ref({}) // app_code -> require_jssdk
|
||||||
const appBaseUrl = ref({}) // app_code -> base_url
|
const appBaseUrl = ref({}) // app_code -> base_url
|
||||||
|
const appConfigSchema = ref({}) // app_code -> config_schema
|
||||||
|
|
||||||
// 企微应用列表(按租户)
|
// 企微应用列表(按租户)
|
||||||
const wechatAppList = ref([])
|
const wechatAppList = ref([])
|
||||||
@@ -46,6 +47,44 @@ const currentAppRequireJssdk = computed(() => {
|
|||||||
return appRequireJssdk.value[form.app_code] || false
|
return appRequireJssdk.value[form.app_code] || false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 当前应用的配置项定义
|
||||||
|
const currentConfigSchema = computed(() => {
|
||||||
|
return appConfigSchema.value[form.app_code] || []
|
||||||
|
})
|
||||||
|
|
||||||
|
// 配置值映射(方便读写)
|
||||||
|
const configValues = computed(() => {
|
||||||
|
const map = {}
|
||||||
|
form.custom_configs.forEach(c => {
|
||||||
|
map[c.key] = c
|
||||||
|
})
|
||||||
|
return map
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取配置值
|
||||||
|
function getConfigValue(key) {
|
||||||
|
return configValues.value[key]?.value || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置配置值
|
||||||
|
function setConfigValue(key, value, remark = '') {
|
||||||
|
const existing = form.custom_configs.find(c => c.key === key)
|
||||||
|
if (existing) {
|
||||||
|
existing.value = value
|
||||||
|
if (remark) existing.remark = remark
|
||||||
|
} else {
|
||||||
|
form.custom_configs.push({ key, value, remark })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取选项显示名称
|
||||||
|
function getOptionLabel(schema, optionValue) {
|
||||||
|
if (schema.option_labels && schema.option_labels[optionValue]) {
|
||||||
|
return schema.option_labels[optionValue]
|
||||||
|
}
|
||||||
|
return optionValue
|
||||||
|
}
|
||||||
|
|
||||||
// 验证 app_code 必须是有效的应用
|
// 验证 app_code 必须是有效的应用
|
||||||
const validateAppCode = (rule, value, callback) => {
|
const validateAppCode = (rule, value, callback) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@@ -72,6 +111,14 @@ watch(() => form.tenant_id, async (newVal) => {
|
|||||||
form.wechat_app_id = null
|
form.wechat_app_id = null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 监听应用选择变化,初始化配置默认值
|
||||||
|
watch(() => form.app_code, (newVal) => {
|
||||||
|
if (newVal && !editingId.value) {
|
||||||
|
// 新建时,根据 schema 初始化默认值
|
||||||
|
initConfigDefaults()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 查看 Token 对话框
|
// 查看 Token 对话框
|
||||||
const tokenDialogVisible = ref(false)
|
const tokenDialogVisible = ref(false)
|
||||||
const currentToken = ref('')
|
const currentToken = ref('')
|
||||||
@@ -95,12 +142,25 @@ async function fetchApps() {
|
|||||||
for (const app of apps) {
|
for (const app of apps) {
|
||||||
appRequireJssdk.value[app.app_code] = app.require_jssdk || false
|
appRequireJssdk.value[app.app_code] = app.require_jssdk || false
|
||||||
appBaseUrl.value[app.app_code] = app.base_url || ''
|
appBaseUrl.value[app.app_code] = app.base_url || ''
|
||||||
|
appConfigSchema.value[app.app_code] = app.config_schema || []
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('获取应用列表失败:', e)
|
console.error('获取应用列表失败:', e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据 schema 初始化配置默认值
|
||||||
|
function initConfigDefaults() {
|
||||||
|
const schema = currentConfigSchema.value
|
||||||
|
if (!schema.length) return
|
||||||
|
|
||||||
|
form.custom_configs = schema.map(s => ({
|
||||||
|
key: s.key,
|
||||||
|
value: s.default || '',
|
||||||
|
remark: ''
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchWechatApps(tenantId) {
|
async function fetchWechatApps(tenantId) {
|
||||||
if (!tenantId) {
|
if (!tenantId) {
|
||||||
wechatAppList.value = []
|
wechatAppList.value = []
|
||||||
@@ -154,18 +214,41 @@ function handleCreate() {
|
|||||||
async function handleEdit(row) {
|
async function handleEdit(row) {
|
||||||
editingId.value = row.id
|
editingId.value = row.id
|
||||||
dialogTitle.value = '编辑应用订阅'
|
dialogTitle.value = '编辑应用订阅'
|
||||||
|
|
||||||
|
// 先获取 schema
|
||||||
|
const schema = appConfigSchema.value[row.app_code] || []
|
||||||
|
|
||||||
|
// 合并已有配置和 schema 默认值
|
||||||
|
const existingConfigs = row.custom_configs || []
|
||||||
|
const existingMap = {}
|
||||||
|
existingConfigs.forEach(c => { existingMap[c.key] = c })
|
||||||
|
|
||||||
|
// 构建完整的配置列表(包含 schema 中的所有配置项)
|
||||||
|
const mergedConfigs = schema.map(s => ({
|
||||||
|
key: s.key,
|
||||||
|
value: existingMap[s.key]?.value ?? s.default ?? '',
|
||||||
|
remark: existingMap[s.key]?.remark ?? ''
|
||||||
|
}))
|
||||||
|
|
||||||
|
// 添加 schema 中没有但已存在的配置(兼容旧数据)
|
||||||
|
existingConfigs.forEach(c => {
|
||||||
|
if (!schema.find(s => s.key === c.key)) {
|
||||||
|
mergedConfigs.push({ ...c })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
Object.assign(form, {
|
Object.assign(form, {
|
||||||
tenant_id: row.tenant_id,
|
tenant_id: row.tenant_id,
|
||||||
app_code: row.app_code,
|
app_code: row.app_code,
|
||||||
app_name: row.app_name || '',
|
app_name: row.app_name || '',
|
||||||
wechat_app_id: row.wechat_app_id || null,
|
wechat_app_id: row.wechat_app_id || null,
|
||||||
custom_configs: row.custom_configs ? [...row.custom_configs] : []
|
custom_configs: mergedConfigs
|
||||||
})
|
})
|
||||||
await fetchWechatApps(row.tenant_id)
|
await fetchWechatApps(row.tenant_id)
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自定义配置管理
|
// 自定义配置管理(用于没有 schema 定义时的手动添加)
|
||||||
function addCustomConfig() {
|
function addCustomConfig() {
|
||||||
form.custom_configs.push({ key: '', value: '', remark: '' })
|
form.custom_configs.push({ key: '', value: '', remark: '' })
|
||||||
}
|
}
|
||||||
@@ -402,49 +485,117 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- 自定义配置 -->
|
<!-- 自定义配置 -->
|
||||||
<el-divider content-position="left">自定义配置</el-divider>
|
<template v-if="currentConfigSchema.length > 0 || form.custom_configs.length > 0">
|
||||||
|
<el-divider content-position="left">应用配置</el-divider>
|
||||||
|
|
||||||
<div class="custom-configs-section">
|
<div class="custom-configs-section">
|
||||||
<div v-for="(config, index) in form.custom_configs" :key="index" class="config-item">
|
<!-- 根据 schema 渲染表单 -->
|
||||||
<div class="config-row">
|
<template v-for="(schema, index) in currentConfigSchema" :key="schema.key">
|
||||||
<el-input
|
<div class="config-item-schema">
|
||||||
v-model="config.key"
|
<div class="config-label">
|
||||||
placeholder="配置键 (如: industry)"
|
{{ schema.label }}
|
||||||
style="width: 150px"
|
<span v-if="schema.required" class="required-star">*</span>
|
||||||
/>
|
</div>
|
||||||
<el-input
|
|
||||||
v-model="config.remark"
|
<!-- text 类型 -->
|
||||||
placeholder="备注说明"
|
<template v-if="schema.type === 'text'">
|
||||||
style="width: 180px; margin-left: 8px"
|
<el-input
|
||||||
/>
|
v-model="form.custom_configs[index].value"
|
||||||
<el-button
|
type="textarea"
|
||||||
type="danger"
|
:rows="2"
|
||||||
:icon="Delete"
|
:autosize="{ minRows: 2, maxRows: 12 }"
|
||||||
circle
|
:placeholder="schema.placeholder || '请输入'"
|
||||||
size="small"
|
/>
|
||||||
style="margin-left: 8px"
|
</template>
|
||||||
@click="removeCustomConfig(index)"
|
|
||||||
/>
|
<!-- radio 类型 -->
|
||||||
</div>
|
<template v-else-if="schema.type === 'radio'">
|
||||||
<el-input
|
<el-radio-group v-model="form.custom_configs[index].value">
|
||||||
v-model="config.value"
|
<el-radio
|
||||||
type="textarea"
|
v-for="opt in schema.options"
|
||||||
:rows="3"
|
:key="opt"
|
||||||
:autosize="{ minRows: 2, maxRows: 10 }"
|
:value="opt"
|
||||||
placeholder="配置值(支持超长文本,如提示词等)"
|
>
|
||||||
style="margin-top: 8px"
|
{{ getOptionLabel(schema, opt) }}
|
||||||
/>
|
</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- select 类型 -->
|
||||||
|
<template v-else-if="schema.type === 'select'">
|
||||||
|
<el-select v-model="form.custom_configs[index].value" placeholder="请选择" style="width: 100%">
|
||||||
|
<el-option
|
||||||
|
v-for="opt in schema.options"
|
||||||
|
:key="opt"
|
||||||
|
:label="getOptionLabel(schema, opt)"
|
||||||
|
:value="opt"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- switch 类型 -->
|
||||||
|
<template v-else-if="schema.type === 'switch'">
|
||||||
|
<el-switch
|
||||||
|
v-model="form.custom_configs[index].value"
|
||||||
|
active-value="true"
|
||||||
|
inactive-value="false"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- 备注输入 -->
|
||||||
|
<el-input
|
||||||
|
v-model="form.custom_configs[index].remark"
|
||||||
|
placeholder="备注(可选)"
|
||||||
|
style="margin-top: 8px; width: 300px"
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- 没有 schema 定义时显示手动配置 -->
|
||||||
|
<template v-if="currentConfigSchema.length === 0">
|
||||||
|
<div v-for="(config, index) in form.custom_configs" :key="index" class="config-item">
|
||||||
|
<div class="config-row">
|
||||||
|
<el-input
|
||||||
|
v-model="config.key"
|
||||||
|
placeholder="配置键 (如: industry)"
|
||||||
|
style="width: 150px"
|
||||||
|
/>
|
||||||
|
<el-input
|
||||||
|
v-model="config.remark"
|
||||||
|
placeholder="备注说明"
|
||||||
|
style="width: 180px; margin-left: 8px"
|
||||||
|
/>
|
||||||
|
<el-button
|
||||||
|
type="danger"
|
||||||
|
:icon="Delete"
|
||||||
|
circle
|
||||||
|
size="small"
|
||||||
|
style="margin-left: 8px"
|
||||||
|
@click="removeCustomConfig(index)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<el-input
|
||||||
|
v-model="config.value"
|
||||||
|
type="textarea"
|
||||||
|
:rows="3"
|
||||||
|
:autosize="{ minRows: 2, maxRows: 10 }"
|
||||||
|
placeholder="配置值(支持超长文本,如提示词等)"
|
||||||
|
style="margin-top: 8px"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-button type="primary" plain @click="addCustomConfig" style="margin-top: 8px">
|
||||||
|
<el-icon><Plus /></el-icon>
|
||||||
|
添加配置项
|
||||||
|
</el-button>
|
||||||
|
|
||||||
|
<div v-if="form.custom_configs.length === 0" class="config-empty-tip">
|
||||||
|
该应用暂无配置项定义
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
<el-button type="primary" plain @click="addCustomConfig" style="margin-top: 8px">
|
|
||||||
<el-icon><Plus /></el-icon>
|
|
||||||
添加配置项
|
|
||||||
</el-button>
|
|
||||||
|
|
||||||
<div v-if="form.custom_configs.length === 0" class="config-empty-tip">
|
|
||||||
暂无自定义配置,点击上方按钮添加
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="dialogVisible = false">取消</el-button>
|
<el-button @click="dialogVisible = false">取消</el-button>
|
||||||
@@ -528,6 +679,25 @@ onMounted(() => {
|
|||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.config-item-schema {
|
||||||
|
background: #f5f7fa;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-label {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #303133;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.required-star {
|
||||||
|
color: #f56c6c;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.config-row {
|
.config-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, onMounted } from 'vue'
|
import { ref, reactive, onMounted } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
|
import { Delete, Plus } from '@element-plus/icons-vue'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
@@ -14,6 +15,14 @@ const query = reactive({
|
|||||||
size: 20
|
size: 20
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 配置项类型选项
|
||||||
|
const configTypes = [
|
||||||
|
{ value: 'text', label: '文本输入' },
|
||||||
|
{ value: 'radio', label: '单选' },
|
||||||
|
{ value: 'select', label: '下拉选择' },
|
||||||
|
{ value: 'switch', label: '开关' }
|
||||||
|
]
|
||||||
|
|
||||||
// 对话框
|
// 对话框
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const dialogTitle = ref('')
|
const dialogTitle = ref('')
|
||||||
@@ -24,7 +33,8 @@ const form = reactive({
|
|||||||
app_name: '',
|
app_name: '',
|
||||||
base_url: '',
|
base_url: '',
|
||||||
description: '',
|
description: '',
|
||||||
require_jssdk: false
|
require_jssdk: false,
|
||||||
|
config_schema: [] // 配置项定义
|
||||||
})
|
})
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
@@ -63,7 +73,8 @@ function handleCreate() {
|
|||||||
app_name: '',
|
app_name: '',
|
||||||
base_url: '',
|
base_url: '',
|
||||||
description: '',
|
description: '',
|
||||||
require_jssdk: false
|
require_jssdk: false,
|
||||||
|
config_schema: []
|
||||||
})
|
})
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
}
|
}
|
||||||
@@ -76,11 +87,55 @@ function handleEdit(row) {
|
|||||||
app_name: row.app_name,
|
app_name: row.app_name,
|
||||||
base_url: row.base_url || '',
|
base_url: row.base_url || '',
|
||||||
description: row.description || '',
|
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
|
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() {
|
async function handleSubmit() {
|
||||||
await formRef.value.validate()
|
await formRef.value.validate()
|
||||||
|
|
||||||
@@ -154,6 +209,14 @@ onMounted(() => {
|
|||||||
<el-table-column prop="app_code" label="应用代码" width="150" />
|
<el-table-column prop="app_code" label="应用代码" width="150" />
|
||||||
<el-table-column prop="app_name" label="应用名称" width="180" />
|
<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 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">
|
<el-table-column label="JS-SDK" width="90">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="row.require_jssdk ? 'warning' : 'info'" size="small">
|
<el-tag :type="row.require_jssdk ? 'warning' : 'info'" size="small">
|
||||||
@@ -191,7 +254,7 @@ onMounted(() => {
|
|||||||
</div>
|
</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 ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||||
<el-form-item label="应用代码" prop="app_code">
|
<el-form-item label="应用代码" prop="app_code">
|
||||||
<el-input v-model="form.app_code" :disabled="!!editingId" placeholder="唯一标识,如: brainstorm" />
|
<el-input v-model="form.app_code" :disabled="!!editingId" placeholder="唯一标识,如: brainstorm" />
|
||||||
@@ -212,6 +275,69 @@ onMounted(() => {
|
|||||||
<el-switch v-model="form.require_jssdk" />
|
<el-switch v-model="form.require_jssdk" />
|
||||||
<span style="margin-left: 12px; color: #909399; font-size: 12px">开启后租户需关联企微应用</span>
|
<span style="margin-left: 12px; color: #909399; font-size: 12px">开启后租户需关联企微应用</span>
|
||||||
</el-form-item>
|
</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>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="dialogVisible = false">取消</el-button>
|
<el-button @click="dialogVisible = false">取消</el-button>
|
||||||
@@ -225,4 +351,61 @@ onMounted(() => {
|
|||||||
.page-tip {
|
.page-tip {
|
||||||
margin-bottom: 16px;
|
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>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user