wangxiaoming 6 лет назад
Родитель
Сommit
accd9d953e

+ 1 - 1
watero-common-tool/src/main/java/com/iamberry/wechat/tools/ResultInfo.java

@@ -91,7 +91,7 @@ public class ResultInfo {
 	/**
 	 * 颜色图片保存路径
 	 */
-	public static String COLOR_IMAGE = "/common/images/productUpload/";
+	public static String COLOR_IMAGE = "/common/images/productUpload";
 
 	/**
 	 * 上传审批合同图片保存路径

+ 10 - 3
watero-rst-web/src/main/java/com/iamberry/rst/controllers/product/AdminProductController.java

@@ -191,9 +191,16 @@ public class AdminProductController {
         //获取项目根目录
         WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
         ServletContext servletContext = webApplicationContext.getServletContext();
-        String realPath = servletContext.getRealPath(ResultInfo.COLOR_IMAGE);
-        String imgUrl = System.currentTimeMillis() + file.getOriginalFilename();
+        String realPath = servletContext.getRealPath(ResultInfo.COLOR_IMAGE)+"/";
+        String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().toString().lastIndexOf("."));
+        String imgUrl = System.currentTimeMillis()+suffix;
         try {
+
+            File targetFile = new File(realPath);
+            if (!targetFile.exists()) {
+                targetFile.mkdirs();
+            }
+
             //获取输出流
             OutputStream os=new FileOutputStream(realPath+imgUrl);
 
@@ -214,7 +221,7 @@ public class AdminProductController {
             e.printStackTrace();
         }
         responseJson.setReturnCode(200);
-        responseJson.addResponseKeyValue("imgUrl",ResultInfo.COLOR_IMAGE+imgUrl);
+        responseJson.addResponseKeyValue("imgUrl",ResultInfo.COLOR_IMAGE+"/"+imgUrl);
         return responseJson;
     }
 

+ 0 - 8
watero-rst-web/src/main/webapp/WEB-INF/views/product/add_product.ftl

@@ -111,14 +111,6 @@
                 </div>
             </div>
 
-
-           <#-- <div class="row cl" id="" style="">
-                <label class="form-label col-1 col-sm-1">备注:</label>
-                <div class="formControls col-6 col-sm-6" style="">
-                    <input type="text" class="input-text" value="" placeholder="产品备注" id="productRemark" name="productRemark">
-                </div>
-            </div>-->
-
             <div class="row cl">
                 <label class="form-label col-3">
                     <div class="tit-2">产品颜色信息</div>

+ 15 - 11
watero-rst-web/src/main/webapp/common/js/product/product.js

@@ -11,9 +11,9 @@ color.html = '<tr class="color_list">'
             + '<td style="text-align: center;" width="10"><input type="text" class="input-text input-number item-num" value="" name="colorBar" id="" placeholder="69码"  datatype="*1-20" errormsg="69码格式不正确!"></td>'
             + '<td style="text-align: center;" width="10"><input type="text" class="input-text input-number item-num" value="0" name="colorIsWeight" id=""  style="width: 100%;text-align: center;"  placeholder="重量" onkeyup="keyFun($(this),9999,1)" onpaste="keyFun($(this),9999,1)"></td>'
             + '<td style="text-align: center;" width="10"><select class="select" id="" name="colorIsMachine" ><option value="2" >否</option><option value="1" >是</option></select></td>'
-            + '<td style="text-align: center;" width="10"><input type="file" class="color_file" name="file" id="fileId_'+ colorNum +'" style="display: none">'
-            + '<a href="javascript:void(0)" class="del_product all_down" onclick="fileOnclick(this)">上传图片</a>'
-            + '<input name="colorPicture" style="display: none;"></td>'
+            + '<td style="text-align: center;" width=""><input type="file" class="color_file" name="file" id="fileId_'+ colorNum +'" style="display: none">'
+            + '<div class="download_file"><a href="javascript:void(0)" class="del_product all_down" num="'+ num +'" onclick="fileOnclick(this)">上传图片</a></div>'
+            + '<input class="colorPicture" name="colorPicture" id="xxx" value="" style="display: none;"></td>'
             + '<td style="text-align: center;" width="10">&nbsp;&nbsp;<a href="javascript:void(0)" class="del_product all_down" onclick="delTr($(this))" >删除</a></td>'
             + '</tr>';
 
@@ -32,19 +32,20 @@ function add_color(){
     $("#add_color").append(getColorHtml());
 
     $("#fileId_"+color.num).change(function() {
-        fileUpload();
+        fileUpload("fileId_"+color.num);
     });
 }
 
 function fileOnclick(node){
-    $(node).siblings('.color_file').click();
-    $("#fileId_"+color.num).change(function() {
-        fileUpload("fileId_" + color.num);
-    });
+    $(node).parent().siblings('.color_file').click();
 }
 
 $(function(){
     $("#add_color").append(getColorHtml());
+
+    $("#fileId_0").change(function() {
+        fileUpload("fileId_0");
+    });
 })
 
 $(function(){
@@ -115,15 +116,18 @@ function delTr($this){
     $this.parents("tr").remove();
 }
 
-function fileUpload(nodo) {
+function fileUpload(idValue) {
     $.ajaxFileUpload({
         url:"/admin/product/fileUpload",
         secureuri:false,
-        fileElementId : nodo,//文件选择框的id属性
+        fileElementId : idValue,//文件选择框的id属性/名称
         dataType: 'json',   //json
         success: function (data) {
             if(data.returnCode == 200){
-
+                var html = '<img style="width: 75px;" src="'+ url_path + data.returnMsg.imgUrl +'"  class="del_product all_down" onclick="fileOnclick(this)">';
+                $("#"+idValue).parent().find(".download_file").html(html);
+                // $("#"+idValue).parent().find(".colorPicture").val(data.returnMsg.imgUrl);
+                $("#xxx").val(data.returnMsg.imgUrl);
             }else{
                 layer.msg('上传失败,请重试!',{icon: 5,time:2000});
             }