麦粉社区
>
帖子详情

想给弹窗传递参数

电子表格软件 发表于 1 小时前
发表于 1 小时前

 


 


 


// 参数列后添加多个按钮(导入 + 导出)
function addButtons(spreadsheetReport){
    var paramTable = spreadsheetReport.paramPanelObj.layoutTable;
    var i, j, cell, lastCell;


    for (i = 0; i < paramTable.rows.length; i++){
        cell = paramTable.rows.insertCell(-1);
        var tr = paramTable.rows;
        if (i == paramTable.rows.length - 1){
            for (j = tr.cells.length - 1; j >= 0; j--){
                var td = tr.cells[j];
                if(td.innerHTML === ""){
                    lastCell = td;
                } else {
                    break;
                }
            }
        }
    }


    if(!spreadsheetReport._newBtn1){
        
        // 按钮1:弹窗 → E1单元格 作为ID参数传递
        var outportButton = document.createElement("button");
        outportButton.type = "button";
        outportButton.innerText = "弹窗";
        outportButton.title = "弹窗";
        outportButton.className = "queryview-toolbar-button";
        outportButton.style.background = "url(img/button/button/bgicon_add.png) no-repeat left center";
        outportButton.style.border = "1px solid #A1ACB9";
        outportButton.style.width = "90px";
        outportButton.style.height = "23px";
        outportButton.style.padding = "2px 0 0 0";
        outportButton.style.margin = "0 9px 0 10px";
        
        var newBtn1 = lastCell.appendChild(outportButton);
        // ===================== 核心:E1 传参给弹窗 =====================
        spreadsheetReport.addListener(outportButton, "click", function(){
            try {
                // ✅ 正确:获取 E1 单元格
                var cellE1 = spreadsheetReport.getCell("E1");
                var val_E1 = cellE1.textContent ? cellE1.textContent.trim() : "";


                // 构造参数:把 E1 的值 传给弹窗的 ID 参数
                var paramsInfo = [];
                paramsInfo.push({
                    name: "id-1776337685173",
                    alias: "id",
                    value: val_E1,
                    displayValue: val_E1
                });


                // 编码 + 拼接URL
                var paramJson = lang.toJSONString(paramsInfo);
                var encParams = encodeURIComponent(paramJson);


                var url = "https://decsmartbi.cloud.smartbi.com.cn/smartbi/vision/openresource.jsp"
                        + "?resid=I0bb87da4c7fab000"
                        + "¶msInfo=" + encParams
                        + "&refresh=true";


                // 打开弹窗
                openInDialog(url);
            } catch (e) {
                alert("参数传递失败:" + e.message);
            }
        }, spreadsheetReport);
        
        spreadsheetReport._newBtn1 = newBtn1;
    }
}
// 声明回调函数 刷新页面数据
function dialogCallback(ret) {



     window.sp.doRefresh();



 }


// ===================== 弹窗代码 =====================
function openInDialog(url) {
    try {
        var dialogFactory = jsloader.resolve("freequery.dialog.dialogFactory");
        var dialogConfig = {
            title: "弹窗内容",
            size: dialogFactory.size.LARGE,
            dialogType: "modeless",
            fullName: "freequery.dialog.BaseDialogEx",
            closeBeforeCallback: true,
            width: 500,
            height: 400
        };
        dialogFactory.showDialog(dialogConfig, {},dialogCallback); //  添加回调函数
        setTimeout(function() {
            var elem = window.dialog.dialogBody;
            var btnOK = window.dialog.btnOK;
            var btnCancel = window.dialog.btnCancel;


            if (btnOK) btnOK.style.display = 'none';
            if (btnCancel) {
                btnCancel.value = "关闭";
                btnCancel.innerHTML = "关闭";
                btnCancel.textContent = "关闭";
            }


            if (elem) elem.innerHTML = '';
        }, 300);
    } catch (error) {
        alert("无法打开对话框: " + error.message);
    }
}


// ===================== 主入口 =====================
function main(spreadsheetReport, isAjaxRefreshCallback){
    addButtons(spreadsheetReport);
    window.sp = spreadsheetReport; // 声明全局变量
}


高级模式
B Color Image Link Quote Code Smilies
您需要登录后才可以回帖 登录 | 立即注册

0回帖数 0关注人数 9浏览人数
最后回复于:1 小时前

社区

指南

AI

搜索

快速回复 返回顶部 返回列表