{include file="public/header" /}
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" id="LAY-user">
			{if condition="$param.type neq 1"}
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" id="searchKey" class="layui-input" name="searchKey" placeholder="输入文件名搜索"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                    <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                    <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                    </div>
                </div>
            </div>
			{else}
			<blockquote class="layui-elem-quote"><font style="color:red">天翼家庭云盘不支持生成m3u8链接，官方有跨域限制，所以不要在家庭云盘中存放切片文件</font></blockquote>
			{/if}
            <div>
				<span class="layui-breadcrumb" lay-separator="/"></span>	
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-table-manage" lay-filter="LAY-table-manage"></table>
			<!--账号模板-->
            <script type="text/html" id="fileBar">
			{{# if(d.fileType !== '文件夹'){ }}
				{{d.fileName}}
			{{# }else{ }}
				<a href="{:url('panList')}?id={$param.id}&fileId={{d.fileId}}&type={$param.type}"  id="fileId-{{d.fileId}}" style="color:blue;">{{d.fileName}}</a>
			{{# } }}
            </script>
			<!--操作模板-->
            <script type="text/html" id="opeBar">
			{{# if(d.fileType !== '文件夹'){ }}
				{{# if(d.fileType.match(/(mp4|mkv|ts)$/i)){ }}
				<a class="layui-btn layui-btn-xs layui-btn-primary" title="播放预览" lay-event="look"><i class="layui-icon layui-icon-play"></i></a>
				{{# }else if(d.fileType.match(/(gif|jpg|jpeg|png|bmp|webp)$/i)){ }}
				<a class="layui-btn layui-btn-xs layui-btn-primary" title="预览图片" lay-event="look"><i class="layui-icon layui-icon-picture"></i></a>
				{{# }else{ }}
				<a class="layui-btn layui-btn-xs layui-btn-primary" title="下载" lay-event="look"><i class="layui-icon layui-icon-download-circle"></i></a>
				{{# } }}
				<a class="layui-btn layui-btn-xs layui-btn-normal" title="复制链接" lay-event="copy"><i class="layui-icon layui-icon-link"></i></a>
				<a class="layui-btn layui-btn-xs " title="分享文件" lay-event="share"><i class="layui-icon layui-icon-share"></i></a>
			{{# }else{ }}
				<a class="layui-btn layui-btn-xs layui-btn-normal" title="打开文件夹" lay-event="openFolder">打开文件夹</a>
				<a class="layui-btn layui-btn-xs " title="分享文件夹" lay-event="share"><i class="layui-icon layui-icon-share"></i></a>
			{{# } }}
            </script>
			<!--批量操作模板-->
			<script type="text/html" id="toolBar">
				<a class="layui-btn layui-btn-xs " lay-event="copyAll"><i class="layui-icon layui-icon-link"></i>批量复制</a>
				<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="fabu"><i class="layui-icon layui-icon-release"></i>一键发布</a>
				{if condition="$param.type neq 1"}
				<a class="layui-btn layui-btn-xs" lay-event="m3u8"><i class="layui-icon layui-icon-senior"></i>生成m3u8链接</a>
				{/if}
			</script>
        </div>
    </div>
</div>
<!--复制-->
{$pan_data}
{include file="public/footer" /}
{include file="public/copy" /}
<script>
	var searchKey = '';
    layui.use(['index','element','table','form'], function () {
        var $ = layui.$ , form = layui.form, element = layui.element, table = layui.table;
		var load = layer.load();
        table.render({
            elem: '#LAY-table-manage'
			, toolbar: '#toolBar'
			, defaultToolbar: ''
            , url: '?id=' + maopan.account_id + '&fileId=' + maopan.fileId + '&type=' + maopan.dataType
            , page: true
            , even: false
            , autoSort: false
            , cellMinWidth: 150
            , limits: [60, 100]
            , limit: "60"
            , loading: true
            , id: 'LAY-table'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'fileName', minWidth: 300, title: '文件名', sort:true, toolbar: '#fileBar'}
				, {field: 'fileId', minWidth: 200, title: '文件ID'}
                , {field: 'fileType', width: 100, title: '文件类型', align: 'center'}
				, {field: 'fileSize', width: 110, title: '文件大小', align: 'center',templet: function (d){
					return d.fileSize ? bytesToSize(d.fileSize) : (d.fabu ? '<font color="green" title="最后发布时间：'+layui.util.toDateString(d.fabu*1000)+'">已发布</font>' : '');
				}}
                , {field: 'update_time', width: 180, title: '更新时间', align: 'center'}				
                , {fixed: 'right', width: 150, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
				layer.close(load);
				html = '';
				var device = layui.device();
				if(typeof res.capacity !== "undefined"){
				    res.capacity.total_size>0 ? device.mobile ? '' : $('.layui-table-tool-self').html('容量：' + bytesToSize(res.capacity.used_size) +' / ' + bytesToSize(res.capacity.total_size)) : '';
				}
				if(typeof res.path !== "undefined"){
					maopan.filePath = '/';
					for(var i=0;i<res.path.length;i++){
						html += '<a href="?id=' + maopan.account_id + '&fileId=' + res.path[i].parentId + '&type=' + maopan.dataType + '">'+res.path[i].name+'</a>';
						maopan.filePath += res.path[i].name +'/';
						maopan.filePath = maopan.filePath.replace('/全部文件/','/');
					}
					if(res.searchKey!=''){
						searchKey = res.searchKey;
						var search_btn = '<a href="javascript:AutoSearch('+curr+','+res.pageCount+');" class="layui-btn layui-btn-xs">一键自动翻页读数据</a>';
						if(res.pageCount>1){
							if ($('#auto-search').length == 0){
								$('.layui-breadcrumb').after(' <span id="auto-search">'+search_btn+'</span>');
							}else{
								$('#auto-search').html(search_btn);
							}
						}
					}else{
						$('#auto-search').html('');
					}
					if(res.isAuto==1 && curr < res.pageCount){
						AutoSearch(curr,res.pageCount);
					}
				}
				$('.layui-breadcrumb').html(html);
				element.render('breadcrumb');
            }
        });
    });
	function AutoSearch(page,pageCount) {
		var curr = page+1;
		var index = layer.msg('翻页任务:<b style="color:red;">'+curr+'</b>/<b style="color:blue;">'+pageCount+'</b> 处理中...',{icon:16,time:10000,shade:0.5});
		setTimeout(function (){
			layui.table.reload('LAY-table', {
				page: {curr: curr}, 
				where: {isAuto:(curr==pageCount ? 0 : 1),'searchKey':searchKey}
			});
			if(curr==pageCount || searchKey==''){
				layer.msg('自动翻页任务执行完毕！',{icon:1});
				layer.close(index);
			}
		}, 500);
	}
</script>
</body>
</html>