This commit is contained in:
贤心
2021-05-31 08:57:00 +08:00
parent b5f6f89cfe
commit 7376bbe00d
20 changed files with 237 additions and 141 deletions

View File

@@ -1,14 +1,16 @@
/**
@Title: colorpicker 颜色选择器组件
@LicenseMIT
/*!
* colorpicker
* 颜色选择组件
*/
layui.define('jquery', function(exports){
layui.define(['jquery', 'lay'], function(exports){
"use strict";
var $ = layui.jquery
,lay = layui.lay
,device = layui.device()
,clickOrMousedown = (device.mobile ? 'click' : 'mousedown')
//外部接口
,colorpicker = {
@@ -217,7 +219,7 @@ layui.define('jquery', function(exports){
,elemColorBox = that.elemColorBox[0]
//颜色选择器对象
,elemPicker = that.elemPicker = $(['<div id="layui-colorpicker'+ that.index +'" data-index="'+ that.index +'" class="layui-anim layui-anim-upbit layui-colorpicker-main">'
,elemPicker = that.elemPicker = $(['<div id="layui-colorpicker'+ that.index +'" data-index="'+ that.index +'" class="layui-anim layui-anim-downbit layui-colorpicker-main">'
//颜色面板
,'<div class="layui-colorpicker-main-wrapper">'
,'<div class="layui-colorpicker-basis">'
@@ -295,45 +297,12 @@ layui.define('jquery', function(exports){
//定位算法
Class.prototype.position = function(){
var that = this
,options = that.config
,elem = that.bindElem || that.elemColorBox[0]
,elemPicker = that.elemPicker[0]
,rect = elem.getBoundingClientRect() //绑定元素的坐标
,elemWidth = elemPicker.offsetWidth //控件的宽度
,elemHeight = elemPicker.offsetHeight //控件的高度
//滚动条高度
,scrollArea = function(type){
type = type ? 'scrollLeft' : 'scrollTop';
return document.body[type] | document.documentElement[type];
}
,winArea = function(type){
return document.documentElement[type ? 'clientWidth' : 'clientHeight']
}, margin = 5, left = rect.left, top = rect.bottom;
left = left - (elemWidth - elem.offsetWidth)/2;
top = top + margin
//如果右侧超出边界
if(left + elemWidth + margin > winArea('width')){
left = winArea('width') - elemWidth - margin;
} else if(left < margin){ //如果左侧超出边界
left = margin;
}
//如果底部超出边界
if(top + elemHeight + margin > winArea()){
top = rect.top > elemHeight //顶部是否有足够区域显示完全
? rect.top - elemHeight
: winArea() - elemHeight;
top = top - margin*2;
}
if(options.position){
elemPicker.style.position = options.position;
}
elemPicker.style.left = left + (options.position === 'fixed' ? 0 : scrollArea(1)) + 'px';
elemPicker.style.top = top + (options.position === 'fixed' ? 0 : scrollArea()) + 'px';
,options = that.config;
lay.position(that.bindElem || that.elemColorBox[0], that.elemPicker[0], {
position: options.position
,align: 'center'
});
return that;
};
//颜色选择器赋值
@@ -435,7 +404,7 @@ layui.define('jquery', function(exports){
}
//拖拽元素
,elemMove = $(['<div class="layui-auxiliar-moving" id="LAY-colorpicker-moving"></div'].join(''))
,elemMove = $(['<div class="layui-auxiliar-moving" id="LAY-colorpicker-moving"></div>'].join(''))
,createMoveElem = function(call){
$('#LAY-colorpicker-moving')[0] || $('body').append(elemMove);
elemMove.on('mousemove', call);
@@ -457,11 +426,12 @@ layui.define('jquery', function(exports){
if(top > maxh)top = maxh;
var h = top/180*360;
_h = h;
change(h, _s, _b, _a);
change(h, _s, _b, _a);
e.preventDefault();
};
createMoveElem(move);
//layui.stope(e);
e.preventDefault();
});
@@ -514,6 +484,7 @@ layui.define('jquery', function(exports){
_b = b;
_s = s;
change(_h, s, b, _a);
layui.stope(e);
e.preventDefault();
choose.trigger(e, 'mousedown');
});
@@ -675,7 +646,7 @@ layui.define('jquery', function(exports){
if(!options.elem[0] || that.elemColorBox[0].eventHandler) return;
//绑定关闭控件事件
$doc.on('click', function(e){
$doc.on(clickOrMousedown, function(e){
//如果点击的元素是颜色框
if($(e.target).hasClass(ELEM)
|| $(e.target).parents('.'+ELEM)[0]

View File

@@ -304,6 +304,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
position: options.position
,e: that.e
,clickType: options.trigger === 'contextmenu' ? 'right' : null
,align: options.align || null
});
};

View File

@@ -46,6 +46,7 @@ layui.define('layer', function(exports){
,'请输入正确的身份证号'
]
}
,autocomplete: null //全局 autocomplete 状态。null 表示不干预
};
};
@@ -139,13 +140,21 @@ layui.define('layer', function(exports){
//表单控件渲染
Form.prototype.render = function(type, filter){
var that = this
,options = that.config
,elemForm = $(ELEM + function(){
return filter ? ('[lay-filter="' + filter +'"]') : '';
}())
,items = {
//输入框
input: function(){
var inputs = elemForm.find('input,textarea');
//初始化全局的 autocomplete
options.autocomplete && inputs.attr('autocomplete', options.autocomplete);
}
//下拉选择框
select: function(){
,select: function(){
var TIPS = '请选择', CLASS = 'layui-form-select', TITLE = 'layui-select-title'
,NONE = 'layui-select-none', initValue = '', thatInput
,selects = elemForm.find('select')
@@ -441,8 +450,8 @@ layui.define('layer', function(exports){
var reElem = $(['<div class="'+ (isSearch ? '' : 'layui-unselect ') + CLASS
,(disabled ? ' layui-select-disabled' : '') +'">'
,'<div class="'+ TITLE +'">'
,('<input type="text" placeholder="'+ placeholder +'" '
+('value="'+ (value ? selected.html() : '') +'"') //默认值
,('<input type="text" placeholder="'+ $.trim(placeholder) +'" '
+('value="'+ $.trim(value ? selected.html() : '') +'"') //默认值
+((!disabled && isSearch) ? '' : ' readonly') //是否开启搜索
+' class="layui-input'
+(isSearch ? '' : ' layui-unselect')
@@ -453,11 +462,11 @@ layui.define('layer', function(exports){
var arr = [];
layui.each(options, function(index, item){
if(index === 0 && !item.value){
arr.push('<dd lay-value="" class="layui-select-tips">'+ (item.innerHTML || TIPS) +'</dd>');
arr.push('<dd lay-value="" class="layui-select-tips">'+ $.trim(item.innerHTML || TIPS) +'</dd>');
} else if(item.tagName.toLowerCase() === 'optgroup'){
arr.push('<dt>'+ item.label +'</dt>');
} else {
arr.push('<dd lay-value="'+ item.value +'" class="'+ (value === item.value ? THIS : '') + (item.disabled ? (' '+DISABLED) : '') +'">'+ item.innerHTML +'</dd>');
arr.push('<dd lay-value="'+ item.value +'" class="'+ (value === item.value ? THIS : '') + (item.disabled ? (' '+DISABLED) : '') +'">'+ $.trim(item.innerHTML) +'</dd>');
}
});
arr.length === 0 && arr.push('<dd lay-value="" class="'+ DISABLED +'">没有选项</dd>');
@@ -517,7 +526,7 @@ layui.define('layer', function(exports){
var hasRender = othis.next('.' + RE_CLASS[0])
,reElem = $(['<div class="layui-unselect '+ RE_CLASS[0]
,(check.checked ? (' '+ RE_CLASS[1]) : '') //选中状态
,(disabled ? ' layui-checkbox-disbaled '+ DISABLED : '') //禁用状态
,(disabled ? ' layui-checkbox-disabled '+ DISABLED : '') //禁用状态
,'"'
,(skin ? ' lay-skin="'+ skin +'"' : '') //风格
,'>'
@@ -586,7 +595,7 @@ layui.define('layer', function(exports){
//替代元素
var reElem = $(['<div class="layui-unselect '+ CLASS
,(radio.checked ? (' '+CLASS+'ed') : '') //选中状态
,(disabled ? ' layui-radio-disbaled '+DISABLED : '') +'">' //禁用状态
,(disabled ? ' layui-radio-disabled '+DISABLED : '') +'">' //禁用状态
,'<i class="layui-anim layui-icon">'+ ICON[radio.checked ? 0 : 1] +'</i>'
,'<div>'+ function(){
var title = radio.title || '';
@@ -604,7 +613,7 @@ layui.define('layer', function(exports){
}
};
type ? (
items[type] ? items[type]() : hint.error('不支持的'+ type + '表单渲染')
items[type] ? items[type]() : hint.error('不支持的 "'+ type + '" 表单渲染')
) : layui.each(items, function(index, item){
item();
});
@@ -641,7 +650,10 @@ layui.define('layer', function(exports){
//匹配验证规则
if(verify[thisVer]){
var isTrue = isFn ? errorText = verify[thisVer](value, item) : !verify[thisVer][0].test(value);
var isTrue = isFn ? errorText = verify[thisVer](value, item) : !verify[thisVer][0].test(value)
//是否属于美化替换后的表单元素
,isForm2Elem = item.tagName.toLowerCase() === 'select' || /^checkbox|radio$/.test(item.type);
errorText = errorText || verify[thisVer][1];
if(thisVer === 'required'){
@@ -654,7 +666,7 @@ layui.define('layer', function(exports){
if(verType === 'tips'){
layer.tips(errorText, function(){
if(typeof othis.attr('lay-ignore') !== 'string'){
if(item.tagName.toLowerCase() === 'select' || /^checkbox|radio$/.test(item.type)){
if(isForm2Elem){
return othis.next();
}
}
@@ -669,10 +681,18 @@ layui.define('layer', function(exports){
}
//非移动设备自动定位焦点
if(!device.android && !device.ios){
if(!device.mobile){
setTimeout(function(){
item.focus();
(isForm2Elem ? othis.next().find('input') : item).focus();
}, 7);
} else { //移动设备定位
$dom.scrollTop(function(){
try {
return (isForm2Elem ? othis.next() : othis).offset().top - 15
} catch(e){
return 0;
}
}());
}
othis.addClass(DANGER);

View File

@@ -35,10 +35,10 @@
lay.extend = function(){
var ai = 1, args = arguments
,clone = function(target, obj){
target = target || (obj.constructor === Array ? [] : {});
target = target || (layui._typeof(obj) === 'array' ? [] : {}); //目标对象
for(var i in obj){
//如果值为对象,则进入递归,继续深度合并
target[i] = (obj[i] && (obj[i].constructor === Object))
//如果值为普通对象,则进入递归,继续深度合并
target[i] = (obj[i] && obj[i].constructor === Object)
? clone(target[i], obj[i])
: obj[i];
}
@@ -49,14 +49,14 @@
for(; ai < args.length; ai++){
if(typeof args[ai] === 'object'){
clone(args[0], args[ai])
clone(args[0], args[ai]);
}
}
return args[0];
};
//lay 模块版本
lay.v = '1.0.7';
lay.v = '1.0.8';
//ie版本
lay.ie = function(){
@@ -75,7 +75,7 @@
* 获取 layui 常见方法,以便用于组件单独版
*/
lay.layui = layui;
lay.layui = layui || {};
lay.getPath = layui.cache.dir; //获取当前 JS 所在目录
lay.stope = layui.stope; //中止冒泡
lay.each = function(){ //遍历
@@ -145,11 +145,20 @@
,winArea = function(type){
return document.documentElement[type ? 'clientWidth' : 'clientHeight']
}, margin = 5, left = rect.left, top = rect.bottom;
//相对元素居中
if(obj.align === 'center'){
left = left - (elemWidth - elem.offsetWidth)/2;
} else if(obj.align === 'right'){
left = left - elemWidth + elem.offsetWidth;
}
//判断右侧是否超出边界
if(left + elemWidth + margin > winArea('width')){
left = winArea('width') - elemWidth - margin; //如果超出右侧,则将面板向右靠齐
}
//左侧是否超出边界
if(left < margin) left = margin;
//判断底部和顶部是否超出边界
if(top + elemHeight + margin > winArea()){

View File

@@ -25,7 +25,7 @@
//外部调用
,laydate = {
v: '5.3.1'
v: '5.3.1' //layDate 版本号
,config: {} //全局配置项
,index: (window.laydate && window.laydate.v) ? 100000 : 0
,path: GLOBAL.laydate_dir || ready.getPath
@@ -192,7 +192,7 @@
that.rangeStr = options.range ? (typeof options.range === 'string' ? options.range : '-') : '';
//若 range 参数为数组,则表示为开始日期和结束日期的 input 对象
if(options.range && options.range.constructor === Array){
if(layui._typeof(options.range) === 'array'){
that.rangeElem = [
lay(options.range[0]),
lay(options.range[1])
@@ -304,7 +304,7 @@
//默认赋值
if(options.value && options.isInitValue){
if(options.value.constructor === Date){
if(layui._typeof(options.value) === 'date'){
that.setValue(that.parse(0, that.systemDate(options.value)));
} else {
that.setValue(options.value);
@@ -696,7 +696,7 @@
) + lang.formatError[1]);
error = true;
}
} else if(value && value.constructor === Date){ //如果值为日期对象时
} else if(value && layui._typeof(value) === 'date'){ //如果值为日期对象时
options.dateTime = that.systemDate(value);
} else {
//重置开始日期
@@ -1248,12 +1248,10 @@
//显示预览
elemPreview.html(value).css({
'color': '#5FB878'
,'font-size': '14px;'
});
setTimeout(function(){
elemPreview.css({
'color': '#666'
,'font-size': '12px;'
});
}, 300);
};
@@ -1556,7 +1554,7 @@
//获取当前实例对象
thisModule.getThis = function(id){
var that = thisModule.that[id];
if(!that) hint.error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required');
if(!that && isLayui) layui.hint().error(id ? (MOD_NAME +' instance with ID \''+ id +'\' not found') : 'ID argument required');
return that;
};

View File

@@ -671,10 +671,10 @@ Class.pt.callback = function(){
if(config.success){
if(config.type == 2){
layero.find('iframe').on('load', function(){
config.success(layero, that.index);
config.success(layero, that.index, that);
});
} else {
config.success(layero, that.index);
config.success(layero, that.index, that);
}
}
layer.ie == 6 && that.IE6(layero);

View File

@@ -72,6 +72,12 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
//解析自定义模板数据
,parseTempData = function(item3, content, tplData, text){ //表头数据、原始内容、表体数据、是否只返回文本
var options = this.config || {};
//是否防 xss
if(options.escape) content = util.escape(content);
//获取内容
var str = item3.templet ? function(){
return typeof item3.templet === 'function'
? item3.templet(tplData)
@@ -738,7 +744,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
typeof options.error === 'function' && options.error(e, msg);
}
});
} else if(options.data && options.data.constructor === Array){ //已知数据
} else if(layui._typeof(options.data) === 'array'){ //已知数据
var res = {}
,startLimit = curr*options.limit - options.limit
@@ -823,6 +829,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
}() +'">' + function(){
var tplData = $.extend(true, {
LAY_INDEX: numbers
,LAY_COL: item3
}, item1)
,checkName = table.config.checkName;
@@ -854,7 +861,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
if(item3.toolbar){
return laytpl($(item3.toolbar).html()||'').render(tplData);
}
return parseTempData(item3, content, tplData);
return parseTempData.call(that, item3, content, tplData);
}()
,'</div></td>'].join('');
@@ -978,7 +985,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
tplData[field] = thisTotalNum;
//获取自动计算的合并内容
getContent = item3.totalRow ? (parseTempData(item3, thisTotalNum, tplData) || text) : text;
getContent = item3.totalRow ? (parseTempData.call(that, item3, thisTotalNum, tplData) || text) : text;
//如果直接传入了合计行数据,则不输出自动计算的结果
return totalRowData ? (totalRowData[item3.field] || getContent) : getContent;
@@ -1135,7 +1142,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
,options = that.config
,thisData = table.cache[that.key];
if(!thisData[index]) return;
if(thisData[index].constructor === Array) return;
if(layui._typeof(thisData[index]) === 'array') return;
thisData[index][options.checkName] = checked;
};
@@ -1524,7 +1531,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
templet = item2.templet;
}
});
td.children(ELEM_CELL).html(parseTempData({
td.children(ELEM_CELL).html(parseTempData.call(that, {
templet: templet
}, value, data));
td.data('content', value);
@@ -1637,7 +1644,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
}
});
othis.siblings(ELEM_CELL).html(function(value){
return parseTempData({
return parseTempData.call(that, {
templet: templet
}, value, data);
}(thisElem.value));
@@ -1767,6 +1774,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
table.init = function(filter, settings){
settings = settings || {};
var that = this
,inst = null
,elemTable = filter ? $('table[lay-filter="'+ filter +'"]') : $(ELEM + '[lay-data]')
,errorTips = 'Table element property lay-data configuration item has a syntax error: ';
@@ -1774,9 +1782,9 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
elemTable.each(function(){
var othis = $(this), tableData = othis.attr('lay-data');
try{
try {
tableData = new Function('return '+ tableData)();
} catch(e){
} catch(e) {
hint.error(errorTips + tableData, 'error')
}
@@ -1832,6 +1840,8 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
});
options.data[i1] = row;
});
//执行渲染
table.render(options);
});
@@ -1894,7 +1904,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
,data = table.cache[id] || [];
//计算全选个数
layui.each(data, function(i, item){
if(item.constructor === Array){
if(layui._typeof(item) === 'array'){
invalidNum++; //无效数据,或已删除的
return;
}
@@ -1914,7 +1924,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
var arr = []
,data = table.cache[id] || [];
layui.each(data, function(i, item){
if(item.constructor === Array){
if(layui._typeof(item) === 'array'){
return;
};
arr.push(table.clearCacheKey(item));
@@ -1929,7 +1939,8 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
data = data || table.clearCacheKey(table.cache[id]);
type = type || 'csv';
var config = thisTable.config[id] || {}
var thatTable = thisTable.that[id]
,config = thisTable.config[id] || {}
,textType = ({
csv: 'text/csv'
,xls: 'application/vnd.ms-excel'
@@ -1958,7 +1969,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
if(content === undefined || content === null) content = '';
i1 == 0 && dataTitle.push(item3.title || '');
vals.push('"'+ parseTempData(item3, content, item1, 'text') + '"');
vals.push('"'+ parseTempData.call(thatTable, item3, content, item1, 'text') + '"');
}
});
}

View File

@@ -101,7 +101,7 @@ layui.define('form', function(exports){
var that = this;
layui.each(options, function(key, item){
if(item.constructor === Array) delete that.config[key];
if(layui._typeof(item) === 'array') delete that.config[key];
});
that.config = $.extend(true, {}, that.config, options);