当前位置: 首页 > 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.jsqmd.com/news/22069/

相关文章:

  • 2025 年不锈钢方管制造厂家最新推荐排行榜:权威测评选出高性能可靠性优质品牌榜单不锈钢矩形管/不锈钢管材/不锈钢异行管/不锈钢毛细管公司推荐
  • 2025年上海机床CE认证公司权威推荐榜单:国外CE认证/快速CE认证/充电桩CE认证源头公司精选
  • 基于Langgraph+Langchain框架实现的旅行规划助手
  • 上古真经:【人不为己,天诛地灭,应该为:人不自指,天诛地灭】
  • 实用指南:【AI入门课程】2、AI 的载体 —— 智能硬件
  • 实用指南:JavaScript继承详讲
  • 一文读懂x402 协议
  • 2025年防水膜厂家推荐排行榜,防水透气膜,防水膜材料,喇叭防水膜,防水网,手机防水膜,咪头防水网,耐高温防水膜公司精选
  • 2025年摩托车厂家权威推荐榜:覆盖街车、跑车、巡航车、越野车的最新选购指南及品牌实力解析
  • 2025年摩托车/机车厂家权威推荐榜:专业制造工艺与卓越性能口碑之选,覆盖街车、跑车、巡航车型的源头厂家深度解析
  • dell服务器SD卡mirror的设置
  • 2025年冷水机/冷冻机/冰水机厂家权威推荐榜:工业制冷设备实力解析与高效节能选购指南
  • 2025年英语学习机推荐:小初高提分路径与主流选择指南
  • 2025年英语学习机推荐:十大知名品牌排行榜与评测报告
  • 2025年英语学习机推荐:市场报告级评测榜单新鲜出炉
  • 2025年英语学习机推荐:主流品牌对比排行榜与避坑指南
  • 2025年暖风机口碑排行榜:五款主流机型对比与避坑指南
  • 深入解析:LeetCode 390 消除游戏
  • 2025年暖风机评测:五款口碑机型横向对比与推荐
  • 感知节点@8@ ESP32+arduino+ 第六个程序 读取射频卡卡号
  • 一个关于cos的极限
  • Ai元人文:共识锚定
  • QEMU 建模硬件
  • P14304 【MX-J27-T1】分块
  • 实现安卓scrollview里的多个按钮实现的每个按钮单选功能
  • ABP - 懒加载 [ILazyServiceProvider、DefaultLazyServiceProvider、LazyServiceProvider]
  • 三角函数的2倍角公式
  • FFmpeg开发笔记(八十五)基于PyQt和FFmpeg的开源视频剪辑器OpenShot
  • 2025年工业风扇厂家权威推荐榜:直流风扇、显卡散热风扇、一体机风扇、轴流风扇及散热风扇专业选购指南
  • 2025年除尘设备厂家权威推荐榜:除尘器/脉冲除尘器/中央脉冲除尘器/工业除尘器源头企业综合测评与选购指南