作业导出的修改2

master
SylorHuang 6 years ago
parent 78c164c08f
commit 43fb9b180b

@ -583,4 +583,8 @@ class ApplicationController < ActionController::Base
def render_parameter_missing def render_parameter_missing
render json: { status: -1, message: '参数缺失' } render json: { status: -1, message: '参数缺失' }
end end
def set_export_cookies
cookies[:fileDownload] = true
end
end end

@ -212,7 +212,7 @@ class HomeworkCommonsController < ApplicationController
else else
respond_to do |format| respond_to do |format|
format.xlsx{ format.xlsx{
cookies[:fileDownload] = true set_export_cookies
student_work_to_xlsx(@work_excel,@homework) 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')}" 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: 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" elsif params[:format] == "zip"
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
elsif params[:export].present? && params[:export]
normal_status(0,"正在下载中")
else else
if @work_excel.present? if @work_excel.present?
zip_works = @work_excel&.where("work_status > 0") zip_works = @work_excel&.where("work_status > 0")
@ -234,13 +232,17 @@ class HomeworkCommonsController < ApplicationController
end end
if status == 0 if status == 0
respond_to do |format| if params[:export].present? && params[:export]
format.zip{ normal_status(0,"正在下载中")
cookies[:fileDownload] = true else
zipfile = zip_homework_common @homework, zip_works respond_to do |format|
file = decode64(zipfile[0][:base64file]) format.zip{
send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/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 end
else else
normal_status(status, status == -2 ? "500M" : "无附件可下载") normal_status(status, status == -2 ? "500M" : "无附件可下载")

@ -11,7 +11,7 @@ class ZipsController < ApplicationController
if params[:export].present? && params[:export] if params[:export].present? && params[:export]
normal_status(0,"正在下载中") normal_status(0,"正在下载中")
else else
cookies[:fileDownload] = true set_export_cookies
send_file service.zip, filename: filename_, type: 'application/zip' send_file service.zip, filename: filename_, type: 'application/zip'
end end

Loading…
Cancel
Save