dever 7 年之前
父节点
当前提交
aca16f0cc0
共有 1 个文件被更改,包括 21 次插入19 次删除
  1. 21 19
      assets/lib/layui/upload.js

+ 21 - 19
assets/lib/layui/upload.js

@@ -2,13 +2,15 @@ var upload_pic = [];
 var upload_file = [];
 var upload = [];
 
-function loadUpload(i,e,key,upload,assets)
+function loadUpload(i,e,key,url,assets)
 {
 	var value = e.attr('v');
 	if (typeof(upload[value]) != "undefined") {
 		return;
 	}
 	upload[value] = true;
+	upload_pic[value] = [];
+	upload_file[value] = [];
 
 	var id = e.attr('id');
 	layui.use(['upload','layer'], function() {
@@ -19,7 +21,7 @@ function loadUpload(i,e,key,upload,assets)
 			elem: '#' + id
 			,data: {'key' : key}
 			,field: 'file'
-			,url: upload
+			,url: url
 			,multiple: true
 			,accept:'file'
 			,choose: function(obj){
@@ -32,34 +34,34 @@ function loadUpload(i,e,key,upload,assets)
 					var mul = e.attr('mul');
 					if (mul == 'yes') {
 						if (e.attr('t') == 'file') {
-							if (upload_file.length <= 0 && $("#" + value).val()) {
-								upload_file = $("#" + value).val().split(',');
+							if (upload_file[value].length <= 0 && $("#" + value).val()) {
+								upload_file[value] = $("#" + value).val().split(',');
 							}
 
 							var m = $('.' +value+'_mul');
-							var i = m.find('li').eq(upload_file.length);
+							var i = m.find('li').eq(upload_file[value].length);
 							if (i.length) {
 								i.find('a').eq(0).html(data.name);
 							} else {
 								m.append('<li><a href="'+data.url+'" target="_blank" title="点此下载" >'+data.name+'</a>&nbsp;&nbsp;<a href="javascript:;" title="点此删除" style="color:red;" onclick="fileDel($(this), \''+value+'\')">[删除]</a></li>');
 							}
 
-							upload_file.push(data.url);
+							upload_file[value].push(data.url);
 
 							$("#" + value).val(upload_file.join(','));
 						} else {
-							if (upload_pic.length <= 0 && $("#" + value).val()) {
-								upload_pic = $("#" + value).val().split(',');
+							if (upload_pic[value].length <= 0 && $("#" + value).val()) {
+								upload_pic[value] = $("#" + value).val().split(',');
 							}
 							var m = $('.' +value+'_mul');
-							var i = m.find('img').eq(upload_pic.length);
+							var i = m.find('img').eq(upload_pic[value].length);
 							if (i.length) {
 								i.attr('src', data.url);
 							} else {
 								m.append('<a href="javascript:;" title="点此删除" onclick="picDel($(this), \''+value+'\')"><img src="'+data.url+'" width="150" style="margin-left:5px;" alt="点此删除"/></a>');
 							}
-							upload_pic.push(data.url);
-							$("#" + value).val(upload_pic.join(','));
+							upload_pic[value].push(data.url);
+							$("#" + value).val(upload_pic[value].join(','));
 						}
 						
 					} else {
@@ -94,13 +96,13 @@ function picDel(e,v,s)
 			e.hide();
 			$("#" + v).val('');
 		} else {
-			if (upload_pic.length <= 0 && $("#" + v).val()) {
-				upload_pic = $("#" + v).val().split(',');
+			if (upload_pic[v].length <= 0 && $("#" + v).val()) {
+				upload_pic[v] = $("#" + v).val().split(',');
 			}
 			var p = e.find('img').attr('src');
 			e.remove();
-			upload_pic.remove(p);
-			$("#" + v).val(upload_pic.join(','));
+			upload_pic[v].remove(p);
+			$("#" + v).val(upload_pic[v].join(','));
 		}
 	}
 }
@@ -110,18 +112,18 @@ function fileDel(e,v)
 {
 	if(confirm('确定要删除文件吗?'))
 	{
-		if(upload_file.length <= 0 && $("#" + v).val())
+		if(upload_file[v].length <= 0 && $("#" + v).val())
 		{
-			upload_file = $("#" + v).val().split(',');
+			upload_file[v] = $("#" + v).val().split(',');
 		}
 
 		var parent = e.parent();
 		var p = parent.find('a').eq(0).attr('href');
 		
 		parent.remove();
-		upload_file.remove(p);
+		upload_file[v].remove(p);
 		//console.info(pic);
-		$("#" + v).val(upload_file.join(','));
+		$("#" + v).val(upload_file[v].join(','));
 	}
 }