admins: shixun weapp image config

problem_set
p31729568 5 years ago
parent 9d5efc98fa
commit bc1b9866fa

@ -4,14 +4,17 @@ $(document).on('turbolinks:load', function() {
var $form = $modal.find('form.admin-upload-file-form') var $form = $modal.find('form.admin-upload-file-form')
var $sourceIdInput = $modal.find('input[name="source_id"]'); var $sourceIdInput = $modal.find('input[name="source_id"]');
var $sourceTypeInput = $modal.find('input[name="source_type"]'); var $sourceTypeInput = $modal.find('input[name="source_type"]');
var $suffixInput = $modal.find('input[name="suffix"]');
$modal.on('show.bs.modal', function(event){ $modal.on('show.bs.modal', function(event){
var $link = $(event.relatedTarget); var $link = $(event.relatedTarget);
var sourceId = $link.data('sourceId'); var sourceId = $link.data('sourceId');
var sourceType = $link.data('sourceType'); var sourceType = $link.data('sourceType');
var suffix = $link.data('suffix');
$sourceIdInput.val(sourceId); $sourceIdInput.val(sourceId);
$sourceTypeInput.val(sourceType); $sourceTypeInput.val(sourceType);
if(suffix != undefined){ $suffixInput.val(suffix); }
$modal.find('.upload-file-input').trigger('click'); $modal.find('.upload-file-input').trigger('click');
}); });
@ -48,6 +51,7 @@ $(document).on('turbolinks:load', function() {
contentType: false, contentType: false,
success: function(data){ success: function(data){
$.notify({ message: '上传成功' }); $.notify({ message: '上传成功' });
$modal.find('.file-names').html('');
$modal.trigger('upload:success', data); $modal.trigger('upload:success', data);
$modal.modal('hide'); $modal.modal('hide');
}, },

@ -34,10 +34,17 @@ $(document).on('turbolinks:load', function() {
}); });
$('.modal.admin-upload-file-modal').on('upload:success', function(e, data){ $('.modal.admin-upload-file-modal').on('upload:success', function(e, data){
var $imageElement = $('.shixun-image-' + data.source_id); if(data.suffix == '_weapp'){
$imageElement.attr('src', data.url); var $imageElement = $('.shixun-weapp-image-' + data.source_id);
$imageElement.show(); $imageElement.attr('src', data.url);
$imageElement.next().html('重新上传'); $imageElement.show();
$imageElement.next().html('重新上传');
} else {
var $imageElement = $('.shixun-image-' + data.source_id);
$imageElement.attr('src', data.url);
$imageElement.show();
$imageElement.next().html('重新上传');
}
}) })
} }
}); });

@ -6,7 +6,12 @@ class Admins::FilesController < Admins::BaseController
Util.write_file(@file, file_path) Util.write_file(@file, file_path)
render_ok(source_id: params[:source_id], source_type: params[:source_type].to_s, url: file_url + "?t=#{Random.rand}") render_ok(
source_id: params[:source_id],
source_type: params[:source_type].to_s,
suffix: params[:suffix].presence,
url: file_url
)
rescue StandardError => ex rescue StandardError => ex
logger_error(ex) logger_error(ex)
render_error('上传失败') render_error('上传失败')
@ -33,14 +38,14 @@ class Admins::FilesController < Admins::BaseController
@_file_path ||= begin @_file_path ||= begin
case params[:source_type].to_s case params[:source_type].to_s
when 'Shixun' then when 'Shixun' then
Util::FileManage.disk_filename('Shixun', params[:source_id]) Util::FileManage.disk_filename('Shixun', params[:source_id], params[:suffix].presence)
else else
Util::FileManage.disk_filename(params[:source_type].to_s, params[:source_id].to_s) Util::FileManage.disk_filename(params[:source_type].to_s, params[:source_id].to_s, params[:suffix].presence)
end end
end end
end end
def file_url def file_url
Util::FileManage.disk_file_url(params[:source_type].to_s, params[:source_id].to_s) Util::FileManage.disk_file_url(params[:source_type].to_s, params[:source_id].to_s, params[:suffix].presence)
end end
end end

@ -11,6 +11,7 @@
<form class="admin-upload-file-form" enctype="multipart/form-data"> <form class="admin-upload-file-form" enctype="multipart/form-data">
<%= hidden_field_tag(:source_type, nil) %> <%= hidden_field_tag(:source_type, nil) %>
<%= hidden_field_tag(:source_id, nil) %> <%= hidden_field_tag(:source_id, nil) %>
<%= hidden_field_tag(:suffix, nil) %>
<div class="input-group"> <div class="input-group">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text">文件</span> <span class="input-group-text">文件</span>

