Showing
2 changed files
with
53 additions
and
18 deletions
@@ -151,13 +151,32 @@ module.exports = { | @@ -151,13 +151,32 @@ module.exports = { | ||
151 | } | 151 | } |
152 | }, | 152 | }, |
153 | baiduUeditor: function (req, callback) { | 153 | baiduUeditor: function (req, callback) { |
154 | + console.log("---------------baidu ueditor-------------"); | ||
154 | var result = {code: "500", message: "接口异常"}; | 155 | var result = {code: "500", message: "接口异常"}; |
155 | var httpHeader = Utils.createHttpHeader(req); | 156 | var httpHeader = Utils.createHttpHeader(req); |
156 | if (!httpHeader) { | 157 | if (!httpHeader) { |
157 | result = {code: "501", message: "用户失效,请重新登录"}; | 158 | result = {code: "501", message: "用户失效,请重新登录"}; |
158 | return callback(null, result); | 159 | return callback(null, result); |
159 | } | 160 | } |
160 | - req.body.files = [fs.createReadStream(req.files.upfile.path)]; | 161 | + |
162 | + var files = req.files.upfile; | ||
163 | + console.log(req.files); | ||
164 | + //判断是单张传还是多张传 | ||
165 | + var flag = Object.prototype.toString.call(files) === '[object Array]'; | ||
166 | + //如果是单张,则数组化 | ||
167 | + if (!flag) { | ||
168 | + files = []; | ||
169 | + files.push(req.files.upfile); | ||
170 | + } | ||
171 | + | ||
172 | + req.body.files = []; | ||
173 | + req.body.fileNames = []; | ||
174 | + for (var index = 0; index < files.length; index++) { | ||
175 | + req.body.files[index] = fs.createReadStream(files[index].path); | ||
176 | + req.body.fileNames[index] = files[index].filename; | ||
177 | + } | ||
178 | + | ||
179 | + // req.body.files = [fs.createReadStream(req.files.upfile.path)]; | ||
161 | req.body.bucket = "goodsimg"; | 180 | req.body.bucket = "goodsimg"; |
162 | request.post({ | 181 | request.post({ |
163 | url: "http://upload.static.yohobuy.com", | 182 | url: "http://upload.static.yohobuy.com", |
@@ -168,18 +187,24 @@ module.exports = { | @@ -168,18 +187,24 @@ module.exports = { | ||
168 | }, function optionalCallback(error, httpResponse, body) { | 187 | }, function optionalCallback(error, httpResponse, body) { |
169 | if (!error && httpResponse.statusCode == 200) { | 188 | if (!error && httpResponse.statusCode == 200) { |
170 | var ret = JSON.parse(body); | 189 | var ret = JSON.parse(body); |
190 | + console.log("--------" + body); | ||
171 | if (ret.code === 200) { | 191 | if (ret.code === 200) { |
172 | - var imgUrl = ret.data.imagesList[0]; | ||
173 | - imgUrl = Utils.joinImg(imgUrl); | ||
174 | - result = {}; | ||
175 | - if (imgUrl) { | ||
176 | - result.originalName = Date.now(); | ||
177 | - result.name = Date.now(); | ||
178 | - result.url = imgUrl; | ||
179 | - result.type = imgUrl.substring(imgUrl.lastIndexOf('.')); | ||
180 | - result.state = "SUCCESS"; | ||
181 | - } else { | ||
182 | - result.state = "FAIL"; | 192 | + result = []; |
193 | + for (var i = 0; i < ret.data.imagesList.length; i++) { | ||
194 | + var imgUrl = ret.data.imagesList[i]; | ||
195 | + var rest = {}; | ||
196 | + imgUrl = Utils.joinImg(imgUrl); | ||
197 | + if (imgUrl) { | ||
198 | + rest.originalName = Date.now(); | ||
199 | + rest.name = Date.now(); | ||
200 | + rest.url = imgUrl; | ||
201 | + rest.type = imgUrl.substring(imgUrl.lastIndexOf('.')); | ||
202 | + rest.state = "SUCCESS"; | ||
203 | + } else { | ||
204 | + rest.state = "FAIL"; | ||
205 | + } | ||
206 | + | ||
207 | + result.push(rest); | ||
183 | } | 208 | } |
184 | } | 209 | } |
185 | } | 210 | } |
@@ -137,7 +137,7 @@ var $=require('jquery'); | @@ -137,7 +137,7 @@ var $=require('jquery'); | ||
137 | '<div class="edui-image-upload%%">' + | 137 | '<div class="edui-image-upload%%">' + |
138 | '<span class="edui-image-icon"></span>' + | 138 | '<span class="edui-image-icon"></span>' + |
139 | '<form class="edui-image-form" method="post" enctype="multipart/form-data" target="up">' + | 139 | '<form class="edui-image-form" method="post" enctype="multipart/form-data" target="up">' + |
140 | - '<input style=\"filter: alpha(opacity=0);\" class="edui-image-file" type="file" hidefocus name="upfile" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"/>' + | 140 | + '<input style=\"filter: alpha(opacity=0);\" class="edui-image-file" type="file" multiple hidefocus name="upfile" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"/>' + |
141 | '</form>' + | 141 | '</form>' + |
142 | 142 | ||
143 | '</div>', | 143 | '</div>', |
@@ -182,9 +182,13 @@ var $=require('jquery'); | @@ -182,9 +182,13 @@ var $=require('jquery'); | ||
182 | uploadComplete: function(r){ | 182 | uploadComplete: function(r){ |
183 | var me = this; | 183 | var me = this; |
184 | try{ | 184 | try{ |
185 | - r=r.match(/\{.*\}/g)[0]; | 185 | + r=r.match(/\[.*\]/g)[0]; |
186 | var json = eval('('+r+')'); | 186 | var json = eval('('+r+')'); |
187 | - Base.callback(me.editor, me.dialog, json.url, json.state); | 187 | + |
188 | + for (var i = 0; i < json.length; i++) { | ||
189 | + Base.callback(me.editor, me.dialog, json[i].url, json[i].state); | ||
190 | + } | ||
191 | + | ||
188 | }catch (e){ | 192 | }catch (e){ |
189 | var lang = me.editor.getLang('image'); | 193 | var lang = me.editor.getLang('image'); |
190 | Base.callback(me.editor, me.dialog, '', (lang && lang.uploadError) || 'Error!'); | 194 | Base.callback(me.editor, me.dialog, '', (lang && lang.uploadError) || 'Error!'); |
@@ -193,7 +197,7 @@ var $=require('jquery'); | @@ -193,7 +197,7 @@ var $=require('jquery'); | ||
193 | submit: function (callback) { | 197 | submit: function (callback) { |
194 | 198 | ||
195 | var me = this, | 199 | var me = this, |
196 | - input = $( '<input style="filter: alpha(opacity=0);" class="edui-image-file" type="file" hidefocus="" name="upfile" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp">'), | 200 | + input = $( '<input style="filter: alpha(opacity=0);" class="edui-image-file" type="file" multiple hidefocus="" name="upfile" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp">'), |
197 | input = input[0]; | 201 | input = input[0]; |
198 | 202 | ||
199 | $(me.dialog).delegate( ".edui-image-file", "change", function ( e ) { | 203 | $(me.dialog).delegate( ".edui-image-file", "change", function ( e ) { |
@@ -405,8 +409,14 @@ var $=require('jquery'); | @@ -405,8 +409,14 @@ var $=require('jquery'); | ||
405 | } | 409 | } |
406 | }); | 410 | }); |
407 | $(document).on("click",".edui-image-product .edui-product-content .edui-image-pic",function(){ | 411 | $(document).on("click",".edui-image-product .edui-product-content .edui-image-pic",function(){ |
408 | - $(".edui-image-product .edui-product-content .edui-image-pic").removeClass("active-product"); | ||
409 | - $(this).addClass("active-product"); | 412 | + //$(".edui-image-product .edui-product-content .edui-image-pic").removeClass("active-product"); |
413 | + if ($(this).hasClass("active-product")) { | ||
414 | + $(this).removeClass("active-product"); | ||
415 | + } | ||
416 | + else { | ||
417 | + $(this).addClass("active-product"); | ||
418 | + } | ||
419 | + | ||
410 | }); | 420 | }); |
411 | } | 421 | } |
412 | } | 422 | } |
-
Please register or login to post a comment