Merge pull request #1167 from layui/2.x

release v2.8.0-rc.2
pull/1171/head v2.8.0-rc.2
贤心 2022-11-14 00:59:50 +08:00 committed by GitHub
commit 1c2742c5ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 27 deletions

2
dist/css/layui.css vendored

File diff suppressed because one or more lines are too long

2
dist/layui.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "layui", "name": "layui",
"version": "2.8.0-rc.1", "version": "2.8.0-rc.2",
"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

@ -15,7 +15,7 @@
} }
,Layui = function(){ ,Layui = function(){
this.v = '2.8.0-rc.1'; // Layui 版本号 this.v = '2.8.0-rc.2'; // Layui 版本号
} }
//识别预先可能定义的指定全局对象 //识别预先可能定义的指定全局对象

View File

@ -208,11 +208,15 @@
var othis = lay(elem); var othis = lay(elem);
var attrName = opts.attr || 'lay-options'; var attrName = opts.attr || 'lay-options';
var attrValue = othis.attr(attrName);
try { try {
return new Function('return '+ (othis.attr(attrName) || '{}'))(); return new Function('return '+ (attrValue || '{}'))();
} catch(ev) { } catch(ev) {
hint.error(opts.errorText || 'parseerror: '+ ev, 'error'); layui.hint().error(opts.errorText || [
attrName + '="'+ attrValue + '"',
'\n parseerror: '+ ev
].join('\n'), 'error');
return {}; return {};
} }
}; };

View File

@ -3,12 +3,11 @@
* 上传组件 * 上传组件
*/ */
layui.define('layer' , function(exports){ layui.define(['lay','layer'], function(exports){
"use strict"; "use strict";
var $ = layui.$ var $ = layui.$
,layer = layui.layer ,layer = layui.layer
,hint = layui.hint()
,device = layui.device() ,device = layui.device()
//外部接口 //外部接口
@ -466,20 +465,20 @@ layui.define('layer' , function(exports){
//事件处理 //事件处理
Class.prototype.events = function(){ Class.prototype.events = function(){
var that = this var that = this;
,options = that.config var options = that.config;
//设置当前选择的文件队列 // 设置当前选择的文件队列
,setChooseFile = function(files){ var setChooseFile = function(files){
that.chooseFiles = {}; that.chooseFiles = {};
layui.each(files, function(i, item){ layui.each(files, function(i, item){
var time = new Date().getTime(); var time = new Date().getTime();
that.chooseFiles[time + '-' + i] = item; that.chooseFiles[time + '-' + i] = item;
}); });
} };
//设置选择的文本 // 设置选择的文本
,setChooseText = function(files, filename){ var setChooseText = function(files, filename){
var elemFile = that.elemFile var elemFile = that.elemFile
,item = options.item ? options.item : options.elem ,item = options.item ? options.item : options.elem
,value = files.length > 1 ,value = files.length > 1
@ -494,19 +493,23 @@ layui.define('layer' , function(exports){
elemFile.after('<span class="layui-inline '+ ELEM_CHOOSE +'">'+ value +'</span>'); elemFile.after('<span class="layui-inline '+ ELEM_CHOOSE +'">'+ value +'</span>');
}; };
// 合并 lay-options/lay-data 属性配置项
var extendAttrs = function(){
var othis = $(this);
var data = othis.attr('lay-data') || othis.attr('lay-options'); // 优先兼容旧版本
if(data){
that.config = $.extend({}, options, lay.options(this, {
attr: othis.attr('lay-data') ? 'lay-data' : null
}));
}
};
//点击上传容器 //点击上传容器
options.elem.off('upload.start').on('upload.start', function(){ options.elem.off('upload.start').on('upload.start', function(){
var othis = $(this), data = othis.attr('lay-data'); var othis = $(this);
if(data){ extendAttrs.call(this);
try{
data = new Function('return '+ data)();
that.config = $.extend({}, options, data);
} catch(e){
hint.error('Upload element property lay-data configuration item has a syntax error: ' + data)
}
}
that.config.item = othis; that.config.item = othis;
that.elemFile[0].click(); that.elemFile[0].click();
}); });
@ -522,9 +525,11 @@ layui.define('layer' , function(exports){
othis.removeAttr('lay-over'); othis.removeAttr('lay-over');
}) })
.off('upload.drop').on('upload.drop', function(e, param){ .off('upload.drop').on('upload.drop', function(e, param){
var othis = $(this), files = param.originalEvent.dataTransfer.files || []; var othis = $(this);
var files = param.originalEvent.dataTransfer.files || [];
othis.removeAttr('lay-over'); othis.removeAttr('lay-over');
extendAttrs.call(this);
setChooseFile(files); setChooseFile(files);
options.auto ? that.upload() : setChooseText(files); //是否自动触发上传 options.auto ? that.upload() : setChooseText(files); //是否自动触发上传
@ -534,6 +539,8 @@ layui.define('layer' , function(exports){
//文件选择 //文件选择
that.elemFile.off('upload.change').on('upload.change', function(){ that.elemFile.off('upload.change').on('upload.change', function(){
var files = this.files || []; var files = this.files || [];
extendAttrs.call(this);
setChooseFile(files); setChooseFile(files);
options.auto ? that.upload() : setChooseText(files); //是否自动触发上传 options.auto ? that.upload() : setChooseText(files); //是否自动触发上传
}); });