qingjian/view/manager/widget/multi.html

231 lines
11 KiB
HTML
Raw Normal View History

2021-08-06 10:50:55 +00:00
{php}
use app\service\Image as WImage;
$numid=0;
{/php}
<div class="upload-image-box">
<div id="upload_img_list{$append}" class="upload_img_list">
{if !empty($imgs)}
{php}$imgs = json_decode($imgs, true); {/php}
{foreach $imgs as $k => $img}
{php}
if($k > $numid){
$numid = $k;
}
{/php}
<dd class="item_img" id="img_{$k}">
<div class="imgs">
<div class="operate">
<i onclick="UPLOAD_IMG_DEL(this)" class="close layui-icon"></i>
</div>
<img src="{:WImage::getThumb($img.src, 100, 100)}"/>
</div>
<div class="info">
<input type="text" class="layui-input" name="img{$append}[{$k}][alt]" value="{$img.alt}" placeholder="alt" />
<input type="text" class="layui-input" name="img{$append}[{$k}][desc]" value="{$img.desc}" placeholder="描述" />
<input type="text" class="layui-input" name="img{$append}[{$k}][link]" value="{$img.link ?? ''}" placeholder="链接,选填" />
<input type="text" class="layui-input" name="img{$append}[{$k}][time]" value="{$img.time ?? ''}" placeholder="日期,选填" />
<input type="hidden" name="img{$append}[{$k}][src]" value="{$img.src}" />
</div>
</dd>
{/foreach}
{/if}
</div>
<div class="upload_img_btn" id="upload-images{$append}">
<i></i><p>上传图片</p>
</div>
<div class="upload_img_btn" id="serverImgList{$append}" style="margin-left: 15px;">
<i></i><p>服务器图片</p>
</div>
<div class="layui-clear"></div>
<div class="upload-image-points">
{if !empty($imgSize)}
<div class="layui-form-mid layui-word-aux">注:图片最佳尺寸为: {$imgSize} 数字0表示不限制</div>
{else /}
<div class="layui-form-mid layui-word-aux">请上传大小合适的图片</div>
{/if}
</div>
</div>
<style type="text/css">
#selectable .ui-selecting { background: #FECA40; }
#selectable .ui-selected { background: #F39814; color: white; }
#selectable { list-style-type: none; margin: 0; padding: 0;}
</style>
<script type="text/javascript">
var _token = $('#token').attr('content');
$(document).on("click", ".layer-photos", function(e) {
layer.photos({
photos: {
"data": [{
"src": e.target.src
}]
},
anim: 5
});
});
$(document).ready(function() {
var numid = {$numid}+1;
$(".upload_img_list").sortable({
cursor: "move",
items: "dd", //只是li可以拖动
opacity: 0.6, //拖动时透明度为0.6
revert: true, //释放时,增加动画
update: function(event, ui) { //更新排序之后
//alert($(this).sortable("toArray"));
}
});
var uploadUrl = "{:url('manager.upload/image')}";
layui.use(['upload', 'element'], function() {
var upload = layui.upload;
var element = layui.element;
upload.render({
elem: '#upload-images{$append}',
url: uploadUrl,
data: {_token:_token},
field: 'image',
multiple: true,
before: function(obj) {
layer.msg('图片上传中...', {
icon: 16,
shade: 0.01,
time: 0
})
},
done: function(res) {
if(res.code == 0){
layer.close(layer.msg()); //关闭上传提示窗口
//调用多图上传方法,其中res.imgid为后台返回的一个随机数字
$('#upload_img_list{$append}').append('<dd class="item_img" id="img_' + numid +'">'+
'<div class="imgs"><div class="operate"><i onclick="UPLOAD_IMG_DEL(this)" class="close layui-icon"></i></div>'+
'<img src="' +res.data.thumb_src +'"></div>'+
'<div class="info"><input type="text" class="layui-input" name="img{$append}['+numid+'][alt]" value="" placeholder="alt" />'+
'<input type="text" class="layui-input" name="img{$append}['+numid+'][desc]" value="" placeholder="描述" />'+
'<input type="text" class="layui-input" name="img{$append}['+numid+'][link]" value="" placeholder="链接,选填" />'+
'<input type="text" class="layui-input" name="img{$append}['+numid+'][time]" value="" placeholder="日期,选填" />'+
'<input type="hidden" name="img{$append}['+numid+'][src]" value="' +res.data.src + '" /></div></dd>');
numid++;
$(window).trigger("resize");
}else{
layer.msg(res.msg);
}
}
})
$('#serverImgList{$append}').click(function(){
var html = '';
$.ajax('/manager/file/list',{
data:{
type:'img',
page:1,
size:30
},
headers: {
'X-CSRF-TOKEN': _token
},
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒
success:function(data){
if(data.code == 0){
if(data.data.length > 0){
html += '<div class="layui-card-body"><div class="serverImgsList"><ul id="selectable">'
$.each(data.data,function(i,item){
html += '<li><img src="'+item.src+'" data-box="upload_img_list{$append}" onclick="imgListUrl(this, ' + numid + ')"></li>'
})
html += '</ul></div>';
if(data.data.length >= 30){
html += '<div class="serverMore"><a data-box="upload_img_list{$append}" onclick="imgsList(this, ' + numid + ')">加载更多</a></div>'
}
html += '<div class="layui-clear"></div></div>';
layer.open({
type: 1,
title: '服务器图片',
shadeClose: true,
area: ['800px',''], //宽高
move: false,
content: html,
success:function(layero, index) {
alertRender()
layero.find('.serverImgsList ul li img').attr('data-id',index)
layero.find('.serverMore a').attr('data-id',index)
}
});
numid++;
}else{
layer.msg('暂无数据')
}
}
},
error:function(xhr,type,errorThrown){
}
});
})
});
});
function imgListUrl(obj, numid){
var imTpl = '<dd class="item_img" id="img_' + numid +'">'+
'<div class="imgs"><div class="operate"><i onclick="UPLOAD_IMG_DEL(this)" class="close layui-icon"></i></div>'+
'<img src="' + $(obj).attr('src') +'"></div>'+
'<div class="info"><input type="text" class="layui-input" name="img{$append}['+numid+'][alt]" value="" placeholder="alt" />'+
'<input type="text" class="layui-input" name="img{$append}['+numid+'][desc]" value="" placeholder="描述" />'+
'<input type="text" class="layui-input" name="img{$append}['+numid+'][link]" value="" placeholder="链接,选填" />'+
'<input type="text" class="layui-input" name="img{$append}['+numid+'][time]" value="" placeholder="日期,选填" />'+
'<input type="hidden" name="img{$append}['+numid+'][src]" value="' + $(obj).attr('src') + '" /></div></dd>';
numid++;
$('#'+$(obj).attr('data-box')).append(imTpl);
parent.layer.close($(obj).attr('data-id'));
}
var page = 2
function imgsList(obj, numid){
$.ajax('/manager/file/list',{
data:{
type:'img',
page:page,
size:30
},
headers: {
'X-CSRF-TOKEN': _token
},
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒
success:function(data){
if(data.code == 0){
if(data.data.length > 0){
var html = ''
$.each(data.data,function(i,item){
html += '<li><img src="'+item.src+'" data-id="'+$(obj).attr('data-id')+'" data-box="'+$(obj).attr('data-box')+'" onclick="imgListUrl(this, ' + numid + ')"></li>'
})
$(obj).parent().parent().find('.serverImgsList ul').append(html)
$(window).trigger("resize");
if(data.data.length < 30){
$(obj).parent().append('<p>没有了</p>')
$(obj).parent().find('a').remove();
}else{
page++;
}
}else{
layer.msg(data.msg)
}
}
},
error:function(xhr,type,errorThrown){
}
});
}
/*
删除上传图片
*/
function UPLOAD_IMG_DEL(divs) {
$(divs).closest('dd.item_img').remove()
}
</script>