Browse Source

nsy 上传视频与pdf文件

ningsy 3 years ago
parent
commit
8290f594eb

+ 22 - 0
suishenbang-admin/src/main/java/com/dgtly/web/controller/common/CommonController.java

@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.multipart.MultipartFile;
 import com.dgtly.common.config.Global;
@@ -93,6 +94,27 @@ public class CommonController
         }
     }
 
+    @PostMapping("/common/uploadCasePicture")
+    @ResponseBody
+    public AjaxResult uploadFile1(@RequestParam("file_data") MultipartFile file) throws Exception
+    {
+        try
+        {
+            // 上传文件路径
+            String filePath = Global.getUploadPath();
+            // 上传并返回新文件名称
+            String fileName = FileUploadUtils.upload(filePath, file);
+            String url = serverConfig.getUrl() + fileName;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.putKV("fileName", fileName);
+            ajax.putKV("url", url);
+            return ajax;
+        }
+        catch (Exception e)
+        {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
 
 
     /**

+ 0 - 1
suishenbang-admin/src/main/resources/static/css/style.css

@@ -3085,7 +3085,6 @@ a:hover, a:focus {
 
 video {
     width: 100% !important;
-    height: auto !important;
 }
 /* GALLERY */
 .gallery>.row>div {

+ 3 - 1
suishenbang-common/src/main/java/com/dgtly/common/utils/file/MimeTypeUtils.java

@@ -32,7 +32,9 @@ public class MimeTypeUtils
             // 压缩文件
             "rar", "zip", "gz", "bz2",
             // pdf
-            "pdf" };
+            "pdf",
+            //video
+            "mp4","m4v","mov","avi","flv","vob"};
 
     public static String getExtension(String prefix)
     {

+ 78 - 18
suishenbang-wxportal/suishenbang-wxportal-manager/src/main/resources/templates/wxportal/helpCenter/add.html

@@ -2,57 +2,117 @@
 <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
 <head>
     <th:block th:include="include :: header('新增帮助中心')" />
+    <th:block th:include="include :: cropbox-css"/>
     <th:block th:include="include :: bootstrap-fileinput-css" />
 </head>
 <body class="white-bg">
     <div class="wrapper wrapper-content animated fadeInRight ibox-content">
         <form class="form-horizontal m" id="form-center-add">
+            <input id="input_fileUrl" name="fileUrl" type="hidden" value="" class="form-control">
+            <div class="form-group">
+                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>文档类别:</label>
+                <div class="col-sm-8">
+                    <select name="classifyTitle" id="sel_classifyTitle" class="form-control m-b"
+                            th:with="type=${@dict.getType('help_center_classify_title')}" onchange="javascript:typeChange()">
+                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
+                    </select>
+                </div>
+            </div>
             <div class="form-group">    
-                <label class="col-sm-3 control-label">标题:</label>
+                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>文件标题:</label>
                 <div class="col-sm-8">
                     <input name="title" class="form-control" type="text">
                 </div>
             </div>
             <div class="form-group">    
-                <label class="col-sm-3 control-label">描述:</label>
+                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>文件描述:</label>
                 <div class="col-sm-8">
                     <input name="describe" class="form-control" type="text">
                 </div>
             </div>
             <div class="form-group">
-                <label class="col-sm-3 control-label">文件地址:</label>
-                <div class="col-sm-8">
-                    <div class="file-loading">
-                        <input class="file" type="file" multiple data-min-file-count="1" data-theme="fas">
-                    </div>
-                </div>
-            </div>
-            <div class="form-group">    
-                <label class="col-sm-3 control-label">文件类型:</label>
+                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>文件类型:</label>
                 <div class="col-sm-8">
                     <select name="fileType" id="sel_fileType" class="form-control m-b"
                             th:with="type=${@dict.getType('help_center_file_type')}" onchange="javascript:typeChange()">
                         <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                     </select>
-                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                 </div>
             </div>
-            <div class="form-group">    
-                <label class="col-sm-3 control-label">分类标题:</label>
+            <div class="form-group">
+                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>文件地址:</label>
                 <div class="col-sm-8">
-                    <input name="classifyTitle" class="form-control" type="text">
+                    <div class="file-loading">
+                        <input id="fileinput-upload-1" type="file">
+                    </div>
                 </div>
             </div>
         </form>
+
+        <div class="row">
+            <div class="col-sm-offset-5 col-sm-10">
+                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
+                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
+            </div>
+        </div>
+
     </div>
     <th:block th:include="include :: footer" />
+    <th:block th:include="include :: cropbox-js"/>
     <th:block th:include="include :: bootstrap-fileinput-js" />
     <script type="text/javascript">
         var prefix = ctx + "helpCenter/center"
-        $("#form-center-add").validate({
-            focusCleanup: true
-        });
+        $(function () {
+            //初始化
+            initFileInput("fileinput-upload-1");
+            //异步上传成功结果处理
+            $("#fileinput-upload-1").on("fileuploaded", function (event, data, previewId, index) {
+                console.log("fileName = "+ data.response.data.fileName);
+                $("#input_fileUrl").val(data.response.data.fileName);
+            });
+
+            //异步上传错误结果处理
+            $("#fileinput-upload-1").on('fileerror', function(event, data, msg) {
+                console.log(msg)
+            });
+
 
+            $("#form-center-add").validate({
+                ignore:"",
+                onkeyup: false,
+                rules: {
+                    title: {
+                        required: true
+                    },
+                    describe: {
+                        required: true
+                    },
+                    fileUrl: {
+                        required: true
+                    },
+                    classifyTitle: {
+                        required: true
+                    }
+                },
+                focusCleanup: true
+            });
+
+        })
+        function initFileInput(ctrlName) {
+            var control = $('#' + ctrlName);
+
+            control.fileinput({
+                language: 'zh', //设置语言
+                theme: 'explorer-fas',
+                uploadUrl: ctx + "common/uploadCasePicture",
+                allowedFileExtensions : ['pdf', 'mp4'],//接收的文件后缀,
+                allowedPreviewTypes: ['pdf','video'],
+                allowedFileTypes:['pdf','video'],
+                overwriteInitial: false,
+                initialPreviewAsData: true,
+                maxFileCount : 1
+            })
+        }
         function submitHandler() {
             if ($.validate.form()) {
                 $.operate.save(prefix + "/add", $('#form-center-add').serialize());

+ 7 - 12
suishenbang-wxportal/suishenbang-wxportal-manager/src/main/resources/templates/wxportal/helpCenter/center.html

@@ -10,6 +10,10 @@
                 <form id="formId">
                     <div class="select-list">
                         <ul>
+                            <li>
+                                <p>分类标题:</p>
+                                <input type="text" name="classifyTitle"/>
+                            </li>
                             <li>
                                 <p>标题:</p>
                                 <input type="text" name="title"/>
@@ -21,18 +25,9 @@
                             <li>
                                 <p>文件类型:</p>
                                 <select name="fileType" th:with="type=${@dict.getType('')}">
-                                    <option value="">所有</option>
                                     <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                 </select>
                             </li>
-                            <li>
-                                <p>分类标题:</p>
-                                <input type="text" name="classifyTitle"/>
-                            </li>
-                            <li>
-                                <p>是否删除:</p>
-                                <input type="text" name="delFlag"/>
-                            </li>
                             <li>
                                 <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                 <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
@@ -43,10 +38,10 @@
             </div>
 
             <div class="btn-group-sm" id="toolbar" role="group">
-                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="helpCenter:center:add">
+                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="helpCenter:center:add">
                     <i class="fa fa-plus"></i> 添加
                 </a>
-                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="helpCenter:center:edit">
+                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="helpCenter:center:edit">
                     <i class="fa fa-edit"></i> 修改
                 </a>
                 <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="helpCenter:center:remove">
@@ -112,7 +107,7 @@
                     align: 'center',
                     formatter: function(value, row, index) {
                         var actions = [];
-                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
+                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                         return actions.join('');
                     }

+ 79 - 23
suishenbang-wxportal/suishenbang-wxportal-manager/src/main/resources/templates/wxportal/helpCenter/edit.html

@@ -2,32 +2,36 @@
 <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
 <head>
     <th:block th:include="include :: header('修改帮助中心')" />
+    <th:block th:include="include :: cropbox-css"/>
     <th:block th:include="include :: bootstrap-fileinput-css" />
 </head>
 <body class="white-bg">
     <div class="wrapper wrapper-content animated fadeInRight ibox-content">
         <form class="form-horizontal m" id="form-center-edit" th:object="${helpCenter}">
             <input name="id" th:field="*{id}" type="hidden">
-            <div class="form-group">    
-                <label class="col-sm-3 control-label">标题:</label>
+            <input id="input_fileUrl" name="fileUrl" type="hidden" value="" class="form-control">
+            <div class="form-group">
+                <label class="col-sm-3 control-label">文档类别:</label>
                 <div class="col-sm-8">
-                    <input name="title" th:field="*{title}" class="form-control" type="text">
+                    <select name="classifyTitle" id="sel_classifyTitle" class="form-control m-b"
+                            th:with="type=${@dict.getType('help_center_classify_title')}" onchange="javascript:typeChange()">
+                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{classifyTitle}" ></option>
+                    </select>
                 </div>
             </div>
             <div class="form-group">    
-                <label class="col-sm-3 control-label">描述:</label>
+                <label class="col-sm-3 control-label">文件标题:</label>
                 <div class="col-sm-8">
-                    <input name="describe" th:field="*{describe}" class="form-control" type="text">
+                    <input name="title" th:field="*{title}" class="form-control" type="text">
                 </div>
             </div>
-            <div class="form-group">
-                <label class="col-sm-3 control-label">文件地址:</label>
+            <div class="form-group">    
+                <label class="col-sm-3 control-label">文件描述:</label>
                 <div class="col-sm-8">
-                    <div class="file-loading">
-                        <input class="file" type="file" multiple data-min-file-count="1" data-theme="fas">
-                    </div>
+                    <input name="describe" th:field="*{describe}" class="form-control" type="text">
                 </div>
             </div>
+
             <div class="form-group">    
                 <label class="col-sm-3 control-label">文件类型:</label>
                 <div class="col-sm-8">
@@ -35,30 +39,82 @@
                             th:with="type=${@dict.getType('help_center_file_type')}" onchange="javascript:typeChange()">
                         <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{fileType}"></option>
                     </select>
-                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                 </div>
             </div>
-            <div class="form-group">    
-                <label class="col-sm-3 control-label">分类标题:</label>
-                <div class="col-sm-8">
-                    <input name="classifyTitle" th:field="*{classifyTitle}" class="form-control" type="text">
-                </div>
-            </div>
-            <div class="form-group">    
-                <label class="col-sm-3 control-label">是否删除:</label>
+
+            <div class="form-group">
+                <label class="col-sm-3 control-label">文件地址:</label>
                 <div class="col-sm-8">
-                    <input name="delFlag" th:field="*{delFlag}" class="form-control" type="text">
+                    <div class="file-loading">
+                        <input id="fileinput-upload-1" type="file">
+                    </div>
                 </div>
             </div>
         </form>
+
+        <div class="row">
+            <div class="col-sm-offset-5 col-sm-10">
+                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
+                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
+            </div>
+        </div>
     </div>
     <th:block th:include="include :: footer" />
+    <th:block th:include="include :: cropbox-js"/>
     <th:block th:include="include :: bootstrap-fileinput-js" />
     <script type="text/javascript">
         var prefix = ctx + "helpCenter/center";
-        $("#form-center-edit").validate({
-            focusCleanup: true
-        });
+        $(function () {
+            //初始化
+            initFileInput("fileinput-upload-1");
+            //异步上传成功结果处理
+            $("#fileinput-upload-1").on("fileuploaded", function (event, data, previewId, index) {
+                console.log("fileName = "+ data.response.data.fileName);
+                $("#input_fileUrl").val(data.response.data.fileName);
+            });
+
+            //异步上传错误结果处理
+            $("#fileinput-upload-1").on('fileerror', function(event, data, msg) {
+                console.log(msg)
+            });
+
+
+            $("#form-center-add").validate({
+                ignore:"",
+                onkeyup: false,
+                rules: {
+                    title: {
+                        required: true
+                    },
+                    describe: {
+                        required: true
+                    },
+                    fileUrl: {
+                        required: true
+                    },
+                    classifyTitle: {
+                        required: true
+                    }
+                },
+                focusCleanup: true
+            });
+
+        })
+        function initFileInput(ctrlName) {
+            var control = $('#' + ctrlName);
+
+            control.fileinput({
+                language: 'zh', //设置语言
+                theme: 'explorer-fas',
+                uploadUrl: ctx + "common/uploadCasePicture",
+                allowedFileExtensions : ['pdf', 'mp4'],//接收的文件后缀,
+                allowedPreviewTypes: ['pdf','video'],
+                allowedFileTypes:['pdf','video'],
+                overwriteInitial: false,
+                initialPreviewAsData: true,
+                maxFileCount : 1
+            })
+        }
 
         function submitHandler() {
             if ($.validate.form()) {