fix: open_tab 同步切换+高亮,content 异步加载避免 401 登录框阻塞

This commit is contained in:
p 2026-08-14 17:02:23 +08:00
parent a7f39d9ea0
commit 5befd51c26

View File

@ -11,9 +11,21 @@
this.toolbar.createTool(desc);
};
// 动态打开 tab已存在opts.items 同名)则切换,不存在则新增
bricks.TabPanel.prototype.open_tab = async function(desc){
// 1. 已存在判断opts.items 里找同名(不用 content_buffer因 content 可能构建失败)
// 异步加载 tab 的 content不阻塞 open_tab401 会触发登录框,等登录后重试)
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<this.opts.items.length;i++){
if (this.opts.items[i].name === desc.name){ existing = this.opts.items[i]; break; }
@ -22,27 +34,19 @@
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);
else this._load_tab_content(desc);
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);
// 高亮新 tab 按钮do_handle 会 select_item + set active
// show_tabcontent 因 cur_tab_name 已设为 desc.name 而直接 return不会二次切换
if (this.toolbar && this.toolbar.click) this.toolbar.click(desc.name);
this._load_tab_content(desc);
};
// 修复 show_tabcontent 的 bugcur_tab_name 赋值用了未定义变量 name