You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
6.4 KiB

2 days ago
# -*- coding: utf-8 -*-
"""Generate column-preference + view-form .bru copies for A4/A3 pages."""
import os
DOCS = r"E:\code\crm-api-docs"
# page -> (dir, scopeKey, page label used in docs text)
PAGES = [
("A4 客户管理/客户总览", "customer.overview", "客户总览"),
("A4 客户管理/我的客户", "customer.mine", "我的客户"),
("A4 客户管理/客户公海", "customer.pool", "客户公海"),
("A4 客户管理/联系人", "contact.list", "联系人"),
("A3 商机管理/销售机会", "opportunity.sales", "销售机会"),
("A3 商机管理/商机管理", "opportunity.manage", "商机管理"),
("A3 商机管理/商机公海", "opportunity.public_pool", "商机公海"),
]
READ_TPL = """meta {
name: 读取列偏好
type: http
seq: 90
tags: [
generated
]
}
get {
url: {baseUrl}/api/preference/get
body: none
auth: inherit
}
params:query {
scopeKey: @SK@
}
docs {
# 读取列偏好
`GET /api/preference/get`
@PAGE@ 读取当前用户在本页列表的列偏好列表设置弹窗回显用户私有userId 取自登录态无偏好时 data null
## 请求参数
| 参数 | 类型 | 必填 | 默认 | 说明 |
| --- | --- | --- | --- | --- |
| scopeKey | string | | - | 偏好范围 code本页固定本页固定传 @SK@ |
## 请求示例
请求头Authorization: Bearer {{token}}
GET /api/preference/get?scopeKey=@SK@
## 响应 data 结构
| 字段 | 类型 | 说明 |
| --- | --- | --- |
| visibleKeys | array<string> | 用户勾选的字段 key 列表语义为显示 |
| columnOrder | array<string> | 用户拖拽后的字段 key 顺序列表 |
## 响应示例
// 示例数据字段结构以上表为准非真实返回
```json
{
"code": 0,
"success": true,
"message": "success",
"data": {
"visibleKeys": [
"customerName",
"ownerUserName"
],
"columnOrder": [
"ownerUserName",
"customerName"
]
}
}
```
}
"""
SAVE_TPL = """meta {
name: 保存列偏好
type: http
seq: 91
tags: [
generated
]
}
post {
url: {baseUrl}/api/preference/save
body: formUrlEncoded
auth: inherit
}
body:form-urlencoded {
scopeKey: @SK@
visibleKeys: customerName,ownerUserName
columnOrder: ownerUserName,customerName
}
docs {
# 保存列偏好
`POST /api/preference/save`
@PAGE@ 保存本页列表的列偏好列表设置弹窗保存显隐+顺序一次写入每菜单独立 scope互不干扰
## 请求参数
| 参数 | 类型 | 必填 | 默认 | 说明 |
| --- | --- | --- | --- | --- |
| scopeKey | string | | - | 偏好范围 code本页固定本页固定传 @SK@ |
| visibleKeys | string[] | | - | 显示字段 key 列表逗号分隔 |
| columnOrder | string[] | | - | 字段顺序列表逗号分隔 |
## 请求示例
请求头Authorization: Bearer {{token}}
Content-Type: application/x-www-form-urlencoded
POST /api/preference/save
scopeKey=@SK@&visibleKeys=customerName,ownerUserName&columnOrder=ownerUserName,customerName
## 响应 data 结构
null
## 响应示例
// 示例数据字段结构以上表为准非真实返回
```json
{
"code": 0,
"success": true,
"message": "success",
"data": null
}
```
}
"""
VF_READ_TPL = """meta {
name: 读取视图形态
type: http
seq: 92
tags: [
generated
]
}
get {
url: {baseUrl}/api/preference/view-form/get
body: none
auth: inherit
}
params:query {
scopeKey: @SK@
}
docs {
# 读取视图形态
`GET /api/preference/view-form/get`
@PAGE@ 读取当前用户在本页的视图形态列表页形态切换的跨会话记忆null=未设置前端默认 list平台白名单校验 list/split/board
## 请求参数
| 参数 | 类型 | 必填 | 默认 | 说明 |
| --- | --- | --- | --- | --- |
| scopeKey | string | | - | 偏好范围 code本页固定本页固定传 @SK@ |
## 请求示例
请求头Authorization: Bearer {{token}}
GET /api/preference/view-form/get?scopeKey=@SK@
## 响应 data 结构
| 字段 | 类型 | 说明 |
| --- | --- | --- |
| (data) | string | 视图形态list / split / boardnull=未设置前端默认 list |
## 响应示例
// 示例数据字段结构以上表为准非真实返回
```json
{
"code": 0,
"success": true,
"message": "success",
"data": "list"
}
```
}
"""
VF_SAVE_TPL = """meta {
name: 保存视图形态
type: http
seq: 93
tags: [
generated
]
}
post {
url: {baseUrl}/api/preference/view-form/save
body: formUrlEncoded
auth: inherit
}
body:form-urlencoded {
scopeKey: @SK@
viewForm: list
}
docs {
# 保存视图形态
`POST /api/preference/view-form/save`
@PAGE@ 保存本页的视图形态list/split/board一次写入平台白名单校验非法值报 68001用户私有userId 取自登录态
## 请求参数
| 参数 | 类型 | 必填 | 默认 | 说明 |
| --- | --- | --- | --- | --- |
| scopeKey | string | | - | 偏好范围 code本页固定本页固定传 @SK@ |
| viewForm | string | | - | 视图形态list/split/board白名单外 68001 |
## 请求示例
请求头Authorization: Bearer {{token}}
Content-Type: application/x-www-form-urlencoded
POST /api/preference/view-form/save
scopeKey=@SK@&viewForm=list
## 响应 data 结构
null
## 响应示例
// 示例数据字段结构以上表为准非真实返回
```json
{
"code": 0,
"success": true,
"message": "success",
"data": null
}
```
}
"""
def main():
n = 0
for d, sk, page in PAGES:
pdir = os.path.join(DOCS, d.replace("/", os.sep))
os.makedirs(pdir, exist_ok=True)
files = [
("读取列偏好.bru", READ_TPL),
("保存列偏好.bru", SAVE_TPL),
("读取视图形态.bru", VF_READ_TPL),
("保存视图形态.bru", VF_SAVE_TPL),
]
for fn, tpl in files:
path = os.path.join(pdir, fn)
if os.path.exists(path):
print("SKIP exists:", d, fn)
continue
open(path, "w", encoding="utf-8", newline="").write(tpl.replace('@SK@', sk).replace('@PAGE@', page))
n += 1
print("written:", n)
if __name__ == "__main__":
main()