From 746bd44e1610cce32236ea064b7111498f4683e3 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 28 Jul 2022 11:35:44 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20layer.photos=20?= =?UTF-8?q?=E5=BA=95=E9=83=A8=E6=8F=90=E7=A4=BA=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/layer.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/modules/layer.js b/src/modules/layer.js index 8e59e25e..4f0cba9b 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -1280,6 +1280,8 @@ layer.photos = function(options, loop, key){ loadImage(data[start].src, function(img){ layer.close(dict.loadi); + let alt = data[start].alt||''; + //切换图片时不出现动画 if(key) options.anim = -1; @@ -1317,15 +1319,36 @@ layer.photos = function(options, loop, key){ isOutAnim: false, skin: 'layui-layer-photos' + skin('photos'), content: '
' - +''+ (data[start].alt||'') +'' + +''+ alt +'' +function(){ + let tip = '
'; + if(data.length > 1){ - return '
' - +'' - +'
'+ (data[start].alt || '') +''+ dict.imgIndex +' / '+ data.length +'
' - +'
' + tip += ''; + + if(alt===''){ + tip += '
'+ dict.imgIndex +' / '+ data.length +'
'; + } + else{ + tip += '
'+ alt +''+ dict.imgIndex +' / '+ data.length +'
'; + } + + tip += '
'; + } + else if(data.length === 1){ + if(alt===''){ + tip = ''; + } + else{ + tip += '
'+ alt +'
'; + tip += '
'; + } + } + else{ + tip = ''; } - return ''; + + return tip; }() +'', success: function(layero, index){ From 821de03d8a17a5f739ae42aa219bfdf1b0b9cc03 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 2 Aug 2022 14:36:21 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=B8=BA=20layer.photo=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E2=80=9C=E6=9F=A5=E7=9C=8B=E5=8E=9F=E5=9B=BE=E2=80=9D?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/modules/layer/default/layer.css | 3 ++- src/modules/layer.js | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/css/modules/layer/default/layer.css b/src/css/modules/layer/default/layer.css index 54a6aeee..75b23654 100644 --- a/src/css/modules/layer/default/layer.css +++ b/src/css/modules/layer/default/layer.css @@ -157,7 +157,8 @@ html #layuicss-layer{display: none; position: absolute; width: 1989px;} .layui-layer-imgtit *{display:inline-block; *display:inline; *zoom:1; vertical-align:top; font-size:12px;} .layui-layer-imgtit a{max-width:65%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; color:#fff;} .layui-layer-imgtit a:hover{color:#fff; text-decoration:underline;} -.layui-layer-imgtit em{padding-left:10px; font-style: normal;} +.layui-layer-imgtit em{padding:0 10px; font-style: normal;} +.layui-layer-imgtit>span+a{margin-left: 10px;} /* 关闭动画 */ @-webkit-keyframes layer-bounceOut { diff --git a/src/modules/layer.js b/src/modules/layer.js index 4f0cba9b..75d98993 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -1327,20 +1327,20 @@ layer.photos = function(options, loop, key){ tip += ''; if(alt===''){ - tip += '
'+ dict.imgIndex +' / '+ data.length +'
'; + tip += '
'+ dict.imgIndex +' / '+ data.length +'查看原图
'; } else{ - tip += '
'+ alt +''+ dict.imgIndex +' / '+ data.length +'
'; + tip += '
'+ alt +''+ dict.imgIndex +' / '+ data.length +'查看原图
'; } tip += ''; } else if(data.length === 1){ if(alt===''){ - tip = ''; + tip = ''; } else{ - tip += '
'+ alt +'
'; + tip += '
'+ alt +'查看原图
'; tip += ''; } } From 7735aeef7bdcc767b3d6cffbede7f04ae1b8c25d Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 2 Aug 2022 14:38:15 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=B0=86=20layer.photo=20=E7=9A=84=20let?= =?UTF-8?q?=20=E6=94=B9=E4=B8=BA=20var?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/layer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/layer.js b/src/modules/layer.js index 75d98993..ecdbbf7d 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -1280,7 +1280,7 @@ layer.photos = function(options, loop, key){ loadImage(data[start].src, function(img){ layer.close(dict.loadi); - let alt = data[start].alt||''; + var alt = data[start].alt||''; //切换图片时不出现动画 if(key) options.anim = -1; @@ -1321,7 +1321,7 @@ layer.photos = function(options, loop, key){ content: '
' +''+ alt +'' +function(){ - let tip = '
'; + var tip = '
'; if(data.length > 1){ tip += ''; From a74548b0408424e4f2859a59b67bf9a0e31970fa Mon Sep 17 00:00:00 2001 From: ZZZping <475377765@qq.com> Date: Mon, 8 Aug 2022 15:08:47 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=A8=E6=A0=91?= =?UTF-8?q?=E5=BD=A2=E7=BB=84=E4=BB=B6=E4=B8=AD=E4=BD=BF=E7=94=A8=E9=95=BF?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?=E8=8A=82=E7=82=B9id=E6=97=B6setChecked=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/tree.js | 144 ++++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/modules/tree.js b/src/modules/tree.js index 7f03e53a..731050e3 100644 --- a/src/modules/tree.js +++ b/src/modules/tree.js @@ -4,11 +4,11 @@ layui.define('form', function(exports){ "use strict"; - + var $ = layui.$ ,form = layui.form ,layer = layui.layer - + //模块名 ,MOD_NAME = 'tree' @@ -23,7 +23,7 @@ layui.define('form', function(exports){ that.config = $.extend({}, that.config, options); return that; } - + //事件 ,on: function(events, callback){ return layui.onevent.call(this, MOD_NAME, events, callback); @@ -35,10 +35,10 @@ layui.define('form', function(exports){ var that = this ,options = that.config ,id = options.id || that.index; - + thisModule.that[id] = that; //记录当前实例对象 thisModule.config[id] = options; //记录当前实例配置项 - + return { config: options //重置实例 @@ -53,7 +53,7 @@ layui.define('form', function(exports){ } } } - + //获取当前实例配置项 ,getThisModuleConfig = function(id){ var config = thisModule.config[id]; @@ -63,11 +63,11 @@ layui.define('form', function(exports){ //字符常量 ,SHOW = 'layui-show', HIDE = 'layui-hide', NONE = 'layui-none', DISABLED = 'layui-disabled' - + ,ELEM_VIEW = 'layui-tree', ELEM_SET = 'layui-tree-set', ICON_CLICK = 'layui-tree-iconClick' ,ICON_ADD = 'layui-icon-addition', ICON_SUB = 'layui-icon-subtraction', ELEM_ENTRY = 'layui-tree-entry', ELEM_MAIN = 'layui-tree-main', ELEM_TEXT = 'layui-tree-txt', ELEM_PACK = 'layui-tree-pack', ELEM_SPREAD = 'layui-tree-spread' ,ELEM_LINE_SHORT = 'layui-tree-setLineShort', ELEM_SHOW = 'layui-tree-showLine', ELEM_EXTEND = 'layui-tree-lineExtend' - + //构造器 ,Class = function(options){ var that = this; @@ -79,28 +79,28 @@ layui.define('form', function(exports){ //默认配置 Class.prototype.config = { data: [] //数据 - + ,showCheckbox: false //是否显示复选框 ,showLine: true //是否开启连接线 ,accordion: false //是否开启手风琴模式 ,onlyIconControl: false //是否仅允许节点左侧图标控制展开收缩 ,isJump: false //是否允许点击节点时弹出新窗口跳转 ,edit: false //是否开启节点的操作图标 - + ,text: { defaultNodeName: '未命名' //节点默认名称 ,none: '无数据' //数据为空时的文本提示 } }; - + //重载实例 Class.prototype.reload = function(options){ var that = this; - + layui.each(options, function(key, item){ if(layui.type(item) === 'array') delete that.config[key]; }); - + that.config = $.extend(true, {}, that.config, options); that.render(); }; @@ -109,7 +109,7 @@ layui.define('form', function(exports){ Class.prototype.render = function(){ var that = this ,options = that.config; - + that.checkids = []; var temp = $('
'); @@ -120,7 +120,7 @@ layui.define('form', function(exports){ //索引 that.key = options.id || that.index; - + //插入组件结构 that.elem = temp; that.elemNone = $('
'+ options.text.none +'
'); @@ -129,7 +129,7 @@ layui.define('form', function(exports){ if(that.elem.find('.layui-tree-set').length == 0){ return that.elem.append(that.elemNone); }; - + //复选框渲染 if(options.showCheckbox){ that.renderForm('checkbox'); @@ -146,7 +146,7 @@ layui.define('form', function(exports){ if(!othis.next()[0] && othis.parents('.layui-tree-pack').eq(1).hasClass('layui-tree-lineExtend')){ othis.addClass(ELEM_LINE_SHORT); }; - + //没有下一个节点 外层最后一个 if(!othis.next()[0] && !othis.parents('.layui-tree-set').eq(0).next()[0]){ othis.addClass(ELEM_LINE_SHORT); @@ -155,7 +155,7 @@ layui.define('form', function(exports){ that.events(); }; - + //渲染表单 Class.prototype.renderForm = function(type){ form.render(type, 'LAY-tree-'+ this.index); @@ -186,12 +186,12 @@ layui.define('form', function(exports){ return ''; }; }() - + //复选框 ,function(){ return options.showCheckbox ? '' : ''; }() - + //节点 ,function(){ if(options.isJump && item.href){ @@ -201,21 +201,21 @@ layui.define('form', function(exports){ } }() ,'
' - + //节点操作图标 ,function(){ if(!options.edit) return ''; - + var editIcon = { add: '' ,update: '' ,del: '' }, arr = ['
']; - + if(options.edit === true){ options.edit = ['update', 'del'] } - + if(typeof options.edit === 'object'){ layui.each(options.edit, function(i, val){ arr.push(editIcon[val] || '') @@ -232,12 +232,12 @@ layui.define('form', function(exports){ }; elem.append(entryDiv); - + //若有前置节点,前置节点加连接线 if(entryDiv.prev('.'+ELEM_SET)[0]){ entryDiv.prev().children('.layui-tree-pack').addClass('layui-tree-showLine'); }; - + //若无子节点,则父节点加延伸线 if(!hasChild){ entryDiv.parent('.layui-tree-pack').addClass('layui-tree-lineExtend'); @@ -245,16 +245,16 @@ layui.define('form', function(exports){ //展开节点操作 that.spread(entryDiv, item); - + //选择框 if(options.showCheckbox){ item.checked && that.checkids.push(item.id); that.checkClick(entryDiv, item); } - + //操作节点 options.edit && that.operate(entryDiv, item); - + }); }; @@ -268,7 +268,7 @@ layui.define('form', function(exports){ ,elemText = entry.find('.'+ ELEM_TEXT) ,touchOpen = options.onlyIconControl ? elemIcon : elemMain //判断展开通过节点还是箭头图标 ,state = ''; - + //展开收缩 touchOpen.on('click', function(e){ var packCont = elem.children('.'+ELEM_PACK) @@ -281,7 +281,7 @@ layui.define('form', function(exports){ if(elem.hasClass(ELEM_SPREAD)){ elem.removeClass(ELEM_SPREAD); packCont.slideUp(200); - iconClick.removeClass(ICON_SUB).addClass(ICON_ADD); + iconClick.removeClass(ICON_SUB).addClass(ICON_ADD); }else{ elem.addClass(ELEM_SPREAD); packCont.slideDown(200); @@ -297,21 +297,21 @@ layui.define('form', function(exports){ }; }; }); - + //点击回调 elemText.on('click', function(){ var othis = $(this); - + //判断是否禁用状态 if(othis.hasClass(DISABLED)) return; - + //判断展开收缩状态 if(elem.hasClass(ELEM_SPREAD)){ state = options.onlyIconControl ? 'open' : 'close'; } else { state = options.onlyIconControl ? 'close' : 'open'; } - + //点击产生的回调 options.click && options.click({ elem: elem @@ -320,13 +320,13 @@ layui.define('form', function(exports){ }); }); }; - + //计算复选框选中状态 Class.prototype.setCheckbox = function(elem, item, elemCheckbox){ var that = this ,options = that.config ,checked = elemCheckbox.prop('checked'); - + if(elemCheckbox.prop('disabled')) return; //同步子节点选中状态 @@ -357,38 +357,38 @@ layui.define('form', function(exports){ state = true; } }); - + //如果兄弟子孙节点全部未选中,则父节点也应为非选中状态 state || parentCheckbox.prop('checked', false); } - + //向父节点递归 setParentsChecked(parentNodeElem); }; - + setParentsChecked(elem); that.renderForm('checkbox'); }; - + //复选框选择 Class.prototype.checkClick = function(elem, item){ var that = this ,options = that.config ,entry = elem.children('.'+ ELEM_ENTRY) ,elemMain = entry.children('.'+ ELEM_MAIN); - - - + + + //点击复选框 elemMain.on('click', 'input[same="layuiTreeCheck"]+', function(e){ layui.stope(e); //阻止点击节点事件 var elemCheckbox = $(this).prev() ,checked = elemCheckbox.prop('checked'); - + if(elemCheckbox.prop('disabled')) return; - + that.setCheckbox(elem, item, elemCheckbox); //复选框点击产生的回调 @@ -439,7 +439,7 @@ layui.define('form', function(exports){ obj.title = options.text.defaultNodeName; obj.id = key; that.tree(elem.children('.'+ELEM_PACK), [obj]); - + //放在新增后面,因为要对元素进行操作 if(options.showLine){ //节点本身无子节点 @@ -495,7 +495,7 @@ layui.define('form', function(exports){ packLast.find('input[same="layuiTreeCheck"]')[0].checked = true; }; that.renderForm('checkbox'); - + //修改 }else if(type == 'update'){ var text = elemMain.children('.'+ ELEM_TEXT).html(); @@ -510,10 +510,10 @@ layui.define('form', function(exports){ textNew = textNew ? textNew : options.text.defaultNodeName; input.remove(); elemMain.children('.'+ ELEM_TEXT).html(textNew); - + //同步数据 returnObj.data.title = textNew; - + //节点修改的回调 options.operate && options.operate(returnObj); }; @@ -534,9 +534,9 @@ layui.define('form', function(exports){ layer.confirm('确认删除该节点 "'+ (item.title || '') +'" 吗?', function(index){ options.operate && options.operate(returnObj); //节点删除的回调 returnObj.status = 'remove'; //标注节点删除 - + layer.close(index); - + //若删除最后一个,显示空数据提示 if(!elem.prev('.'+ELEM_SET)[0] && !elem.next('.'+ELEM_SET)[0] && !elem.parent('.'+ELEM_PACK)[0]){ elem.remove(); @@ -616,7 +616,7 @@ layui.define('form', function(exports){ }; }; }; - + }else{ //若无兄弟节点 var prevDiv = elem.parent('.'+ELEM_PACK).prev(); @@ -644,7 +644,7 @@ layui.define('form', function(exports){ elem.remove(); }); - + }; }); }; @@ -654,10 +654,10 @@ layui.define('form', function(exports){ var that = this ,options = that.config ,checkWarp = that.elem.find('.layui-tree-checkedFirst'); - + //初始选中 that.setChecked(that.checkids); - + //搜索 that.elem.find('.layui-tree-search').on('keyup', function(){ var input = $(this) @@ -671,7 +671,7 @@ layui.define('form', function(exports){ //若值匹配,加一个类以作标识 if($(this).html().indexOf(val) != -1){ arr.push($(this).parent()); - + var select = function(div){ div.addClass('layui-tree-searchShow'); //向上父节点渲染 @@ -716,12 +716,12 @@ layui.define('form', function(exports){ ,options = that.config ,checkId = [] ,checkData = []; - + //遍历节点找到选中索引 that.elem.find('.layui-form-checked').each(function(){ checkId.push($(this).prev()[0].value); }); - + //遍历节点 var eachNodes = function(data, checkNode){ layui.each(data, function(index, item){ @@ -729,9 +729,9 @@ layui.define('form', function(exports){ if(item.id == item2){ var cloneItem = $.extend({}, item); delete cloneItem.children; - + checkNode.push(cloneItem); - + if(item.children){ cloneItem.children = []; eachNodes(item.children, cloneItem.children); @@ -743,7 +743,7 @@ layui.define('form', function(exports){ }; eachNodes($.extend({}, options.data), checkData); - + return checkData; }; @@ -757,20 +757,20 @@ layui.define('form', function(exports){ var thisId = $(this).data('id') ,input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]') ,reInput = input.next(); - + //若返回数字 if(typeof checkedId === 'number'){ - if(thisId == checkedId){ + if(thisId.toString() == checkedId.toString()){ if(!input[0].checked){ reInput.click(); }; return false; }; - } + } //若返回数组 else if(typeof checkedId === 'object'){ layui.each(checkedId, function(index, value){ - if(value == thisId && !input[0].checked){ + if(value.toString() == thisId.toString() && !input[0].checked){ reInput.click(); return true; } @@ -782,27 +782,27 @@ layui.define('form', function(exports){ //记录所有实例 thisModule.that = {}; //记录所有实例对象 thisModule.config = {}; //记录所有实例配置项 - + //重载实例 tree.reload = function(id, options){ var that = thisModule.that[id]; that.reload(options); - + return thisModule.call(that); }; - + //获得选中的节点数据 tree.getChecked = function(id){ var that = thisModule.that[id]; return that.getChecked(); }; - + //设置选中节点 tree.setChecked = function(id, checkedId){ var that = thisModule.that[id]; return that.setChecked(checkedId); }; - + //核心入口 tree.render = function(options){ var inst = new Class(options); @@ -810,4 +810,4 @@ layui.define('form', function(exports){ }; exports(MOD_NAME, tree); -}) \ No newline at end of file +}) From ce4dfc3d07edac34da61c2a6b66b3f8e5d7cb511 Mon Sep 17 00:00:00 2001 From: YONG PENG Date: Thu, 11 Aug 2022 18:46:32 +0800 Subject: [PATCH 5/8] =?UTF-8?q?table=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94=E7=88=B6=E5=85=83=E7=B4=A0=E9=AB=98?= =?UTF-8?q?=E5=BA=A6=EF=BC=9A#=E7=88=B6=E5=85=83=E7=B4=A0ID-=E5=B7=AE?= =?UTF-8?q?=E8=B7=9D=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/table.js b/src/modules/table.js index 25cd0f60..b2be5ea1 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -347,6 +347,11 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ if(options.height && /^full-\d+$/.test(options.height)){ that.fullHeightGap = options.height.split('-')[1]; options.height = _WIN.height() - that.fullHeightGap; + } else if (options.height && /^#\w+-{1}\d+$/.test(options.height)) { + var parentDiv = options.height.split("-"); + that.parentHeightGap = parentDiv.pop(); + that.parentDiv = parentDiv.join("-"); + options.height = $(that.parentDiv).height() - that.parentHeightGap; } //初始化一些参数 @@ -1479,6 +1484,10 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ height = _WIN.height() - that.fullHeightGap; if(height < 135) height = 135; that.elem.css('height', height); + } else if (that.parentDiv && that.parentHeightGap) { + height = $(that.parentDiv).height() - that.parentHeightGap; + if (height < 135) height = 135; + that.elem.css("height", height); } if(!height) return; From 018c2069a7ea6333e1f68e3d65e66d2413d94834 Mon Sep 17 00:00:00 2001 From: ZZZping <475377765@qq.com> Date: Tue, 16 Aug 2022 15:10:17 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0pr=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pull_request_template.md | 54 ++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 60abdbc5..c546389e 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,7 +10,55 @@ ### 🌱 本次 PR 的变化内容 -- 在此处尽可能列出本次 PR 的每一项改动的内容 +- 在树形组件中的**setChecked**方法中,当节点id为长数字字符串时, +设置已选择节点的复选框时,在判断节点id时添加字符串转换 +````javascript + //line 763 + thisId.toString() == checkedId.toString() + //lin 773 + value.toString() == thisId.toString() && !input[0].checked +```` +- 如果缺少类型转换的话,在使用长数字字符串作为节点id时,如果选择了某个节点,在第二次 +渲染树时,会将一些未选择的节点的checkbox渲染为已选择;以下数据中,如果第一次选择了域名 +节点但是没有选择概览节点,在不加类型转换时会将概览节点渲染为已选择状态。 +````javascript +var data2 = [ + { + title: '控制台' + , id: '113715891127976666' + , spread: true + , checked: false + , children: [ + { + title: '概览' + , id: '113715891127976000' + , spread: true + , checked: false, + }, { + title: '域名' + , id: '113715891127976001' + , spread: true + , checked: false, + }, { + title: '域名1' + , id: '113715891127976002' + , spread: true + , checked: true, + }, + ], + }]; + + tree.render({ + elem: '#test1' + , data: data2 + , id: 'demoId2' + , showCheckbox: true //是否显示复选框 + , accordion: 0 //是否开启手风琴模式 + , onlyIconControl: true //是否仅允许节点左侧图标控制展开收缩 + , isJump: 0 //点击文案跳转地址 + , edit: true, //操作节点图标 + }); +```` ### ✅ 本次 PR 的满足条件 @@ -18,6 +66,6 @@ > 请在申请合并之前,将符合条件的每一项进行勾选(即 [ ] 内填写 x ) - [ ] 已提供在线演示地址(如:[codepen](https://codepen.io/))或无需演示 -- [ ] 已对每一项的改动均测试通过 -- [ ] 已提供具体的变化内容说明 +- [x] 已对每一项的改动均测试通过 +- [x] 已提供具体的变化内容说明 From e8819bfdc14ac050842af53f26c1cbd19f75f1de Mon Sep 17 00:00:00 2001 From: ZZZping <475377765@qq.com> Date: Tue, 16 Aug 2022 15:15:02 +0800 Subject: [PATCH 7/8] =?UTF-8?q?Revert=20"=E6=B7=BB=E5=8A=A0pr=E8=AF=B4?= =?UTF-8?q?=E6=98=8E"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 018c2069a7ea6333e1f68e3d65e66d2413d94834. --- .github/pull_request_template.md | 54 ++------------------------------ 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index c546389e..60abdbc5 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,55 +10,7 @@ ### 🌱 本次 PR 的变化内容 -- 在树形组件中的**setChecked**方法中,当节点id为长数字字符串时, -设置已选择节点的复选框时,在判断节点id时添加字符串转换 -````javascript - //line 763 - thisId.toString() == checkedId.toString() - //lin 773 - value.toString() == thisId.toString() && !input[0].checked -```` -- 如果缺少类型转换的话,在使用长数字字符串作为节点id时,如果选择了某个节点,在第二次 -渲染树时,会将一些未选择的节点的checkbox渲染为已选择;以下数据中,如果第一次选择了域名 -节点但是没有选择概览节点,在不加类型转换时会将概览节点渲染为已选择状态。 -````javascript -var data2 = [ - { - title: '控制台' - , id: '113715891127976666' - , spread: true - , checked: false - , children: [ - { - title: '概览' - , id: '113715891127976000' - , spread: true - , checked: false, - }, { - title: '域名' - , id: '113715891127976001' - , spread: true - , checked: false, - }, { - title: '域名1' - , id: '113715891127976002' - , spread: true - , checked: true, - }, - ], - }]; - - tree.render({ - elem: '#test1' - , data: data2 - , id: 'demoId2' - , showCheckbox: true //是否显示复选框 - , accordion: 0 //是否开启手风琴模式 - , onlyIconControl: true //是否仅允许节点左侧图标控制展开收缩 - , isJump: 0 //点击文案跳转地址 - , edit: true, //操作节点图标 - }); -```` +- 在此处尽可能列出本次 PR 的每一项改动的内容 ### ✅ 本次 PR 的满足条件 @@ -66,6 +18,6 @@ var data2 = [ > 请在申请合并之前,将符合条件的每一项进行勾选(即 [ ] 内填写 x ) - [ ] 已提供在线演示地址(如:[codepen](https://codepen.io/))或无需演示 -- [x] 已对每一项的改动均测试通过 -- [x] 已提供具体的变化内容说明 +- [ ] 已对每一项的改动均测试通过 +- [ ] 已提供具体的变化内容说明 From f481b6acd075e9fbe9c041a50fc4f2ea18512207 Mon Sep 17 00:00:00 2001 From: ZZZping <475377765@qq.com> Date: Thu, 18 Aug 2022 13:03:29 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=A8=E6=A0=91?= =?UTF-8?q?=E5=BD=A2=E7=BB=84=E4=BB=B6=E4=B8=AD=E4=BD=BF=E7=94=A8=E9=95=BF?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?=E8=8A=82=E7=82=B9id=E6=97=B6=E8=8A=82=E7=82=B9=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/tree.js | 140 ++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/src/modules/tree.js b/src/modules/tree.js index 731050e3..634a8c4e 100644 --- a/src/modules/tree.js +++ b/src/modules/tree.js @@ -4,11 +4,11 @@ layui.define('form', function(exports){ "use strict"; - + var $ = layui.$ ,form = layui.form ,layer = layui.layer - + //模块名 ,MOD_NAME = 'tree' @@ -23,7 +23,7 @@ layui.define('form', function(exports){ that.config = $.extend({}, that.config, options); return that; } - + //事件 ,on: function(events, callback){ return layui.onevent.call(this, MOD_NAME, events, callback); @@ -35,10 +35,10 @@ layui.define('form', function(exports){ var that = this ,options = that.config ,id = options.id || that.index; - + thisModule.that[id] = that; //记录当前实例对象 thisModule.config[id] = options; //记录当前实例配置项 - + return { config: options //重置实例 @@ -53,7 +53,7 @@ layui.define('form', function(exports){ } } } - + //获取当前实例配置项 ,getThisModuleConfig = function(id){ var config = thisModule.config[id]; @@ -63,11 +63,11 @@ layui.define('form', function(exports){ //字符常量 ,SHOW = 'layui-show', HIDE = 'layui-hide', NONE = 'layui-none', DISABLED = 'layui-disabled' - + ,ELEM_VIEW = 'layui-tree', ELEM_SET = 'layui-tree-set', ICON_CLICK = 'layui-tree-iconClick' ,ICON_ADD = 'layui-icon-addition', ICON_SUB = 'layui-icon-subtraction', ELEM_ENTRY = 'layui-tree-entry', ELEM_MAIN = 'layui-tree-main', ELEM_TEXT = 'layui-tree-txt', ELEM_PACK = 'layui-tree-pack', ELEM_SPREAD = 'layui-tree-spread' ,ELEM_LINE_SHORT = 'layui-tree-setLineShort', ELEM_SHOW = 'layui-tree-showLine', ELEM_EXTEND = 'layui-tree-lineExtend' - + //构造器 ,Class = function(options){ var that = this; @@ -79,28 +79,28 @@ layui.define('form', function(exports){ //默认配置 Class.prototype.config = { data: [] //数据 - + ,showCheckbox: false //是否显示复选框 ,showLine: true //是否开启连接线 ,accordion: false //是否开启手风琴模式 ,onlyIconControl: false //是否仅允许节点左侧图标控制展开收缩 ,isJump: false //是否允许点击节点时弹出新窗口跳转 ,edit: false //是否开启节点的操作图标 - + ,text: { defaultNodeName: '未命名' //节点默认名称 ,none: '无数据' //数据为空时的文本提示 } }; - + //重载实例 Class.prototype.reload = function(options){ var that = this; - + layui.each(options, function(key, item){ if(layui.type(item) === 'array') delete that.config[key]; }); - + that.config = $.extend(true, {}, that.config, options); that.render(); }; @@ -109,7 +109,7 @@ layui.define('form', function(exports){ Class.prototype.render = function(){ var that = this ,options = that.config; - + that.checkids = []; var temp = $('
'); @@ -120,7 +120,7 @@ layui.define('form', function(exports){ //索引 that.key = options.id || that.index; - + //插入组件结构 that.elem = temp; that.elemNone = $('
'+ options.text.none +'
'); @@ -129,7 +129,7 @@ layui.define('form', function(exports){ if(that.elem.find('.layui-tree-set').length == 0){ return that.elem.append(that.elemNone); }; - + //复选框渲染 if(options.showCheckbox){ that.renderForm('checkbox'); @@ -146,7 +146,7 @@ layui.define('form', function(exports){ if(!othis.next()[0] && othis.parents('.layui-tree-pack').eq(1).hasClass('layui-tree-lineExtend')){ othis.addClass(ELEM_LINE_SHORT); }; - + //没有下一个节点 外层最后一个 if(!othis.next()[0] && !othis.parents('.layui-tree-set').eq(0).next()[0]){ othis.addClass(ELEM_LINE_SHORT); @@ -155,7 +155,7 @@ layui.define('form', function(exports){ that.events(); }; - + //渲染表单 Class.prototype.renderForm = function(type){ form.render(type, 'LAY-tree-'+ this.index); @@ -186,12 +186,12 @@ layui.define('form', function(exports){ return ''; }; }() - + //复选框 ,function(){ return options.showCheckbox ? '' : ''; }() - + //节点 ,function(){ if(options.isJump && item.href){ @@ -201,21 +201,21 @@ layui.define('form', function(exports){ } }() ,'
' - + //节点操作图标 ,function(){ if(!options.edit) return ''; - + var editIcon = { add: '' ,update: '' ,del: '' }, arr = ['
']; - + if(options.edit === true){ options.edit = ['update', 'del'] } - + if(typeof options.edit === 'object'){ layui.each(options.edit, function(i, val){ arr.push(editIcon[val] || '') @@ -232,12 +232,12 @@ layui.define('form', function(exports){ }; elem.append(entryDiv); - + //若有前置节点,前置节点加连接线 if(entryDiv.prev('.'+ELEM_SET)[0]){ entryDiv.prev().children('.layui-tree-pack').addClass('layui-tree-showLine'); }; - + //若无子节点,则父节点加延伸线 if(!hasChild){ entryDiv.parent('.layui-tree-pack').addClass('layui-tree-lineExtend'); @@ -245,16 +245,16 @@ layui.define('form', function(exports){ //展开节点操作 that.spread(entryDiv, item); - + //选择框 if(options.showCheckbox){ item.checked && that.checkids.push(item.id); that.checkClick(entryDiv, item); } - + //操作节点 options.edit && that.operate(entryDiv, item); - + }); }; @@ -268,7 +268,7 @@ layui.define('form', function(exports){ ,elemText = entry.find('.'+ ELEM_TEXT) ,touchOpen = options.onlyIconControl ? elemIcon : elemMain //判断展开通过节点还是箭头图标 ,state = ''; - + //展开收缩 touchOpen.on('click', function(e){ var packCont = elem.children('.'+ELEM_PACK) @@ -281,7 +281,7 @@ layui.define('form', function(exports){ if(elem.hasClass(ELEM_SPREAD)){ elem.removeClass(ELEM_SPREAD); packCont.slideUp(200); - iconClick.removeClass(ICON_SUB).addClass(ICON_ADD); + iconClick.removeClass(ICON_SUB).addClass(ICON_ADD); }else{ elem.addClass(ELEM_SPREAD); packCont.slideDown(200); @@ -297,21 +297,21 @@ layui.define('form', function(exports){ }; }; }); - + //点击回调 elemText.on('click', function(){ var othis = $(this); - + //判断是否禁用状态 if(othis.hasClass(DISABLED)) return; - + //判断展开收缩状态 if(elem.hasClass(ELEM_SPREAD)){ state = options.onlyIconControl ? 'open' : 'close'; } else { state = options.onlyIconControl ? 'close' : 'open'; } - + //点击产生的回调 options.click && options.click({ elem: elem @@ -320,13 +320,13 @@ layui.define('form', function(exports){ }); }); }; - + //计算复选框选中状态 Class.prototype.setCheckbox = function(elem, item, elemCheckbox){ var that = this ,options = that.config ,checked = elemCheckbox.prop('checked'); - + if(elemCheckbox.prop('disabled')) return; //同步子节点选中状态 @@ -357,38 +357,38 @@ layui.define('form', function(exports){ state = true; } }); - + //如果兄弟子孙节点全部未选中,则父节点也应为非选中状态 state || parentCheckbox.prop('checked', false); } - + //向父节点递归 setParentsChecked(parentNodeElem); }; - + setParentsChecked(elem); that.renderForm('checkbox'); }; - + //复选框选择 Class.prototype.checkClick = function(elem, item){ var that = this ,options = that.config ,entry = elem.children('.'+ ELEM_ENTRY) ,elemMain = entry.children('.'+ ELEM_MAIN); - - - + + + //点击复选框 elemMain.on('click', 'input[same="layuiTreeCheck"]+', function(e){ layui.stope(e); //阻止点击节点事件 var elemCheckbox = $(this).prev() ,checked = elemCheckbox.prop('checked'); - + if(elemCheckbox.prop('disabled')) return; - + that.setCheckbox(elem, item, elemCheckbox); //复选框点击产生的回调 @@ -439,7 +439,7 @@ layui.define('form', function(exports){ obj.title = options.text.defaultNodeName; obj.id = key; that.tree(elem.children('.'+ELEM_PACK), [obj]); - + //放在新增后面,因为要对元素进行操作 if(options.showLine){ //节点本身无子节点 @@ -495,7 +495,7 @@ layui.define('form', function(exports){ packLast.find('input[same="layuiTreeCheck"]')[0].checked = true; }; that.renderForm('checkbox'); - + //修改 }else if(type == 'update'){ var text = elemMain.children('.'+ ELEM_TEXT).html(); @@ -510,10 +510,10 @@ layui.define('form', function(exports){ textNew = textNew ? textNew : options.text.defaultNodeName; input.remove(); elemMain.children('.'+ ELEM_TEXT).html(textNew); - + //同步数据 returnObj.data.title = textNew; - + //节点修改的回调 options.operate && options.operate(returnObj); }; @@ -534,9 +534,9 @@ layui.define('form', function(exports){ layer.confirm('确认删除该节点 "'+ (item.title || '') +'" 吗?', function(index){ options.operate && options.operate(returnObj); //节点删除的回调 returnObj.status = 'remove'; //标注节点删除 - + layer.close(index); - + //若删除最后一个,显示空数据提示 if(!elem.prev('.'+ELEM_SET)[0] && !elem.next('.'+ELEM_SET)[0] && !elem.parent('.'+ELEM_PACK)[0]){ elem.remove(); @@ -616,7 +616,7 @@ layui.define('form', function(exports){ }; }; }; - + }else{ //若无兄弟节点 var prevDiv = elem.parent('.'+ELEM_PACK).prev(); @@ -644,7 +644,7 @@ layui.define('form', function(exports){ elem.remove(); }); - + }; }); }; @@ -654,10 +654,10 @@ layui.define('form', function(exports){ var that = this ,options = that.config ,checkWarp = that.elem.find('.layui-tree-checkedFirst'); - + //初始选中 that.setChecked(that.checkids); - + //搜索 that.elem.find('.layui-tree-search').on('keyup', function(){ var input = $(this) @@ -671,7 +671,7 @@ layui.define('form', function(exports){ //若值匹配,加一个类以作标识 if($(this).html().indexOf(val) != -1){ arr.push($(this).parent()); - + var select = function(div){ div.addClass('layui-tree-searchShow'); //向上父节点渲染 @@ -716,12 +716,12 @@ layui.define('form', function(exports){ ,options = that.config ,checkId = [] ,checkData = []; - + //遍历节点找到选中索引 that.elem.find('.layui-form-checked').each(function(){ checkId.push($(this).prev()[0].value); }); - + //遍历节点 var eachNodes = function(data, checkNode){ layui.each(data, function(index, item){ @@ -729,9 +729,9 @@ layui.define('form', function(exports){ if(item.id == item2){ var cloneItem = $.extend({}, item); delete cloneItem.children; - + checkNode.push(cloneItem); - + if(item.children){ cloneItem.children = []; eachNodes(item.children, cloneItem.children); @@ -743,7 +743,7 @@ layui.define('form', function(exports){ }; eachNodes($.extend({}, options.data), checkData); - + return checkData; }; @@ -757,7 +757,7 @@ layui.define('form', function(exports){ var thisId = $(this).data('id') ,input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]') ,reInput = input.next(); - + //若返回数字 if(typeof checkedId === 'number'){ if(thisId.toString() == checkedId.toString()){ @@ -766,7 +766,7 @@ layui.define('form', function(exports){ }; return false; }; - } + } //若返回数组 else if(typeof checkedId === 'object'){ layui.each(checkedId, function(index, value){ @@ -782,27 +782,27 @@ layui.define('form', function(exports){ //记录所有实例 thisModule.that = {}; //记录所有实例对象 thisModule.config = {}; //记录所有实例配置项 - + //重载实例 tree.reload = function(id, options){ var that = thisModule.that[id]; that.reload(options); - + return thisModule.call(that); }; - + //获得选中的节点数据 tree.getChecked = function(id){ var that = thisModule.that[id]; return that.getChecked(); }; - + //设置选中节点 tree.setChecked = function(id, checkedId){ var that = thisModule.that[id]; return that.setChecked(checkedId); }; - + //核心入口 tree.render = function(options){ var inst = new Class(options); @@ -810,4 +810,4 @@ layui.define('form', function(exports){ }; exports(MOD_NAME, tree); -}) +}) \ No newline at end of file