mirror of https://github.com/layui/layui
Merge branch 'layui:2.x' into 2.x
commit
c50b1197b6
File diff suppressed because one or more lines are too long
|
@ -12,21 +12,21 @@ toc: true
|
|||
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code']}">
|
||||
<textarea>
|
||||
<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 layui-btn-normal">百搭按钮</button>
|
||||
<button type="button" class="layui-btn layui-btn-warm">暖色按钮</button>
|
||||
<button type="button" class="layui-btn layui-btn-danger">警告按钮</button>
|
||||
<button type="button" class="layui-btn layui-bg-blue">蓝色按钮</button>
|
||||
<button type="button" class="layui-btn layui-bg-orange">橙色按钮</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>
|
||||
</div>
|
||||
|
||||
<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-blue">百搭按钮</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-black">深色按钮</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-red">红色按钮</button>
|
||||
<button class="layui-btn layui-btn-primary layui-border-purple">紫色按钮</button>
|
||||
<button class="layui-btn layui-btn-primary layui-border">普通按钮</button>
|
||||
</div>
|
||||
</textarea>
|
||||
</pre>
|
||||
|
|
|
@ -266,6 +266,7 @@ click: function(data, othis){
|
|||
/*
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
```
|
||||
|
||||
用法详见:[#示例](#examples)
|
||||
|
|
|
@ -61,8 +61,8 @@ toc: true
|
|||
- 通过 `class="layui-form"` 定义一个表单域,通常设置在`<form>`标签上, 或普通`<div>` 标签亦可。
|
||||
- 通过 `class="layui-form-item"` 定义一个块级元素的表单项容器
|
||||
- 通过 `class="layui-form-label"` 定义标签
|
||||
- 通过 `class="layui-form-block"` 定义表单项父容器为块级元素
|
||||
- 通过 `class="layui-form-inline"` 或 `class="layui-inline"` 定义表单项父容器为行内块元素
|
||||
- 通过 `class="layui-input-block"` 定义表单项父容器为块级元素
|
||||
- 通过 `class="layui-input-inline"` 或 `class="layui-inline"` 定义表单项父容器为行内块元素
|
||||
|
||||
即必须按照规定的层级定义相应的 `class`。
|
||||
|
||||
|
@ -408,7 +408,7 @@ form.on('select(test)', function(data){
|
|||
| 属性名 | 描述 | 类型 | 默认值 |
|
||||
| --- | --- | --- | --- |
|
||||
| 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 组件进行全局设置。
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ toc: true
|
|||
数字输入框 <sup>2.8.9+</sup>
|
||||
</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){
|
||||
obj.render();
|
||||
|
@ -130,8 +130,11 @@ toc: true
|
|||
<div class="layui-col-xs6">
|
||||
<input type="number" lay-affix="number" placeholder="设置 step,min,max" step="10" min="0" max="100" class="layui-input">
|
||||
</div>
|
||||
<div class="layui-col-xs12">
|
||||
<input type="number" lay-affix="number" disabled placeholder="禁用状态" value="0" class="layui-input">
|
||||
<div class="layui-col-xs6">
|
||||
<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>
|
||||
|
|
|
@ -24,7 +24,7 @@ toc: true
|
|||
- 通过 `<li></li>` 放置菜单列表项
|
||||
- 属性:
|
||||
- 追加 `className` 为 `layui-menu-item-group` 可设置当前菜单为菜单组,即子菜单为纵向层级。
|
||||
- 或追加 `className` 为 `layui-menu-item-parent` 可这支当前菜单为父级菜单,即子菜单为横向层级。
|
||||
- 或追加 `className` 为 `layui-menu-item-parent` 可设置当前菜单为父级菜单,即子菜单为横向层级。
|
||||
- 追加 `className` 为 `layui-menu-item-divider` 可设置分隔线。
|
||||
- 追加 `className` 为 `layui-menu-item-up` 或 `layui-menu-item-down` 可设置子菜单默认收缩或展开。
|
||||
- 追加 `className` 为 `layui-menu-item-checked` 可设置当前菜单为选中状态
|
||||
|
|
|
@ -19,7 +19,7 @@ layui.use(function(){
|
|||
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({
|
||||
|
|
|
@ -11,6 +11,28 @@ toc: true
|
|||
|
||||
> 导读:📑 [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">
|
||||
2.8.10
|
||||
<span class="layui-badge-rim">2023-07-03</span>
|
||||
|
|
|
@ -120,6 +120,9 @@
|
|||
</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">
|
||||
<input type="number" step="0.01" min="0" max="10" name="arr[]" required placeholder="数字输入框" lay-affix="number" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
|
@ -341,17 +344,13 @@
|
|||
<div class="layui-form-item" pane>
|
||||
<label class="layui-form-label">单选框</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="sex" value="男" title="男">
|
||||
<input type="radio" name="sex" value="女" title="女" checked>
|
||||
<input type="radio" name="sex" value="中型" title="中" disabled>
|
||||
<input type="radio" name="sex" value="1" title="男">
|
||||
<input type="radio" name="sex" value="0" title="女" checked>
|
||||
<input type="radio" name="sex" value="-1">
|
||||
<div lay-radio>
|
||||
保密 <i class="layui-icon layui-icon-user"></i>
|
||||
</div>
|
||||
</div>
|
||||
<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="中">
|
||||
<input type="radio" name="sex" value="" title="禁用" disabled>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
|
@ -436,7 +435,7 @@
|
|||
,'interest': 3
|
||||
,'like[write]': true
|
||||
//,'open': false
|
||||
,'sex': '男'
|
||||
,'sex': '0'
|
||||
,'desc': 'form 是我们非常看重的一块'
|
||||
,xxxxxxxxx: 123
|
||||
});
|
||||
|
|
|
@ -1,18 +1,10 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<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="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
|
||||
<title>树组件 - layui</title>
|
||||
<link rel="stylesheet" href="../src/css/layui.css" media="all">
|
||||
|
||||
<style>
|
||||
body{padding: 100px;}
|
||||
#test1,#test2{margin-bottom: 100px; width: 400px;}
|
||||
|
@ -48,118 +40,118 @@
|
|||
|
||||
//数据源
|
||||
var data1 = [{
|
||||
title: '一级1'
|
||||
title: 'A-1'
|
||||
,id: 1
|
||||
,children: [{
|
||||
title: '二级1-1'
|
||||
title: 'B-1-1'
|
||||
,id: 3
|
||||
,href: 'https://www.layui.com/doc/'
|
||||
,children: [{
|
||||
title: '三级1-1-3'
|
||||
title: 'C-1-1-3'
|
||||
,id: 23
|
||||
,children: [{
|
||||
title: '四级1-1-3-1'
|
||||
title: 'D-1-1-3-1'
|
||||
,id: 24
|
||||
,children: [{
|
||||
title: '五级1-1-3-1-1'
|
||||
title: 'E-1-1-3-1-1'
|
||||
,id: 30
|
||||
},{
|
||||
title: '五级1-1-3-1-2'
|
||||
title: 'E-1-1-3-1-2'
|
||||
,id: 31
|
||||
}]
|
||||
}]
|
||||
},{
|
||||
title: '三级1-1-1'
|
||||
title: 'C-1-1-1'
|
||||
,id: 7
|
||||
,checked: true
|
||||
,children: [{
|
||||
title: '四级1-1-1-1'
|
||||
title: 'D-1-1-1-1'
|
||||
,id: 15
|
||||
//,checked: true
|
||||
,href: 'https://www.layui.com/doc/base/infrastructure.html'
|
||||
}]
|
||||
},{
|
||||
title: '三级1-1-2'
|
||||
title: 'C-1-1-2'
|
||||
,id: 8
|
||||
,children: [{
|
||||
title: '四级1-1-2-1'
|
||||
title: 'D-1-1-2-1'
|
||||
,id: 32
|
||||
}]
|
||||
}]
|
||||
},{
|
||||
title: '二级1-2'
|
||||
title: 'B-1-2'
|
||||
,id: 4
|
||||
,spread: true
|
||||
,children: [{
|
||||
title: '三级1-2-1'
|
||||
title: 'C-1-2-1'
|
||||
,id: 9
|
||||
,checked: true
|
||||
,disabled: true
|
||||
},{
|
||||
title: '三级1-2-2'
|
||||
title: 'C-1-2-2'
|
||||
,id: 10
|
||||
}]
|
||||
},{
|
||||
title: '二级1-3'
|
||||
title: 'B-1-3'
|
||||
,id: 20
|
||||
,children: [{
|
||||
title: '三级1-3-1'
|
||||
title: 'C-1-3-1'
|
||||
,id: 21
|
||||
},{
|
||||
title: '三级1-3-2'
|
||||
title: 'C-1-3-2'
|
||||
,id: 22
|
||||
}]
|
||||
}]
|
||||
},{
|
||||
title: '一级2'
|
||||
title: 'A-2'
|
||||
,id: 2
|
||||
,spread: true
|
||||
,children: [{
|
||||
title: '二级2-1'
|
||||
title: 'B-2-1'
|
||||
,id: 5
|
||||
,spread: true
|
||||
,children: [{
|
||||
title: '三级2-1-1'
|
||||
title: 'C-2-1-1'
|
||||
,id: 11
|
||||
},{
|
||||
title: '三级2-1-2'
|
||||
title: 'C-2-1-2'
|
||||
,id: 12
|
||||
}]
|
||||
},{
|
||||
title: '二级2-2'
|
||||
title: 'B-2-2'
|
||||
,id: 6
|
||||
,checked: true
|
||||
,children: [{
|
||||
title: '三级2-2-1'
|
||||
title: 'C-2-2-1'
|
||||
,id: 13
|
||||
},{
|
||||
title: '三级2-2-2'
|
||||
title: 'C-2-2-2'
|
||||
,id: 14
|
||||
,disabled: true
|
||||
}]
|
||||
}]
|
||||
},{
|
||||
title: '一级3'
|
||||
title: 'A-3'
|
||||
,id: 16
|
||||
,children: [{
|
||||
title: '二级3-1'
|
||||
title: 'B-3-1'
|
||||
,id: 17
|
||||
,fixed: true
|
||||
,children: [{
|
||||
title: '三级3-1-1'
|
||||
title: 'C-3-1-1'
|
||||
,id: 18
|
||||
},{
|
||||
title: '三级3-1-2'
|
||||
title: 'C-3-1-2'
|
||||
,id: 19
|
||||
}]
|
||||
},{
|
||||
title: '二级3-2'
|
||||
title: 'B-3-2'
|
||||
,id: 27
|
||||
,children: [{
|
||||
title: '三级3-2-1'
|
||||
title: 'C-3-2-1'
|
||||
,id: 28
|
||||
},{
|
||||
title: '三级3-2-2'
|
||||
title: 'C-3-2-2'
|
||||
,id: 29
|
||||
}]
|
||||
}]
|
||||
|
@ -222,7 +214,7 @@
|
|||
console.log(checkedData);
|
||||
}
|
||||
,setChecked: function(){
|
||||
tree.setChecked('demoId1', [1000, 1001, 1002]);
|
||||
tree.setChecked('demoId1', [11,12]);
|
||||
}
|
||||
,reload: function(){
|
||||
tree.reload('demoId1', {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "layui",
|
||||
"version": "2.8.10",
|
||||
"version": "2.8.11",
|
||||
"description": "Classic modular Front-End UI library",
|
||||
"main": "dist/layui.js",
|
||||
"license": "MIT",
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
};
|
||||
|
||||
var Layui = function(){
|
||||
this.v = '2.8.10'; // Layui 版本号
|
||||
this.v = '2.8.11'; // Layui 版本号
|
||||
};
|
||||
|
||||
// 识别预先可能定义的指定全局对象
|
||||
|
|
|
@ -6,36 +6,36 @@
|
|||
layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,laytpl = layui.laytpl
|
||||
,hint = layui.hint()
|
||||
,device = layui.device()
|
||||
,clickOrMousedown = (device.mobile ? 'touchstart' : 'mousedown')
|
||||
var $ = layui.$;
|
||||
var laytpl = layui.laytpl;
|
||||
var hint = layui.hint();
|
||||
var device = layui.device();
|
||||
var clickOrMousedown = (device.mobile ? 'touchstart' : 'mousedown');
|
||||
|
||||
// 模块名
|
||||
,MOD_NAME = 'dropdown'
|
||||
,MOD_INDEX = 'layui_'+ MOD_NAME +'_index' //模块索引名
|
||||
var MOD_NAME = 'dropdown';
|
||||
var MOD_INDEX = 'layui_'+ MOD_NAME +'_index'; // 模块索引名
|
||||
|
||||
// 外部接口
|
||||
,dropdown = {
|
||||
config: {}
|
||||
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0
|
||||
var dropdown = {
|
||||
config: {},
|
||||
index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0,
|
||||
|
||||
// 设置全局项
|
||||
,set: function(options){
|
||||
set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
},
|
||||
|
||||
// 事件
|
||||
,on: function(events, callback){
|
||||
on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 操作当前实例
|
||||
,thisModule = function(){
|
||||
var thisModule = function(){
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var id = options.id;
|
||||
|
@ -43,28 +43,41 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
thisModule.that[id] = that; // 记录当前实例对象
|
||||
|
||||
return {
|
||||
config: options
|
||||
config: options,
|
||||
// 重置实例
|
||||
,reload: function(options){
|
||||
reload: function(options){
|
||||
that.reload.call(that, options);
|
||||
}
|
||||
,reloadData: function(options){
|
||||
},
|
||||
reloadData: function(options){
|
||||
dropdown.reloadData(id, options);
|
||||
}
|
||||
,close: function () {
|
||||
},
|
||||
close: function () {
|
||||
that.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 字符常量
|
||||
,STR_ELEM = 'layui-dropdown', STR_HIDE = 'layui-hide', STR_DISABLED = 'layui-disabled', STR_NONE = 'layui-none'
|
||||
,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_ELEM = 'layui-dropdown';
|
||||
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;
|
||||
that.index = ++dropdown.index;
|
||||
that.config = $.extend({}, that.config, dropdown.config, options);
|
||||
|
@ -73,16 +86,16 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
|
||||
// 默认配置
|
||||
Class.prototype.config = {
|
||||
trigger: 'click' //事件类型
|
||||
,content: '' //自定义菜单内容
|
||||
,className: '' //自定义样式类名
|
||||
,style: '' //设置面板 style 属性
|
||||
,show: false //是否初始即显示菜单面板
|
||||
,isAllowSpread: true //是否允许菜单组展开收缩
|
||||
,isSpreadItem: true //是否初始展开子菜单
|
||||
,data: [] //菜单数据结构
|
||||
,delay: 300 //延迟关闭的毫秒数,若 trigger 为 hover 时才生效
|
||||
,shade: 0 // 遮罩
|
||||
trigger: 'click', // 事件类型
|
||||
content: '', // 自定义菜单内容
|
||||
className: '', // 自定义样式类名
|
||||
style: '', // 设置面板 style 属性
|
||||
show: false, // 是否初始即显示菜单面板
|
||||
isAllowSpread: true, // 是否允许菜单组展开收缩
|
||||
isSpreadItem: true, // 是否初始展开子菜单
|
||||
data: [], // 菜单数据结构
|
||||
delay: 300, // 延迟关闭的毫秒数,若 trigger 为 hover 时才生效
|
||||
shade: 0 // 遮罩
|
||||
};
|
||||
|
||||
// 重载实例
|
||||
|
@ -240,10 +253,10 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
views.append(viewLi);
|
||||
});
|
||||
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('');
|
||||
|
||||
// 如果是右键事件,则每次触发事件时,将允许重新渲染
|
||||
|
@ -336,22 +349,22 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
|
||||
// 位置定位
|
||||
Class.prototype.position = function(obj){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
|
||||
lay.position(options.elem[0], that.elemView[0], {
|
||||
position: options.position
|
||||
,e: that.e
|
||||
,clickType: options.trigger === 'contextmenu' ? 'right' : null
|
||||
,align: options.align || null
|
||||
position: options.position,
|
||||
e: that.e,
|
||||
clickType: options.trigger === 'contextmenu' ? 'right' : null,
|
||||
align: options.align || null
|
||||
});
|
||||
};
|
||||
|
||||
// 删除视图
|
||||
Class.prototype.remove = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,elemPrev = thisModule.prevElem;
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var elemPrev = thisModule.prevElem;
|
||||
|
||||
// 若存在已打开的面板元素,则移除
|
||||
if(elemPrev){
|
||||
|
@ -365,8 +378,8 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
|
||||
// 延迟删除视图
|
||||
Class.prototype.delayRemove = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
clearTimeout(thisModule.timer);
|
||||
|
||||
thisModule.timer = setTimeout(function(){
|
||||
|
@ -376,10 +389,10 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
|
||||
// 事件
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
|
||||
//如果传入 hover,则解析为 mouseenter
|
||||
// 若传入 hover,则解析为 mouseenter
|
||||
if(options.trigger === 'hover') options.trigger = 'mouseenter';
|
||||
|
||||
// 解除上一个事件
|
||||
|
@ -419,20 +432,21 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
// 设置菜单组展开和收缩状态
|
||||
thisModule.spread = function(othis){
|
||||
// 菜单组展开和收缩
|
||||
var elemIcon = othis.children('.'+ STR_MENU_TITLE).find('.layui-icon');
|
||||
if(othis.hasClass(STR_ITEM_UP)){
|
||||
var needSpread = 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);
|
||||
elemIcon.removeClass('layui-icon-down').addClass('layui-icon-up');
|
||||
} else {
|
||||
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(){
|
||||
var _WIN = $(window)
|
||||
,_DOC = $(document);
|
||||
(function(){
|
||||
var _WIN = $(window);
|
||||
var _DOC = $(document);
|
||||
|
||||
// 自适应定位
|
||||
_WIN.on('resize', function(){
|
||||
|
@ -463,7 +477,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
|
||||
var options = that.config;
|
||||
|
||||
//如果触发的是绑定的元素,或者属于绑定元素的子元素,则不关闭
|
||||
// 若触发的是绑定的元素,或者属于绑定元素的子元素,则不关闭
|
||||
// 满足条件:当前绑定的元素不是 body document,或者不是鼠标右键事件
|
||||
if(!(lay.isTopElem(options.elem[0]) || options.trigger === 'contextmenu')){
|
||||
if(
|
||||
|
@ -480,11 +494,11 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
// 基础菜单的静态元素事件
|
||||
var ELEM_LI = '.layui-menu:not(.layui-dropdown-menu) li';
|
||||
_DOC.on('click', ELEM_LI, function(e){
|
||||
var othis = $(this)
|
||||
,parent = othis.parents('.layui-menu').eq(0)
|
||||
,isChild = othis.hasClass(STR_ITEM_GROUP) || othis.hasClass(STR_ITEM_PARENT)
|
||||
,filter = parent.attr('lay-filter') || parent.attr('id')
|
||||
,options = lay.options(this);
|
||||
var othis = $(this);
|
||||
var parent = othis.parents('.layui-menu').eq(0);
|
||||
var isChild = othis.hasClass(STR_ITEM_GROUP) || othis.hasClass(STR_ITEM_PARENT);
|
||||
var filter = parent.attr('lay-filter') || parent.attr('id');
|
||||
var options = lay.options(this);
|
||||
|
||||
// 非触发元素
|
||||
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){
|
||||
var othis = $(this)
|
||||
,elemGroup = othis.parents('.'+ STR_ITEM_GROUP +':eq(0)')
|
||||
,options = lay.options(elemGroup[0]);
|
||||
var othis = $(this);
|
||||
var elemGroup = othis.parents('.'+ STR_ITEM_GROUP +':eq(0)');
|
||||
var options = lay.options(elemGroup[0]);
|
||||
|
||||
if(('isAllowSpread' in options) ? options.isAllowSpread : true){
|
||||
thisModule.spread(elemGroup);
|
||||
|
@ -518,8 +532,8 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
// 判断子级菜单是否超出屏幕
|
||||
var ELEM_LI_PAR = '.layui-menu .'+ STR_ITEM_PARENT
|
||||
_DOC.on('mouseenter', ELEM_LI_PAR, function(e){
|
||||
var othis = $(this)
|
||||
,elemPanel = othis.find('.'+ STR_MENU_PANEL);
|
||||
var othis = $(this);
|
||||
var elemPanel = othis.find('.'+ STR_MENU_PANEL);
|
||||
|
||||
if(!elemPanel[0]) return;
|
||||
var rect = elemPanel[0].getBoundingClientRect();
|
||||
|
@ -540,13 +554,13 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
|||
}
|
||||
}).on('mouseleave', ELEM_LI_PAR, function(e){
|
||||
var othis = $(this)
|
||||
,elemPanel = othis.children('.'+ STR_MENU_PANEL);
|
||||
var elemPanel = othis.children('.'+ STR_MENU_PANEL);
|
||||
|
||||
elemPanel.removeClass(STR_MENU_PANEL_L);
|
||||
elemPanel.css('margin-top', 0);
|
||||
});
|
||||
|
||||
}();
|
||||
})();
|
||||
|
||||
// 关闭面板
|
||||
dropdown.close = function(id){
|
||||
|
|
|
@ -46,7 +46,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
|||
'请输入正确的身份证号'
|
||||
]
|
||||
},
|
||||
verIncludelRequired: false, // 验证规则是否包含必填 --- 为兼容旧版的验证机制
|
||||
verIncludeRequired: false, // 验证规则是否包含必填 --- 为兼容旧版的验证机制
|
||||
autocomplete: null // 全局 autocomplete 状态。 null 表示不干预
|
||||
};
|
||||
};
|
||||
|
@ -277,10 +277,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
|||
value: ['up', 'down'],
|
||||
split: true,
|
||||
className: 'layui-input-number',
|
||||
disabled: disabled, // 跟随输入框禁用状态
|
||||
disabled: othis.is('[disabled]'), // 跟随输入框禁用状态
|
||||
click: function(elem){
|
||||
var index = $(this).index();
|
||||
var value = elem.val();
|
||||
var rawValue = value;
|
||||
var step = Number(elem.attr('step')) || 1; // 加减的数字间隔
|
||||
var min = Number(elem.attr('min'));
|
||||
var max = Number(elem.attr('max'));
|
||||
|
@ -294,11 +295,15 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
|||
if(value < min) value = min;
|
||||
if(value > max) value = max;
|
||||
|
||||
// 小数点后保留位数
|
||||
var fixed = function(step){
|
||||
var decimals = (step.match(/\.(\d+$)/) || [])[1] || '';
|
||||
// 获取小数点后位数
|
||||
var decimals = function(step){
|
||||
var decimals = (step.toString().match(/\.(\d+$)/) || [])[1] || '';
|
||||
return decimals.length;
|
||||
}(step.toString());
|
||||
};
|
||||
|
||||
// 位数比较
|
||||
var fixed = Math.max(decimals(step), decimals(rawValue));
|
||||
|
||||
if(fixed) value = value.toFixed(fixed);
|
||||
|
||||
elem.val(value);
|
||||
|
@ -386,7 +391,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
|||
// 如果是第一项,且文本值等于 placeholder,则清空初始值
|
||||
if(selectedIndex === 0 && initValue === input.attr('placeholder')){
|
||||
initValue = '';
|
||||
};
|
||||
}
|
||||
|
||||
// 如果有选中值,则将输入框纠正为该值。否则清空输入框
|
||||
input.val(initValue || '');
|
||||
|
@ -576,7 +581,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
|||
// 如果是第一项,且文本值等于 placeholder,则清空初始值
|
||||
if(selectedIndex === 0 && initValue === input.attr('placeholder')){
|
||||
initValue = '';
|
||||
};
|
||||
}
|
||||
|
||||
setTimeout(function(){
|
||||
notOption(input.val(), function(none){
|
||||
|
@ -807,12 +812,12 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
|||
var next = $(this).next('.' + CLASS);
|
||||
this.checked = false;
|
||||
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;
|
||||
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 +')', {
|
||||
elem: radio[0],
|
||||
|
@ -928,7 +933,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
|||
|
||||
// 匹配验证规则
|
||||
if(rule){
|
||||
var isTrue = typeof rule === 'function'
|
||||
isTrue = typeof rule === 'function'
|
||||
? errorText = rule(value, item)
|
||||
: !rule[0].test(value);
|
||||
|
||||
|
@ -946,7 +951,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
|
|||
|
||||
// 若为必填项或者非空命中校验,则阻止提交,弹出提示
|
||||
if(isTrue && (
|
||||
options.verIncludelRequired || (
|
||||
options.verIncludeRequired || (
|
||||
thisVer === 'required' || (
|
||||
value && thisVer !== 'required'
|
||||
)
|
||||
|
|
|
@ -6,12 +6,15 @@
|
|||
;!function(window, undefined){
|
||||
"use strict";
|
||||
|
||||
var isLayui = window.layui && layui.define, $, win, ready = {
|
||||
var isLayui = window.layui && layui.define;
|
||||
var $;
|
||||
var win;
|
||||
var ready = {
|
||||
getPath: function(){
|
||||
var jsPath = document.currentScript ? document.currentScript.src : function(){
|
||||
var js = document.scripts
|
||||
,last = js.length - 1
|
||||
,src;
|
||||
var js = document.scripts;
|
||||
var last = js.length - 1;
|
||||
var src;
|
||||
for(var i = last; i > 0; i--){
|
||||
if(js[i].readyState === 'interactive'){
|
||||
src = js[i].src;
|
||||
|
@ -19,8 +22,8 @@ var isLayui = window.layui && layui.define, $, win, ready = {
|
|||
}
|
||||
}
|
||||
return src || js[last].src;
|
||||
}()
|
||||
,GLOBAL = window.LAYUI_GLOBAL || {};
|
||||
}();
|
||||
var GLOBAL = window.LAYUI_GLOBAL || {};
|
||||
return GLOBAL.layer_dir || jsPath.substring(0, jsPath.lastIndexOf('/') + 1);
|
||||
}(),
|
||||
config: {
|
||||
|
@ -46,15 +49,15 @@ var isLayui = window.layui && layui.define, $, win, ready = {
|
|||
// 未设置路径,则不主动加载 css
|
||||
if(!layer.path) return;
|
||||
|
||||
var head = document.getElementsByTagName("head")[0]
|
||||
,link = document.createElement('link');
|
||||
var head = document.getElementsByTagName("head")[0];
|
||||
var link = document.createElement('link');
|
||||
|
||||
if(typeof fn === 'string') cssname = fn;
|
||||
|
||||
var app = (cssname || href).replace(/\.|\//g, '');
|
||||
var id = 'layuicss-'+ app
|
||||
,STATUS_NAME = 'creating'
|
||||
,timeout = 0;
|
||||
var id = 'layuicss-'+ app;
|
||||
var STATUS_NAME = 'creating'
|
||||
var timeout = 0;
|
||||
|
||||
link.rel = 'stylesheet';
|
||||
link.href = layer.path + href;
|
||||
|
@ -68,8 +71,8 @@ var isLayui = window.layui && layui.define, $, win, ready = {
|
|||
|
||||
// 轮询 css 是否加载完毕
|
||||
(function poll(status) {
|
||||
var delay = 100
|
||||
,getLinkElem = document.getElementById(id); //获取动态插入的 link 元素
|
||||
var delay = 100;
|
||||
var getLinkElem = document.getElementById(id); // 获取动态插入的 link 元素
|
||||
|
||||
// 如果轮询超过指定秒数,则视为请求文件失败或 css 文件不符合规范
|
||||
if(++timeout > 10 * 1000 / delay){
|
||||
|
@ -97,7 +100,7 @@ var isLayui = window.layui && layui.define, $, win, ready = {
|
|||
|
||||
// 默认内置方法。
|
||||
var layer = {
|
||||
v: '3.6.0',
|
||||
v: '3.7.0',
|
||||
ie: function(){ // ie 版本
|
||||
var agent = navigator.userAgent.toLowerCase();
|
||||
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);
|
||||
|
||||
if(config.area[0] === '' && config.maxWidth > 0){
|
||||
//为了修复IE7下一个让人难以理解的bug
|
||||
// 适配 ie7
|
||||
if(layer.ie && layer.ie < 8 && config.btn){
|
||||
layero.width(layero.innerWidth());
|
||||
}
|
||||
layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth);
|
||||
}
|
||||
|
||||
var area = [layero.innerWidth(), layero.innerHeight()]
|
||||
,titHeight = layero.find(doms[1]).outerHeight() || 0
|
||||
,btnHeight = layero.find('.'+doms[6]).outerHeight() || 0
|
||||
,setHeight = function(elem){
|
||||
var area = [layero.innerWidth(), layero.innerHeight()];
|
||||
var titHeight = layero.find(doms[1]).outerHeight() || 0;
|
||||
var btnHeight = layero.find('.'+doms[6]).outerHeight() || 0;
|
||||
var setHeight = function(elem){
|
||||
elem = layero.find(elem);
|
||||
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];
|
||||
} else if(config.offset === 'l'){ // 左
|
||||
that.offsetLeft = 0;
|
||||
} else if(config.offset === 'lt'){ //左上角
|
||||
} else if(config.offset === 'lt'){ // 左上
|
||||
that.offsetTop = 0;
|
||||
that.offsetLeft = 0;
|
||||
} else if(config.offset === 'lb'){ //左下角
|
||||
} else if(config.offset === 'lb'){ // 左下
|
||||
that.offsetTop = win.height() - area[1];
|
||||
that.offsetLeft = 0;
|
||||
} else if(config.offset === 'rt'){ //右上角
|
||||
} else if(config.offset === 'rt'){ // 右上
|
||||
that.offsetTop = 0;
|
||||
that.offsetLeft = win.width() - area[0];
|
||||
} else if(config.offset === 'rb'){ //右下角
|
||||
} else if(config.offset === 'rb'){ // 右下
|
||||
that.offsetTop = win.height() - area[1];
|
||||
that.offsetLeft = win.width() - area[0];
|
||||
} else {
|
||||
|
@ -706,13 +709,13 @@ Class.pt.tips = function(){
|
|||
|
||||
// 拖拽层
|
||||
Class.pt.move = function(){
|
||||
var that = this
|
||||
,config = that.config
|
||||
,_DOC = $(document)
|
||||
,layero = that.layero
|
||||
,DATA_NAME = ['LAY_MOVE_DICT', 'LAY_RESIZE_DICT']
|
||||
,moveElem = layero.find(config.move)
|
||||
,resizeElem = layero.find('.layui-layer-resize');
|
||||
var that = this;
|
||||
var config = that.config;
|
||||
var _DOC = $(document);
|
||||
var layero = that.layero;
|
||||
var DATA_NAME = ['LAY_MOVE_DICT', 'LAY_RESIZE_DICT'];
|
||||
var moveElem = layero.find(config.move);
|
||||
var resizeElem = layero.find('.layui-layer-resize');
|
||||
|
||||
// 给指定元素添加拖动光标
|
||||
if(config.move) moveElem.css('cursor', 'move');
|
||||
|
@ -720,15 +723,15 @@ Class.pt.move = function(){
|
|||
// 按下拖动元素
|
||||
moveElem.on('mousedown', function(e){
|
||||
if (e.button) {return;} // 不是左键不处理
|
||||
var othis = $(this)
|
||||
,dict = {};
|
||||
var othis = $(this);
|
||||
var dict = {};
|
||||
|
||||
if(config.move){
|
||||
dict.layero = layero;
|
||||
dict.config = config;
|
||||
dict.offset = [
|
||||
e.clientX - parseFloat(layero.css('left'))
|
||||
,e.clientY - parseFloat(layero.css('top'))
|
||||
e.clientX - parseFloat(layero.css('left')),
|
||||
e.clientY - parseFloat(layero.css('top'))
|
||||
];
|
||||
|
||||
othis.data(DATA_NAME[0], dict);
|
||||
|
@ -741,8 +744,8 @@ Class.pt.move = function(){
|
|||
|
||||
// 按下右下角拉伸
|
||||
resizeElem.on('mousedown', function(e){
|
||||
var othis = $(this)
|
||||
,dict = {};
|
||||
var othis = $(this);
|
||||
var dict = {};
|
||||
|
||||
if(config.resize){
|
||||
dict.layero = layero;
|
||||
|
@ -771,9 +774,9 @@ Class.pt.move = function(){
|
|||
,layero = dict.layero
|
||||
,config = dict.config;
|
||||
|
||||
var X = e.clientX - dict.offset[0]
|
||||
,Y = e.clientY - dict.offset[1]
|
||||
,fixed = layero.css('position') === 'fixed';
|
||||
var X = e.clientX - dict.offset[0];
|
||||
var Y = e.clientY - dict.offset[1];
|
||||
var fixed = layero.css('position') === 'fixed';
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
|
@ -782,8 +785,8 @@ Class.pt.move = function(){
|
|||
|
||||
// 控制元素不被拖出窗口外
|
||||
if(!config.moveOut){
|
||||
var setRig = win.width() - layero.outerWidth() + dict.stX
|
||||
,setBot = win.height() - layero.outerHeight() + dict.stY;
|
||||
var setRig = win.width() - layero.outerWidth() + dict.stX;
|
||||
var setBot = win.height() - layero.outerHeight() + dict.stY;
|
||||
X < dict.stX && (X = dict.stX);
|
||||
X > setRig && (X = setRig);
|
||||
Y < dict.stY && (Y = dict.stY);
|
||||
|
@ -792,18 +795,18 @@ Class.pt.move = function(){
|
|||
|
||||
// 拖动时跟随鼠标位置
|
||||
layero.css({
|
||||
left: X
|
||||
,top: Y
|
||||
left: X,
|
||||
top: Y
|
||||
});
|
||||
}
|
||||
|
||||
// Resize
|
||||
if(ready.eventResizeElem){
|
||||
var dict = ready.eventResizeElem.data(DATA_NAME[1]) || {}
|
||||
,config = dict.config;
|
||||
var dict = ready.eventResizeElem.data(DATA_NAME[1]) || {};
|
||||
var config = dict.config;
|
||||
|
||||
var X = e.clientX - dict.offset[0]
|
||||
,Y = e.clientY - dict.offset[1];
|
||||
var X = e.clientX - dict.offset[0];
|
||||
var Y = e.clientY - dict.offset[1];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
|
@ -817,8 +820,8 @@ Class.pt.move = function(){
|
|||
}
|
||||
}).on('mouseup', function(e){
|
||||
if(ready.eventMoveElem){
|
||||
var dict = ready.eventMoveElem.data(DATA_NAME[0]) || {}
|
||||
,config = dict.config;
|
||||
var dict = ready.eventMoveElem.data(DATA_NAME[0]) || {};
|
||||
var config = dict.config;
|
||||
|
||||
ready.eventMoveElem.removeData(DATA_NAME[0]);
|
||||
delete ready.eventMoveElem;
|
||||
|
@ -1279,13 +1282,14 @@ layer.closeLast = function(type){
|
|||
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) : '');
|
||||
};
|
||||
|
||||
|
@ -1312,18 +1316,18 @@ layer.prompt = function(options, yes){
|
|||
delete options.success;
|
||||
|
||||
return layer.open($.extend({
|
||||
type: 1
|
||||
,btn: ['确定','取消']
|
||||
,content: content
|
||||
,skin: 'layui-layer-prompt' + skin('prompt')
|
||||
,maxWidth: win.width()
|
||||
,success: function(layero){
|
||||
type: 1,
|
||||
btn: ['确定','取消'],
|
||||
content: content,
|
||||
skin: 'layui-layer-prompt' + skin('prompt'),
|
||||
maxWidth: win.width(),
|
||||
success: function(layero){
|
||||
prompt = layero.find('.layui-layer-input');
|
||||
prompt.val(options.value || '').focus();
|
||||
typeof success === 'function' && success(layero);
|
||||
}
|
||||
,resize: false
|
||||
,yes: function(index){
|
||||
},
|
||||
resize: false,
|
||||
yes: function(index){
|
||||
var value = prompt.val();
|
||||
if(value.length > (options.maxlength||500)) {
|
||||
layer.tips('最多输入'+ (options.maxlength || 500) +'个字数', prompt, {tips: 1});
|
||||
|
@ -1390,10 +1394,10 @@ layer.photos = function(options, loop, key){
|
|||
if(!options.photos) return;
|
||||
|
||||
// 若 photos 并非选择器或 jQuery 对象,则为普通 object
|
||||
var isObject = !(typeof options.photos === 'string' || options.photos instanceof $)
|
||||
,photos = isObject ? options.photos : {}
|
||||
,data = photos.data || []
|
||||
,start = photos.start || 0;
|
||||
var isObject = !(typeof options.photos === 'string' || options.photos instanceof $);
|
||||
var photos = isObject ? options.photos : {};
|
||||
var data = photos.data || [];
|
||||
var start = photos.start || 0;
|
||||
|
||||
dict.imgIndex = (start|0) + 1;
|
||||
options.img = options.img || 'img';
|
||||
|
@ -1401,7 +1405,7 @@ layer.photos = function(options, loop, key){
|
|||
var success = options.success;
|
||||
delete options.success;
|
||||
|
||||
//如果 options.photos 不是一个对象
|
||||
// 若 options.photos 不是一个对象
|
||||
if(!isObject){ // 页面直接获取
|
||||
var parent = $(options.photos), pushData = function(){
|
||||
data = [];
|
||||
|
@ -1544,7 +1548,7 @@ layer.photos = function(options, loop, key){
|
|||
var imgarea = [img.width, img.height];
|
||||
var winarea = [$(window).width() - 100, $(window).height() - 100];
|
||||
|
||||
//如果 实际图片的宽或者高比 屏幕大(那么进行缩放)
|
||||
// 若实际图片的宽或者高比 屏幕大(那么进行缩放)
|
||||
if(!options.full && (imgarea[0]>winarea[0]||imgarea[1]>winarea[1])){
|
||||
var wh = [imgarea[0]/winarea[0],imgarea[1]/winarea[1]];// 取宽度缩放比例、高度缩放比例
|
||||
if(wh[0] > wh[1]){// 取缩放比例最大的进行缩放
|
||||
|
@ -1633,20 +1637,20 @@ ready.run = function(_$){
|
|||
|
||||
// 加载方式
|
||||
window.layui && layui.define ? (
|
||||
layer.ready()
|
||||
,layui.define('jquery', function(exports){ //layui 加载
|
||||
layer.ready(),
|
||||
layui.define('jquery', function(exports){ // layui
|
||||
layer.path = layui.cache.dir;
|
||||
ready.run(layui.$);
|
||||
|
||||
//暴露模块
|
||||
// export api
|
||||
window.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);
|
||||
return layer;
|
||||
}) : function(){ //普通 script 标签加载
|
||||
}) : function(){ // 普通 script 标签引入
|
||||
layer.ready();
|
||||
ready.run(window.jQuery);
|
||||
}()
|
||||
|
|
|
@ -555,15 +555,15 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
// 初始工具栏
|
||||
Class.prototype.renderToolbar = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
var options = that.config
|
||||
|
||||
// 添加工具栏左侧模板
|
||||
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="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>'
|
||||
].join('')
|
||||
,elemToolTemp = that.layTool.find('.layui-table-tool-temp');
|
||||
'<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="delete"><i class="layui-icon layui-icon-delete"></i></div>'
|
||||
].join('');
|
||||
var elemToolTemp = that.layTool.find('.layui-table-tool-temp');
|
||||
|
||||
if(options.toolbar === 'default'){
|
||||
elemToolTemp.html(leftDefaultTemp);
|
||||
|
@ -577,19 +577,19 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
// 添加工具栏右侧面板
|
||||
var layout = {
|
||||
filter: {
|
||||
title: '筛选列'
|
||||
,layEvent: 'LAYTABLE_COLS'
|
||||
,icon: 'layui-icon-cols'
|
||||
}
|
||||
,exports: {
|
||||
title: '导出'
|
||||
,layEvent: 'LAYTABLE_EXPORT'
|
||||
,icon: 'layui-icon-export'
|
||||
}
|
||||
,print: {
|
||||
title: '打印'
|
||||
,layEvent: 'LAYTABLE_PRINT'
|
||||
,icon: 'layui-icon-print'
|
||||
title: '筛选列',
|
||||
layEvent: 'LAYTABLE_COLS',
|
||||
icon: 'layui-icon-cols'
|
||||
},
|
||||
exports: {
|
||||
title: '导出',
|
||||
layEvent: 'LAYTABLE_EXPORT',
|
||||
icon: 'layui-icon-export'
|
||||
},
|
||||
print: {
|
||||
title: '打印',
|
||||
layEvent: 'LAYTABLE_PRINT',
|
||||
icon: 'layui-icon-print'
|
||||
}
|
||||
}, iconElem = [];
|
||||
|
||||
|
@ -608,10 +608,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
|
||||
// 分页栏
|
||||
Class.prototype.renderPagebar = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
var that = this;
|
||||
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){
|
||||
|
@ -623,15 +623,15 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
|
||||
// 同步表头父列的相关值
|
||||
Class.prototype.setParentCol = function(hide, parentKey){
|
||||
var that = this
|
||||
,options = that.config
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
|
||||
,parentTh = that.layHeader.find('th[data-key="'+ parentKey +'"]') //获取父列元素
|
||||
,parentColspan = parseInt(parentTh.attr('colspan')) || 0;
|
||||
var parentTh = that.layHeader.find('th[data-key="'+ parentKey +'"]'); // 获取父列元素
|
||||
var parentColspan = parseInt(parentTh.attr('colspan')) || 0;
|
||||
|
||||
if(parentTh[0]){
|
||||
var arrParentKey = parentKey.split('-')
|
||||
,getThisCol = options.cols[arrParentKey[1]][arrParentKey[2]];
|
||||
var arrParentKey = parentKey.split('-');
|
||||
var getThisCol = options.cols[arrParentKey[1]][arrParentKey[2]];
|
||||
|
||||
hide ? parentColspan-- : parentColspan++;
|
||||
|
||||
|
@ -1784,7 +1784,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
that.layFixed.find(ELEM_BODY).css(
|
||||
'height',
|
||||
layMainTable.height() >= fixHeight ? fixHeight : 'auto'
|
||||
);
|
||||
).scrollTop(that.layMain.scrollTop()); // 固定列滚动条高度
|
||||
|
||||
// 表格宽度小于容器宽度时,隐藏固定列
|
||||
that.layFixRight[
|
||||
|
@ -2484,9 +2484,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
|
||||
// 同步滚动条
|
||||
that.layMain.on('scroll', function(){
|
||||
var othis = $(this)
|
||||
,scrollLeft = othis.scrollLeft()
|
||||
,scrollTop = othis.scrollTop();
|
||||
var othis = $(this);
|
||||
var scrollLeft = othis.scrollLeft();
|
||||
var scrollTop = othis.scrollTop();
|
||||
|
||||
that.layHeader.scrollLeft(scrollLeft);
|
||||
that.layTotal.scrollLeft(scrollLeft);
|
||||
|
@ -2495,7 +2495,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
layer.close(that.tipsIndex);
|
||||
});
|
||||
|
||||
//自适应
|
||||
// 适应
|
||||
_WIN.on('resize', function(){
|
||||
that.resize();
|
||||
});
|
||||
|
@ -2796,7 +2796,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
|
||||
// 表合计
|
||||
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(',');
|
||||
|
|
|
@ -5,71 +5,84 @@
|
|||
layui.define('form', function(exports){
|
||||
"use strict";
|
||||
|
||||
var $ = layui.$
|
||||
,form = layui.form
|
||||
,layer = layui.layer
|
||||
var $ = layui.$;
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
|
||||
// 模块名
|
||||
,MOD_NAME = 'tree'
|
||||
var MOD_NAME = 'tree';
|
||||
|
||||
// 外部接口
|
||||
,tree = {
|
||||
config: {}
|
||||
,index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0
|
||||
var tree = {
|
||||
config: {},
|
||||
index: layui[MOD_NAME] ? (layui[MOD_NAME].index + 10000) : 0,
|
||||
|
||||
// 设置全局项
|
||||
,set: function(options){
|
||||
set: function(options){
|
||||
var that = this;
|
||||
that.config = $.extend({}, that.config, options);
|
||||
return that;
|
||||
}
|
||||
},
|
||||
|
||||
// 事件
|
||||
,on: function(events, callback){
|
||||
on: function(events, callback){
|
||||
return layui.onevent.call(this, MOD_NAME, events, callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 操作当前实例
|
||||
,thisModule = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,id = options.id || that.index;
|
||||
var thisModule = function(){
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var id = options.id || that.index;
|
||||
|
||||
thisModule.that[id] = that; // 记录当前实例对象
|
||||
thisModule.config[id] = options; // 记录当前实例配置项
|
||||
|
||||
return {
|
||||
config: options
|
||||
config: options,
|
||||
// 重置实例
|
||||
,reload: function(options){
|
||||
reload: function(options){
|
||||
that.reload.call(that, options);
|
||||
}
|
||||
,getChecked: function(){
|
||||
},
|
||||
getChecked: function(){
|
||||
return that.getChecked.call(that);
|
||||
}
|
||||
,setChecked: function(id){//设置值
|
||||
},
|
||||
setChecked: function(id){// 设置值
|
||||
return that.setChecked.call(that, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 获取当前实例配置项
|
||||
,getThisModuleConfig = function(id){
|
||||
var getThisModuleConfig = function(id){
|
||||
var config = thisModule.config[id];
|
||||
if(!config) hint.error('The ID option was not found in the '+ MOD_NAME +' instance');
|
||||
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'
|
||||
,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'
|
||||
var ELEM_VIEW = 'layui-tree';
|
||||
var ELEM_SET = 'layui-tree-set';
|
||||
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;
|
||||
that.index = ++tree.index;
|
||||
that.config = $.extend({}, that.config, tree.config, options);
|
||||
|
@ -78,18 +91,18 @@ layui.define('form', function(exports){
|
|||
|
||||
// 默认配置
|
||||
Class.prototype.config = {
|
||||
data: [] //数据
|
||||
data: [], // 数据
|
||||
|
||||
,showCheckbox: false //是否显示复选框
|
||||
,showLine: true //是否开启连接线
|
||||
,accordion: false //是否开启手风琴模式
|
||||
,onlyIconControl: false //是否仅允许节点左侧图标控制展开收缩
|
||||
,isJump: false //是否允许点击节点时弹出新窗口跳转
|
||||
,edit: false //是否开启节点的操作图标
|
||||
showCheckbox: false, // 是否显示复选框
|
||||
showLine: true, // 是否开启连接线
|
||||
accordion: false, // 是否开启手风琴模式
|
||||
onlyIconControl: false, // 是否仅允许节点左侧图标控制展开收缩
|
||||
isJump: false, // 是否允许点击节点时弹出新窗口跳转
|
||||
edit: false, // 是否开启节点的操作图标
|
||||
|
||||
,text: {
|
||||
defaultNodeName: '未命名' //节点默认名称
|
||||
,none: '无数据' //数据为空时的文本提示
|
||||
text: {
|
||||
defaultNodeName: '未命名', // 节点默认名称
|
||||
none: '无数据' // 数据为空时的文本提示
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -107,8 +120,8 @@ layui.define('form', function(exports){
|
|||
|
||||
// 主体渲染
|
||||
Class.prototype.render = function(){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
|
||||
that.checkids = [];
|
||||
|
||||
|
@ -163,15 +176,15 @@ layui.define('form', function(exports){
|
|||
|
||||
// 节点解析
|
||||
Class.prototype.tree = function(elem, children){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,data = children || options.data;
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var data = children || options.data;
|
||||
|
||||
// 遍历数据
|
||||
layui.each(data, function(index, item){
|
||||
var hasChild = item.children && item.children.length > 0
|
||||
,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 hasChild = item.children && item.children.length > 0;
|
||||
var packDiv = $('<div class="layui-tree-pack" '+ (item.spread ? 'style="display: block;"' : '') +'></div>');
|
||||
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-main">'
|
||||
// 箭头
|
||||
|
@ -260,14 +273,15 @@ layui.define('form', function(exports){
|
|||
|
||||
// 展开节点
|
||||
Class.prototype.spread = function(elem, item){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,entry = elem.children('.'+ELEM_ENTRY)
|
||||
,elemMain = entry.children('.'+ ELEM_MAIN)
|
||||
,elemIcon = entry.find('.'+ ICON_CLICK)
|
||||
,elemText = entry.find('.'+ ELEM_TEXT)
|
||||
,touchOpen = options.onlyIconControl ? elemIcon : elemMain //判断展开通过节点还是箭头图标
|
||||
,state = '';
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var entry = elem.children('.'+ELEM_ENTRY);
|
||||
var elemMain = entry.children('.'+ ELEM_MAIN);
|
||||
var elemCheckbox = elemMain.find('input[same="layuiTreeCheck"]');
|
||||
var elemIcon = entry.find('.'+ ICON_CLICK);
|
||||
var elemText = entry.find('.'+ ELEM_TEXT);
|
||||
var touchOpen = options.onlyIconControl ? elemIcon : elemMain; // 判断展开通过节点还是箭头图标
|
||||
var state = '';
|
||||
|
||||
// 展开收缩
|
||||
touchOpen.on('click', function(e){
|
||||
|
@ -312,28 +326,34 @@ layui.define('form', function(exports){
|
|||
state = options.onlyIconControl ? 'close' : 'open';
|
||||
}
|
||||
|
||||
// 获取选中状态
|
||||
if(elemCheckbox[0]){
|
||||
item['checked'] = elemCheckbox.prop('checked');
|
||||
}
|
||||
|
||||
// 点击产生的回调
|
||||
options.click && options.click({
|
||||
elem: elem
|
||||
,state: state
|
||||
,data: item
|
||||
elem: elem,
|
||||
state: state,
|
||||
data: item
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 计算复选框选中状态
|
||||
Class.prototype.setCheckbox = function(elem, item, elemCheckbox){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,checked = elemCheckbox.prop('checked');
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var checked = elemCheckbox.prop('checked');
|
||||
|
||||
if(elemCheckbox.prop('disabled')) return;
|
||||
|
||||
// 同步子节点选中状态
|
||||
if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){
|
||||
var childs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]');
|
||||
childs.each(function(){
|
||||
var elemCheckboxs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]');
|
||||
elemCheckboxs.each(function(index){
|
||||
if(this.disabled) return; // 不可点击则跳过
|
||||
if(item.children[index]) item.children[index]['checked'] = checked;
|
||||
this.checked = checked;
|
||||
});
|
||||
};
|
||||
|
@ -343,10 +363,10 @@ layui.define('form', function(exports){
|
|||
// 若无父节点,则终止递归
|
||||
if(!thisNodeElem.parents('.'+ ELEM_SET)[0]) return;
|
||||
|
||||
var state
|
||||
,parentPack = thisNodeElem.parent('.'+ ELEM_PACK)
|
||||
,parentNodeElem = parentPack.parent()
|
||||
,parentCheckbox = parentPack.prev().find('input[same="layuiTreeCheck"]');
|
||||
var state;
|
||||
var parentPack = thisNodeElem.parent('.'+ ELEM_PACK);
|
||||
var parentNodeElem = parentPack.parent();
|
||||
var parentCheckbox = parentPack.prev().find('input[same="layuiTreeCheck"]');
|
||||
|
||||
// 如果子节点有任意一条选中,则父节点为选中状态
|
||||
if(checked){
|
||||
|
@ -373,10 +393,10 @@ layui.define('form', function(exports){
|
|||
|
||||
// 复选框选择
|
||||
Class.prototype.checkClick = function(elem, item){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,entry = elem.children('.'+ ELEM_ENTRY)
|
||||
,elemMain = entry.children('.'+ ELEM_MAIN);
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var entry = elem.children('.'+ ELEM_ENTRY);
|
||||
var elemMain = entry.children('.'+ ELEM_MAIN);
|
||||
|
||||
|
||||
|
||||
|
@ -384,38 +404,39 @@ layui.define('form', function(exports){
|
|||
elemMain.on('click', 'input[same="layuiTreeCheck"]+', function(e){
|
||||
layui.stope(e); // 阻止点击节点事件
|
||||
|
||||
var elemCheckbox = $(this).prev()
|
||||
,checked = elemCheckbox.prop('checked');
|
||||
var elemCheckbox = $(this).prev();
|
||||
var checked = elemCheckbox.prop('checked');
|
||||
|
||||
if(elemCheckbox.prop('disabled')) return;
|
||||
|
||||
that.setCheckbox(elem, item, elemCheckbox);
|
||||
item.checked = checked;
|
||||
|
||||
// 复选框点击产生的回调
|
||||
options.oncheck && options.oncheck({
|
||||
elem: elem
|
||||
,checked: checked
|
||||
,data: item
|
||||
elem: elem,
|
||||
checked: checked,
|
||||
data: item
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 节点操作
|
||||
Class.prototype.operate = function(elem, item){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,entry = elem.children('.'+ ELEM_ENTRY)
|
||||
,elemMain = entry.children('.'+ ELEM_MAIN);
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var entry = elem.children('.'+ ELEM_ENTRY);
|
||||
var elemMain = entry.children('.'+ ELEM_MAIN);
|
||||
|
||||
entry.children('.layui-tree-btnGroup').on('click', '.layui-icon', function(e){
|
||||
layui.stope(e); // 阻止节点操作
|
||||
|
||||
var type = $(this).data("type")
|
||||
,packCont = elem.children('.'+ELEM_PACK)
|
||||
,returnObj = {
|
||||
data: item
|
||||
,type: type
|
||||
,elem:elem
|
||||
var type = $(this).data("type");
|
||||
var packCont = elem.children('.'+ELEM_PACK);
|
||||
var returnObj = {
|
||||
data: item,
|
||||
type: type,
|
||||
elem:elem
|
||||
};
|
||||
// 增加
|
||||
if(type == 'add'){
|
||||
|
@ -434,8 +455,9 @@ layui.define('form', function(exports){
|
|||
};
|
||||
|
||||
// 新增节点
|
||||
var key = options.operate && options.operate(returnObj)
|
||||
,obj = {};
|
||||
var key = options.operate && options.operate(returnObj);
|
||||
var obj = {};
|
||||
|
||||
obj.title = options.text.defaultNodeName;
|
||||
obj.id = key;
|
||||
that.tree(elem.children('.'+ELEM_PACK), [obj]);
|
||||
|
@ -445,8 +467,10 @@ layui.define('form', function(exports){
|
|||
// 节点本身无子节点
|
||||
if(!packCont[0]){
|
||||
// 遍历兄弟节点,判断兄弟节点是否有子节点
|
||||
var siblings = elem.siblings('.'+ELEM_SET), num = 1
|
||||
,parentPack = elem.parent('.'+ELEM_PACK);
|
||||
var siblings = elem.siblings('.'+ELEM_SET)
|
||||
var num = 1;
|
||||
var parentPack = elem.parent('.'+ELEM_PACK);
|
||||
|
||||
layui.each(siblings, function(index, i){
|
||||
if(!$(i).children('.'+ELEM_PACK)[0]){
|
||||
num = 0;
|
||||
|
@ -551,10 +575,12 @@ layui.define('form', function(exports){
|
|||
var elemDel = function(elem){
|
||||
// 若无父结点,则不执行
|
||||
if(!elem.parents('.'+ELEM_SET)[0]) return;
|
||||
var siblingTree = elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY)
|
||||
,parentTree = elem.parent('.'+ELEM_PACK).prev()
|
||||
,checkState = parentTree.find('input[same="layuiTreeCheck"]')[0]
|
||||
,state = 1, num = 0;
|
||||
var siblingTree = elem.siblings('.'+ELEM_SET).children('.'+ELEM_ENTRY);
|
||||
var parentTree = elem.parent('.'+ELEM_PACK).prev();
|
||||
var checkState = parentTree.find('input[same="layuiTreeCheck"]')[0];
|
||||
var state = 1;
|
||||
var num = 0;
|
||||
|
||||
// 若父节点未勾选
|
||||
if(checkState.checked == false){
|
||||
// 遍历兄弟节点
|
||||
|
@ -583,8 +609,10 @@ layui.define('form', function(exports){
|
|||
// 若开启连接线
|
||||
if(options.showLine){
|
||||
// 遍历兄弟节点,判断兄弟节点是否有子节点
|
||||
var siblings = elem.siblings('.'+ELEM_SET), num = 1
|
||||
,parentPack = elem.parent('.'+ELEM_PACK);
|
||||
var siblings = elem.siblings('.'+ELEM_SET);
|
||||
var num = 1;
|
||||
var parentPack = elem.parent('.'+ELEM_PACK);
|
||||
|
||||
layui.each(siblings, function(index, i){
|
||||
if(!$(i).children('.'+ELEM_PACK)[0]){
|
||||
num = 0;
|
||||
|
@ -651,19 +679,19 @@ layui.define('form', function(exports){
|
|||
|
||||
// 部分事件
|
||||
Class.prototype.events = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,checkWarp = that.elem.find('.layui-tree-checkedFirst');
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var checkWarp = that.elem.find('.layui-tree-checkedFirst');
|
||||
|
||||
// 初始选中
|
||||
that.setChecked(that.checkids);
|
||||
|
||||
// 搜索
|
||||
that.elem.find('.layui-tree-search').on('keyup', function(){
|
||||
var input = $(this)
|
||||
,val = input.val()
|
||||
,pack = input.nextAll()
|
||||
,arr = [];
|
||||
var input = $(this);
|
||||
var val = input.val();
|
||||
var pack = input.nextAll();
|
||||
var arr = [];
|
||||
|
||||
// 遍历所有的值
|
||||
pack.find('.'+ ELEM_TEXT).each(function(){
|
||||
|
@ -712,10 +740,10 @@ layui.define('form', function(exports){
|
|||
|
||||
// 得到选中节点
|
||||
Class.prototype.getChecked = function(){
|
||||
var that = this
|
||||
,options = that.config
|
||||
,checkId = []
|
||||
,checkData = [];
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
var checkId = [];
|
||||
var checkData = [];
|
||||
|
||||
// 遍历节点找到选中索引
|
||||
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(checkId, function(index2, item2){
|
||||
if(item.id == item2){
|
||||
item['checked'] = true;
|
||||
var cloneItem = $.extend({}, item);
|
||||
delete cloneItem.children;
|
||||
|
||||
|
@ -749,14 +778,14 @@ layui.define('form', function(exports){
|
|||
|
||||
// 设置选中节点
|
||||
Class.prototype.setChecked = function(checkedId){
|
||||
var that = this
|
||||
,options = that.config;
|
||||
var that = this;
|
||||
var options = that.config;
|
||||
|
||||
// 初始选中
|
||||
that.elem.find('.'+ELEM_SET).each(function(i, item){
|
||||
var thisId = $(this).data('id')
|
||||
,input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]')
|
||||
,reInput = input.next();
|
||||
var thisId = $(this).data('id');
|
||||
var input = $(item).children('.'+ELEM_ENTRY).find('input[same="layuiTreeCheck"]');
|
||||
var reInput = input.next();
|
||||
|
||||
// 若返回数字
|
||||
if(typeof checkedId === 'number'){
|
||||
|
|
|
@ -1007,7 +1007,7 @@ layui.define(['table'], function (exports) {
|
|||
layui.stope(event);
|
||||
// 处理数据
|
||||
// var trElem = item.closest('tr');
|
||||
expandNode({trElem}, null, null, null, true);
|
||||
expandNode({trElem: trElem}, null, null, null, true);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue