Эх сурвалжийг харах

修改富文本编辑器图片上传到服务器。

dongbw 8 жил өмнө
parent
commit
9db5da995f

+ 0 - 15
donate-console/src/main/java/com/uas/console/donate/controller/ActivityController.java

@@ -61,21 +61,6 @@ public class ActivityController {
         return activityService.show();
     }
 
-
-
-    /**
-     * 上传文件
-     */
-    @ResponseBody
-    @RequestMapping(value = "/upload",method = RequestMethod.POST)
-    public String ueditorUpload(MultipartFile file) throws IOException {
-        //上传图片
-        String path=fileClient.upload(file.getBytes(),file.getSize(),"jpg",null);
-
-        return path;
-    }
-
-
     /**
      * 保存活动
      */

+ 13 - 0
donate-console/src/main/java/com/uas/console/donate/controller/ProjectController.java

@@ -379,4 +379,17 @@ public class ProjectController {
         return projectService.getProjectsNum();
     }
 
+    /**
+     * 编辑器删除图片
+     */
+    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
+    @ResponseBody
+    public void deletePrizeImg(@RequestParam String path) {
+        try {
+            fileClient.delete(path);
+        } catch (RuntimeException e) {
+            e.printStackTrace();
+        }
+    }
+
 }

+ 1 - 0
donate-console/src/main/webapp/resources/js/common/ui-form.js

