From 135e02504ec4d154ecac2214aae203c095a04e32 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Wed, 11 May 2016 11:40:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=87=AA=E5=8A=A8=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 4 ++- lib/grack/Gemfile.lock | 2 +- .../kindeditor/assets_controller.rb | 33 ++++++++++++++--- public/assets/kindeditor/kindeditor.js | 4 ++- public/assets/kindeditor/pasteimg.js | 36 ++++++------------- 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/Gemfile b/Gemfile index 2b12860f0..97d0e5a4f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://ruby.taobao.org' +source 'https://rubygems.org/' #source 'http://ruby.sdutlinux.org/' unless RUBY_PLATFORM =~ /w32/ @@ -40,6 +40,8 @@ gem 'kaminari' gem 'elasticsearch-model' gem 'elasticsearch-rails' +gem 'certified' + group :development do gem 'grape-swagger' gem 'better_errors', '~> 1.1.0' diff --git a/lib/grack/Gemfile.lock b/lib/grack/Gemfile.lock index 68fa71a2b..8ae4dcc6c 100644 --- a/lib/grack/Gemfile.lock +++ b/lib/grack/Gemfile.lock @@ -5,7 +5,7 @@ PATH rack (~> 1.5.1) GEM - remote: https://ruby.taobao.org/ + remote: https://rubygems.org/ specs: byebug (4.0.5) columnize (= 0.9.0) diff --git a/lib/rails_kindeditor/app/controllers/kindeditor/assets_controller.rb b/lib/rails_kindeditor/app/controllers/kindeditor/assets_controller.rb index c94a3944e..30b532acb 100644 --- a/lib/rails_kindeditor/app/controllers/kindeditor/assets_controller.rb +++ b/lib/rails_kindeditor/app/controllers/kindeditor/assets_controller.rb @@ -119,16 +119,41 @@ class Kindeditor::AssetsController < ApplicationController render :text => @result.to_json end + #在KE里面复制粘贴的时候 把图片下载到服务器上 def uploadpic - picstr = params["pic"]; + picStr = params["pic"] + picArry = picStr.split("|") - picArry = picstr.split("|") + #图片存放目录 + dirPath = "public/files/uploads/image/" + dirDate = Time.now.strftime('%Y%m') - picArry.each do |picurl| - puts picurl + unless Dir.exist?(dirPath+dirDate) + Dir.mkdir(dirPath+dirDate) end + fileStr = [] + picArry.each_with_index do |picUrl,index| + imgBaseName = File.basename(picUrl) + tmpImgType = imgBaseName.split(".").last[0..2] + # 仅支持如下图片格式:bmp,jpeg,jpg,png,gif,BMP,JPEG,JPG,PNG,GIF + + fileType = tmpImgType.match("gif|jpg|jpeg|png|bmp|BMP|JPEG|JPG|PNG|GIF") + + fileName = fileType.nil? ? Time.now.to_i.to_s+index.to_s : Time.now.to_i.to_s+index.to_s+"."+fileType[0] + + # fileType = File.basename(picurl).split(".").last[0..2] + # fileName = Time.now.to_i.to_s+index.to_s + fileDir = dirPath + dirDate + "/"+fileName + + #重点!! + File.open(fileDir,'wb'){ |f| f.write(open(picUrl).read) } + fileDir = fileDir.split("public")[1] + fileStr = filedir + "|" + + end + render :text =>fileStr end private diff --git a/public/assets/kindeditor/kindeditor.js b/public/assets/kindeditor/kindeditor.js index 579da5d0c..cb66f91ee 100644 --- a/public/assets/kindeditor/kindeditor.js +++ b/public/assets/kindeditor/kindeditor.js @@ -4689,7 +4689,6 @@ function _bindNewlineEvent() { }); K(doc).keyup(function(e) { if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) { - df(); return; } if (newlineTag == 'br') { @@ -5995,6 +5994,9 @@ _plugin('core', function(K) { } } self.insertHtml(html, true); + df(); + +// $("#ajax-indicator").hide(); } K(doc.body).bind('paste', function(e){ if (self.pasteType === 0) { diff --git a/public/assets/kindeditor/pasteimg.js b/public/assets/kindeditor/pasteimg.js index 5f62eac17..a9505f8d6 100644 --- a/public/assets/kindeditor/pasteimg.js +++ b/public/assets/kindeditor/pasteimg.js @@ -354,16 +354,7 @@ function enablePasteImg(_editor) { }; function df() { - var haspicContainer = document.getElementById("has_pic"); - if (haspicContainer == null) { - haspicContainer = document.createElement("div"); - haspicContainer.id = "has_pic"; - haspicContainer.innerHTML = "
您有图片需要上传到服务器  上传
"; - $(".ke-toolbar").after(haspicContainer); - } - var img = $(".ke-edit-iframe").contents().find("img"); - var piccount = 0; var sstr = ""; $(img).each(function (i) { @@ -376,26 +367,17 @@ function df() { sstr += that.attr("src") + "|"; } }); - - $("#piclist").val(sstr); - document.getElementById("has_pic").style.display = (piccount > 0) ? "block" : "none"; + uploadpic(sstr); } -function closeupload() { - $("#has_pic").hide(); - $("#upload").show(); -} - -function uploadpic() { - var piclist = encodeURI($("#piclist").val()); +function uploadpic(piclist) { if (piclist.length == 0) return false; $.ajax({ url: "/kindeditor/uploadpic", data: "pic=" + piclist, type: "GET", beforeSend: function () { - $("#upload").hide(); - $("#confirm").text("正在上传中..."); + $("#ajax-indicator").text("图片上传中请稍等..."); }, success: function (msg) { if (msg !== "") { @@ -403,17 +385,19 @@ function uploadpic() { str = msg.split('|'); var img = $(".ke-edit-iframe").contents().find("img"); + var tIndex = 0; $(img).each(function (i) { var that = $(this); if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) { - that.attr("src", "/uploads/image/" + str[i]); - that.attr("data-ke-src", "/uploads/image/" + str[i]); + that.attr("src", str[tIndex]); + that.attr("data-ke-src", str[tIndex]); + that.parent().attr("href", str[tIndex]); + that.parent().attr("data-ke-src", str[tIndex]); + tIndex = tIndex + 1; } }); - - $("#confirm").html(img.length + "张图片已经上传成功!  关闭"); } - else $("#confirm").text("上传失败!"); +// else $("#confirm").text("上传失败!"); } }); }