release v2.8.11

release v2.8.11
pull/1308/head v2.8.11
贤心 2023-07-13 10:02:54 +08:00 committed by GitHub
commit 8a8193b6e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 733 additions and 664 deletions

2
dist/layui.js vendored

File diff suppressed because one or more lines are too long

View File

@ -12,21 +12,21 @@ toc: true
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code']}"> <pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code']}">
<textarea> <textarea>
<div class="layui-btn-container"> <div class="layui-btn-container">
<button type="button" class="layui-btn layui-btn-primary">原始按钮</button>
<button type="button" class="layui-btn">默认按钮</button> <button type="button" class="layui-btn">默认按钮</button>
<button type="button" class="layui-btn layui-btn-normal">百搭按钮</button> <button type="button" class="layui-btn layui-bg-blue">蓝色按钮</button>
<button type="button" class="layui-btn layui-btn-warm">暖色按钮</button> <button type="button" class="layui-btn layui-bg-orange">橙色按钮</button>
<button type="button" class="layui-btn layui-btn-danger">警告按钮</button> <button type="button" class="layui-btn layui-bg-red">红色按钮</button>
<button type="button" class="layui-btn layui-bg-purple">紫色按钮</button>
<button type="button" class="layui-btn layui-btn-disabled">禁用按钮</button> <button type="button" class="layui-btn layui-btn-disabled">禁用按钮</button>
</div> </div>
<div class="layui-btn-container"> <div class="layui-btn-container">
<button class="layui-btn layui-btn-primary layui-border">原始按钮</button>
<button class="layui-btn layui-btn-primary layui-border-green">主色按钮</button> <button class="layui-btn layui-btn-primary layui-border-green">主色按钮</button>
<button class="layui-btn layui-btn-primary layui-border-blue">百搭按钮</button> <button class="layui-btn layui-btn-primary layui-border-blue">蓝色按钮</button>
<button class="layui-btn layui-btn-primary layui-border-orange">暖色按钮</button> <button class="layui-btn layui-btn-primary layui-border-orange">橙色按钮</button>
<button class="layui-btn layui-btn-primary layui-border-red">警告按钮</button> <button class="layui-btn layui-btn-primary layui-border-red">红色按钮</button>
<button class="layui-btn layui-btn-primary layui-border-black">深色按钮</button> <button class="layui-btn layui-btn-primary layui-border-purple">紫色按钮</button>
<button class="layui-btn layui-btn-primary layui-border">普通按钮</button>
</div> </div>
</textarea> </textarea>
</pre> </pre>

View File

