1.找到上传图片的模板页面 webuploader.html

在上传文件标签后面 添加

<li class=""><a href="#explorer" data-toggle="tab" class="history">文件管理</a></li>

下边便签对应的展示容器中加上

<div class="tab-pane" id="explorer">
<input type="hidden" id="history_path" value="">
<input type="hidden" id="history_view" value="">
<div class="files-wrapper" style="height:270px; overflow-y:scroll;">
<ul id="files-container-history">
<div class="k" style="width:100%;height:10px;clear:both;"></div>
</ul>
</div>
</div>

图片选择样式稍微美化一下

#files-container-history{
list-style:none;
height:270px;
overflow:scorll;
}
.uploaded{
float:left;
width:200px;
height:100px;
padding:5px;
margin-top:10px;
margin-left:10px;
border:1px solid #ccc;
overflow:hidden;
}
.selected{
border:1px solid #00a1ff;
}
.uploaded img{width:100%;}
.filename{
position:relative; width:100%; height:20px;
margin-top:-20px; color:#fff; background-color:rgba(1,1,1,0.5);
font-size:14px;}

添加异步取回已上传文件列表功能

//拉取图片
var listEnd = false, isLoadingData = false, listIndex = 0, listSize = 10;
$('.history').on('click',function(){
if($('#explorer ul li').length == 0){
get_list();
}
});
function get_list(){
if(!listEnd && !isLoadingData) {
isLoadingData = true;
var url = "/user/admin_asset/listimage";
$.ajax({
type: "GET",
url: url,
dataType: "json",
timeout : 10000,
data: {
page: Math.ceil(listIndex/listSize),
},
success: function (json) {
try {
if (json.state == 'SUCCESS') {
show_img(json.list);
listIndex += parseInt(json.list.length);
if(listIndex >= json.total) {
listEnd = true;
}
isLoadingData = false;
}
} catch (e) {
if(json.indexOf('ue_separate_ue') != -1) {
var list = json.split(r.responseText);
listIndex = parseInt(list.length);
listEnd = true;
isLoadingData = false;
}
}
},
error: function () {
isLoadingData = false;
}
});
}
}
//显示图片
function show_img(list){
var str = '';
for (i = 0; i < list.length; i++) {
if(list[i] && list[i].file_path) {
str = str + '<li class="uploaded" data-path="' + list[i].file_path + '" data-view="/upload/' + list[i].file_path + '">'
+ '<div><img src="/upload/' + list[i].file_path + '">'
+ '<div class="filename">' + list[i].filename + '</div></div></li>'; }
}
$('#explorer ul .k').before(str);
}
//滚动
$('.files-wrapper').on('scroll', function(e){
var scrollTop = $(this).scrollTop() + $(this).outerHeight(true);
var ktop = $(this).find('.k').offset().top;
if(scrollTop >= ktop){
get_list();
}
}); //选择
$('#files-container-history').on('click','li',function(){
$(this).addClass('selected').siblings().removeClass('selected');
$('#history_path').val($(this).data('path'));
$('#history_view').val($(this).data('view'));
});

滚动加载更多,展示都有了,

修改文件选择后的回调处理

function get_selected_files() {

        var tab = $(".tab-content > div.active").attr('id');

        var files = [];

        var idPre = 'id' + new Date().getTime();

        if (tab == 'wrapper') {
var number = jQuery(".filelist li").size();
for (var i = 0; i < number; i++) { var file = new Object();
var $file = jQuery(".filelist li").eq(i);
file.id = idPre + i;
file.filepath = $file.data("filepath");
file.preview_url = $file.data("preview_url");//httpUrl+file.filepath;
file.url = $file.data("url");
file.name = $file.data("name");
if (file.url == undefined) {
continue;
} else {
files.push(file);
} }
}else if(tab == 'explorer'){
if($('#history_path').val() == ''){
alert('请选择图片!');
return false;
}
var file = new Object();
file.id = "historyfile"+new Date().getTime();
file.filepath = $('#history_path').val();
file.preview_url = $('#history_view').val();
file.url = $('#history_path').val();
file.name = "";
files.push(file);
}else{
var file = new Object();
file.id = idPre + '1';
file.filepath = jQuery("#info").val();
file.preview_url = file.filepath;
file.url = file.filepath;
file.name = "";//jQuery(".filelist li .title").eq(i).html();
files.push(file);
}
return files;
}

2.后端添加获取listimage的功能

取个巧在user/controller下的资源管理中添加列出已上传图片

public function listimage()
{
$page = $this->request->param('page');
$join = [
['__USER__ u', 'a.user_id = u.id']
];
$total = Db::name('asset')->field('a.id,a.file_path,a.filename,a.create_time')
->alias('a')->join($join)
->count();
$result = Db::name('asset')->field('a.id,a.file_path,a.filename,a.create_time')
->alias('a')->join($join)
->order('create_time', 'DESC')
->paginate(10);
$result = array(
"state" => "SUCCESS",
"list" => $result->items(),
"total" => $total
);
die(json_encode($result));
}

最新文章

  1. Linux或Unix环境利用符号链接升级Maven
  2. asp.net MVC 回顾 Html.ActionLink
  3. PHP规范PSR2
  4. OneNote 2013 快捷键
  5. [转载] 散列表(Hash Table) 从理论到实用(下)
  6. LXNetwork – 基于AF3.0封装的iOS网络请求库
  7. 非spring环境中配置文件工具
  8. 盘点 PHP 和 ASP.NET 的10大对比!
  9. [BZOJ 1046] [HAOI2007] 上升序列 【DP】
  10. form表单和表格
  11. MySQL的my-innodb-heavy-4G.ini配置文件的翻译
  12. jquery.jconfirm兼容IE6
  13. H - transaction transaction transaction
  14. BZOJ-5055-膜法师(离散化+树状数组)
  15. Oracle中session和processes的设置
  16. centos中释放缓存的方法
  17. 《CLR via C#》读书笔记 之 泛型
  18. CSS尺寸与补白属性-----margin和padding
  19. Jenkins参数化构建(一)之 Maven Command Line传递TestNG构建参数
  20. BZOJ 4591 【SHOI2015】 超能粒子炮&#183;改

热门文章

  1. 160-PHP 文本替换函数str_replace(一)
  2. 061-PHP函数定义默认参数
  3. 干货分享|留学Essay怎么写?
  4. NASA的10条编码规则
  5. 二、【未来】React环境安装:npx
  6. Apache nifi 第二篇(小白初试) nifi数据对接流程初次尝试
  7. C# 使用复选框实现循环添加多条信息入库!
  8. Mybatis实体类的映射文件中select,insert语句使用
  9. POJ 2182&amp;&amp; POJ 2828:Lost Cows 从后往前 线段树
  10. HDU 5464:Clarke and problem