1.上传音频文件到帆软安装目录的指定环境
准备一个音频文件(如 mp3 格式),并将其放置在合适的目录。
例如:
%FR_HOME%\webapps\
webroot\help
2.点击 FVS 模板左上角「模板>页面加载结束事件」,输入以下 JavaScript 代码:
"use document";const audio = document.createElement("audio");audio.id = "audio";audio.src = "/webroot/help/音频文件.mp3"; document.body.appendChild(audio);setTimeout(function() {const table = duchamp.getWidgetByName("表格1");// 初始化上次行数let lastRowCount = 0;for(let r=1; ;r++) {if(!table.getCellValue(r,1)) break;lastRowCount++;}setInterval(() => {let currentRowCount = 0;for(let r=1; ;r++) {if(!table.getCellValue(r,1)) break;currentRowCount++;}// 核心变化:只要比上次多就提醒if(currentRowCount > lastRowCount) {audio.play();}// 关键:无论是否增加,都更新为当前值lastRowCount = currentRowCount;}, 5000);}, 1000);
扩展:
点击表格,找到相关表属性设置 ,在其右上角【交互】-【交互事件】,通过点击【添加事件】,找到初始后的JavaScript功能,进行添加相应脚本也可以实现。
3. 浏览器中设置允许播放声音
以谷歌浏览器为例:
通过【设置】- 【隐私和安全】-【网站设置】-【更多内容设置:声音】, 然后【添加】
输入需要自动播放音频的网站地址:
- 决策系统地址:
http://IP:端口/webroot/decision
- 自定义服务地址:
http://ip:端口
备注:
如果只是单纯判断表格是否有数据,可以换成以下JavaScript 代码。
"use document";const audio = document.createElement("audio");audio.id = "audio";audio.src = "/webroot/help/音频文件.mp3"; document.body.appendChild(audio);// 使用 setInterval 实现持续检测setInterval(function() {const table = duchamp.getWidgetByName("表格1");let hasData = false;// 从第二行开始检测(假设表头是第一行)for(let r=2; ;r++) { // 注意这里从2开始const cellValue = table.getCellValue(r,1);// 终止条件:遇到第一个空单元格if(!cellValue) break;// 找到有效数据立即标记hasData = true;break; // 检测到数据即可退出循环}if(hasData) {audio.play();}}, 10000);