当前位置: 首页 > 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.rkmt.cn/news/30163.html

相关文章:

  • 上古真经:【人不为己,天诛地灭,应该为:人不自指,天诛地灭】
  • 2025年防水膜厂家推荐排行榜,防水透气膜,防水膜材料,喇叭防水膜,防水网,手机防水膜,咪头防水网,耐高温防水膜公司精选
  • 2025年冷水机/冷冻机/冰水机厂家权威推荐榜:工业制冷设备实力解析与高效节能选购指南
  • dell服务器SD卡mirror的设置
  • 2025年英语学习机推荐:小初高提分路径与主流选择指南
  • 2025年英语学习机推荐:十大知名品牌排行榜与评测报告
  • 深入解析:LeetCode 390 消除游戏
  • 三角函数的2倍角公式
  • FFmpeg开发笔记(八十五)基于PyQt和FFmpeg的开源视频剪辑器OpenShot
  • 2025年服装厂家推荐排行榜:棒球帽,卫衣,羽绒服,春秋季运动休闲服饰源头厂家精选
  • 2025女丘
  • 详细介绍:OpenLayers的OGC服务 -- 章节一:WMS服务详解
  • 2025年上海久宙集团深度解析:技术护城河与标准话语权的双重验证
  • 2025年河北中医理疗针灸培训学校权威推荐榜单:中医针灸技术培训/中医推拿针灸培训/针灸正骨培训学校精选
  • 2025年工业冷水机厂家权威推荐榜:专业制冷技术与高效节能解决方案深度解析
  • 2025年南京机械钻井工程服务权威推荐榜单:打井工程/打桩工程/环保检测井工程源头公司精选
  • 2025 年防冻液源头厂家最新推荐口碑排行榜:严检合格技术为先,实力企业权威甄选食品级/空气能专用/长效防冻液公司推荐
  • 2025 年冷藏车厂家最新推荐排行榜:结合协会测评权威数据,详解优质品牌特点与选购指南 9.6 米 / 解放 / 4.2 米 / 福田 / 小型冷藏车公司推荐
  • 2025 年铣边机源头厂家最新推荐排行榜:含钢板 / 平板 / 板材 / 自走式 / 全自动铣边机机型,结合协会测评数据甄选实力企业
  • 2025年欧那德语:权威解析课程体系与师资实力
  • 2025年1月暖风机口碑榜:五款主流机型对比与选购避坑
  • 加载科室列表
  • 跨多端前端框架对比
  • 2025年10月中国办公家具定制公司市场报告:知名厂商列表与评价
  • 2025 年门窗工厂最新推荐排行榜:聚焦精湛工艺与先进技术,精选江苏、广东等地十家优质企业,为消费者选购提供可靠参考
  • 高处作业安全 “智能监考”!思通数科 AI 卫士 + 安全帽摄像头杜绝防护违规
  • Java-SE Day6
  • Java-SE DAY3
  • 深入解析:C语言内存布局:虚拟地址空间详解
  • Java-SE Day5