// pipeline-app 首页 TabPanel 动态 tab 支持
// 由 HTML shell 自动加载(configuredServer.get_js_files 收集 wwwroot 下 .js)
// 每个浏览器 tab 一个 session_id(sessionStorage 隔离),用于多 tab 项目上下文隔离
window._sid = function(){
var sid = null;
try { sid = sessionStorage.getItem('pipeline_sid'); } catch(e){}
if(!sid){ sid = 's' + Date.now().toString(36) + Math.random().toString(36).slice(2,10); try{ sessionStorage.setItem('pipeline_sid', sid); }catch(e){} }
return sid;
};
(function(){
if (typeof bricks === 'undefined' || !bricks.TabPanel) return;
if (bricks.TabPanel.prototype._dyn_patched) return;
bricks.TabPanel.prototype._dyn_patched = true;
// 修复原生 add_tab 的 bug:this.add_removeable 不存在(应为 toolbar.add_removable),
// 且 createTool 内部已调用 add_removable,这里只需创建 tool 按钮
bricks.TabPanel.prototype.add_tab = function(desc){
this.toolbar.createTool(desc);
};
// 异步加载 tab 的 content(不阻塞 open_tab;401 会触发登录框,等登录后重试)
bricks.TabPanel.prototype._load_tab_content = async function(desc){
if (this.content_buffer[desc.name]){
if (this.cur_tab_name === desc.name) this.switch_content(this.content_buffer[desc.name]);
return;
}
var w = await bricks.widgetBuild(desc.content, this, {});
this.content_buffer[desc.name] = w;
if (w && this.cur_tab_name === desc.name) this.switch_content(w);
};
// 动态打开 tab:已存在(opts.items 同名)则切换,不存在则新增。
// 同步返回:立即创建/切换 + 高亮 tab 按钮,content 交由 _load_tab_content 异步加载,
// 避免 await widgetBuild 被 401 登录框阻塞导致 tab 不切换。
bricks.TabPanel.prototype.open_tab = function(desc){
var existing = null;
for (var i=0;i