浏览代码

修改ptsbug

liujiankang 7 年之前
父节点
当前提交
6273329947

+ 3 - 2
watero-rst-web/src/main/java/com/iamberry/rst/controllers/pts/AdminMachinePartsController.java

@@ -182,7 +182,8 @@ public class AdminMachinePartsController {
     }
 
 
-    /*
+    /**
+     * 上传零件图片
      * 通过流的方式上传文件
      * @RequestParam("file") 将name=file控件得到的文件封装成CommonsMultipartFile 对象
      */
@@ -217,7 +218,7 @@ public class AdminMachinePartsController {
             e.printStackTrace();
         }
         responseJson.setReturnCode(200);
-        responseJson.addResponseKeyValue("imgUrl",imgUrl);
+        responseJson.addResponseKeyValue("imgUrl",ResultInfo.PARTS_IMAGE+imgUrl);
         return responseJson;
     }
 }

+ 16 - 9
watero-rst-web/src/main/webapp/WEB-INF/views/pts/machinePtras/ptras_add.ftl

@@ -69,11 +69,11 @@
 
         <div class="row cl">
             <label class="form-label col-xs-4 col-sm-3">零件图片:</label>
-            <div class="formControls col-xs-8 col-sm-9">
-                <input type="file" name="file" id="fileid">
+            <div class="formControls col-xs-8 col-sm-9" id="fileDiv">
+                <input type="file" name="file" id="fileid" style="opacity: 0; position: absolute; width: 90px;height: 80px;">
                 <img alt="介绍图" src="/common/images/pts/addparts.jpg" id="partsImg" width="90" height="80">
                 <input type="hidden" id="componentsImg" name="componentsImg" value=""/>
-                <button type="button" class="btn" style="background: #32a3d8;color: #fff;-webkit-transform:translateY(-5%);" id="uploadSubmit"><i class="Hui-iconfont">&#xe665;</i> 上传</button>
+                <#--<button type="button" class="btn" style="background: #32a3d8;color: #fff;-webkit-transform:translateY(-5%);" id="uploadSubmit"><i class="Hui-iconfont">&#xe665;</i> 上传</button>-->
             </div>
         </div>
         <#--<div class="row cl">
@@ -280,23 +280,30 @@
 });
 
 
-    $('#uploadSubmit').click(function() {
+   /* $('#uploadSubmit').click(function() {*/
+    $('#fileid').change(function() {
+        fileUpload();
+    });
+
+    function fileUpload() {
         $.ajaxFileUpload({
-            url:"${path}/admin/machineParts/fileUpload",//需要链接到服务器地址
+            url:"${path}/admin/machineParts/fileUpload",
             secureuri:false,
             fileElementId:"fileid",//文件选择框的id属性
             dataType: 'json',   //json
             success: function (data) {
                 if(data.returnCode == 200){
-                    alert(${path});
                     $('#componentsImg').val(data.returnMsg.imgUrl);
-                    $('#partsImg').attr("src",${path}+"/"+data.returnMsg.imgUrl);
+                    $('#partsImg').attr("src",data.returnMsg.imgUrl);
+                    $("#fileid").remove();
+                    /*<input type="file" name="file" id="fileid" style="opacity: 0; position: absolute; width: 90px;height: 80px;">*/
+                    $("#fileDiv").prepend('<input type="file" name="file" id="fileid" style="opacity: 0; position: absolute; width: 90px;height: 80px;" onchange="fileUpload()">');
                 }else{
-                    alert('上传失败!');
+                    layer.msg('上传失败,请重试!',{icon: 5,time:2000});
                 }
             }
         });
-    });
+    }
 </script> 
 <!--/请在上方写此页面业务相关的脚本-->
 </body>