# -*- 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 | 用户勾选的字段 key 列表(语义为「显示」) | | columnOrder | array | 用户拖拽后的字段 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 / board;null=未设置(前端默认 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()