@@ -30,6 +30,7 @@ define([ 'angular', 'jquery-summernote'], function(angular) {
 	    if (angular.isDefined($attrs.onImageUpload)) {
 	      summernoteConfig.onImageUpload = function(files, editor, welEditable) {
 	        $scope.imageUpload({files:files, editor:editor, welEditable:welEditable});
+	        //TODO 修改上传方法
 	      };
 	    }
 

+ 91 - 2
donate-console/src/main/webapp/resources/js/index/app.js

@@ -1448,8 +1448,8 @@ define([ 'angularAMD', 'ui.router', 'ui-bootstrap', 'ngLocal', 'ngTable', 'file-
     /**
      * 新建项目
      */
-    app.controller('ProjectNewCtrl', ['$scope', 'BaseService', 'Project', '$http', 'toaster', '$stateParams', '$rootScope', 'AuthenticationService', 'User',
-        function($scope, BaseService, Project, $http, toaster, $stateParams, $rootScope, AuthenticationService, User) {
+    app.controller('ProjectNewCtrl', ['$scope', 'BaseService', 'Project', '$http', 'toaster', '$stateParams', '$rootScope', 'AuthenticationService', 'User', '$upload',
+        function($scope, BaseService, Project, $http, toaster, $stateParams, $rootScope, AuthenticationService, User, $upload) {
         $scope.loading = true;
         BaseService.scrollBackToTop();
         $rootScope.tree = 'project';
@@ -1688,6 +1688,48 @@ define([ 'angularAMD', 'ui.router', 'ui-bootstrap', 'ngLocal', 'ngTable', 'file-
             }
         };
 
+        /**
+         * 编辑器上传图片
+         * @param files 图片
+         */
+        $scope.uploadEditorImg = function(files) {
+            // 清空输入框内容(不清空选同样的图片不会上传) note-image-input
+            var file=$('.note-image-input').get(0);
+            //IE,Safari,chrome
+            if(file.outerHTML){
+                file.outerHTML=file.outerHTML;
+            }
+            else{      //FF
+                file.value="";
+            }
+            $scope.loading = true;
+            $upload.upload({
+                url: 'base/upload',
+                method: 'POST',
+                file: files[0]
+            }).success(function (data) {
+                console.log(data);
+                $scope.project.introduction = $scope.project.introduction + '<img src="' + data + '">';
+                $scope.loading = false;
+            }).error(function (data) {
+                $scope.loading = false;
+                console.log(data);
+                toaster.pop('error', '上传图片失败');
+            });
+        };
+
+        /**
+         * 删除编辑器图片
+         * @param path 路径
+         */
+        $scope.deleteEditorImg = function(path) {
+            if (!angular.isUndefined(path)) {
+                Project.deleteEditorImg({path: path}, {}, function(data) {
+
+                });
+            }
+        };
+
         // 设置active
         $scope.setActive = function(value) {
           $rootScope.active = value;
@@ -2742,6 +2784,11 @@ define([ 'angularAMD', 'ui.router', 'ui-bootstrap', 'ngLocal', 'ngTable', 'file-
             }
         };
 
+            /**
+             * 上传奖品图片
+             * @param award 奖品
+             * @param index 序号
+             */
         $scope.uploadPrizeImg = function(award, index) {
             $scope.loading = true;
             var files = award.prizeImgs, file = files && files.length > 0 ? files[0] : null;
@@ -2758,6 +2805,48 @@ define([ 'angularAMD', 'ui.router', 'ui-bootstrap', 'ngLocal', 'ngTable', 'file-
             });
         };
 
+            /**
+             * 编辑框上传图片
+             * @param files 图片
+             */
+        $scope.uploadEditorImg = function(files) {
+            // 清空输入框内容(不清空选同样的图片不会上传) note-image-input
+            var file=$('.note-image-input').get(0);
+            //IE,Safari,chrome
+            if(file.outerHTML){
+                file.outerHTML=file.outerHTML;
+            }
+            else{      //FF
+                file.value="";
+            }
+            $scope.loading = true;
+            $upload.upload({
+                url: 'base/upload',
+                method: 'POST',
+                file: files[0]
+            }).success(function (data) {
+                console.log(data);
+                $scope.activity.summary = $scope.activity.summary + '<img src="' + data + '">';
+                $scope.loading = false;
+            }).error(function (data) {
+                $scope.loading = false;
+                console.log(data);
+                toaster.pop('error', '上传图片失败');
+            });
+        };
+
+            /**
+             * 删除编辑器图片
+             * @param path 路径
+             */
+        $scope.deleteEditorImg = function(path) {
+            if (!angular.isUndefined(path)) {
+                Activity.deletePrizeImg({path: path}, {}, function(data) {
+
+                });
+            }
+        };
+
         // 保存 或 提交
         $scope.submit = function(type, invalid) {
             if (invalid == true) {

+ 8 - 0
donate-console/src/main/webapp/resources/js/index/services/Project.js

@@ -112,6 +112,14 @@ define ([ 'ngResource' ], function() {
             getProjectsNum: {
                 url: 'project/getProjectsNum',
                 method: 'GET'
+            },
+            // 编辑器删除图片
+            deleteEditorImg : {
+                url: 'project/delete/:path',
+                method: 'DELETE',
+                params: {
+                    path: 'path'
+                }
             }
             // // 保存财务信息
             // saveFinance: {

+ 2 - 1
donate-console/src/main/webapp/resources/view/activity/activity_launch.html

@@ -701,7 +701,8 @@
                     <div class="form-group clearfix">
                         <label class="control-label fl">活动介绍</label>
                         <div class="fl introduce">
-                            <summernote lang="zh-CN" ng-model="activity.summary" height="300px" config="editorConfig" maxlength="3500">
+                            <!-- 删除未生效。。 -->
+                            <summernote lang="zh-CN" ng-model="activity.summary" height="300px" config="editorConfig" maxlength="3500" on-image-upload="uploadEditorImg(files)" on-image-delete="deleteEditorImg(target)">
                             </summernote>
                         </div>
                         <span class="error" ng-show="submited && !activity.summary">*请填写活动介绍</span>

+ 3 - 1
donate-console/src/main/webapp/resources/view/project/project_launch_2.html

@@ -727,8 +727,10 @@
                             <div class="list-item clearfix">
                                 <span class="fl">项目介绍</span>
                                 <div class="fl simple">
+                                    <!-- 删除未生效 -->
                                     <summernote lang="zh-CN" ng-model="project.introduction" height="300px" config="editorConfig" maxlength="3500"
-                                                ng-class="{'showEmpty': submited && project.introduction == null}">
+                                                ng-class="{'showEmpty': submited && project.introduction == null}"
+                                                on-image-upload="uploadEditorImg(files)" on-image-delete="deleteEditorImg(target)">
                                         请填写介绍
                                     </summernote>