//加载模块 layui.use(function(){ //亦可加载特定模块:layui.use(['layer', 'laydate', function(){ //得到各种内置组件 var layer = layui.layer //弹层 ,laypage = layui.laypage //分页 ,laydate = layui.laydate //日期 ,table = layui.table //表格 ,carousel = layui.carousel //轮播 ,upload = layui.upload //上传 ,element = layui.element //元素操作 ,slider = layui.slider //滑块 ,dropdown = layui.dropdown //下拉菜单 ,$ = layui.$; //下载文件函数 function downFile(title,url){ const filePath = url; const fileExt = filePath.substr(filePath.lastIndexOf('.') + 1); var title = title + '.' + fileExt; // 【步骤1】创建一个文件,该文件支持写入操作 const fileStream = streamSaver.createWriteStream(title); // 这里传入的是下载后的文件名,这个名字可以自定义 // 【步骤2】使用 fetch 方法访问文件的url,将内容一点点的放到 StreamSaver 创建的文件里 fetch(url).then(res => { const readableStream = res.body if (window.WritableStream && readableStream.pipeTo) { return readableStream.pipeTo(fileStream) .then(() => console.log('完成写入')) } // 【步骤3】监听文件内容是否读取完整,读取完就执行“保存并关闭文件”的操作。 window.writer = fileStream.getWriter() const reader = res.body.getReader() const pump = () => reader.read() .then(res => res.done ? writer.close() : writer.write(res.value).then(pump) ) pump() }); } //点击下载文档 $('#down_btn').click(function (){ layer.msg('正在处理'); var aid = $(this).attr('aid'); var title = $(this).attr('title'); $.ajax({ type: "POST", url: '/api/Ajax/get_user_download', data: {del_id:0,_ajax:1,aid:aid}, dataType: 'json', success: function (data) { layer.closeAll(); if(parseInt(data.code) == 1){ layer.msg(data.msg, {icon: 1}); //window.location.reload(); //window.location.href = data.data.down; /*启动下载*/ //downFile(title,data.data.down); //window.location.href = data.data.down; window.open(data.data.down,"_blank"); }else{ //layer.alert(data.msg, {icon: 5}); layer.confirm(data.msg, {icon: 3,title:false}, function(){ if(data.url != ''){ //window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank'); var currentUrl = window.location.href; var r_url = '&referurl=' + encodeURIComponent(currentUrl); //{$web_domain}{$web_url} //window.location.href = 'https://www.zc10000.com/?m=user&c=Users&a=login'+r_url; window.open('https://www.zc10000.com/?m=user&c=Users&a=login'+r_url,'_blank'); }else{ layer.closeAll(); } }, function(){ //layer.msg('点击取消的回调'); }); } }, error:function(e){ layer.closeAll(); layer.alert(e.responseText, {icon: 5}); } }); return false; }); //文档点赞 $('#like_btn').click(function (){ layer.msg('正在处理'); var aid = $(this).attr('aid'); var title = $(this).attr('title'); $.ajax({ type: "POST", url: '/api/Ajax/get_user_like', data: {del_id:0,_ajax:1,aid:aid}, dataType: 'json', success: function (data) { layer.closeAll(); if(parseInt(data.code) == 1){ layer.msg(data.msg, {icon: 1,title:false}); //window.location.reload(); //window.location.href = data.data.down; /*增加点赞数*/ //data.data.likecount $("#likecount").html(data.data.likecount); //复选框 if(data.data.type == 1 || data.data.type == '1'){ console.log('1111'); //勾选 $('.btn-e').addClass('btn-e-active'); }else{ $('.btn-e').removeClass('btn-e-active'); } }else{ //layer.alert(data.msg, {icon: 5}); layer.confirm(data.msg, {icon: 3}, function(){ if(data.url != ''){ window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank'); }else{ layer.closeAll(); } }, function(){ //layer.msg('点击取消的回调'); }); } }, error:function(e){ layer.closeAll(); layer.alert(e.responseText, {icon: 5}); } }); return false; }); //文档收藏 $('#collect_btn').click(function (){ layer.msg('正在处理'); var aid = $(this).attr('aid'); var title = $(this).attr('title'); $.ajax({ type: "POST", url: '/api/Ajax/get_user_collect', data: {del_id:0,_ajax:1,aid:aid}, dataType: 'json', success: function (data) { layer.closeAll(); if(parseInt(data.code) == 1){ layer.msg(data.msg, {icon: 1,title:false}); //window.location.reload(); //window.location.href = data.data.down; /*增加点赞数*/ //data.data.likecount $("#collection").html(data.data.collection); //复选框 if(data.data.type == 1 || data.data.type == '1'){ console.log('1111'); //勾选 $('.btn-d').addClass('btn-e-active'); }else{ $('.btn-d').removeClass('btn-e-active'); } }else{ //layer.alert(data.msg, {icon: 5}); layer.confirm(data.msg, {icon: 3}, function(){ if(data.url != ''){ window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank'); }else{ layer.closeAll(); } }, function(){ //layer.msg('点击取消的回调'); }); } }, error:function(e){ layer.closeAll(); layer.alert(e.responseText, {icon: 5}); } }); return false; }); //点击分享 $('#share_btn').on('click',function (){ $('#share-box').toggle(); if ($(this).hasClass('btn-e-active')) { // 存在class $('.btn-c').removeClass('btn-e-active'); } else { // 不存在class $('.btn-c').addClass('btn-e-active'); } }); });