@ -266,6 +266,7 @@ click: function(data, othis){
/* /*
return false; return false;
*/ */
}
``` ```
用法详见:[#示例](#examples) 用法详见:[#示例](#examples)

View File

@ -61,8 +61,8 @@ toc: true
- 通过 `class="layui-form"` 定义一个表单域,通常设置在`<form>`标签上, 或普通`<div>` 标签亦可。 - 通过 `class="layui-form"` 定义一个表单域,通常设置在`<form>`标签上, 或普通`<div>` 标签亦可。
- 通过 `class="layui-form-item"` 定义一个块级元素的表单项容器 - 通过 `class="layui-form-item"` 定义一个块级元素的表单项容器
- 通过 `class="layui-form-label"` 定义标签 - 通过 `class="layui-form-label"` 定义标签
- 通过 `class="layui-form-block"` 定义表单项父容器为块级元素 - 通过 `class="layui-input-block"` 定义表单项父容器为块级元素
- 通过 `class="layui-form-inline"` 或 `class="layui-inline"` 定义表单项父容器为行内块元素 - 通过 `class="layui-input-inline"` 或 `class="layui-inline"` 定义表单项父容器为行内块元素
即必须按照规定的层级定义相应的 `class` 即必须按照规定的层级定义相应的 `class`
@ -408,7 +408,7 @@ form.on('select(test)', function(data){
| 属性名 | 描述 | 类型 | 默认值 | | 属性名 | 描述 | 类型 | 默认值 |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| autocomplete | 设置 input 框的 `autocomplete` 属性初始值 | string | - | | autocomplete | 设置 input 框的 `autocomplete` 属性初始值 | string | - |
| verIncludelRequired <sup>2.8.4+</sup> | 验证规则中是否同时包含必填。 form 组件在 `2.8.3` 版本中调整了内置校验规则,即:仅当非空时进行校验,避免强制携带必填的校验规则。如需保留之前的验证规则(即同时校验必填),可将该属性设置为 `true`。但一般还是建议将必填项放置在 `lay-verify` 属性上,如: `lay-verify="required\|number"` | boolean | `false` | | verIncludeRequired <sup>2.8.4+</sup> | 验证规则中是否同时包含必填。 form 组件在 `2.8.3` 版本中调整了内置校验规则,即:仅当非空时进行校验,避免强制携带必填的校验规则。如需保留之前的验证规则(即同时校验必填),可将该属性设置为 `true`。但一般还是建议将必填项放置在 `lay-verify` 属性上,如: `lay-verify="required\|number"` | boolean | `false` |
该方法用于对 form 组件进行全局设置。 该方法用于对 form 组件进行全局设置。

View File

@ -114,7 +114,7 @@ toc: true
数字输入框 <sup>2.8.9+</sup> 数字输入框 <sup>2.8.9+</sup>
</h3> </h3>
一般搭配 `<input type="number">` 使用,用于替代原生输入框,可继承 `step,min,max` 等原生属性。 一般搭配 `<input type="number">` 使用,用于替代原生数字输入框,可继承 `step,min,max` 等原生属性。
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], done: function(obj){ <pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], done: function(obj){
obj.render(); obj.render();
@ -130,8 +130,11 @@ toc: true
<div class="layui-col-xs6"> <div class="layui-col-xs6">
<input type="number" lay-affix="number" placeholder="设置 step,min,max" step="10" min="0" max="100" class="layui-input"> <input type="number" lay-affix="number" placeholder="设置 step,min,max" step="10" min="0" max="100" class="layui-input">
</div> </div>
<div class="layui-col-xs12"> <div class="layui-col-xs6">
<input type="number" lay-affix="number" disabled placeholder="禁用状态" value="0" class="layui-input"> <input type="number" lay-affix="number" readonly placeholder="不允许输入状态" class="layui-input">
</div>
<div class="layui-col-xs6">
<input type="number" lay-affix="number" disabled placeholder="禁用状态" class="layui-input">
</div> </div>
</div> </div>
</div> </div>

View File

@ -19,7 +19,7 @@ layui.use(function(){
var util = layui.util; var util = layui.util;
// 模拟数据 // 模拟数据
var data = [{title:'一级1',id:1,field:'name1',checked:true,spread:true,children:[{title:'二级1-1 可允许跳转',id:3,field:'name11',href:'',children:[{title:'三级1-1-3',id:23,field:'',children:[{title:'四级1-1-3-1',id:24,field:'',children:[{title:'五级1-1-3-1-1',id:30,field:''},{title:'五级1-1-3-1-2',id:31,field:''}]}]},{title:'三级1-1-1',id:7,field:'',children:[{title:'四级1-1-1-1 可允许跳转',id:15,field:'',href:''}]},{title:'三级1-1-2',id:8,field:'',children:[{title:'四级1-1-2-1',id:32,field:''}]}]},{title:'二级1-2',id:4,spread:true,children:[{title:'三级1-2-1',id:9,field:'',disabled:true},{title:'三级1-2-2',id:10,field:''}]},{title:'二级1-3',id:20,field:'',children:[{title:'三级1-3-1',id:21,field:''},{title:'三级1-3-2',id:22,field:''}]}]},{title:'一级2',id:2,field:'',spread:true,children:[{title:'二级2-1',id:5,field:'',spread:true,children:[{title:'三级2-1-1',id:11,field:''},{title:'三级2-1-2',id:12,field:''}]},{title:'二级2-2',id:6,field:'',children:[{title:'三级2-2-1',id:13,field:''},{title:'三级2-2-2',id:14,field:'',disabled:true}]}]},{title:'一级3',id:16,field:'',children:[{title:'二级3-1',id:17,field:'',fixed:true,children:[{title:'三级3-1-1',id:18,field:''},{title:'三级3-1-2',id:19,field:''}]},{title:'二级3-2',id:27,field:'',children:[{title:'三级3-2-1',id:28,field:''},{title:'三级3-2-2',id:29,field:''}]}]}]; var data = [{title:'A-1',id:1,field:'name1',checked:true,spread:true,children:[{title:'B-1-1 可允许跳转',id:3,field:'name11',href:'',children:[{title:'C-1-1-3',id:23,field:'',children:[{title:'D-1-1-3-1',id:24,field:'',children:[{title:'E-1-1-3-1-1',id:30,field:''},{title:'E-1-1-3-1-2',id:31,field:''}]}]},{title:'C-1-1-1',id:7,field:'',children:[{title:'D-1-1-1-1 可允许跳转',id:15,field:'',href:''}]},{title:'C-1-1-2',id:8,field:'',children:[{title:'D-1-1-2-1',id:32,field:''}]}]},{title:'B-1-2',id:4,spread:true,children:[{title:'C-1-2-1',id:9,field:'',disabled:true},{title:'C-1-2-2',id:10,field:''}]},{title:'B-1-3',id:20,field:'',children:[{title:'C-1-3-1',id:21,field:''},{title:'C-1-3-2',id:22,field:''}]}]},{title:'A-2',id:2,field:'',spread:true,children:[{title:'B-2-1',id:5,field:'',spread:true,children:[{title:'C-2-1-1',id:11,field:''},{title:'C-2-1-2',id:12,field:''}]},{title:'B-2-2',id:6,field:'',children:[{title:'C-2-2-1',id:13,field:''},{title:'C-2-2-2',id:14,field:'',disabled:true}]}]},{title:'A-3',id:16,field:'',children:[{title:'B-3-1',id:17,field:'',fixed:true,children:[{title:'C-3-1-1',id:18,field:''},{title:'C-3-1-2',id:19,field:''}]},{title:'B-3-2',id:27,field:'',children:[{title:'C-3-2-1',id:28,field:''},{title:'C-3-2-2',id:29,field:''}]}]}];
// 渲染 // 渲染
tree.render({ tree.render({

View File

@ -11,6 +11,28 @@ toc: true
> 导读:📑 [Layui 2.8 《升级指南》](/notes/2.8/upgrade-guide.html) · 📑 [Layui 新版文档站上线初衷](/notes/2.8/news.html) > 导读:📑 [Layui 2.8 《升级指南》](/notes/2.8/upgrade-guide.html) · 📑 [Layui 新版文档站上线初衷](/notes/2.8/news.html)
<h2 id="2.8.11" class="ws-anchor">
2.8.11
<span class="layui-badge-rim">2023-07-13</span>
</h2>
- #### form
- 修复 `radio` 标题模板中若存在图标,选中时该图标被强制更改的问题 # I7IERB
- 优化 `input` 数字输入框的精度问题 # I7I7J2
- 修正 `verIncludelRequired` 属性名为 `verIncludeRequired` # 1305
- #### table
- 修复 导出统计行中若存在逗号出现的内容分隔异常问题 # I7IDA3
- 修复 当点击筛选显示隐藏固定列时出现的未对齐的问题 # I7KQ0O
- #### menu
- 修复 `menu` 标题项自定义图标在展开收缩后被强制更改的问题 # 1303/I7JAPU
- #### tree
- 修复 点击复选框时未将对应的数据中的 `checked` 属性值进行同步的问题
### 下载: [layui-v2.8.11.zip](https://gitee.com/layui/layui/attach_files/1464525/download)
---
<h2 id="2.8.10" class="ws-anchor"> <h2 id="2.8.10" class="ws-anchor">
2.8.10 2.8.10
<span class="layui-badge-rim">2023-07-03</span> <span class="layui-badge-rim">2023-07-03</span>

View File

@ -120,6 +120,9 @@
</div> </div>
</div> </div>
</div> </div>
<div class="layui-col-md3">
<input type="number" value="1.1" name="arr[]" required placeholder="数字输入框" lay-affix="number" autocomplete="off" class="layui-input">
</div>
<div class="layui-col-md3"> <div class="layui-col-md3">
<input type="number" step="0.01" min="0" max="10" name="arr[]" required placeholder="数字输入框" lay-affix="number" autocomplete="off" class="layui-input"> <input type="number" step="0.01" min="0" max="10" name="arr[]" required placeholder="数字输入框" lay-affix="number" autocomplete="off" class="layui-input">
</div> </div>
@ -341,17 +344,13 @@
<div class="layui-form-item" pane> <div class="layui-form-item" pane>
<label class="layui-form-label">单选框</label> <label class="layui-form-label">单选框</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="sex" value="男" title="男"> <input type="radio" name="sex" value="1" title="男">
<input type="radio" name="sex" value="女" title="女" checked> <input type="radio" name="sex" value="0" title="女" checked>
<input type="radio" name="sex" value="中型" title="中" disabled> <input type="radio" name="sex" value="-1">
<div lay-radio>
保密 <i class="layui-icon layui-icon-user"></i>
</div> </div>
</div> <input type="radio" name="sex" value="" title="禁用" disabled>
<div class="layui-form-item" pane>
<label class="layui-form-label">单选框</label>
<div class="layui-input-block">
<input type="radio" name="sex.id" value="男" title="男">
<input type="radio" name="sex.id" value="女" title="女" checked>
<input type="radio" name="sex.id" value="中型" title="中">
</div> </div>
</div> </div>
<div class="layui-form-item layui-form-text"> <div class="layui-form-item layui-form-text">
@ -436,7 +435,7 @@
,'interest': 3 ,'interest': 3
,'like[write]': true ,'like[write]': true
//,'open': false //,'open': false
,'sex': '' ,'sex': '0'
,'desc': 'form 是我们非常看重的一块' ,'desc': 'form 是我们非常看重的一块'
,xxxxxxxxx: 123 ,xxxxxxxxx: 123
}); });

View File

@ -1,18 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>树组件 - layui</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black"> <title>树组件 - layui</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../src/css/layui.css" media="all"> <link rel="stylesheet" href="../src/css/layui.css" media="all">
<style> <style>
body{padding: 100px;} body{padding: 100px;}
#test1,#test2{margin-bottom: 100px; width: 400px;} #test1,#test2{margin-bottom: 100px; width: 400px;}
@ -48,118 +40,118 @@
//数据源 //数据源
var data1 = [{ var data1 = [{
title: '一级1' title: 'A-1'
,id: 1 ,id: 1
,children: [{ ,children: [{
title: '二级1-1' title: 'B-1-1'
,id: 3 ,id: 3
,href: 'https://www.layui.com/doc/' ,href: 'https://www.layui.com/doc/'
,children: [{ ,children: [{
title: '三级1-1-3' title: 'C-1-1-3'
,id: 23 ,id: 23
,children: [{ ,children: [{
title: '四级1-1-3-1' title: 'D-1-1-3-1'
,id: 24 ,id: 24
,children: [{ ,children: [{
title: '五级1-1-3-1-1' title: 'E-1-1-3-1-1'
,id: 30 ,id: 30
},{ },{
title: '五级1-1-3-1-2' title: 'E-1-1-3-1-2'
,id: 31 ,id: 31
}] }]
}] }]
},{ },{
title: '三级1-1-1' title: 'C-1-1-1'
,id: 7 ,id: 7
,checked: true ,checked: true
,children: [{ ,children: [{
title: '四级1-1-1-1' title: 'D-1-1-1-1'
,id: 15 ,id: 15
//,checked: true //,checked: true
,href: 'https://www.layui.com/doc/base/infrastructure.html' ,href: 'https://www.layui.com/doc/base/infrastructure.html'
}] }]
},{ },{
title: '三级1-1-2' title: 'C-1-1-2'
,id: 8 ,id: 8
,children: [{ ,children: [{
title: '四级1-1-2-1' title: 'D-1-1-2-1'
,id: 32 ,id: 32
}] }]
}] }]
},{ },{
title: '二级1-2' title: 'B-1-2'
,id: 4 ,id: 4
,spread: true ,spread: true
,children: [{ ,children: [{
title: '三级1-2-1' title: 'C-1-2-1'
,id: 9 ,id: 9
,checked: true ,checked: true
,disabled: true ,disabled: true
},{ },{
title: '三级1-2-2' title: 'C-1-2-2'
,id: 10 ,id: 10
}] }]
},{ },{
title: '二级1-3' title: 'B-1-3'
,id: 20 ,id: 20
,children: [{ ,children: [{
title: '三级1-3-1' title: 'C-1-3-1'
,id: 21 ,id: 21
},{ },{
title: '三级1-3-2' title: 'C-1-3-2'
,id: 22 ,id: 22
}] }]
}] }]
},{ },{
title: '一级2' title: 'A-2'
,id: 2 ,id: 2
,spread: true ,spread: true
,children: [{ ,children: [{
title: '二级2-1' title: 'B-2-1'
,id: 5 ,id: 5
,spread: true ,spread: true
,children: [{ ,children: [{
title: '三级2-1-1' title: 'C-2-1-1'
,id: 11 ,id: 11
},{ },{
title: '三级2-1-2' title: 'C-2-1-2'
,id: 12 ,id: 12
}] }]
},{ },{
title: '二级2-2' title: 'B-2-2'
,id: 6 ,id: 6
,checked: true ,checked: true
,children: [{ ,children: [{
title: '三级2-2-1' title: 'C-2-2-1'
,id: 13 ,id: 13
},{ },{
title: '三级2-2-2' title: 'C-2-2-2'
,id: 14 ,id: 14
,disabled: true ,disabled: true
}] }]
}] }]
},{ },{
title: '一级3' title: 'A-3'
,id: 16 ,id: 16
,children: [{ ,children: [{
title: '二级3-1' title: 'B-3-1'
,id: 17 ,id: 17
,fixed: true ,fixed: true
,children: [{ ,children: [{
title: '三级3-1-1' title: 'C-3-1-1'
,id: 18 ,id: 18
},{ },{
title: '三级3-1-2' title: 'C-3-1-2'
,id: 19 ,id: 19
}] }]
},{ },{
title: '二级3-2' title: 'B-3-2'
,id: 27 ,id: 27
,children: [{ ,children: [{
title: '三级3-2-1' title: 'C-3-2-1'
,id: 28 ,id: 28
},{ },{
title: '三级3-2-2' title: 'C-3-2-2'
,id: 29 ,id: 29
}] }]
}] }]
@ -222,7 +214,7 @@
console.log(checkedData); console.log(checkedData);
} }
,setChecked: function(){ ,setChecked: function(){
tree.setChecked('demoId1', [1000, 1001, 1002]); tree.setChecked('demoId1', [11,12]);
} }
,reload: function(){ ,reload: function(){
tree.reload('demoId1', { tree.reload('demoId1', {

View File

@ -1,6 +1,6 @@
{ {
"name": "layui", "name": "layui",
"version": "2.8.10", "version": "2.8.11",
"description": "Classic modular Front-End UI library", "description": "Classic modular Front-End UI library",
"main": "dist/layui.js", "main": "dist/layui.js",
"license": "MIT", "license": "MIT",

View File

@ -16,7 +16,7 @@
}; };
var Layui = function(){ var Layui = function(){
this.v = '2.8.10'; // Layui 版本号 this.v = '2.8.11'; // Layui 版本号
}; };
// 识别预先可能定义的指定全局对象 // 识别预先可能定义的指定全局对象

View File

@ -6,36 +6,36 @@
layui.define(['jquery', 'laytpl', 'lay'], function(exports){ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
"use strict"; "use strict";
var $ = layui.$ var $ = layui.$;
,laytpl = layui.laytpl var laytpl = layui.laytpl;
,hint = layui.hint() var hint = layui.hint();
,device = layui.device() var device = layui.device();
,clickOrMousedown = (device.mobile ? 'touchstart' : 'mousedown') var clickOrMousedown = (device.mobile ? 'touchstart' : 'mousedown');
// 模块名 // 模块名
,MOD_NAME = 'dropdown' var MOD_NAME = 'dropdown';
,MOD_INDEX = 'layui_'+ MOD_NAME +'_index' //模块索引名 var MOD_INDEX = 'layui_'+ MOD_NAME +'_index'; // 模块索引名
// 外部接口 // 外部接口
,dropdown = { var dropdown = {
config: {} config: {},
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0 index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0,
// 设置全局项 // 设置全局项
,set: function(options){ set: function(options){
var that = this; var that = this;
that.config = $.extend({}, that.config, options); that.config = $.extend({}, that.config, options);
return that; return that;
} },
// 事件 // 事件
,on: function(events, callback){ on: function(events, callback){
return layui.onevent.call(this, MOD_NAME, events, callback); return layui.onevent.call(this, MOD_NAME, events, callback);
} }
} };
// 操作当前实例 // 操作当前实例
,thisModule = function(){ var thisModule = function(){
var that = this; var that = this;
var options = that.config; var options = that.config;
var id = options.id; var id = options.id;
@ -43,28 +43,41 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
thisModule.that[id] = that; // 记录当前实例对象 thisModule.that[id] = that; // 记录当前实例对象
return { return {
config: options config: options,
// 重置实例 // 重置实例
,reload: function(options){ reload: function(options){
that.reload.call(that, options); that.reload.call(that, options);
} },
,reloadData: function(options){ reloadData: function(options){
dropdown.reloadData(id, options); dropdown.reloadData(id, options);
} },
,close: function () { close: function () {
that.remove() that.remove()
} }
} }
} };
// 字符常量 // 字符常量
,STR_ELEM = 'layui-dropdown', STR_HIDE = 'layui-hide', STR_DISABLED = 'layui-disabled', STR_NONE = 'layui-none' var STR_ELEM = 'layui-dropdown';
,STR_ITEM_UP = 'layui-menu-item-up', STR_ITEM_DOWN = 'layui-menu-item-down', STR_MENU_TITLE = 'layui-menu-body-title', STR_ITEM_GROUP = 'layui-menu-item-group', STR_ITEM_PARENT = 'layui-menu-item-parent', STR_ITEM_DIV = 'layui-menu-item-divider', STR_ITEM_CHECKED = 'layui-menu-item-checked', STR_ITEM_CHECKED2 = 'layui-menu-item-checked2', STR_MENU_PANEL = 'layui-menu-body-panel', STR_MENU_PANEL_L = 'layui-menu-body-panel-left', STR_ELEM_SHADE = 'layui-dropdown-shade' var STR_HIDE = 'layui-hide';
var STR_DISABLED = 'layui-disabled';
var STR_NONE = 'layui-none';
var STR_ITEM_UP = 'layui-menu-item-up';
var STR_ITEM_DOWN = 'layui-menu-item-down';
var STR_MENU_TITLE = 'layui-menu-body-title';
var STR_ITEM_GROUP = 'layui-menu-item-group';
var STR_ITEM_PARENT = 'layui-menu-item-parent';
var STR_ITEM_DIV = 'layui-menu-item-divider';
var STR_ITEM_CHECKED = 'layui-menu-item-checked';
var STR_ITEM_CHECKED2 = 'layui-menu-item-checked2';
var STR_MENU_PANEL = 'layui-menu-body-panel';
var STR_MENU_PANEL_L = 'layui-menu-body-panel-left';
var STR_ELEM_SHADE = 'layui-dropdown-shade';
,STR_GROUP_TITLE = '.'+ STR_ITEM_GROUP + '>.'+ STR_MENU_TITLE var STR_GROUP_TITLE = '.'+ STR_ITEM_GROUP + '>.'+ STR_MENU_TITLE;
// 构造器 // 构造器
,Class = function(options){ var Class = function(options){
var that = this; var that = this;
that.index = ++dropdown.index; that.index = ++dropdown.index;
that.config = $.extend({}, that.config, dropdown.config, options); that.config = $.extend({}, that.config, dropdown.config, options);
@ -73,16 +86,16 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 默认配置 // 默认配置
Class.prototype.config = { Class.prototype.config = {
trigger: 'click' //事件类型 trigger: 'click', // 事件类型
,content: '' //自定义菜单内容 content: '', // 自定义菜单内容
,className: '' //自定义样式类名 className: '', // 自定义样式类名
,style: '' //设置面板 style 属性 style: '', // 设置面板 style 属性
,show: false //是否初始即显示菜单面板 show: false, // 是否初始即显示菜单面板
,isAllowSpread: true //是否允许菜单组展开收缩 isAllowSpread: true, // 是否允许菜单组展开收缩
,isSpreadItem: true //是否初始展开子菜单 isSpreadItem: true, // 是否初始展开子菜单
,data: [] //菜单数据结构 data: [], // 菜单数据结构
,delay: 300 //延迟关闭的毫秒数,若 trigger 为 hover 时才生效 delay: 300, // 延迟关闭的毫秒数,若 trigger 为 hover 时才生效
,shade: 0 // 遮罩 shade: 0 // 遮罩
}; };
// 重载实例 // 重载实例
@ -240,10 +253,10 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
views.append(viewLi); views.append(viewLi);
}); });
return views; return views;
} };
// 主模板 // 主模板
,TPL_MAIN = ['<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit" lay-id="' + options.id + '">' var TPL_MAIN = ['<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit" lay-id="' + options.id + '">'
,'</div>'].join(''); ,'</div>'].join('');
// 如果是右键事件,则每次触发事件时,将允许重新渲染 // 如果是右键事件,则每次触发事件时,将允许重新渲染
@ -336,22 +349,22 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 位置定位 // 位置定位
Class.prototype.position = function(obj){ Class.prototype.position = function(obj){
var that = this var that = this;
,options = that.config; var options = that.config;
lay.position(options.elem[0], that.elemView[0], { lay.position(options.elem[0], that.elemView[0], {
position: options.position position: options.position,
,e: that.e e: that.e,
,clickType: options.trigger === 'contextmenu' ? 'right' : null clickType: options.trigger === 'contextmenu' ? 'right' : null,
,align: options.align || null align: options.align || null
}); });
}; };
// 删除视图 // 删除视图
Class.prototype.remove = function(){ Class.prototype.remove = function(){
var that = this var that = this;
,options = that.config var options = that.config;
,elemPrev = thisModule.prevElem; var elemPrev = thisModule.prevElem;
// 若存在已打开的面板元素,则移除 // 若存在已打开的面板元素,则移除
if(elemPrev){ if(elemPrev){
@ -365,8 +378,8 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 延迟删除视图 // 延迟删除视图
Class.prototype.delayRemove = function(){ Class.prototype.delayRemove = function(){
var that = this var that = this;
,options = that.config; var options = that.config;
clearTimeout(thisModule.timer); clearTimeout(thisModule.timer);
thisModule.timer = setTimeout(function(){ thisModule.timer = setTimeout(function(){
@ -376,10 +389,10 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 事件 // 事件
Class.prototype.events = function(){ Class.prototype.events = function(){
var that = this var that = this;
,options = that.config; var options = that.config;
//如果传入 hover则解析为 mouseenter //传入 hover则解析为 mouseenter
if(options.trigger === 'hover') options.trigger = 'mouseenter'; if(options.trigger === 'hover') options.trigger = 'mouseenter';
// 解除上一个事件 // 解除上一个事件
@ -419,20 +432,21 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 设置菜单组展开和收缩状态 // 设置菜单组展开和收缩状态
thisModule.spread = function(othis){ thisModule.spread = function(othis){
// 菜单组展开和收缩 // 菜单组展开和收缩
var elemIcon = othis.children('.'+ STR_MENU_TITLE).find('.layui-icon'); var needSpread = othis.hasClass(STR_ITEM_UP);
if(othis.hasClass(STR_ITEM_UP)){ var elemIcon = othis.children('.'+ STR_MENU_TITLE).find('.layui-icon-' + (needSpread ? 'down' : 'up'));
if(needSpread){
othis.removeClass(STR_ITEM_UP).addClass(STR_ITEM_DOWN); othis.removeClass(STR_ITEM_UP).addClass(STR_ITEM_DOWN);
elemIcon.removeClass('layui-icon-down').addClass('layui-icon-up'); elemIcon.removeClass('layui-icon-down').addClass('layui-icon-up');
} else { } else {
othis.removeClass(STR_ITEM_DOWN).addClass(STR_ITEM_UP); othis.removeClass(STR_ITEM_DOWN).addClass(STR_ITEM_UP);
elemIcon.removeClass('layui-icon-up').addClass('layui-icon-down') elemIcon.removeClass('layui-icon-up').addClass('layui-icon-down');
} }
}; };
// 全局事件 // 全局事件
;!function(){ (function(){
var _WIN = $(window) var _WIN = $(window);
,_DOC = $(document); var _DOC = $(document);
// 自适应定位 // 自适应定位
_WIN.on('resize', function(){ _WIN.on('resize', function(){
@ -463,7 +477,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
var options = that.config; var options = that.config;
//如果触发的是绑定的元素,或者属于绑定元素的子元素,则不关闭 //触发的是绑定的元素,或者属于绑定元素的子元素,则不关闭
// 满足条件:当前绑定的元素不是 body document或者不是鼠标右键事件 // 满足条件:当前绑定的元素不是 body document或者不是鼠标右键事件
if(!(lay.isTopElem(options.elem[0]) || options.trigger === 'contextmenu')){ if(!(lay.isTopElem(options.elem[0]) || options.trigger === 'contextmenu')){
if( if(
@ -480,11 +494,11 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 基础菜单的静态元素事件 // 基础菜单的静态元素事件
var ELEM_LI = '.layui-menu:not(.layui-dropdown-menu) li'; var ELEM_LI = '.layui-menu:not(.layui-dropdown-menu) li';
_DOC.on('click', ELEM_LI, function(e){ _DOC.on('click', ELEM_LI, function(e){
var othis = $(this) var othis = $(this);
,parent = othis.parents('.layui-menu').eq(0) var parent = othis.parents('.layui-menu').eq(0);
,isChild = othis.hasClass(STR_ITEM_GROUP) || othis.hasClass(STR_ITEM_PARENT) var isChild = othis.hasClass(STR_ITEM_GROUP) || othis.hasClass(STR_ITEM_PARENT);
,filter = parent.attr('lay-filter') || parent.attr('id') var filter = parent.attr('lay-filter') || parent.attr('id');
,options = lay.options(this); var options = lay.options(this);
// 非触发元素 // 非触发元素
if(othis.hasClass(STR_ITEM_DIV)) return; if(othis.hasClass(STR_ITEM_DIV)) return;
@ -506,9 +520,9 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 基础菜单的展开收缩事件 // 基础菜单的展开收缩事件
_DOC.on('click', (ELEM_LI + STR_GROUP_TITLE), function(e){ _DOC.on('click', (ELEM_LI + STR_GROUP_TITLE), function(e){
var othis = $(this) var othis = $(this);
,elemGroup = othis.parents('.'+ STR_ITEM_GROUP +':eq(0)') var elemGroup = othis.parents('.'+ STR_ITEM_GROUP +':eq(0)');
,options = lay.options(elemGroup[0]); var options = lay.options(elemGroup[0]);
if(('isAllowSpread' in options) ? options.isAllowSpread : true){ if(('isAllowSpread' in options) ? options.isAllowSpread : true){
thisModule.spread(elemGroup); thisModule.spread(elemGroup);
@ -518,8 +532,8 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 判断子级菜单是否超出屏幕 // 判断子级菜单是否超出屏幕
var ELEM_LI_PAR = '.layui-menu .'+ STR_ITEM_PARENT var ELEM_LI_PAR = '.layui-menu .'+ STR_ITEM_PARENT
_DOC.on('mouseenter', ELEM_LI_PAR, function(e){ _DOC.on('mouseenter', ELEM_LI_PAR, function(e){
var othis = $(this) var othis = $(this);
,elemPanel = othis.find('.'+ STR_MENU_PANEL); var elemPanel = othis.find('.'+ STR_MENU_PANEL);
if(!elemPanel[0]) return; if(!elemPanel[0]) return;
var rect = elemPanel[0].getBoundingClientRect(); var rect = elemPanel[0].getBoundingClientRect();
@ -540,13 +554,13 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
} }
}).on('mouseleave', ELEM_LI_PAR, function(e){ }).on('mouseleave', ELEM_LI_PAR, function(e){
var othis = $(this) var othis = $(this)
,elemPanel = othis.children('.'+ STR_MENU_PANEL); var elemPanel = othis.children('.'+ STR_MENU_PANEL);
elemPanel.removeClass(STR_MENU_PANEL_L); elemPanel.removeClass(STR_MENU_PANEL_L);
elemPanel.css('margin-top', 0); elemPanel.css('margin-top', 0);
}); });
}(); })();
// 关闭面板 // 关闭面板
dropdown.close = function(id){ dropdown.close = function(id){

View File

@ -277,10 +277,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
value: ['up', 'down'], value: ['up', 'down'],
split: true, split: true,
className: 'layui-input-number', className: 'layui-input-number',
disabled: disabled, // 跟随输入框禁用状态 disabled: othis.is('[disabled]'), // 跟随输入框禁用状态
click: function(elem){ click: function(elem){
var index = $(this).index(); var index = $(this).index();
var value = elem.val(); var value = elem.val();
var rawValue = value;
var step = Number(elem.attr('step')) || 1; // 加减的数字间隔 var step = Number(elem.attr('step')) || 1; // 加减的数字间隔
var min = Number(elem.attr('min')); var min = Number(elem.attr('min'));
var max = Number(elem.attr('max')); var max = Number(elem.attr('max'));
@ -294,11 +295,15 @@ layui.define(['lay', 'layer', 'util'], function(exports){
if(value < min) value = min; if(value < min) value = min;
if(value > max) value = max; if(value > max) value = max;
// 小数点后保留位数 // 获取小数点后位数
var fixed = function(step){ var decimals = function(step){
var decimals = (step.match(/\.(\d+$)/) || [])[1] || ''; var decimals = (step.toString().match(/\.(\d+$)/) || [])[1] || '';
return decimals.length; return decimals.length;
}(step.toString()); };
// 位数比较
var fixed = Math.max(decimals(step), decimals(rawValue));
if(fixed) value = value.toFixed(fixed); if(fixed) value = value.toFixed(fixed);
elem.val(value); elem.val(value);
@ -807,12 +812,12 @@ layui.define(['lay', 'layer', 'util'], function(exports){
var next = $(this).next('.' + CLASS); var next = $(this).next('.' + CLASS);
this.checked = false; this.checked = false;
next.removeClass(CLASS + 'ed'); next.removeClass(CLASS + 'ed');
next.find('.layui-icon').removeClass(ANIM + ' ' + ICON[0]).addClass(ICON[1]); next.children('.layui-icon').removeClass(ANIM + ' ' + ICON[0]).addClass(ICON[1]);
}); });
radio[0].checked = true; radio[0].checked = true;
reElem.addClass(CLASS + 'ed'); reElem.addClass(CLASS + 'ed');
reElem.find('.layui-icon').addClass(ANIM + ' ' + ICON[0]); reElem.children('.layui-icon').addClass(ANIM + ' ' + ICON[0]);
layui.event.call(radio[0], MOD_NAME, 'radio('+ filter +')', { layui.event.call(radio[0], MOD_NAME, 'radio('+ filter +')', {
elem: radio[0], elem: radio[0],

View File

@ -6,12 +6,15 @@
;!function(window, undefined){ ;!function(window, undefined){
"use strict"; "use strict";
var isLayui = window.layui && layui.define, $, win, ready = { var isLayui = window.layui && layui.define;
var $;
var win;
var ready = {
getPath: function(){ getPath: function(){
var jsPath = document.currentScript ? document.currentScript.src : function(){ var jsPath = document.currentScript ? document.currentScript.src : function(){
var js = document.scripts var js = document.scripts;
,last = js.length - 1 var last = js.length - 1;
,src; var src;
for(var i = last; i > 0; i--){ for(var i = last; i > 0; i--){
if(js[i].readyState === 'interactive'){ if(js[i].readyState === 'interactive'){
src = js[i].src; src = js[i].src;
@ -19,8 +22,8 @@ var isLayui = window.layui && layui.define, $, win, ready = {
} }
} }
return src || js[last].src; return src || js[last].src;
}() }();
,GLOBAL = window.LAYUI_GLOBAL || {}; var GLOBAL = window.LAYUI_GLOBAL || {};
return GLOBAL.layer_dir || jsPath.substring(0, jsPath.lastIndexOf('/') + 1); return GLOBAL.layer_dir || jsPath.substring(0, jsPath.lastIndexOf('/') + 1);
}(), }(),
config: { config: {
@ -46,15 +49,15 @@ var isLayui = window.layui && layui.define, $, win, ready = {
// 未设置路径,则不主动加载 css // 未设置路径,则不主动加载 css
if(!layer.path) return; if(!layer.path) return;
var head = document.getElementsByTagName("head")[0] var head = document.getElementsByTagName("head")[0];
,link = document.createElement('link'); var link = document.createElement('link');
if(typeof fn === 'string') cssname = fn; if(typeof fn === 'string') cssname = fn;
var app = (cssname || href).replace(/\.|\//g, ''); var app = (cssname || href).replace(/\.|\//g, '');
var id = 'layuicss-'+ app var id = 'layuicss-'+ app;
,STATUS_NAME = 'creating' var STATUS_NAME = 'creating'
,timeout = 0; var timeout = 0;
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.href = layer.path + href; link.href = layer.path + href;
@ -68,8 +71,8 @@ var isLayui = window.layui && layui.define, $, win, ready = {
// 轮询 css 是否加载完毕 // 轮询 css 是否加载完毕
(function poll(status) { (function poll(status) {
var delay = 100 var delay = 100;
,getLinkElem = document.getElementById(id); //获取动态插入的 link 元素 var getLinkElem = document.getElementById(id); // 获取动态插入的 link 元素
// 如果轮询超过指定秒数,则视为请求文件失败或 css 文件不符合规范 // 如果轮询超过指定秒数,则视为请求文件失败或 css 文件不符合规范
if(++timeout > 10 * 1000 / delay){ if(++timeout > 10 * 1000 / delay){
@ -97,7 +100,7 @@ var isLayui = window.layui && layui.define, $, win, ready = {
// 默认内置方法。 // 默认内置方法。
var layer = { var layer = {
v: '3.6.0', v: '3.7.0',
ie: function(){ // ie 版本 ie: function(){ // ie 版本
var agent = navigator.userAgent.toLowerCase(); var agent = navigator.userAgent.toLowerCase();
return (!!window.ActiveXObject || "ActiveXObject" in window) ? ( return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
@ -539,17 +542,17 @@ Class.pt.auto = function(index){
var that = this, config = that.config, layero = $('#'+ doms[0] + index); var that = this, config = that.config, layero = $('#'+ doms[0] + index);
if(config.area[0] === '' && config.maxWidth > 0){ if(config.area[0] === '' && config.maxWidth > 0){
//为了修复IE7下一个让人难以理解的bug // 适配 ie7
if(layer.ie && layer.ie < 8 && config.btn){ if(layer.ie && layer.ie < 8 && config.btn){
layero.width(layero.innerWidth()); layero.width(layero.innerWidth());
} }
layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth); layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth);
} }
var area = [layero.innerWidth(), layero.innerHeight()] var area = [layero.innerWidth(), layero.innerHeight()];
,titHeight = layero.find(doms[1]).outerHeight() || 0 var titHeight = layero.find(doms[1]).outerHeight() || 0;
,btnHeight = layero.find('.'+doms[6]).outerHeight() || 0 var btnHeight = layero.find('.'+doms[6]).outerHeight() || 0;
,setHeight = function(elem){ var setHeight = function(elem){
elem = layero.find(elem); elem = layero.find(elem);
elem.height(area[1] - titHeight - btnHeight - 2*(parseFloat(elem.css('padding-top'))|0)); elem.height(area[1] - titHeight - btnHeight - 2*(parseFloat(elem.css('padding-top'))|0));
}; };
@ -597,16 +600,16 @@ Class.pt.offset = function(){
that.offsetTop = win.height() - area[1]; that.offsetTop = win.height() - area[1];
} else if(config.offset === 'l'){ // 左 } else if(config.offset === 'l'){ // 左
that.offsetLeft = 0; that.offsetLeft = 0;
} else if(config.offset === 'lt'){ //左上 } else if(config.offset === 'lt'){ // 左上
that.offsetTop = 0; that.offsetTop = 0;
that.offsetLeft = 0; that.offsetLeft = 0;
} else if(config.offset === 'lb'){ //左下 } else if(config.offset === 'lb'){ // 左下
that.offsetTop = win.height() - area[1]; that.offsetTop = win.height() - area[1];
that.offsetLeft = 0; that.offsetLeft = 0;
} else if(config.offset === 'rt'){ //右上 } else if(config.offset === 'rt'){ // 右上
that.offsetTop = 0; that.offsetTop = 0;
that.offsetLeft = win.width() - area[0]; that.offsetLeft = win.width() - area[0];
} else if(config.offset === 'rb'){ //右下 } else if(config.offset === 'rb'){ // 右下
that.offsetTop = win.height() - area[1]; that.offsetTop = win.height() - area[1];
that.offsetLeft = win.width() - area[0]; that.offsetLeft = win.width() - area[0];
} else { } else {
@ -706,13 +709,13 @@ Class.pt.tips = function(){
// 拖拽层 // 拖拽层
Class.pt.move = function(){ Class.pt.move = function(){
var that = this var that = this;
,config = that.config var config = that.config;
,_DOC = $(document) var _DOC = $(document);
,layero = that.layero var layero = that.layero;
,DATA_NAME = ['LAY_MOVE_DICT', 'LAY_RESIZE_DICT'] var DATA_NAME = ['LAY_MOVE_DICT', 'LAY_RESIZE_DICT'];
,moveElem = layero.find(config.move) var moveElem = layero.find(config.move);
,resizeElem = layero.find('.layui-layer-resize'); var resizeElem = layero.find('.layui-layer-resize');
// 给指定元素添加拖动光标 // 给指定元素添加拖动光标
if(config.move) moveElem.css('cursor', 'move'); if(config.move) moveElem.css('cursor', 'move');
@ -720,15 +723,15 @@ Class.pt.move = function(){
// 按下拖动元素 // 按下拖动元素
moveElem.on('mousedown', function(e){ moveElem.on('mousedown', function(e){
if (e.button) {return;} // 不是左键不处理 if (e.button) {return;} // 不是左键不处理
var othis = $(this) var othis = $(this);
,dict = {}; var dict = {};
if(config.move){ if(config.move){
dict.layero = layero; dict.layero = layero;
dict.config = config; dict.config = config;
dict.offset = [ dict.offset = [
e.clientX - parseFloat(layero.css('left')) e.clientX - parseFloat(layero.css('left')),
,e.clientY - parseFloat(layero.css('top')) e.clientY - parseFloat(layero.css('top'))
]; ];
othis.data(DATA_NAME[0], dict); othis.data(DATA_NAME[0], dict);
@ -741,8 +744,8 @@ Class.pt.move = function(){
// 按下右下角拉伸 // 按下右下角拉伸
resizeElem.on('mousedown', function(e){ resizeElem.on('mousedown', function(e){
var othis = $(this) var othis = $(this);
,dict = {}; var dict = {};
if(config.resize){ if(config.resize){
dict.layero = layero; dict.layero = layero;
@ -771,9 +774,9 @@ Class.pt.move = function(){
,layero = dict.layero ,layero = dict.layero
,config = dict.config; ,config = dict.config;
var X = e.clientX - dict.offset[0] var X = e.clientX - dict.offset[0];
,Y = e.clientY - dict.offset[1] var Y = e.clientY - dict.offset[1];
,fixed = layero.css('position') === 'fixed'; var fixed = layero.css('position') === 'fixed';
e.preventDefault(); e.preventDefault();
@ -782,8 +785,8 @@ Class.pt.move = function(){
// 控制元素不被拖出窗口外 // 控制元素不被拖出窗口外
if(!config.moveOut){ if(!config.moveOut){
var setRig = win.width() - layero.outerWidth() + dict.stX var setRig = win.width() - layero.outerWidth() + dict.stX;
,setBot = win.height() - layero.outerHeight() + dict.stY; var setBot = win.height() - layero.outerHeight() + dict.stY;
X < dict.stX && (X = dict.stX); X < dict.stX && (X = dict.stX);
X > setRig && (X = setRig); X > setRig && (X = setRig);
Y < dict.stY && (Y = dict.stY); Y < dict.stY && (Y = dict.stY);
@ -792,18 +795,18 @@ Class.pt.move = function(){
// 拖动时跟随鼠标位置 // 拖动时跟随鼠标位置
layero.css({ layero.css({
left: X left: X,
,top: Y top: Y
}); });
} }
// Resize // Resize
if(ready.eventResizeElem){ if(ready.eventResizeElem){
var dict = ready.eventResizeElem.data(DATA_NAME[1]) || {} var dict = ready.eventResizeElem.data(DATA_NAME[1]) || {};
,config = dict.config; var config = dict.config;
var X = e.clientX - dict.offset[0] var X = e.clientX - dict.offset[0];
,Y = e.clientY - dict.offset[1]; var Y = e.clientY - dict.offset[1];
e.preventDefault(); e.preventDefault();
@ -817,8 +820,8 @@ Class.pt.move = function(){
} }
}).on('mouseup', function(e){ }).on('mouseup', function(e){
if(ready.eventMoveElem){ if(ready.eventMoveElem){
var dict = ready.eventMoveElem.data(DATA_NAME[0]) || {} var dict = ready.eventMoveElem.data(DATA_NAME[0]) || {};
,config = dict.config; var config = dict.config;
ready.eventMoveElem.removeData(DATA_NAME[0]); ready.eventMoveElem.removeData(DATA_NAME[0]);
delete ready.eventMoveElem; delete ready.eventMoveElem;
@ -1279,13 +1282,14 @@ layer.closeLast = function(type){
layer.close($('.layui-layer-'+ type +':last').attr("times")); layer.close($('.layui-layer-'+ type +':last').attr("times"));
}; };
/**
拓展模块layui 开始合并在一起
/*
* 拓展模块layui 开始合并在一起
*/ */
var cache = layer.cache||{}, skin = function(type){
var cache = layer.cache || {};
var skin = function(type){
return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-'+type) : ''); return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-'+type) : '');
}; };
@ -1312,18 +1316,18 @@ layer.prompt = function(options, yes){
delete options.success; delete options.success;
return layer.open($.extend({ return layer.open($.extend({
type: 1 type: 1,
,btn: ['&#x786E;&#x5B9A;','&#x53D6;&#x6D88;'] btn: ['&#x786E;&#x5B9A;','&#x53D6;&#x6D88;'],
,content: content content: content,
,skin: 'layui-layer-prompt' + skin('prompt') skin: 'layui-layer-prompt' + skin('prompt'),
,maxWidth: win.width() maxWidth: win.width(),
,success: function(layero){ success: function(layero){
prompt = layero.find('.layui-layer-input'); prompt = layero.find('.layui-layer-input');
prompt.val(options.value || '').focus(); prompt.val(options.value || '').focus();
typeof success === 'function' && success(layero); typeof success === 'function' && success(layero);
} },
,resize: false resize: false,
,yes: function(index){ yes: function(index){
var value = prompt.val(); var value = prompt.val();
if(value.length > (options.maxlength||500)) { if(value.length > (options.maxlength||500)) {
layer.tips('&#x6700;&#x591A;&#x8F93;&#x5165;'+ (options.maxlength || 500) +'&#x4E2A;&#x5B57;&#x6570;', prompt, {tips: 1}); layer.tips('&#x6700;&#x591A;&#x8F93;&#x5165;'+ (options.maxlength || 500) +'&#x4E2A;&#x5B57;&#x6570;', prompt, {tips: 1});
@ -1390,10 +1394,10 @@ layer.photos = function(options, loop, key){
if(!options.photos) return; if(!options.photos) return;
// 若 photos 并非选择器或 jQuery 对象,则为普通 object // 若 photos 并非选择器或 jQuery 对象,则为普通 object
var isObject = !(typeof options.photos === 'string' || options.photos instanceof $) var isObject = !(typeof options.photos === 'string' || options.photos instanceof $);
,photos = isObject ? options.photos : {} var photos = isObject ? options.photos : {};
,data = photos.data || [] var data = photos.data || [];
,start = photos.start || 0; var start = photos.start || 0;
dict.imgIndex = (start|0) + 1; dict.imgIndex = (start|0) + 1;
options.img = options.img || 'img'; options.img = options.img || 'img';
@ -1401,7 +1405,7 @@ layer.photos = function(options, loop, key){
var success = options.success; var success = options.success;
delete options.success; delete options.success;
//如果 options.photos 不是一个对象 // options.photos 不是一个对象
if(!isObject){ // 页面直接获取 if(!isObject){ // 页面直接获取
var parent = $(options.photos), pushData = function(){ var parent = $(options.photos), pushData = function(){
data = []; data = [];
@ -1544,7 +1548,7 @@ layer.photos = function(options, loop, key){
var imgarea = [img.width, img.height]; var imgarea = [img.width, img.height];
var winarea = [$(window).width() - 100, $(window).height() - 100]; var winarea = [$(window).width() - 100, $(window).height() - 100];
//如果 实际图片的宽或者高比 屏幕大(那么进行缩放) // 实际图片的宽或者高比 屏幕大(那么进行缩放)
if(!options.full && (imgarea[0]>winarea[0]||imgarea[1]>winarea[1])){ if(!options.full && (imgarea[0]>winarea[0]||imgarea[1]>winarea[1])){
var wh = [imgarea[0]/winarea[0],imgarea[1]/winarea[1]];// 取宽度缩放比例、高度缩放比例 var wh = [imgarea[0]/winarea[0],imgarea[1]/winarea[1]];// 取宽度缩放比例、高度缩放比例
if(wh[0] > wh[1]){// 取缩放比例最大的进行缩放 if(wh[0] > wh[1]){// 取缩放比例最大的进行缩放
@ -1633,20 +1637,20 @@ ready.run = function(_$){
// 加载方式 // 加载方式
window.layui && layui.define ? ( window.layui && layui.define ? (
layer.ready() layer.ready(),
,layui.define('jquery', function(exports){ //layui 加载 layui.define('jquery', function(exports){ // layui
layer.path = layui.cache.dir; layer.path = layui.cache.dir;
ready.run(layui.$); ready.run(layui.$);
//暴露模块 // export api
window.layer = layer; window.layer = layer;
exports('layer', layer); exports('layer', layer);
}) })
) : ( ) : (
(typeof define === 'function' && define.amd) ? define(['jquery'], function(){ //requirejs 加载 (typeof define === 'function' && define.amd) ? define(['jquery'], function(){ // requirejs
ready.run(window.jQuery); ready.run(window.jQuery);
return layer; return layer;
}) : function(){ //普通 script 标签加载 }) : function(){ // 普通 script 标签引入
layer.ready(); layer.ready();
ready.run(window.jQuery); ready.run(window.jQuery);
}() }()

View File

@ -555,15 +555,15 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 初始工具栏 // 初始工具栏
Class.prototype.renderToolbar = function(){ Class.prototype.renderToolbar = function(){
var that = this var that = this
,options = that.config var options = that.config
// 添加工具栏左侧模板 // 添加工具栏左侧模板
var leftDefaultTemp = [ var leftDefaultTemp = [
'<div class="layui-inline" lay-event="add"><i class="layui-icon layui-icon-add-1"></i></div>' '<div class="layui-inline" lay-event="add"><i class="layui-icon layui-icon-add-1"></i></div>',
,'<div class="layui-inline" lay-event="update"><i class="layui-icon layui-icon-edit"></i></div>' '<div class="layui-inline" lay-event="update"><i class="layui-icon layui-icon-edit"></i></div>',
,'<div class="layui-inline" lay-event="delete"><i class="layui-icon layui-icon-delete"></i></div>' '<div class="layui-inline" lay-event="delete"><i class="layui-icon layui-icon-delete"></i></div>'
].join('') ].join('');
,elemToolTemp = that.layTool.find('.layui-table-tool-temp'); var elemToolTemp = that.layTool.find('.layui-table-tool-temp');
if(options.toolbar === 'default'){ if(options.toolbar === 'default'){
elemToolTemp.html(leftDefaultTemp); elemToolTemp.html(leftDefaultTemp);
@ -577,19 +577,19 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 添加工具栏右侧面板 // 添加工具栏右侧面板
var layout = { var layout = {
filter: { filter: {
title: '筛选列' title: '筛选列',
,layEvent: 'LAYTABLE_COLS' layEvent: 'LAYTABLE_COLS',
,icon: 'layui-icon-cols' icon: 'layui-icon-cols'
} },
,exports: { exports: {
title: '导出' title: '导出',
,layEvent: 'LAYTABLE_EXPORT' layEvent: 'LAYTABLE_EXPORT',
,icon: 'layui-icon-export' icon: 'layui-icon-export'
} },
,print: { print: {
title: '打印' title: '打印',
,layEvent: 'LAYTABLE_PRINT' layEvent: 'LAYTABLE_PRINT',
,icon: 'layui-icon-print' icon: 'layui-icon-print'
} }
}, iconElem = []; }, iconElem = [];
@ -608,10 +608,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 分页栏 // 分页栏
Class.prototype.renderPagebar = function(){ Class.prototype.renderPagebar = function(){
var that = this var that = this;
,options = that.config var options = that.config;
,layPagebar = that.layPagebar = $('<div class="layui-inline layui-table-pagebar"></div>') var layPagebar = that.layPagebar = $('<div class="layui-inline layui-table-pagebar"></div>');
// 开启分页栏自定义模板 // 开启分页栏自定义模板
if(options.pagebar){ if(options.pagebar){
@ -623,15 +623,15 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 同步表头父列的相关值 // 同步表头父列的相关值
Class.prototype.setParentCol = function(hide, parentKey){ Class.prototype.setParentCol = function(hide, parentKey){
var that = this var that = this;
,options = that.config var options = that.config;
,parentTh = that.layHeader.find('th[data-key="'+ parentKey +'"]') //获取父列元素 var parentTh = that.layHeader.find('th[data-key="'+ parentKey +'"]'); // 获取父列元素
,parentColspan = parseInt(parentTh.attr('colspan')) || 0; var parentColspan = parseInt(parentTh.attr('colspan')) || 0;
if(parentTh[0]){ if(parentTh[0]){
var arrParentKey = parentKey.split('-') var arrParentKey = parentKey.split('-');
,getThisCol = options.cols[arrParentKey[1]][arrParentKey[2]]; var getThisCol = options.cols[arrParentKey[1]][arrParentKey[2]];
hide ? parentColspan-- : parentColspan++; hide ? parentColspan-- : parentColspan++;
@ -1784,7 +1784,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
that.layFixed.find(ELEM_BODY).css( that.layFixed.find(ELEM_BODY).css(
'height', 'height',
layMainTable.height() >= fixHeight ? fixHeight : 'auto' layMainTable.height() >= fixHeight ? fixHeight : 'auto'
); ).scrollTop(that.layMain.scrollTop()); // 固定列滚动条高度
// 表格宽度小于容器宽度时,隐藏固定列 // 表格宽度小于容器宽度时,隐藏固定列
that.layFixRight[ that.layFixRight[
@ -2484,9 +2484,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 同步滚动条 // 同步滚动条
that.layMain.on('scroll', function(){ that.layMain.on('scroll', function(){
var othis = $(this) var othis = $(this);
,scrollLeft = othis.scrollLeft() var scrollLeft = othis.scrollLeft();
,scrollTop = othis.scrollTop(); var scrollTop = othis.scrollTop();
that.layHeader.scrollLeft(scrollLeft); that.layHeader.scrollLeft(scrollLeft);
that.layTotal.scrollLeft(scrollLeft); that.layTotal.scrollLeft(scrollLeft);
@ -2495,7 +2495,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
layer.close(that.tipsIndex); layer.close(that.tipsIndex);
}); });
//适应 // 适应
_WIN.on('resize', function(){ _WIN.on('resize', function(){
that.resize(); that.resize();
}); });
@ -2796,7 +2796,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 表合计 // 表合计
thatTable && layui.each(thatTable.dataTotal, function(i, o){ thatTable && layui.each(thatTable.dataTotal, function(i, o){
fieldsIsHide[o.field] || dataTotal.push(o.total); fieldsIsHide[o.field] || dataTotal.push('"' + (o.total || '') + '"');
}); });
return dataTitle.join(',') + '\r\n' + dataMain.join('\r\n') + '\r\n' + dataTotal.join(','); return dataTitle.join(',') + '\r\n' + dataMain.join('\r\n') + '\r\n' + dataTotal.join(',');

View File

@ -5,71 +5,84 @@
layui.define('form', function(exports){ layui.define('form', function(exports){
"use strict"; "use strict";
var $ = layui.$ var $ = layui.$;
,form = layui.form var form = layui.form;
,layer = layui.layer var layer = layui.layer;
// 模块名 // 模块名
,MOD_NAME = 'tree' var MOD_NAME = 'tree';
// 外部接口 // 外部接口
,tree = { var tree = {
config: {} config: {},
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0 index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0,
// 设置全局项 // 设置全局项
,set: function(options){ set: function(options){
var that = this; var that = this;
that.config = $.extend({}, that.config, options); that.config = $.extend({}, that.config, options);
return that; return that;
} },
// 事件 // 事件
,on: function(events, callback){ on: function(events, callback){
return layui.onevent.call(this, MOD_NAME, events, callback); return layui.onevent.call(this, MOD_NAME, events, callback);
} }
} };
// 操作当前实例 // 操作当前实例
,thisModule = function(){ var thisModule = function(){
var that = this var that = this;
,options = that.config var options = that.config;
,id = options.id || that.index; var id = options.id || that.index;
thisModule.that[id] = that; // 记录当前实例对象 thisModule.that[id] = that; // 记录当前实例对象
thisModule.config[id] = options; // 记录当前实例配置项 thisModule.config[id] = options; // 记录当前实例配置项
return { return {
config: options config: options,
// 重置实例 // 重置实例
,reload: function(options){ reload: function(options){
that.reload.call(that, options); that.reload.call(that, options);
} },
,getChecked: function(){ getChecked: function(){
return that.getChecked.call(that); return that.getChecked.call(that);
} },
,setChecked: function(id){//设置值 setChecked: function(id){// 设置值
return that.setChecked.call(that, id); return that.setChecked.call(that, id);
} }
} }
} };
// 获取当前实例配置项 // 获取当前实例配置项
,getThisModuleConfig = function(id){ var getThisModuleConfig = function(id){
var config = thisModule.config[id]; var config = thisModule.config[id];
if(!config) hint.error('The ID option was not found in the '+ MOD_NAME +' instance'); if(!config) hint.error('The ID option was not found in the '+ MOD_NAME +' instance');
return config || null; return config || null;
} }
// 字符常量 // 字符常量
,SHOW = 'layui-show', HIDE = 'layui-hide', NONE = 'layui-none', DISABLED = 'layui-disabled' var SHOW = 'layui-show';
var HIDE = 'layui-hide';
var NONE = 'layui-none';
var DISABLED = 'layui-disabled';
,ELEM_VIEW = 'layui-tree', ELEM_SET = 'layui-tree-set', ICON_CLICK = 'layui-tree-iconClick' var ELEM_VIEW = 'layui-tree';
,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' var ELEM_SET = 'layui-tree-set';
,ELEM_LINE_SHORT = 'layui-tree-setLineShort', ELEM_SHOW = 'layui-tree-showLine', ELEM_EXTEND = 'layui-tree-lineExtend' var ICON_CLICK = 'layui-tree-iconClick';
var ICON_ADD = 'layui-icon-addition';
var ICON_SUB = 'layui-icon-subtraction';
var ELEM_ENTRY = 'layui-tree-entry';
var ELEM_MAIN = 'layui-tree-main';
var ELEM_TEXT = 'layui-tree-txt';
var ELEM_PACK = 'layui-tree-pack';
var ELEM_SPREAD = 'layui-tree-spread';
var ELEM_LINE_SHORT = 'layui-tree-setLineShort';
var ELEM_SHOW = 'layui-tree-showLine';
var ELEM_EXTEND = 'layui-tree-lineExtend';
// 构造器 // 构造器
,Class = function(options){ var Class = function(options){
var that = this; var that = this;
that.index = ++tree.index; that.index = ++tree.index;
that.config = $.extend({}, that.config, tree.config, options); that.config = $.extend({}, that.config, tree.config, options);
@ -78,18 +91,18 @@ layui.define('form', function(exports){
// 默认配置 // 默认配置
Class.prototype.config = { Class.prototype.config = {
data: [] //数据 data: [], // 数据
,showCheckbox: false //是否显示复选框 showCheckbox: false, // 是否显示复选框
,showLine: true //是否开启连接线 showLine: true, // 是否开启连接线
,accordion: false //是否开启手风琴模式 accordion: false, // 是否开启手风琴模式
,onlyIconControl: false //是否仅允许节点左侧图标控制展开收缩 onlyIconControl: false, // 是否仅允许节点左侧图标控制展开收缩
,isJump: false //是否允许点击节点时弹出新窗口跳转 isJump: false, // 是否允许点击节点时弹出新窗口跳转
,edit: false //是否开启节点的操作图标 edit: false, // 是否开启节点的操作图标
,text: { text: {
defaultNodeName: '未命名' //节点默认名称 defaultNodeName: '未命名', // 节点默认名称
,none: '无数据' //数据为空时的文本提示 none: '无数据' // 数据为空时的文本提示
} }
}; };
@ -107,8 +120,8 @@ layui.define('form', function(exports){
// 主体渲染 // 主体渲染
Class.prototype.render = function(){ Class.prototype.render = function(){
var that = this var that = this;
,options = that.config; var options = that.config;
that.checkids = []; that.checkids = [];
@ -163,15 +176,15 @@ layui.define('form', function(exports){
// 节点解析 // 节点解析
Class.prototype.tree = function(elem, children){ Class.prototype.tree = function(elem, children){
var that = this var that = this;
,options = that.config var options = that.config;
,data = children || options.data; var data = children || options.data;
// 遍历数据 // 遍历数据
layui.each(data, function(index, item){ layui.each(data, function(index, item){
var hasChild = item.children && item.children.length > 0 var hasChild = item.children && item.children.length > 0;
,packDiv = $('<div class="layui-tree-pack" '+ (item.spread ? 'style="display: block;"' : '') +'></div>') var packDiv = $('<div class="layui-tree-pack" '+ (item.spread ? 'style="display: block;"' : '') +'></div>');
,entryDiv = $(['<div data-id="'+ item.id +'" class="layui-tree-set'+ (item.spread ? " layui-tree-spread" : "") + (item.checked ? " layui-tree-checkedFirst" : "") +'">' var entryDiv = $(['<div data-id="'+ item.id +'" class="layui-tree-set'+ (item.spread ? " layui-tree-spread" : "") + (item.checked ? " layui-tree-checkedFirst" : "") +'">'
,'<div class="layui-tree-entry">' ,'<div class="layui-tree-entry">'
,'<div class="layui-tree-main">' ,'<div class="layui-tree-main">'
// 箭头 // 箭头
@ -260,14 +273,15 @@ layui.define('form', function(exports){
// 展开节点 // 展开节点
Class.prototype.spread = function(elem, item){ Class.prototype.spread = function(elem, item){
var that = this var that = this;
,options = that.config var options = that.config;
,entry = elem.children('.'+ELEM_ENTRY) var entry = elem.children('.'+ELEM_ENTRY);
,elemMain = entry.children('.'+ ELEM_MAIN) var elemMain = entry.children('.'+ ELEM_MAIN);
,elemIcon = entry.find('.'+ ICON_CLICK) var elemCheckbox = elemMain.find('input[same="layuiTreeCheck"]');
,elemText = entry.find('.'+ ELEM_TEXT) var elemIcon = entry.find('.'+ ICON_CLICK);
,touchOpen = options.onlyIconControl ? elemIcon : elemMain //判断展开通过节点还是箭头图标 var elemText = entry.find('.'+ ELEM_TEXT);
,state = ''; var touchOpen = options.onlyIconControl ? elemIcon : elemMain; // 判断展开通过节点还是箭头图标
var state = '';
// 展开收缩 // 展开收缩
touchOpen.on('click', function(e){ touchOpen.on('click', function(e){
@ -312,28 +326,34 @@ layui.define('form', function(exports){
state = options.onlyIconControl ? 'close' : 'open'; state = options.onlyIconControl ? 'close' : 'open';
} }
// 获取选中状态
if(elemCheckbox[0]){
item['checked'] = elemCheckbox.prop('checked');
}
// 点击产生的回调 // 点击产生的回调
options.click && options.click({ options.click && options.click({
elem: elem elem: elem,
,state: state state: state,
,data: item data: item
}); });
}); });
}; };
// 计算复选框选中状态 // 计算复选框选中状态
Class.prototype.setCheckbox = function(elem, item, elemCheckbox){ Class.prototype.setCheckbox = function(elem, item, elemCheckbox){
var that = this var that = this;
,options = that.config var options = that.config;
,checked = elemCheckbox.prop('checked'); var checked = elemCheckbox.prop('checked');
if(elemCheckbox.prop('disabled')) return; if(elemCheckbox.prop('disabled')) return;
// 同步子节点选中状态 // 同步子节点选中状态
if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){ if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){
var childs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]'); var elemCheckboxs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]');
childs.each(function(){ elemCheckboxs.each(function(index){
if(this.disabled) return; // 不可点击则跳过 if(this.disabled) return; // 不可点击则跳过
if(item.children[index]) item.children[index]['checked'] = checked;
this.checked = checked; this.checked = checked;
}); });
}; };
@ -343,10 +363,10 @@ layui.define('form', function(exports){
// 若无父节点,则终止递归 // 若无父节点,则终止递归
if(!thisNodeElem.parents('.'+ ELEM_SET)[0]) return; if(!thisNodeElem.parents('.'+ ELEM_SET)[0]) return;
var state var state;
,parentPack = thisNodeElem.parent('.'+ ELEM_PACK) var parentPack = thisNodeElem.parent('.'+ ELEM_PACK);
,parentNodeElem = parentPack.parent() var parentNodeElem = parentPack.parent();
,parentCheckbox = parentPack.prev().find('input[same="layuiTreeCheck"]'); var parentCheckbox = parentPack.prev().find('input[same="layuiTreeCheck"]');
// 如果子节点有任意一条选中,则父节点为选中状态 // 如果子节点有任意一条选中,则父节点为选中状态
if(checked){ if(checked){
@ -373,10 +393,10 @@ layui.define('form', function(exports){
// 复选框选择 // 复选框选择
Class.prototype.checkClick = function(elem, item){ Class.prototype.checkClick = function(elem, item){
var that = this var that = this;
,options = that.config var options = that.config;
,entry = elem.children('.'+ ELEM_ENTRY) var entry = elem.children('.'+ ELEM_ENTRY);
,elemMain = entry.children('.'+ ELEM_MAIN); var elemMain = entry.children('.'+ ELEM_MAIN);
@ -384,38 +404,39 @@ layui.define('form', function(exports){
elemMain.on('click', 'input[same="layuiTreeCheck"]+', function(e){ elemMain.on('click', 'input[same="layuiTreeCheck"]+', function(e){
layui.stope(e); // 阻止点击节点事件 layui.stope(e); // 阻止点击节点事件
var elemCheckbox = $(this).prev() var elemCheckbox = $(this).prev();
,checked = elemCheckbox.prop('checked'); var checked = elemCheckbox.prop('checked');
if(elemCheckbox.prop('disabled')) return; if(elemCheckbox.prop('disabled')) return;
that.setCheckbox(elem, item, elemCheckbox); that.setCheckbox(elem, item, elemCheckbox);
item.checked = checked;
// 复选框点击产生的回调 // 复选框点击产生的回调
options.oncheck && options.oncheck({ options.oncheck && options.oncheck({
elem: elem elem: elem,
,checked: checked checked: checked,
,data: item data: item
}); });
}); });
}; };
// 节点操作 // 节点操作
Class.prototype.operate = function(elem, item){ Class.prototype.operate = function(elem, item){
var that = this var that = this;
,options = that.config var options = that.config;
,entry = elem.children('.'+ ELEM_ENTRY) var entry = elem.children('.'+ ELEM_ENTRY);
,elemMain = entry.children('.'+ ELEM_MAIN); var elemMain = entry.children('.'+ ELEM_MAIN);
entry.children('.layui-tree-btnGroup').on('click', '.layui-icon', function(e){ entry.children('.layui-tree-btnGroup').on('click', '.layui-icon', function(e){
layui.stope(e); // 阻止节点操作 layui.stope(e); // 阻止节点操作
var type = $(this).data("type") var type = $(this).data("type");
,packCont = elem.children('.'+ELEM_PACK) var packCont = elem.children('.'+ELEM_PACK);
,returnObj = { var returnObj = {
data: item data: item,
,type: type type: type,
,elem:elem elem:elem
}; };
// 增加 // 增加
if(type == 'add'){ if(type == 'add'){
@ -434,8 +455,9 @@ layui.define('form', function(exports){
}; };
// 新增节点 // 新增节点
var key = options.operate && options.operate(returnObj) var key = options.operate && options.operate(returnObj);
,obj = {}; var obj = {};
obj.title = options.text.defaultNodeName; obj.title = options.text.defaultNodeName;
obj.id = key; obj.id = key;
that.tree(elem.children('.'+ELEM_PACK), [obj]); that.tree(elem.children('.'+ELEM_PACK), [obj]);
@ -445,8 +467,10 @@ layui.define('form', function(exports){
// 节点本身无子节点 // 节点本身无子节点
if(!packCont[0]){ if(!packCont[0]){
// 遍历兄弟节点,判断兄弟节点是否有子节点 // 遍历兄弟节点,判断兄弟节点是否有子节点
var siblings = elem.siblings('.'+ELEM_SET), num = 1 var siblings = elem.siblings('.'+ELEM_SET)
,parentPack = elem.parent('.'+ELEM_PACK); var num = 1;
var parentPack = elem.parent('.'+ELEM_PACK);
layui.each(siblings, function(index, i){ layui.each(siblings, function(index, i){
if(!$(i).children('.'+ELEM_PACK)[0]){ if(!$(i).children('.'+ELEM_PACK)[0]){
num = 0; num = 0;
@ -551,10 +575,12 @@ layui.define('form', function(exports){
var elemDel = function(elem){ var elemDel = function(elem){
// 若无父结点,则不执行 // 若无父结点,则不执行
if(!elem.parents('.'+ELEM_SET)[0]) return; if(!elem.parents('.'+ELEM_SET)[0]) return;
var siblingTree = elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY) var siblingTree = elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY);
,parentTree = elem.parent('.'+ELEM_PACK).prev() var parentTree = elem.parent('.'+ELEM_PACK).prev();
,checkState = parentTree.find('input[same="layuiTreeCheck"]')[0] var checkState = parentTree.find('input[same="layuiTreeCheck"]')[0];
,state = 1, num = 0; var state = 1;
var num = 0;
// 若父节点未勾选 // 若父节点未勾选
if(checkState.checked == false){ if(checkState.checked == false){
// 遍历兄弟节点 // 遍历兄弟节点
@ -583,8 +609,10 @@ layui.define('form', function(exports){
// 若开启连接线 // 若开启连接线
if(options.showLine){ if(options.showLine){
// 遍历兄弟节点,判断兄弟节点是否有子节点 // 遍历兄弟节点,判断兄弟节点是否有子节点
var siblings = elem.siblings('.'+ELEM_SET), num = 1 var siblings = elem.siblings('.'+ELEM_SET);
,parentPack = elem.parent('.'+ELEM_PACK); var num = 1;
var parentPack = elem.parent('.'+ELEM_PACK);
layui.each(siblings, function(index, i){ layui.each(siblings, function(index, i){
if(!$(i).children('.'+ELEM_PACK)[0]){ if(!$(i).children('.'+ELEM_PACK)[0]){
num = 0; num = 0;
@ -651,19 +679,19 @@ layui.define('form', function(exports){
// 部分事件 // 部分事件
Class.prototype.events = function(){ Class.prototype.events = function(){
var that = this var that = this;
,options = that.config var options = that.config;
,checkWarp = that.elem.find('.layui-tree-checkedFirst'); var checkWarp = that.elem.find('.layui-tree-checkedFirst');
// 初始选中 // 初始选中
that.setChecked(that.checkids); that.setChecked(that.checkids);
// 搜索 // 搜索
that.elem.find('.layui-tree-search').on('keyup', function(){ that.elem.find('.layui-tree-search').on('keyup', function(){
var input = $(this) var input = $(this);
,val = input.val() var val = input.val();
,pack = input.nextAll() var pack = input.nextAll();
,arr = []; var arr = [];
// 遍历所有的值 // 遍历所有的值
pack.find('.'+ ELEM_TEXT).each(function(){ pack.find('.'+ ELEM_TEXT).each(function(){
@ -712,10 +740,10 @@ layui.define('form', function(exports){
// 得到选中节点 // 得到选中节点
Class.prototype.getChecked = function(){ Class.prototype.getChecked = function(){
var that = this var that = this;
,options = that.config var options = that.config;
,checkId = [] var checkId = [];
,checkData = []; var checkData = [];
// 遍历节点找到选中索引 // 遍历节点找到选中索引
that.elem.find('.layui-form-checked').each(function(){ that.elem.find('.layui-form-checked').each(function(){
@ -727,6 +755,7 @@ layui.define('form', function(exports){
layui.each(data, function(index, item){ layui.each(data, function(index, item){
layui.each(checkId, function(index2, item2){ layui.each(checkId, function(index2, item2){
if(item.id == item2){ if(item.id == item2){
item['checked'] = true;
var cloneItem = $.extend({}, item); var cloneItem = $.extend({}, item);
delete cloneItem.children; delete cloneItem.children;
@ -749,14 +778,14 @@ layui.define('form', function(exports){
// 设置选中节点 // 设置选中节点
Class.prototype.setChecked = function(checkedId){ Class.prototype.setChecked = function(checkedId){
var that = this var that = this;
,options = that.config; var options = that.config;
// 初始选中 // 初始选中
that.elem.find('.'+ELEM_SET).each(function(i, item){ that.elem.find('.'+ELEM_SET).each(function(i, item){
var thisId = $(this).data('id') var thisId = $(this).data('id');
,input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]') var input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]');
,reInput = input.next(); var reInput = input.next();
// 若返回数字 // 若返回数字
if(typeof checkedId === 'number'){ if(typeof checkedId === 'number'){

View File

@ -1008,7 +1008,7 @@ layui.define(['table'], function (exports) {
layui.stope(event); layui.stope(event);
// 处理数据 // 处理数据
// var trElem = item.closest('tr'); // var trElem = item.closest('tr');
expandNode({trElem}, null, null, null, true); expandNode({trElem: trElem}, null, null, null, true);
}); });
}); });