pipeline-app/wwwroot/index_tab.js

58 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pipeline-app 首页 TabPanel 动态 tab 支持
// 由 HTML shell 自动加载(configuredServer.get_js_files 收集 wwwroot 下 .js)
(function(){
if (typeof bricks === 'undefined' || !bricks.TabPanel) return;
if (bricks.TabPanel.prototype._dyn_patched) return;
bricks.TabPanel.prototype._dyn_patched = true;
// 动态打开 tab:已存在(opts.items 同名)则切换,不存在则新增
bricks.TabPanel.prototype.open_tab = async function(desc){
// 1. 已存在判断:opts.items 里找同名(不用 content_buffer,因 content 可能构建失败)
var existing = null;
for (var i=0;i<this.opts.items.length;i++){
if (this.opts.items[i].name === desc.name){ existing = this.opts.items[i]; break; }
}
if (existing){
if (desc.name !== this.cur_tab_name){
this.cur_tab_name = desc.name;
var w = this.content_buffer[desc.name];
if (!w){
var c = existing.content || {"widgettype":"urlwidget","options":{"url":existing.url}};
w = await bricks.widgetBuild(c, this, {});
if (w) this.content_buffer[desc.name] = w;
}
if (w) this.switch_content(w);
if (this.toolbar && this.toolbar.click) this.toolbar.click(desc.name);
}
return;
}
// 2. 新增
desc.content = desc.content || {"widgettype":"urlwidget","options":{"url":desc.url}};
this.opts.items.push(desc);
if (this.add_tab) this.add_tab(desc);
var w = await bricks.widgetBuild(desc.content, this, {});
this.content_buffer[desc.name] = w; // 即使 null 也记录(标记已存在,避免重复新增)
this.cur_tab_name = desc.name;
if (w) this.switch_content(w);
};
// 修复 show_tabcontent 的 bug(cur_tab_name 赋值用了未定义变量 name)
bricks.TabPanel.prototype.show_tabcontent = async function(event){
var tdesc = event.params;
if (tdesc.name === this.cur_tab_name) return;
var items = this.opts.items;
for (var i=0;i<items.length;i++){
if (tdesc.name === items[i].name){
var w = this.content_buffer[tdesc.name];
if (!w){
var c = items[i].content || {"widgettype":"urlwidget","options":{"url":items[i].url}};
w = await bricks.widgetBuild(c, this, {});
if (w) this.content_buffer[tdesc.name] = w;
}
if (w){ this.cur_tab_name = tdesc.name; this.switch_content(w); }
return;
}
}
};
})();