From 22d8fc9abd7c4d5d3138593ce4bbc851c184ab14 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 22 Dec 2015 15:45:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E9=99=84=E4=BB=B6=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zipdown_controller.rb | 21 +++++++++++++++++---- public/javascripts/application.js | 27 ++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 1a01ac97b..2a4430935 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -1,4 +1,8 @@ -require 'zip' +#coding=utf-8 + +require "base64" +require 'zip' + class ZipdownController < ApplicationController #查找项目(课程) before_filter :find_project_by_bid_id, :only => [:assort] @@ -11,7 +15,12 @@ class ZipdownController < ApplicationController def download if User.current.logged? begin - send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file]) + if params[:base64file] + file = Base64.decode64(params[:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file) + else + send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file]) + end rescue => e render file: 'public/no_file_found.html' end @@ -107,7 +116,9 @@ class ZipdownController < ApplicationController bid_homework_path, OUTPUT_FOLDER) } [{files:[out_file.file_path], count: 1, index: 1, - real_file: out_file.file_path, file: File.basename(out_file.file_path), + real_file: out_file.file_path, + file: File.basename(out_file.file_path), + base64file: Base64.encode64(File.basename(out_file.file_path)), size:(out_file.pack_size / 1024.0 / 1024.0).round(2) }] end @@ -129,7 +140,9 @@ class ZipdownController < ApplicationController bid_homework_path, OUTPUT_FOLDER) } [{files:[out_file.file_path], count: 1, index: 1, - real_file: out_file.file_path, file: File.basename(out_file.file_path), + real_file: out_file.file_path, + file: File.basename(out_file.file_path), + base64file: Base64.encode64(File.basename(out_file.file_path)), size:(out_file.pack_size / 1024.0 / 1024.0).round(2) }] end diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 901e302d3..0cbe647d6 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -870,7 +870,10 @@ function redo() { window.location.reload() } -function encodeHomeworkUrl(url){ +function encodeHomeworkUrl(url, is_base64){ + if(typeof is_base64 === 'boolean' && is_base64){ + return '/zipdown/download?base64file='+url; + } var file = encodeURI(url).replace(/\+/g, '%2B'); return '/zipdown/download?file='+file; } @@ -891,7 +894,10 @@ $(function(){ } if(res.length==1){ - location.href = encodeHomeworkUrl(res[0].file);return; + if(res[0].base64file){ + location.href = encodeHomeworkUrl(res[0].base64file, true);return; + } + location.href = encodeHomeworkUrl(res[0].file);return; } document.getElementById('light').style.display='block'; @@ -904,8 +910,12 @@ $(function(){ } else { des = '第'+res[i].index+'个学生的作品下载'; } - $('
  • '+(i+1)+'. '+des+'  (共'+res[i].size+'M)
  • ').appendTo($container); + if(res[i].base64file){ + $('
  • '+(i+1)+'. '+des+'  (共'+res[i].size+'M)
  • ').appendTo($container); + } else { + $('
  • '+(i+1)+'. '+des+'  (共'+res[i].size+'M)
  • ').appendTo($container); + } } } }); @@ -973,3 +983,14 @@ function showNormalImage(id) { } } + +$(function(){ + //at 加链接 + $("span.at").hover(function(){ + $(this).css('cursor', 'pointer'); + }); + $("span.at").live('click', function(){ + var userId = $(this).attr('data-user-id'); + $(window.location).attr('href', '/users/'+userId); + }); +}); \ No newline at end of file