修复table重新渲染的内存泄漏

This commit is contained in:
theluyuan 2024-10-08 16:10:23 +08:00
parent 526d1cbec1
commit c3ac588bdb
5 changed files with 51 additions and 16 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"svn.ignoreMissingSvnWarning": true
}

25
dist/layui.js vendored
View File

@ -18487,6 +18487,7 @@ layui.define('layer' , function(exports){
,contentType: false ,contentType: false
,processData: false ,processData: false
,dataType: 'json' ,dataType: 'json'
,async: false
,headers: options.headers || {} ,headers: options.headers || {}
//成功回调 //成功回调
,success: function(res){ ,success: function(res){
@ -19719,7 +19720,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
,cache: {} //数据缓存 ,cache: {} //数据缓存
,allData:[] // 全部数据 ,allData:[] // 全部数据
,index: layui.table ? (layui.table.index + 10000) : 0 ,index: layui.table ? (layui.table.index + 10000) : 0
,winResiz:[]
//设置全局项 //设置全局项
,set: function(options){ ,set: function(options){
var that = this; var that = this;
@ -20059,6 +20060,8 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
that.key = options.id || options.index; that.key = options.id || options.index;
table.allData[that.key] = options.data table.allData[that.key] = options.data
// 添加到全局渲染中为了全局resize防止内存泄漏
table.winResiz[that.key] = that
//生成替代元素 //生成替代元素
hasRender[0] && hasRender.remove(); //如果已经渲染则Rerender hasRender[0] && hasRender.remove(); //如果已经渲染则Rerender
othis.after(reElem); othis.after(reElem);
@ -21344,6 +21347,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
} }
} }
that.config.onColumnsWidth && that.config.onColumnsWidth(that.config.cols) that.config.onColumnsWidth && that.config.onColumnsWidth(that.config.cols)
if (layui.soulTable) { layui.soulTable.fixTableRemember(that.config, dict) } //拖动列宽 记忆开启
dict = {}; dict = {};
_BODY.css('cursor', ''); _BODY.css('cursor', '');
that.scrollPatch(); that.scrollPatch();
@ -21680,10 +21684,10 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
layer.close(that.tipsIndex); layer.close(that.tipsIndex);
}); });
//自适应 // //自适应
_WIN.on('resize', function(){ // _WIN.on('resize', function(){
that.resize(); // that.resize();
}); // });
}; };
//一次性事件 //一次性事件
@ -22061,6 +22065,17 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
table.init(); table.init();
}); });
$(function (){
//自适应
_WIN.on('resize', function(){
// that.resize();
for(let i in table.winResiz){
table.winResiz[i].resize()
}
})
})
exports(MOD_NAME, table); exports(MOD_NAME, table);
}); });

View File

@ -12,21 +12,23 @@
}, },
"homepage": "https://github.com/layui/layui/", "homepage": "https://github.com/layui/layui/",
"devDependencies": { "devDependencies": {
"del": "^2.2.2",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-uglify": "^3.0.2",
"gulp-clean-css": "^4.3.0", "gulp-clean-css": "^4.3.0",
"gulp-concat": "^2.6.1", "gulp-concat": "^2.6.1",
"gulp-replace": "^1.1.3",
"gulp-rename": "^2.0.0",
"gulp-header": "^2.0.9",
"gulp-footer": "^2.1.0", "gulp-footer": "^2.1.0",
"del": "^2.2.2", "gulp-header": "^2.0.9",
"gulp-rename": "^2.0.0",
"gulp-replace": "^1.1.3",
"gulp-uglify": "^3.0.2",
"minimist": "^1.2.5" "minimist": "^1.2.5"
}, },
"bugs": { "bugs": {
"url": "https://gitee.com/sentsin/layui/issues" "url": "https://gitee.com/sentsin/layui/issues"
}, },
"dependencies": {}, "dependencies": {
"layui": "file:"
},
"keywords": [ "keywords": [
"layui", "layui",
"ui", "ui",

View File

@ -25,7 +25,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
,cache: {} //数据缓存 ,cache: {} //数据缓存
,allData:[] // 全部数据 ,allData:[] // 全部数据
,index: layui.table ? (layui.table.index + 10000) : 0 ,index: layui.table ? (layui.table.index + 10000) : 0
,winResiz:[]
//设置全局项 //设置全局项
,set: function(options){ ,set: function(options){
var that = this; var that = this;
@ -365,6 +365,8 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
that.key = options.id || options.index; that.key = options.id || options.index;
table.allData[that.key] = options.data table.allData[that.key] = options.data
// 添加到全局渲染中为了全局resize防止内存泄漏
table.winResiz[that.key] = that
//生成替代元素 //生成替代元素
hasRender[0] && hasRender.remove(); //如果已经渲染则Rerender hasRender[0] && hasRender.remove(); //如果已经渲染则Rerender
othis.after(reElem); othis.after(reElem);
@ -1650,6 +1652,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
} }
} }
that.config.onColumnsWidth && that.config.onColumnsWidth(that.config.cols) that.config.onColumnsWidth && that.config.onColumnsWidth(that.config.cols)
if (layui.soulTable) { layui.soulTable.fixTableRemember(that.config, dict) } //拖动列宽 记忆开启
dict = {}; dict = {};
_BODY.css('cursor', ''); _BODY.css('cursor', '');
that.scrollPatch(); that.scrollPatch();
@ -1986,10 +1989,10 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
layer.close(that.tipsIndex); layer.close(that.tipsIndex);
}); });
//自适应 // //自适应
_WIN.on('resize', function(){ // _WIN.on('resize', function(){
that.resize(); // that.resize();
}); // });
}; };
//一次性事件 //一次性事件
@ -2367,6 +2370,17 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
table.init(); table.init();
}); });
$(function (){
//自适应
_WIN.on('resize', function(){
// that.resize();
for(let i in table.winResiz){
table.winResiz[i].resize()
}
})
})
exports(MOD_NAME, table); exports(MOD_NAME, table);
}); });

View File

@ -210,6 +210,7 @@ layui.define('layer' , function(exports){
,contentType: false ,contentType: false
,processData: false ,processData: false
,dataType: 'json' ,dataType: 'json'
,async: false
,headers: options.headers || {} ,headers: options.headers || {}
//成功回调 //成功回调
,success: function(res){ ,success: function(res){