# 使用示例 ## 示例 1: 创建带图表的门户 ### 目标 创建一个销售数据看板,包含数据面板和柱状图。 ```python import json from aibridge import JNPFClient client = JNPFClient(base_url="http://localhost:30000", app_code="sales") client.login("admin", password) system_id = "your_system_id" # 1. 创建门户 portal = client.portal.create({ "fullName": "销售数据看板", "enCode": "sales_dashboard", "type": 0, "systemId": system_id, "state": 1 }) portal_id = portal.data.id # 2. 配置组件 config = { "layoutId": 100, "layout": [ { "jnpfKey": "dataBoard", "title": "销售概览", "x": 0, "y": 0, "w": 12, "h": 4, "option": { "styleType": 1, "rowNumber": 4, "defaultValue": [ {"fullName": "今日销售额", "unit": "元", "num": 125000, "icon": "icon-ym icon-ym-wf-incomeRecognition", "iconColor": "rgb(255, 139, 88)"}, {"fullName": "新增客户", "unit": "个", "num": 23, "icon": "icon-ym icon-ym-wf-contractApproval", "iconColor": "rgb(123, 26, 225)"}, {"fullName": "新增商机", "unit": "个", "num": 15, "icon": "icon-ym icon-ym-wf-outgoingApply", "iconColor": "rgb(74, 184, 255)"}, {"fullName": "合同金额", "unit": "元", "num": 856000, "icon": "icon-ym icon-ym-wf-payDistribution", "iconColor": "rgb(252, 91, 135)"} ] } }, { "jnpfKey": "barChart", "title": "月度销售趋势", "x": 0, "y": 4, "w": 6, "h": 8, "dataType": "dynamic", "propsApi": "di_sales_monthly", # 数据接口ID "mappingConfig": [ {"field": "系列", "value": ""}, {"field": "维度", "value": "month"}, {"field": "数值", "value": "amount"} ] }, { "jnpfKey": "pieChart", "title": "产品分类占比", "x": 6, "y": 4, "w": 6, "h": 8, "dataType": "dynamic", "propsApi": "di_sales_category", "mappingConfig": [ {"field": "系列", "value": ""}, {"field": "维度", "value": "category"}, {"field": "数值", "value": "amount"} ] } ] } client.portal.update({ "id": portal_id, "formData": json.dumps(config) }) # 3. 发布 client.portal.release(portal_id, {"systemId": system_id}) print(f"销售看板创建成功: {portal_id}") ``` --- ## 示例 2: 创建流程门户 ### 目标 创建展示流程待办事项的门户。 ```python import json # 创建流程门户 portal = client.portal.create({ "fullName": "流程工作台", "enCode": "flow_workbench", "type": 0, "systemId": system_id }) portal_id = portal.data.id config = { "layoutId": 100, "layout": [ { "jnpfKey": "todo", "title": "我的流程", "x": 0, "y": 0, "w": 12, "h": 4, "option": { "styleType": 1, "defaultValue": [ {"fullName": "流程待签", "id": "flowToSign", "urlAddress": "/workFlow/flowToSign", "icon": "icon-ym icon-ym-flowToSign", "iconBgColor": "#1997f4"}, {"fullName": "流程待办", "id": "flowTodo", "urlAddress": "/workFlow/flowTodo", "icon": "icon-ym icon-ym-flowTodo", "iconBgColor": "#f29700"}, {"fullName": "流程在办", "id": "flowDoing", "urlAddress": "/workFlow/flowDoing", "icon": "icon-ym icon-ym-flowDoing", "iconBgColor": "#495dfd"}, {"fullName": "流程已办", "id": "flowDone", "urlAddress": "/workFlow/flowDone", "icon": "icon-ym icon-ym-flowDone", "iconBgColor": "#7b1ae1"} ], "rowNumber": 4 } }, { "jnpfKey": "todoList", "title": "待签事项", "type": 0, "x": 0, "y": 4, "w": 6, "h": 7 }, { "jnpfKey": "todoList", "title": "待办事项", "type": 1, "x": 6, "y": 4, "w": 6, "h": 7 } ] } client.portal.update({ "id": portal_id, "formData": json.dumps(config) }) client.portal.release(portal_id, {"systemId": system_id}) ``` --- ## 示例 3: 创建带筛选的图表门户 ### 目标 创建支持筛选的图表看板。 ```python import json portal = client.portal.create({ "fullName": "人才信息看板", "enCode": "talent_dashboard", "type": 0, "systemId": system_id }) portal_id = portal.data.id config = { "layoutId": 100, "layout": [ { "jnpfKey": "filter", "title": "筛选", "x": 0, "y": 0, "w": 12, "h": 3, "option": { "showActionButtonGroup": True, "colCount": 12, "filterList": [ {"id": "keyWord", "fullName": "关键词", "sourceType": 2, "defaultValue": ""}, {"id": "department", "fullName": "部门", "sourceType": 1, "filterInfo": [], "defaultValue": ""} ] } }, { "jnpfKey": "tableList", "title": "人才列表", "x": 0, "y": 3, "w": 6, "h": 8, "dataType": "dynamic", "propsApi": "di_talent_list" }, { "jnpfKey": "barChart", "title": "年龄分布", "x": 6, "y": 3, "w": 6, "h": 8, "dataType": "dynamic", "propsApi": "di_talent_age" } ] } client.portal.update({"id": portal_id, "formData": json.dumps(config)}) client.portal.release(portal_id, {"systemId": system_id}) ``` --- ## 示例 4: 获取并复制门户 ```python # 获取现有门户 portal = client.portal.get_info("584307823228223493") print(f"原始门户: {portal.data.fullName}") # 复制门户 copy = client.portal.copy("584307823228223493") new_id = copy.data.id # 修改名称 client.portal.update({ "id": new_id, "fullName": "销售看板(副本)" }) print(f"复制成功: {new_id}") ``` --- ## 示例 5: 获取门户展示数据 ```python # 获取门户展示数据(含权限判断) resp = client.portal.get_auth_portal("584307823228223493", {"platform": "Web"}) print(f"门户数据: {resp.data}") ``` --- ## 示例 6: 门户导出导入 ```python # 导出门户 export_data = client.portal.export_portal("584307823228223493") print(export_data.data) # 在其他环境导入 (通过其他系统API) # POST /api/visualdev/Portal/Actions/Import ``` --- ## 示例 7: 获取通知公告 ```python # 获取通知公告 notice = client.portal.get_notice_list({"size": 5}) print(f"公告列表: {notice.data}") # 获取未读邮件 email = client.portal.get_email_list() print(f"未读邮件: {email.data}") ``` --- ## 示例 8: 获取地图数据 ```python # 获取全国省市区 atlas = client.portal.get_atlas() print(f"省市区数据: {atlas.data}") # 获取地图JSON map_data = client.portal.get_map_data({"code": "100000"}) print(f"地图JSON: {map_data.data}") ``` --- ## 示例 9: 完整的多平台发布 ```python import json portal = client.portal.create({ "fullName": "双平台门户", "enCode": "dual_portal", "type": 0, "systemId": system_id }) portal_id = portal.data.id # PC端配置 pc_config = { "layoutId": 100, "layout": [ {"jnpfKey": "dataBoard", "title": "PC指标", "w": 12, "h": 4} ] } # 更新门户 client.portal.update({ "id": portal_id, "formData": json.dumps(pc_config) }) # 创建PC端管理 client.portal.create_manage({ "portalId": portal_id, "systemId": system_id, "platform": "Web", "homeShow": 1, "defaultPortal": 1 }) # 发布PC端 client.portal.release(portal_id, {"systemId": system_id}) # 设置默认 client.portal.set_default(portal_id) ```