From 43fb9b180b04087bc6773287581d1705b35a51a6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 30 Jul 2019 17:59:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 ++++ .../homework_commons_controller.rb | 22 ++++++++++--------- app/controllers/zips_controller.rb | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e825d53da..c76ca51a7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -583,4 +583,8 @@ class ApplicationController < ActionController::Base def render_parameter_missing render json: { status: -1, message: '参数缺失' } end + + def set_export_cookies + cookies[:fileDownload] = true + end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index dfa6795fb..f7906ecda 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -212,7 +212,7 @@ class HomeworkCommonsController < ApplicationController else respond_to do |format| format.xlsx{ - cookies[:fileDownload] = true + set_export_cookies student_work_to_xlsx(@work_excel,@homework) exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@homework.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" render xlsx: "#{exercise_export_name.strip}",template: "homework_commons/works_list.xlsx.axlsx",locals: @@ -223,8 +223,6 @@ class HomeworkCommonsController < ApplicationController elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") - elsif params[:export].present? && params[:export] - normal_status(0,"正在下载中") else if @work_excel.present? zip_works = @work_excel&.where("work_status > 0") @@ -234,13 +232,17 @@ class HomeworkCommonsController < ApplicationController end if status == 0 - respond_to do |format| - format.zip{ - cookies[:fileDownload] = true - zipfile = zip_homework_common @homework, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - } + if params[:export].present? && params[:export] + normal_status(0,"正在下载中") + else + respond_to do |format| + format.zip{ + set_export_cookies + zipfile = zip_homework_common @homework, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + } + end end else normal_status(status, status == -2 ? "500M" : "无附件可下载") diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index bea5784c7..b1f7804a9 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -11,7 +11,7 @@ class ZipsController < ApplicationController if params[:export].present? && params[:export] normal_status(0,"正在下载中") else - cookies[:fileDownload] = true + set_export_cookies send_file service.zip, filename: filename_, type: 'application/zip' end