Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

common.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //加载模块
  2. layui.use(function(){ //亦可加载特定模块:layui.use(['layer', 'laydate', function(){
  3. //得到各种内置组件
  4. var layer = layui.layer //弹层
  5. ,laypage = layui.laypage //分页
  6. ,laydate = layui.laydate //日期
  7. ,table = layui.table //表格
  8. ,carousel = layui.carousel //轮播
  9. ,upload = layui.upload //上传
  10. ,element = layui.element //元素操作
  11. ,slider = layui.slider //滑块
  12. ,dropdown = layui.dropdown //下拉菜单
  13. ,$ = layui.$;
  14. //下载文件函数
  15. function downFile(title,url){
  16. const filePath = url;
  17. const fileExt = filePath.substr(filePath.lastIndexOf('.') + 1);
  18. var title = title + '.' + fileExt;
  19. // 【步骤1】创建一个文件,该文件支持写入操作
  20. const fileStream = streamSaver.createWriteStream(title);
  21. // 这里传入的是下载后的文件名,这个名字可以自定义
  22. // 【步骤2】使用 fetch 方法访问文件的url,将内容一点点的放到 StreamSaver 创建的文件里
  23. fetch(url).then(res => {
  24. const readableStream = res.body
  25. if (window.WritableStream && readableStream.pipeTo) {
  26. return readableStream.pipeTo(fileStream)
  27. .then(() => console.log('完成写入'))
  28. }
  29. // 【步骤3】监听文件内容是否读取完整,读取完就执行“保存并关闭文件”的操作。
  30. window.writer = fileStream.getWriter()
  31. const reader = res.body.getReader()
  32. const pump = () => reader.read()
  33. .then(res => res.done
  34. ? writer.close()
  35. : writer.write(res.value).then(pump)
  36. )
  37. pump()
  38. });
  39. }
  40. //点击下载文档
  41. $('#down_btn').click(function (){
  42. layer.msg('正在处理');
  43. var aid = $(this).attr('aid');
  44. var title = $(this).attr('title');
  45. $.ajax({
  46. type: "POST",
  47. url: '/api/Ajax/get_user_download',
  48. data: {del_id:0,_ajax:1,aid:aid},
  49. dataType: 'json',
  50. success: function (data) {
  51. layer.closeAll();
  52. if(parseInt(data.code) == 1){
  53. layer.msg(data.msg, {icon: 1});
  54. //window.location.reload();
  55. //window.location.href = data.data.down;
  56. /*启动下载*/
  57. downFile(title,data.data.down);
  58. }else{
  59. //layer.alert(data.msg, {icon: 5});
  60. layer.confirm(data.msg, {icon: 3}, function(){
  61. if(data.url != ''){
  62. window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank');
  63. }else{
  64. layer.closeAll();
  65. }
  66. }, function(){
  67. //layer.msg('点击取消的回调');
  68. });
  69. }
  70. },
  71. error:function(e){
  72. layer.closeAll();
  73. layer.alert(e.responseText, {icon: 5});
  74. }
  75. });
  76. return false;
  77. });
  78. //文档点赞
  79. $('#like_btn').click(function (){
  80. layer.msg('正在处理');
  81. var aid = $(this).attr('aid');
  82. var title = $(this).attr('title');
  83. $.ajax({
  84. type: "POST",
  85. url: '/api/Ajax/get_user_like',
  86. data: {del_id:0,_ajax:1,aid:aid},
  87. dataType: 'json',
  88. success: function (data) {
  89. layer.closeAll();
  90. if(parseInt(data.code) == 1){
  91. layer.msg(data.msg, {icon: 1});
  92. //window.location.reload();
  93. //window.location.href = data.data.down;
  94. /*增加点赞数*/
  95. //data.data.likecount
  96. $("#likecount").html(data.data.likecount);
  97. //复选框
  98. if(data.data.type == 1 || data.data.type == '1'){
  99. console.log('1111');
  100. //勾选
  101. $('.btn-e').addClass('btn-e-active');
  102. }else{
  103. $('.btn-e').removeClass('btn-e-active');
  104. }
  105. }else{
  106. //layer.alert(data.msg, {icon: 5});
  107. layer.confirm(data.msg, {icon: 3}, function(){
  108. if(data.url != ''){
  109. window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank');
  110. }else{
  111. layer.closeAll();
  112. }
  113. }, function(){
  114. //layer.msg('点击取消的回调');
  115. });
  116. }
  117. },
  118. error:function(e){
  119. layer.closeAll();
  120. layer.alert(e.responseText, {icon: 5});
  121. }
  122. });
  123. return false;
  124. });
  125. //文档收藏
  126. $('#collect_btn').click(function (){
  127. layer.msg('正在处理');
  128. var aid = $(this).attr('aid');
  129. var title = $(this).attr('title');
  130. $.ajax({
  131. type: "POST",
  132. url: '/api/Ajax/get_user_collect',
  133. data: {del_id:0,_ajax:1,aid:aid},
  134. dataType: 'json',
  135. success: function (data) {
  136. layer.closeAll();
  137. if(parseInt(data.code) == 1){
  138. layer.msg(data.msg, {icon: 1});
  139. //window.location.reload();
  140. //window.location.href = data.data.down;
  141. /*增加点赞数*/
  142. //data.data.likecount
  143. $("#collection").html(data.data.collection);
  144. //复选框
  145. if(data.data.type == 1 || data.data.type == '1'){
  146. console.log('1111');
  147. //勾选
  148. $('.btn-d').addClass('btn-e-active');
  149. }else{
  150. $('.btn-d').removeClass('btn-e-active');
  151. }
  152. }else{
  153. //layer.alert(data.msg, {icon: 5});
  154. layer.confirm(data.msg, {icon: 3}, function(){
  155. if(data.url != ''){
  156. window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank');
  157. }else{
  158. layer.closeAll();
  159. }
  160. }, function(){
  161. //layer.msg('点击取消的回调');
  162. });
  163. }
  164. },
  165. error:function(e){
  166. layer.closeAll();
  167. layer.alert(e.responseText, {icon: 5});
  168. }
  169. });
  170. return false;
  171. });
  172. //点击分享
  173. $('#share_btn').on('click',function (){
  174. $('#share-box').toggle();
  175. if ($(this).hasClass('btn-e-active')) {
  176. // 存在class
  177. $('.btn-c').removeClass('btn-e-active');
  178. } else {
  179. // 不存在class
  180. $('.btn-c').addClass('btn-e-active');
  181. }
  182. });
  183. });