Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
3afcd6eedf
@ -1,14 +1,22 @@
|
|||||||
$(document).on('turbolinks:load', function() {
|
$(document).on('turbolinks:load', function() {
|
||||||
var $modal = $('.modal.admin-message-modal');
|
var $modal = $('.modal.admin-message-modal');
|
||||||
|
var $submitBtn = $modal.find('.submit-btn');
|
||||||
if ($modal.length > 0) {
|
if ($modal.length > 0) {
|
||||||
$modal.on('hide.bs.modal', function(){
|
$modal.on('hide.bs.modal', function(){
|
||||||
$modal.find('.modal-body').html('');
|
$modal.find('.modal-body').html('');
|
||||||
|
$submitBtn.unbind();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function showMessageModal(html) {
|
function showMessageModal(html, callback) {
|
||||||
var $modal = $('.modal.admin-message-modal');
|
var $modal = $('.modal.admin-message-modal');
|
||||||
|
var $submitBtn = $modal.find('.submit-btn');
|
||||||
|
$submitBtn.unbind();
|
||||||
|
if(callback !== undefined && typeof callback === 'function'){
|
||||||
|
$submitBtn.on('click', callback);
|
||||||
|
}
|
||||||
|
|
||||||
$modal.find('.modal-body').html(html);
|
$modal.find('.modal-body').html(html);
|
||||||
$modal.modal('show');
|
$modal.modal('show');
|
||||||
}
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
var $modal = $('.modal.admin-import-course-member-modal');
|
||||||
|
if ($modal.length > 0) {
|
||||||
|
var $form = $modal.find('form.admin-import-course-member-form');
|
||||||
|
|
||||||
|
var resetFileInputFunc = function(file){
|
||||||
|
file.after(file.clone().val(""));
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
$modal.on('show.bs.modal', function(){
|
||||||
|
$modal.find('.file-names').html('选择文件');
|
||||||
|
$modal.find('.upload-file-input').trigger('click');
|
||||||
|
});
|
||||||
|
$modal.on('hide.bs.modal', function(){
|
||||||
|
resetFileInputFunc($modal.find('.upload-file-input'));
|
||||||
|
});
|
||||||
|
$modal.on('change', '.upload-file-input', function(e){
|
||||||
|
var file = $(this)[0].files[0];
|
||||||
|
$modal.find('.file-names').html(file ? file.name : '请选择文件');
|
||||||
|
})
|
||||||
|
|
||||||
|
var importFormValid = function(){
|
||||||
|
if($form.find('input[name="file"]').val() == undefined || $form.find('input[name="file"]').val().length == 0){
|
||||||
|
$form.find('.error').html('请选择文件');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
var buildResultMessage = function(data){
|
||||||
|
var messageHtml = "<div>导入结果:成功" + data.success + "条,失败"+ data.fail.length + "条</div>";
|
||||||
|
|
||||||
|
if(data.fail.length > 0){
|
||||||
|
messageHtml += '<table class="table"><thead class="thead-light"><tr><th>数据</th><th>失败原因</th></tr></thead><tbody>';
|
||||||
|
|
||||||
|
data.fail.forEach(function(item){
|
||||||
|
messageHtml += '<tr><td>' + item.data + '</td><td>' + item.message + '</td></tr>';
|
||||||
|
});
|
||||||
|
|
||||||
|
messageHtml += '</tbody></table>'
|
||||||
|
}
|
||||||
|
|
||||||
|
return messageHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
$modal.on('click', '.submit-btn', function(){
|
||||||
|
$form.find('.error').html('');
|
||||||
|
|
||||||
|
if (importFormValid()) {
|
||||||
|
$('body').mLoading({ text: '正在导入...' });
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: '/admins/import_course_members',
|
||||||
|
data: new FormData($form[0]),
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
success: function(data){
|
||||||
|
$('body').mLoading('destroy');
|
||||||
|
$modal.modal('hide');
|
||||||
|
|
||||||
|
showMessageModal(buildResultMessage(data), function(){
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function(res){
|
||||||
|
$('body').mLoading('destroy');
|
||||||
|
var data = res.responseJSON;
|
||||||
|
$form.find('.error').html(data.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -1,7 +1,10 @@
|
|||||||
class Wechats::JsSdkSignaturesController < ApplicationController
|
class Wechats::JsSdkSignaturesController < ApplicationController
|
||||||
def create
|
def create
|
||||||
signature = Util::Wechat.js_sdk_signature(params[:url], params[:noncestr], params[:timestamp])
|
timestamp = (Time.now.to_f * 1000).to_i
|
||||||
render_ok(signature: signature)
|
noncestr = ('A'..'z').to_a.sample(8).join
|
||||||
|
signature = Util::Wechat.js_sdk_signature(params[:url], noncestr, timestamp)
|
||||||
|
|
||||||
|
render_ok(appid: Util::Wechat.appid, timestamp: timestamp, noncestr: noncestr, signature: signature)
|
||||||
rescue Util::Wechat::Error => ex
|
rescue Util::Wechat::Error => ex
|
||||||
render_error(ex.message)
|
render_error(ex.message)
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
<div class="modal fade admin-import-course-member-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">导入课堂成员</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="admin-import-course-member-form" enctype="multipart/form-data">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text">文件</span>
|
||||||
|
</div>
|
||||||
|
<div class="custom-file">
|
||||||
|
<input type="file" name="file" id="import-course-member-input" class="upload-file-input" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
|
||||||
|
<label class="custom-file-label file-names" for="import-course-member-input">选择文件</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="error text-danger"></div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-primary submit-btn">确认</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
Loading…
Reference in new issue