function WmUploader(options) { this.randomNum = function(min, max){ var range = max - min; var rand = Math.random(); var num = min + Math.round(rand * range); return num; } this.accept = options.accept == undefined ? { title: '图片', extensions: 'png,gif,jpg,jpeg,bmp', mimeTypes: 'image/*', } : options.accept // fileType: img file this.fileType = options.fileType == undefined ? 'img' : options.fileType this.uploadKey = options.uniqueCode == undefined ? this.randomNum(10000, 99999) : options.uniqueCode this.uploadSelector = options.selector this.uploadUrl = options.url this.uploadWrapper = $(this.uploadSelector).parents('.upload-wrapper').eq(0); this.uploadList = this.uploadWrapper.find('.uploader-list'); this.afterSuccess = options.afterSuccess this.afterDelete = options.afterDelete var that = this this.getFileId = function(file) { return file.id + '-' + that.uploadKey } this.getFileTag = function(file) { return $('#' + that.getFileId(file)) } this.uploader = WebUploader.create({ auto: true, swf: '/Public/static/webuploader/Uploader.swf', server: that.uploadUrl, pick: { id: that.uploadSelector, multiple: false }, accept: that.accept, resize: false, disableGlobalDnd: true, fileNumLimit: 1, threads: 5, thumb: true, compress: false, prepareNextFile: true, formData: function(){ return $.extend(true, {}, {}); }, chunked: false, duplicate: true }); this.uploader.on('fileQueued', function(file) { if (that.fileType == 'img') { var html = ''; html += '
'; that.uploadList.append(html); that.uploadList.css('margin-top','10px'); var imgNode = that.uploadList.children(that.getFileTag(file)).find('img'); that.uploader.makeThumb(file, function (error, src) { if (error) { return; } imgNode.attr('src', src); }, 300, 300); } else { that.uploadList.append( '等待上传...
' + '