新增:导出用户时间范围筛选

This commit is contained in:
yystopf 2026-07-02 11:16:18 +08:00
parent 5805033de0
commit 5074c32802
12 changed files with 430226 additions and 7 deletions

View File

@ -28,7 +28,8 @@ class Admins::UsersController < Admins::BaseController
def export
params[:sort_by] = params[:sort_by].presence || 'created_on'
params[:sort_direction] = params[:sort_direction].presence || 'desc'
params[:time_type] = params[:time_type].presence || 'created_on'
users = Admins::UserQuery.call(params)
@users = users.includes(:user_extension, projects: :members)
filename = ["用户列表", Time.zone.now.strftime('%Y%m%d%H%M%S')].join('-') << '.xlsx'

View File

@ -73,6 +73,21 @@ class Admins::UserQuery < ApplicationQuery
school_name = params[:school_name].to_s.strip.presence
users = users.joins(user_extension: :school).where('schools.name LIKE ?', "%#{school_name}%") if school_name
# 时间范围搜索
if params[:start_time].present? && params[:end_time].present?
time_type = params[:time_type].presence || 'created_on'
time_type = 'created_on' unless %w[created_on last_login_on].include?(time_type)
users = users.where("#{time_type} >= ? AND #{time_type} <= ?", params[:start_time], params[:end_time])
elsif params[:start_time].present?
time_type = params[:time_type].presence || 'created_on'
time_type = 'created_on' unless %w[created_on last_login_on].include?(time_type)
users = users.where("#{time_type} >= ?", params[:start_time])
elsif params[:end_time].present?
time_type = params[:time_type].presence || 'created_on'
time_type = 'created_on' unless %w[created_on last_login_on].include?(time_type)
users = users.where("#{time_type} <= ?", params[:end_time])
end
custom_sort(users, params[:sort_by], params[:sort_direction])
end
end

View File

@ -45,7 +45,7 @@
<%= check_box_tag("bank_certification", true, false, id: "user_bank_certification", style: 'margin-left: 2px;') %>
<%= submit_tag('搜索', class: 'btn btn-primary mr-3', style: 'margin-left:50px;', 'data-disable-with': '搜索中...') %>
<!-- <button type="reset" class="btn btn-default">清除</button>-->
<a href="javascript:void(0)" class="btn btn-outline-primary export-action" style="margin-left:20px;" id="users-export" data-disable-with = '导出中...'>导出</a>
<%= javascript_void_link '导出', class:'btn btn-outline-primary export-action', style: 'margin-left:20px;', id: 'users-export', data: { toggle: 'modal', target: '.admin-export-user-modal'}, "data-disable_with":'导出中...' %>
</div>
<% end %>
<% if current_user.admin? %>
@ -61,13 +61,29 @@
<%= render partial: 'admins/users/shared/reward_grade_modal' %>
<%= render partial: 'admins/users/shared/import_user_modal' %>
<%= render partial: 'admins/users/shared/export_modal' %>
<script>
$(function () {
var search_form = $("#user-search-form");
//导出
$("#user-search-form").on("click", "#users-export", function () {
window.location.href = "/admins/users/export.xlsx?" + search_form.serialize();
$('#users-export').removeAttr('data-disable-with');
//导出确认
$("#confirm-export-btn").on("click", function () {
var time_type = $("input[name='export_time_type']:checked").val();
var start_time = $("#export_start_time").val();
var end_time = $("#export_end_time").val();
var params = search_form.serialize();
if (time_type) {
params += "&time_type=" + encodeURIComponent(time_type);
}
if (start_time) {
params += "&start_time=" + encodeURIComponent(start_time);
}
if (end_time) {
params += "&end_time=" + encodeURIComponent(end_time);
}
window.location.href = "/admins/users/export.xlsx?" + params;
$('.admin-export-user-modal').modal('hide');
});
})

View File

@ -0,0 +1,41 @@
<div class="modal fade admin-export-user-modal" tabindex="-1" role="dialog" aria-labelledby="exportModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="exportModalLabel">导出用户</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>时间类型:</label>
<div class="radio">
<label>
<input type="radio" name="export_time_type" value="created_on" checked>
创建时间
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="export_time_type" value="last_login_on">
上次登录时间
</label>
</div>
</div>
<div class="form-group">
<label for="export_start_time">开始时间:</label>
<input type="date" class="form-control" id="export_start_time">
</div>
<div class="form-group">
<label for="export_end_time">结束时间:</label>
<input type="date" class="form-control" id="export_end_time">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary" id="confirm-export-btn">导出</button>
</div>
</div>
</div>
</div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long