Solve the problem that when xadmin.add_tab adds a new tab page, the entire page needs to be refreshed to display the problem

Solve the problem that when xadmin.add_tab adds a new tab page, the entire page needs to be refreshed to display the problem

Recently, I am writing a simple crawler scheduling management background that sends and executes commands through ssh. Django is used in the background and xadmin is used in the front end. Since the front end is not familiar with it, various problems have appeared (make a complaint, the front end is really disgusting)

I encountered such a problem. When using xadmin.add_tab to open a new tab in the tab page, there is no response. After refreshing the entire page (not refreshing the tab), the newly opened tab will appear. This problem needs to be modified In xadmin.js, add the following code in the first function which is ;!function (win)

//在xadmin.js中;!function (win)中添加
 Xadmin.prototype.add_tab_f = function (title,url,is_refresh) {
    
    
    var element=parent.layui.element;
    var id = md5(url);
//防止标签重复打开
    for (var i = 0; i < parent.$('.x-iframe').length; i++) {
    
    
        if(parent.$('.x-iframe').eq(i).attr('tab-id')==id){
    
    
            element.tabChange('xbs_tab', id);
            if(is_refresh)
                parent.$('.x-iframe').eq(i).attr("src",parent.$('.x-iframe').eq(i).attr('src'));
            return;
        }
    };
    element.tabAdd('xbs_tab', {
    
    
        title: title
        ,content: '<iframe tab-id="'+id+'" frameborder="0" src="'+url+'" scrolling="yes" class="x-iframe"></iframe>'
        ,id: id
    });
    element.tabChange('xbs_tab', id);
}

Then use the method we added add_tab_f to use

 xadmin.add_tab_f("标签名", 'url' )

xadmin uses layui, you can see the development and use documents

In addition, when I encountered a front-end problem at the time, I asked the front-end boss among my friends, and crazily complained that I used such an old thing.

Guess you like

Origin blog.csdn.net/L_W_D_/article/details/118068504