fix: open_tab 扩展改用独立 .js 文件(HTML shell 自动加载)

This commit is contained in:
p 2026-08-14 16:14:42 +08:00
parent f5ac6e38f4
commit 852d0886e5
2 changed files with 46 additions and 8 deletions

View File

@ -7,14 +7,6 @@
"padding": "0"
},
"subwidgets": [
{
"widgettype": "Html",
"options": {
"html": "<script>\n(function(){\n if (bricks.TabPanel.prototype._dyn_patched) return;\n bricks.TabPanel.prototype._dyn_patched = true;\n bricks.TabPanel.prototype.open_tab = async function(desc){\n if (this.content_buffer.hasOwnProperty(desc.name)){\n if (desc.name !== this.cur_tab_name){\n this.cur_tab_name = desc.name;\n this.switch_content(this.content_buffer[desc.name]);\n if (this.toolbar && this.toolbar.click) this.toolbar.click(desc.name);\n }\n return;\n }\n desc.content = desc.content || {\"widgettype\":\"urlwidget\",\"options\":{\"url\":desc.url}};\n this.opts.items.push(desc);\n if (this.add_tab) this.add_tab(desc);\n var w = await bricks.widgetBuild(desc.content, this, {});\n if (!w) return;\n this.content_buffer[desc.name] = w;\n this.cur_tab_name = desc.name;\n this.switch_content(w);\n };\n bricks.TabPanel.prototype.show_tabcontent = async function(event){\n var tdesc = event.params;\n if (tdesc.name === this.cur_tab_name) return;\n var items = this.opts.items;\n for (var i=0;i<items.length;i++){\n if (tdesc.name === items[i].name){\n var w = this.content_buffer[tdesc.name];\n if (!w){\n var c = items[i].content || {\"widgettype\":\"urlwidget\",\"options\":{\"url\":items[i].url}};\n w = await bricks.widgetBuild(c, this, {});\n if (w) this.content_buffer[tdesc.name] = w;\n }\n if (w){ this.cur_tab_name = tdesc.name; this.switch_content(w); }\n return;\n }\n }\n };\n})();\n<\\/script>",
"width": "0",
"height": "0"
}
},
{
"widgettype": "HBox",
"options": {

46
wwwroot/index_tab.js Normal file
View File

@ -0,0 +1,46 @@
// 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已存在则切换不存在则新增
bricks.TabPanel.prototype.open_tab = async function(desc){
if (this.content_buffer.hasOwnProperty(desc.name)){
if (desc.name !== this.cur_tab_name){
this.cur_tab_name = desc.name;
this.switch_content(this.content_buffer[desc.name]);
if (this.toolbar && this.toolbar.click) this.toolbar.click(desc.name);
}
return;
}
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, {});
if (!w) return;
this.content_buffer[desc.name] = w;
this.cur_tab_name = desc.name;
this.switch_content(w);
};
// 修复 show_tabcontent 的 bugcur_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;
}
}
};
})();