dever 6 rokov pred
rodič
commit
d116281381
2 zmenil súbory, kde vykonal 31 pridanie a 7 odobranie
  1. 30 6
      assets/dever/core.js
  2. 1 1
      assets/lib/manage/main.js

+ 30 - 6
assets/dever/core.js

@@ -979,6 +979,7 @@ var _Dever_Upload =
         var id = e.attr('id');
         var value = e.attr('dever-upload-value');
         var key = e.attr('dever-upload-key');
+        var pic = e.attr('dever-upload-pic');
         var type = e.attr('dever-upload-type');
         var callback = e.attr('dever-upload-callback');
         var input = $("#" + value);
@@ -1013,13 +1014,14 @@ var _Dever_Upload =
                 ,field: 'file'
                 ,url: url
                 ,multiple: true
+                ,xhr:xhrOnProgress
                 ,before: function(obj) {
                     layer.load();
                 }
                 ,done: function(data) {
                     layer.closeAll('loading');
                     if (data.status == 1) {
-                        self.Set(type, e, input, value, callback, data.url);
+                        self.Set(type, e, input, value, callback, data.url, pic);
                     } else {
                         layer.msg(data.msg, {icon: 4});
                         return false;
@@ -1034,22 +1036,27 @@ var _Dever_Upload =
         });
     }
 
-    ,Set : function(type, e, input, value, callback, url)
+    ,Set : function(type, e, input, value, callback, url, pic)
     {
         if (type == 'mul') {
             this.SetMul(e, input, value, callback, url);
         } else {
-            this.SetOne(e, input, value, callback, url);
+            this.SetOne(e, input, value, callback, url, pic);
         }
     }
 
-    ,SetOne : function(e, input, value, callback, url)
+    ,SetOne : function(e, input, value, callback, url, pic)
     {
         var html = '';
         if (this.callback && this.callback[callback]) {
             html = this.callback[callback].call(this, e, url, 'dever-upload-close');
         } else {
-            html = '<img src="'+url+'" class="pics">';
+            pic = $("#" + pic);
+            if (pic.length) {
+                pic.attr('src', url).show();
+            } else {
+                html = '<img src="'+url+'" class="dever-upload-pic">';
+            }
         }
 
         if (html) {
@@ -1073,7 +1080,7 @@ var _Dever_Upload =
         if (this.callback && this.callback[callback]) {
             html += this.callback[callback].call(this, e, url, 'dever-upload-close');
         } else {
-            html += '<li><img src="'+url+'" class="pics"><em class="dever-upload-close"></em></li>';
+            html += '<li><img src="'+url+'" class="dever-upload-pics"><em class="dever-upload-close"></em></li>';
         }
 
         if (html) {
@@ -1109,4 +1116,21 @@ var _Dever_Upload =
             });
         });
     }
+}
+
+//创建监听函数
+var xhrOnProgress=function(fun) {
+    xhrOnProgress.onprogress = fun; //绑定监听
+    //使用闭包实现监听绑
+    return function() {
+        //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
+        var xhr = $.ajaxSettings.xhr();
+        //判断监听函数是否为函数
+        if (typeof xhrOnProgress.onprogress !== 'function') return xhr;
+        //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
+        if (xhrOnProgress.onprogress && xhr.upload) {
+            xhr.upload.onprogress = xhrOnProgress.onprogress;
+        }
+        return xhr;
+    }
 }

+ 1 - 1
assets/lib/manage/main.js

@@ -1992,7 +1992,7 @@ function select_linkage(level, id, url, name, value, valid, w, total, search, le
 			var data = t.data.list;
 
 			if(!$(e + '_' + level).length) {
-				html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+'" id="'+id+'_'+level+'" name="'+name+'[]" onchange="select_linkage(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+total+', \''+search+'\', \''+level_param+'\');">';
+				html = '<select style="display:inline;margin-top:10px;'+w+'" class="layui-input layui-select update_value form-control '+valid+'" id="'+id+'_'+level+'" name="'+name+'[]" onchange="select_linkage(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+total+', \''+search+'\', \''+level_param+'\');">';
 			}
 
 			for (a in data) {