当前位置: 首页 > news >正文

FR报表中调用py接口返回数据成功后,刷新报表报表

FR报表中调用py接口返回数据成功后,刷新报表报表

有时候需要调用py接口处理数据后,拿到返回值,再填入报表中,下面的具体的代码实现方案(已测可用)

方式1 基础方式,用FR自己的接口提示数据加载中

点击查询,提示加载中(加载提示一定时间后会自动消失)。

image

查询结束,提示数据查询完成。

image

方式1 代码如下:

var kongjian = _g().getParameterContainer().getWidgetByName("kongjian")
//kongjian.setValue("1")
// 显示加载提示
function showLoading() {// 使用帆软内置的加载提示FR.Msg.toast('加载中...' ); 
}// 加载结束提示
function showEnding() {// 帆软内置的结束提示//FR.Msg.hideToast();FR.Msg.toast('数据查询完成', 'loading', 0);
}// 调用Python接口并处理返回结果
function callPythonAPIAndRefresh() {// 显示加载showLoading();// 调用Python接口 $.ajax({url: 'http://localhost:8000/api/v1/calculate',type: 'POST',contentType: 'application/json',timeout: 30000, // 添加超时设置,单位毫秒(30秒)data: JSON.stringify({start_date: "2024-01-02",end_date: "2024-01-31",security_codes: "000001,600036,128013"}), success: function(response) {console.log('✅ 请求成功');//console.log('响应数据:', response);if (response) {kongjian.setValue(JSON.stringify(response.data));// 加载结束showEnding();// 刷新报表_g().parameterCommit();} else { FR.Msg.alert('提示', response.message || '操作失败');}},error: function(xhr, status, error) {console.error('❌ 请求失败:', status, error);console.error('接口调用失败:', error); if (status === 'timeout') {FR.Msg.alert('错误', '请求超时,请检查网络连接或稍后重试');} else {FR.Msg.alert('错误', '接口调用失败: ' + error);}}}); }// 绑定按钮点击事件或其它触发方式
// 例如在按钮的点击事件中调用:
callPythonAPIAndRefresh();

方式2 升级方式,增加转圈加载样式

点击查询,提示加载中(加载转圈圈一直持续)。

image

查询结束,提示消失(成功或者接口调用失败、超时,加载动画消失)

image

方式2 代码如下:

// 添加CSS样式
const style = document.createElement('style');
style.textContent = `.custom-loader {position: fixed;top: 0;left: 0;width: 100%;height: 100%;/* background-color: rgba(0, 0, 0, 0.7); */display: flex;justify-content: center;align-items: center;z-index: 9999;flex-direction: column;}.loader-spinner {width: 60px;height: 60px;border: 5px solid rgba(255, 255, 255, 0.3);border-radius: 50%;border-top-color: #3498db;animation: spin 1s ease-in-out infinite;}.loader-text {color: #0083dc;margin-top: 15px;font-size: 18px;font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;}@keyframes spin {to { transform: rotate(360deg); }}.hidden {display: none;}
`;document.head.appendChild(style);// 显示自定义加载动画
function showCustomLoader(message) {// 如果已经存在,先移除hideCustomLoader();// 创建加载元素const loader = document.createElement('div');loader.className = 'custom-loader';loader.id = 'customLoader';loader.innerHTML = `<div class="loader-spinner"></div><div class="loader-text">${message || '加载中...'}</div>`;// 添加到页面document.body.appendChild(loader);
}// 隐藏自定义加载动画
function hideCustomLoader() {const loader = document.getElementById('customLoader');if (loader) {document.body.removeChild(loader);}
}// 在控件点击事件中调用
// showCustomLoader('数据加载中,请稍候...');// 当操作完成时调用隐藏
// hideCustomLoader();var kongjian = _g().getParameterContainer().getWidgetByName("kongjian")
//kongjian.setValue("1")
// 显示加载动画// 调用Python接口并处理返回结果
function callPythonAPIAndRefresh() {// 显示加载动画showCustomLoader('数据加载中,请稍候...');// 调用Python接口 $.ajax({url: 'http://localhost:8000/api/v1/calculate',type: 'POST',contentType: 'application/json',timeout: 30000, // 添加超时设置,单位毫秒(30秒)data: JSON.stringify({start_date: "2024-01-02",end_date: "2024-01-31",security_codes: "000001,600036,128013"}), success: function(response) {console.log('✅ 请求成功');//console.log('响应数据:', response);if (response) { kongjian.setValue(JSON.stringify(response.data));// 当操作完成时调用隐藏hideCustomLoader();	// 刷新报表_g().parameterCommit();} else { FR.Msg.alert('提示', response.message || '操作失败');}},error: function(xhr, status, error) {hideCustomLoader();	console.error('❌ 请求失败:', status, error);console.error('接口调用失败:', error); if (status === 'timeout') {FR.Msg.alert('错误', '请求超时,请检查网络连接或稍后重试');} else {FR.Msg.alert('错误', '接口调用失败: ' + error);}}}); }callPythonAPIAndRefresh();
http://www.hskmm.com/?act=detail&tid=38792

相关文章:

  • Yolo11Onnx——图像后处理
  • 【ROS2学习笔记】话题通信篇:python话题订阅与发布 - 详解
  • Aseprite:专业像素艺术与动画制作工具
  • 2025 年不锈钢方管制造厂家最新推荐排行榜:权威测评选出高性能可靠性优质品牌榜单不锈钢矩形管/不锈钢管材/不锈钢异行管/不锈钢毛细管公司推荐
  • 2025年上海机床CE认证公司权威推荐榜单:国外CE认证/快速CE认证/充电桩CE认证源头公司精选
  • 基于Langgraph+Langchain框架实现的旅行规划助手
  • 上古真经:【人不为己,天诛地灭,应该为:人不自指,天诛地灭】
  • 2025 年最新展会展台搭建设计公司推荐排行榜:结合协会测评权威数据的优质服务商甄选榜单聚焦上海/深圳/国外/海外/美国‌/法国/德国/俄罗斯等地公司推荐
  • [Bug]: Your system has an unsupported version of sqlite3. Chroma requires sqlite3 = 3.35.0
  • Linux Ubuntu / Debian / CentOS 下载编译安装最新版 SQLite3 教程
  • P14306 【MX-J27-T3】旋律
  • AI元人文:未来价值权衡的演进图景
  • 2025年电力绝缘围栏制造商权威推荐榜单:绝缘围栏/电力安全围栏/变压器围栏源头厂家精选
  • 2025年五金喷粉直销厂家权威推荐榜单:五金喷涂/喷塑处理/喷塑加工源头厂家精选
  • 责任链模式 - Higurashi
  • P3799题解(枚举)
  • 安卓无线调试
  • B3611 【模板】传递闭包
  • 感知节点@9@ ESP32+arduino+FreeRTOS 第七个程序 读取射频卡卡号
  • QEMU 实现新指令
  • 一文读懂x402 协议
  • 2025年实木家具厂家权威推荐榜:原木/全实木/北美黑胡桃/樱桃木/榫卯工艺/高端定制/全屋整装,烘干白胚木蜡油保养全流程解析
  • 2025年防水膜厂家推荐排行榜,防水透气膜,防水膜材料,喇叭防水膜,防水网,手机防水膜,咪头防水网,耐高温防水膜公司精选
  • 2025年摩托车厂家权威推荐榜:覆盖街车、跑车、巡航车、越野车的最新选购指南及品牌实力解析
  • 2025年摩托车/机车厂家权威推荐榜:专业制造工艺与卓越性能口碑之选,覆盖街车、跑车、巡航车型的源头厂家深度解析
  • 2025年冷水机/冷冻机/冰水机厂家权威推荐榜:工业制冷设备实力解析与高效节能选购指南
  • 2025年英语学习机推荐:小初高提分路径与主流选择指南
  • 2025年英语学习机推荐:十大知名品牌排行榜与评测报告
  • 2025年英语学习机推荐:市场报告级评测榜单新鲜出炉
  • 2025年英语学习机推荐:主流品牌对比排行榜与避坑指南