6.3 KiB
6.3 KiB
发布流程
完整发布流程
┌─────────────────────────────────────────────────────────┐
│ 1. 创建门户 (type=model) │
│ client.portal.create({...}) │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 2. 设计门户组件 │
│ client.portal.update({formData: {...}}) │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 3. 创建门户管理配置 │
│ client.portal.create_manage({...}) │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 4. 发布门户 │
│ client.portal.release(portal_id, {...}) │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 5. 设置默认门户 (可选) │
│ client.portal.set_default(portal_id) │
└─────────────────────────────────────────────────────────┘
代码示例
基本发布流程
import json
from aibridge import JNPFClient
client = JNPFClient(base_url="http://localhost:30000", app_code="myapp")
client.login("admin", password)
system_id = "your_system_id"
# 1. 创建门户
portal = client.portal.create({
"fullName": "销售数据看板",
"enCode": "sales_dashboard",
"type": 0, # 0=页面设计
"systemId": system_id,
"state": 1
})
portal_id = portal.data.id
print(f"门户创建成功: {portal_id}")
# 2. 设计门户组件
layout_config = {
"layoutId": 100,
"layout": [
{
"jnpfKey": "dataBoard",
"title": "关键指标",
"x": 0, "y": 0, "w": 12, "h": 4,
"option": {
"styleType": 1,
"rowNumber": 4,
"defaultValue": [
{"fullName": "今日销售额", "num": 125000, "unit": "元",
"icon": "icon-ym icon-ym-wf-incomeRecognition"},
{"fullName": "新增客户", "num": 23, "unit": "个",
"icon": "icon-ym icon-ym-wf-contractApproval"}
]
}
},
{
"jnpfKey": "barChart",
"title": "月度销售趋势",
"x": 0, "y": 4, "w": 6, "h": 8,
"dataType": "dynamic",
"propsApi": "di_xxx", # 数据接口ID
"mappingConfig": [
{"field": "系列", "value": ""},
{"field": "维度", "value": "month"},
{"field": "数值", "value": "amount"}
]
}
]
}
client.portal.update({
"id": portal_id,
"formData": json.dumps(layout_config)
})
print("门户组件更新成功")
# 3. 创建门户管理配置
manage = client.portal.create_manage({
"portalId": portal_id,
"systemId": system_id,
"homeShow": 1,
"defaultPortal": 1,
"sort": 1,
"enabled": 1
})
print(f"门户管理创建成功: {manage.data.id}")
# 4. 发布门户
client.portal.release(portal_id, {"systemId": system_id})
print("门户发布成功")
# 5. 设置默认门户
client.portal.set_default(portal_id)
print("默认门户设置成功")
发布配置参数
release 方法参数
client.portal.release(portal_id, {
"systemId": "system_xxx" # 目标系统ID
})
platformRelease 字段
发布时会在 base_portal 的 platformRelease 字段存储:
{"pc": 1, "app": 1}
| 平台 | 值 | 说明 |
|---|---|---|
| pc | 0/1 | 是否发布PC端 |
| app | 0/1 | 是否发布APP端 |
发布校验
发布前可使用 get_system_filter 检查目标系统是否可用:
# 获取可发布到的应用列表
resp = client.portal.get_system_filter({"systemId": "system_xxx"}, portal_id)
print(resp.data)
回滚操作
取消发布
发布后的门户不会自动取消,如需更新:
# 1. 修改设计
client.portal.update({
"id": portal_id,
"formData": json.dumps(new_config)
})
# 2. 重新发布
client.portal.release(portal_id, {"systemId": "system_xxx"})
常见问题
Q: 发布后不显示?
- 检查门户管理配置是否存在
- 确认
homeShow和enabled为 1 - 检查
set_default是否设置正确 - 确认用户有权限访问该门户
Q: 发布失败?
- 检查 systemId 是否正确
- 使用
get_system_filter验证目标系统 - 查看后端日志
log/jnpf-java-boot/log_error.log
Q: 如何更新已发布的门户?
不需要取消发布,直接修改 designData 后重新 release 即可:
# 修改设计
client.portal.update({...})
# 重新发布
client.portal.release(portal_id, {...})