You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

382 lines
18 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

function upload(tab,tablist,fileNumLimit=5,data,data1,datakeyname,name,url) {
var uploaderImgLogo = WebUploader.create({
// 选完文件后,是否自动上传。
auto: true,
// swf文件路径
swf: '__STATIC__/webuploader/Uploader.swf',
server: url,
// 选择文件的按钮。可选。
// 内部根据当前运行是创建可能是input元素也可能是flash.
pick: {
id:'#'+tab,
multiple:true
},
// dnd: false,
paste: document.body,
accept: {
title: '图片',
extensions: 'png,gif,jpg,jpeg,bmp',
mimeTypes: '.png,.gif,.jpg,.jpeg,.bmp',
},
// 不压缩image, 默认如果是jpeg文件上传前会压缩一把再上传
resize: false,
disableGlobalDnd: true,
fileNumLimit:1,
threads:5,
thumb:true,
compress:false,
prepareNextFile: true,
formData: function(){return $.extend(true, {}, userInfo);},
chunked:false,
duplicate: true
});
var imgLogoListData = [];
newdata = data.split(',')
newdata1 = data1.split(',')
console.log(newdata)
console.log(newdata1)
if(newdata.length > 0 && newdata[0] !=="") {
var html = '';
$('#'+tablist).css('margin-top','10px');
/*newdata.forEach(v=>{
console.log(v)
imgLogoListData.push(v);
html += '<div id="' + v + '" class="item flooring_page_img_box" style="margin-right: 10px;">';
var imgurl =
html += '<a href="javascript:;"><img src='+v+ 'style="width: 100px;height: 100px;cursor: move;"></a>';
html += '<h4 class="info" style="text-align: center;">';
html += '<a href="javascript:;" class="jsdelzip table_click" style="float:none;display:inline-block;" img-id="' + v + '">删除</a>';
html += '</h4>';
html += '<div class="progress progress-striped active" style="display: none;">';
html += '<div class="progress-bar" role="progressbar" style="width: 100%;">100%</div>';
html += '</div>';
html += '</div>';
})*/
for(var i=0;i<newdata.length;i++) {
var v = newdata[i];
var imgurl = newdata1[i]
imgLogoListData.push(v);
html += '<div id="' + v + '" class="item flooring_page_img_box" style="margin-right: 10px;">';
html += '<a href="javascript:;"><img src="'+imgurl+'"style="width: 100px;height: 100px;cursor: move;"></a>';
html += '<h4 class="info" style="text-align: center;">';
html += '<a href="javascript:;" class="jsdelzip table_click" style="float:none;display:inline-block;" img-id="' + v + '">删除</a>';
html += '</h4>';
html += '<div class="progress progress-striped active" style="display: none;">';
html += '<div class="progress-bar" role="progressbar" style="width: 100%;">100%</div>';
html += '</div>';
html += '</div>';
}
$('#'+tablist).html(html);
$('#'+tablist).children().children('h4').children('.jsdelzip').on('click', function() {
var thisId = $(this).attr('img-id');
$(this).parent().parent().remove();
$.each(imgLogoListData,function(index, item) {
if (thisId == item) {
imgLogoListData.splice(index,1);
return false;
}
});
setLogoVal(name);
});
}
/* <?php if (!empty($config['logo_data'])) :?>
var html = '';
$('#logoList').css('margin-top','10px');
<?php foreach ($config['logo_data'] as $value1) {?>
<?php $value1 = (int)$value1;?>
imgLogoListData.push(<?=$value1?>);
html += '<div id="' + <?=$value1?> + '" class="item flooring_page_img_box" style="margin-right: 10px;">';
html += '<a href="javascript:;"><img src="<?=get_cover($value1,"path")?>" style="width: 100px;height: 100px;cursor: move;"></a>';
html += '<h4 class="info" style="text-align: center;">';
html += '<a href="javascript:;" class="jsdelzip table_click" style="float:none;display:inline-block;" img-id="' + <?=$value1?> + '">删除</a>';
html += '</h4>';
html += '<div class="progress progress-striped active" style="display: none;">';
html += '<div class="progress-bar" role="progressbar" style="width: 100%;">100%</div>';
html += '</div>';
html += '</div>';
<?php }?>
$('#logoList').html(html);
$('#logoList').children().children('h4').children('.jsdelzip').on('click', function() {
var thisId = $(this).attr('img-id');
$(this).parent().parent().remove();
$.each(imgLogoListData,function(index, item) {
if (thisId == item) {
imgLogoListData.splice(index,1);
return false;
}
});
setLogoVal();
});
<?php endif ;?>*/
var thisIndex1 = 0;
var imgLogoList = $("#"+tablist);
uploaderImgLogo.on( 'fileQueued', function( file ) {
var html = '';
html += '<div id="' + file.id + '" class="item" style="margin-right: 10px;">';
html += '<a href="javascript:;"><img src="" style="width: 100px;height: 100px;cursor: move;"></a>';
html += '<h4 class="info">' + file.name + '</h4>';
html += '<p class="state">等待上传...</p>';
html += '</div>';
imgLogoList.append(html);
imgLogoList.css('margin-top','10px');
var img = imgLogoList.children('#'+file.id).find('img');
uploaderImgLogo.makeThumb(file, function (error, src) {
if (error) {
return;
}
img.attr('src', src);
}, 300, 300);
});
// 文件上传过程中创建进度条实时显示。
uploaderImgLogo.on( 'uploadProgress', function( file, percentage ) {
var $li = $( '#'+file.id ),
$percent = $li.find('.progress .progress-bar');
// 避免重复创建
if ( !$percent.length ) {
$percent = $('<div class="progress progress-striped active">' +
'<div class="progress-bar" role="progressbar" style="width: 0%">' +
'</div>' +
'</div>').appendTo( $li ).find('.progress-bar');
}
$li.find('p.state').text('上传中');
$percent.css( 'width', percentage * 100 + '%' );
$percent.text( (percentage * 100).toFixed(0) + '%' );
});
uploaderImgLogo.on( 'uploadSuccess', function( file , response) {
imgLogoListData.push(Number(response.id));
console.log(imgLogoListData)
setLogoVal(name);
$( '#'+file.id ).find('p.state').text('已上传').fadeOut(800);
//alert(JSON.stringify(response));
$('#'+file.id).find('h4.info').append('<a href="javascript:;" class="jsdelzip table_click" style="float:none;display:inline-block;margin-left:10px;">删除</a>');
$('#'+file.id).find('.jsdelzip').on('click',function() {
uploaderImgLogo.removeFile( file.id );
$('#'+file.id).remove();
$.each(imgLogoListData,function(index, item) {
if (response.id == item) {
imgLogoListData.splice(index,1);
return false;
}
});
setLogoVal(name);
console.log(imgIconListData);
return false;
});
});
uploaderImgLogo.on('uploadError', function(file) {
$( '#'+file.id ).find('p.state').text('上传出错');
});
uploaderImgLogo.on( 'uploadComplete', function(file) {
$( '#'+file.id ).find('.progress').fadeOut();
});
function setLogoVal(keyName)
{
var logo = '';
$.each(imgLogoListData,function(index, item) {
logo += item + ',';
});
logo = logo.substring(0, logo.length - 1);
console.log(logo)
$("input[name='config["+keyName+"]']").val(logo);
}
}
function documentUpload(tab,tablist,fileNumLimit=5,data,data1,datakeyname,name,url) {
console.log(data)
console.log(data1)
var uploaderImgLogo = WebUploader.create({
// 选完文件后,是否自动上传。
auto: true,
// swf文件路径
swf: '__STATIC__/webuploader/Uploader.swf',
server: url,
// 选择文件的按钮。可选。
// 内部根据当前运行是创建可能是input元素也可能是flash.
pick: {
id:'#'+tab,
multiple:true
},
// dnd: false,
paste: document.body,
accept: {
title: '图片',
extensions: 'png,gif,jpg,jpeg,bmp',
mimeTypes: '.png,.gif,.jpg,.jpeg,.bmp',
},
// 不压缩image, 默认如果是jpeg文件上传前会压缩一把再上传
resize: false,
disableGlobalDnd: true,
fileNumLimit:1,
threads:5,
thumb:true,
compress:false,
prepareNextFile: true,
formData: function(){return $.extend(true, {}, userInfo);},
chunked:false,
duplicate: true
});
var imgLogoListData = [];
newdata = data.split(',')
newdata1 = data1.split(',')
console.log(newdata)
console.log(newdata1)
if(newdata.length > 0 && newdata[0] !=="" ) {
var html = '';
$('#'+tablist).css('margin-top','10px');
/*newdata.forEach(v=>{
console.log(v)
imgLogoListData.push(v);
html += '<div id="' + v + '" class="item flooring_page_img_box" style="margin-right: 10px;">';
var imgurl =
html += '<a href="javascript:;"><img src='+v+ 'style="width: 100px;height: 100px;cursor: move;"></a>';
html += '<h4 class="info" style="text-align: center;">';
html += '<a href="javascript:;" class="jsdelzip table_click" style="float:none;display:inline-block;" img-id="' + v + '">删除</a>';
html += '</h4>';
html += '<div class="progress progress-striped active" style="display: none;">';
html += '<div class="progress-bar" role="progressbar" style="width: 100%;">100%</div>';
html += '</div>';
html += '</div>';
})*/
for(var i=0;i<newdata.length;i++) {
var v = newdata[i];
var imgurl = newdata1[i]
imgLogoListData.push(Number(v));
html += '<div id="' + v + '" class="item flooring_page_img_box" style="margin-right: 10px;">';
html += '<a href="javascript:;"><img src="'+imgurl+'"style="width: 100px;height: 100px;cursor: move;"></a>';
html += '<h4 class="info" style="text-align: center;">';
html += '<a href="javascript:;" class="jsdelzip table_click" style="float:none;display:inline-block;" img-id="' + v + '">删除</a>';
html += '</h4>';
html += '<div class="progress progress-striped active" style="display: none;">';
html += '<div class="progress-bar" role="progressbar" style="width: 100%;">100%</div>';
html += '</div>';
html += '</div>';
}
$('#'+tablist).html(html);
$('#'+tablist).children().children('h4').children('.jsdelzip').on('click', function() {
var thisId = $(this).attr('img-id');
$(this).parent().parent().remove();
$.each(imgLogoListData,function(index, item) {
if (thisId == item) {
imgLogoListData.splice(index,1);
return false;
}
});
setLogoVal(name);
});
}
var thisIndex1 = 0;
var imgLogoList = $("#"+tablist);
uploaderImgLogo.on( 'fileQueued', function( file ) {
var html = '';
html += '<div id="' + file.id + '" class="item" style="margin-right: 10px;">';
html += '<a href="javascript:;"><img src="" style="width: 100px;height: 100px;cursor: move;"></a>';
html += '<h4 class="info">' + file.name + '</h4>';
html += '<p class="state">等待上传...</p>';
html += '</div>';
imgLogoList.append(html);
imgLogoList.css('margin-top','10px');
var img = imgLogoList.children('#'+file.id).find('img');
uploaderImgLogo.makeThumb(file, function (error, src) {
if (error) {
return;
}
img.attr('src', src);
}, 300, 300);
});
// 文件上传过程中创建进度条实时显示。
uploaderImgLogo.on( 'uploadProgress', function( file, percentage ) {
var $li = $( '#'+file.id ),
$percent = $li.find('.progress .progress-bar');
// 避免重复创建
if ( !$percent.length ) {
$percent = $('<div class="progress progress-striped active">' +
'<div class="progress-bar" role="progressbar" style="width: 0%">' +
'</div>' +
'</div>').appendTo( $li ).find('.progress-bar');
}
$li.find('p.state').text('上传中');
$percent.css( 'width', percentage * 100 + '%' );
$percent.text( (percentage * 100).toFixed(0) + '%' );
});
uploaderImgLogo.on( 'uploadSuccess', function( file , response) {
imgLogoListData.push(Number(response.id));
console.log(imgLogoListData)
setLogoVal(name);
$( '#'+file.id ).find('p.state').text('已上传').fadeOut(800);
//alert(JSON.stringify(response));
$('#'+file.id).find('h4.info').append('<a href="javascript:;" class="jsdelzip table_click" style="float:none;display:inline-block;margin-left:10px;">删除</a>');
$('#'+file.id).find('.jsdelzip').on('click',function() {
uploaderImgLogo.removeFile( file.id );
$('#'+file.id).remove();
$.each(imgLogoListData,function(index, item) {
if (response.id == item) {
imgLogoListData.splice(index,1);
return false;
}
});
setLogoVal(name);
console.log(imgIconListData);
return false;
});
});
uploaderImgLogo.on('uploadError', function(file) {
$( '#'+file.id ).find('p.state').text('上传出错');
});
uploaderImgLogo.on( 'uploadComplete', function(file) {
$( '#'+file.id ).find('.progress').fadeOut();
});
function setLogoVal(keyName)
{
var logo = '';
$.each(imgLogoListData,function(index, item) {
logo += item + ',';
});
logo = logo.substring(0, logo.length - 1);
console.log(keyName)
console.log(logo)
$("input[name='"+keyName+"']").val(logo);
}
}