@ -1,12 +1,12 @@
<table class="table text-center shixun-settings-list-table"> <table class="table text-center shixun-settings-list-table">
<thead class="thead-light"> <thead class="thead-light">
<th width="4%">序号</th>
<th width="8%">ID</th> <th width="8%">ID</th>
<th width="12%" class="text-left">实训名称</th> <th width="12%" class="text-left">实训名称</th>
<th width="8%">技术平台</th> <th width="8%">技术平台</th>
<th width="8%">权限</th> <th width="8%">权限</th>
<th width="15%">技术体系</th> <th width="15%">技术体系</th>
<th width="12%">上传图片</th> <th width="8%">上传图片</th>
<th width="8%">小程序封面</th>
<th width="5%">创建者</th> <th width="5%">创建者</th>
<th width="5%">关闭</th> <th width="5%">关闭</th>
<th width="4%">复制</th> <th width="4%">复制</th>

@ -1,4 +1,3 @@
<td class="shixun-line-no"><%= page_no %></td>
<td><%= shixun.identifier %></td> <td><%= shixun.identifier %></td>
<td class="text-left"> <td class="text-left">
<span> <span>
@ -21,6 +20,13 @@
<%= image_tag(imageUrl, width: 60, height: 40, class: "preview-image shixun-image-#{shixun.id}", data: { toggle: 'tooltip', title: '点击预览' }, style: imageExists ? '' : 'display:none') %> <%= image_tag(imageUrl, width: 60, height: 40, class: "preview-image shixun-image-#{shixun.id}", data: { toggle: 'tooltip', title: '点击预览' }, style: imageExists ? '' : 'display:none') %>
<%= javascript_void_link imageExists ? '重新上传' : '上传图片', class: 'action upload-shixun-image-action', data: { source_id: shixun.id, source_type: 'Shixun', toggle: 'modal', target: '.admin-upload-file-modal' } %> <%= javascript_void_link imageExists ? '重新上传' : '上传图片', class: 'action upload-shixun-image-action', data: { source_id: shixun.id, source_type: 'Shixun', toggle: 'modal', target: '.admin-upload-file-modal' } %>
</td> </td>
<td class="shixun-setting-weapp-image">
<% weappImageExists = Util::FileManage.exists?(shixun, '_weapp') %>
<% imageUrl = weappImageExists ? Util::FileManage.source_disk_file_url(shixun, '_weapp') : '' %>
<%= image_tag(imageUrl, width: 60, height: 40, class: "preview-image shixun-weapp-image-#{shixun.id}", data: { toggle: 'tooltip', title: '点击预览' }, style: weappImageExists ? '' : 'display:none') %>
<%= raw '<br/>' if weappImageExists %>
<%= javascript_void_link weappImageExists ? '重新上传' : '上传图片', class: 'action upload-shixun-weapp-image-action', data: { source_id: shixun.id, source_type: 'Shixun', suffix: '_weapp', toggle: 'modal', target: '.admin-upload-file-modal' } %>
</td>
<td><%= link_to shixun.owner.try(:real_name),"/users/#{shixun.owner.login}",target:'_blank' %></td> <td><%= link_to shixun.owner.try(:real_name),"/users/#{shixun.owner.login}",target:'_blank' %></td>
<td> <td>
<% if shixun.status.to_i < 3 %> <% if shixun.status.to_i < 3 %>

@ -6,7 +6,22 @@ json.images do
end end
json.shixuns do json.shixuns do
json.partial! 'shixuns/shixun', locals: { shixuns: @shixuns } json.array! @shixuns do |shixun|
json.id shixun.id
json.identifier shixun.identifier
json.name shixun.name
json.status shixun.status
json.power (current_user.shixun_permission(shixun)) # 现在首页只显示已发布的实训
# REDO: 局部缓存
json.tag_name @tag_name_map&.fetch(shixun.id, nil) || shixun.tag_repertoires.first.try(:name)
json.myshixuns_count shixun.myshixuns_count
json.stu_num shixun.myshixuns_count
json.score_info shixun.averge_star
json.challenges_count shixun.challenges_count
#json.exp shixun.all_score
json.level level_to_s(shixun.trainee)
json.pic Util::FileManage.source_disk_file_url(shixun, '_weapp')
end
end end
json.subjects do json.subjects do

Loading…
Cancel
Save