214 lines
4.1 KiB
Markdown
214 lines
4.1 KiB
Markdown
# 三种数据模式
|
|
|
|
## 模式总览
|
|
|
|
| 模式 | type值 | 数据表字段 | 说明 |
|
|
|------|--------|-----------|------|
|
|
| **model** | mod | formData | 模板模式,门户设计态 |
|
|
| **custom** | custom | formData | 自定义模式,用户个性化定制 |
|
|
| **release** | release | formData | 发布模式,正式版本 |
|
|
|
|
---
|
|
|
|
## 1. model (模板模式)
|
|
|
|
### 用途
|
|
门户设计的草稿状态,包含完整的组件配置。
|
|
|
|
### 创建
|
|
```python
|
|
resp = client.portal.create({
|
|
"fullName": "销售看板",
|
|
"enCode": "sales_dashboard",
|
|
"type": 0, # 0=页面设计
|
|
"systemId": "system_xxx"
|
|
})
|
|
portal_id = resp.data.id
|
|
```
|
|
|
|
### 更新
|
|
```python
|
|
client.portal.update({
|
|
"id": portal_id,
|
|
"fullName": "销售看板(更新)",
|
|
"formData": json.dumps({
|
|
"layoutId": 100,
|
|
"layout": [
|
|
{
|
|
"jnpfKey": "dataBoard",
|
|
"title": "关键指标",
|
|
"w": 12, "h": 4,
|
|
"option": {
|
|
"styleType": 1,
|
|
"defaultValue": [
|
|
{"fullName": "今日销售额", "num": 125000, "unit": "元"}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
})
|
|
})
|
|
```
|
|
|
|
### 特点
|
|
- 可反复修改
|
|
- 保存完整组件配置
|
|
- 发布前必须先设计完成
|
|
|
|
---
|
|
|
|
## 2. custom (自定义模式)
|
|
|
|
### 用途
|
|
用户个性化定制,允许用户拖拽调整自己的门户布局。
|
|
|
|
### 更新
|
|
```python
|
|
client.portal.update_custom_portal(portal_id, {
|
|
"formData": json.dumps({
|
|
"layoutId": 100,
|
|
"layout": [
|
|
# 用户自定义的布局
|
|
]
|
|
})
|
|
})
|
|
```
|
|
|
|
### 获取用户定制
|
|
```python
|
|
resp = client.portal.get_auth_portal(portal_id, {"platform": "Web"})
|
|
# 返回: custom版本(如有) > release版本
|
|
```
|
|
|
|
### 特点
|
|
- 每个用户独立一份
|
|
- 仅保存用户修改的部分
|
|
- 与 model 合并后渲染
|
|
|
|
---
|
|
|
|
## 3. release (发布模式)
|
|
|
|
### 用途
|
|
正式发布的生产版本,供最终用户访问。
|
|
|
|
### 发布
|
|
```python
|
|
resp = client.portal.release(portal_id, {
|
|
"systemId": "system_xxx"
|
|
})
|
|
```
|
|
|
|
### 获取已发布版本
|
|
```python
|
|
resp = client.portal.get_auth_portal(portal_id, {"platform": "Web"})
|
|
# 返回: custom版本(优先) > release版本
|
|
```
|
|
|
|
### 特点
|
|
- 只读,不可直接修改
|
|
- 用户看到的最终版本
|
|
- 支持回滚到 model
|
|
|
|
---
|
|
|
|
## 数据流转
|
|
|
|
```
|
|
[创建门户]
|
|
│
|
|
▼
|
|
[model - 设计态]
|
|
│ update()
|
|
│ create_form_data()
|
|
▼
|
|
[发布 release]
|
|
│ release()
|
|
▼
|
|
[release - 发布态]
|
|
│
|
|
▼
|
|
[用户访问 get_auth_portal]
|
|
│
|
|
▼
|
|
[用户自定义 custom]
|
|
│ update_custom_portal()
|
|
▼
|
|
[custom - 用户定制]
|
|
```
|
|
|
|
---
|
|
|
|
## 渲染优先级
|
|
|
|
当用户访问门户时,系统按以下顺序查找可用版本:
|
|
|
|
```
|
|
1. custom (用户自定义) - 最高优先
|
|
└─ 如果用户有定制,返回用户定制版本
|
|
|
|
2. release (已发布版本)
|
|
└─ 如果没有定制,返回发布版本
|
|
|
|
3. model (设计模板) - 最低优先
|
|
└─ 如果没有发布,返回设计模板
|
|
```
|
|
|
|
---
|
|
|
|
## 代码示例
|
|
|
|
### 完整发布流程
|
|
|
|
```python
|
|
import json
|
|
|
|
# 1. 创建门户 (model模式)
|
|
portal = client.portal.create({
|
|
"fullName": "销售看板",
|
|
"enCode": "sales_dashboard",
|
|
"type": 0,
|
|
"systemId": "system_xxx"
|
|
})
|
|
portal_id = portal.data.id
|
|
|
|
# 2. 更新门户组件 (model)
|
|
client.portal.update({
|
|
"id": portal_id,
|
|
"formData": json.dumps({
|
|
"layoutId": 100,
|
|
"layout": [
|
|
{"jnpfKey": "dataBoard", "title": "指标", "w": 12, "h": 4}
|
|
]
|
|
})
|
|
})
|
|
|
|
# 3. 创建门户管理
|
|
client.portal.create_manage({
|
|
"portalId": portal_id,
|
|
"systemId": "system_xxx",
|
|
"homeShow": 1,
|
|
"defaultPortal": 1
|
|
})
|
|
|
|
# 4. 发布 (release模式)
|
|
client.portal.release(portal_id, {"systemId": "system_xxx"})
|
|
|
|
# 5. 用户访问时 (自动返回 custom > release)
|
|
resp = client.portal.get_auth_portal(portal_id, {"platform": "Web"})
|
|
```
|
|
|
|
### 用户自定义布局
|
|
|
|
```python
|
|
# 用户调整布局后保存
|
|
client.portal.update_custom_portal(portal_id, {
|
|
"formData": json.dumps({
|
|
"layoutId": 101,
|
|
"layout": [
|
|
# 新的布局
|
|
]
|
|
})
|
|
})
|
|
```
|