diff --git a/src/main/java/com/quinn/common/EditText.java b/src/main/java/com/quinn/common/EditText.java index f2e95b8..99e1bde 100644 --- a/src/main/java/com/quinn/common/EditText.java +++ b/src/main/java/com/quinn/common/EditText.java @@ -2,7 +2,14 @@ package com.quinn.common; import lombok.Data; +import java.util.List; + @Data public class EditText { + + List children; + String text; + + String type; } diff --git a/src/main/java/com/quinn/common/RoleType.java b/src/main/java/com/quinn/common/RoleType.java index 8d7165e..bd949d6 100644 --- a/src/main/java/com/quinn/common/RoleType.java +++ b/src/main/java/com/quinn/common/RoleType.java @@ -35,7 +35,7 @@ public enum RoleType { * @return */ public static RoleType parse(String name){ - if (StringUtils.isEmpty(name)){ + if (!StringUtils.isEmpty(name)){ if (ADMIN.getName().equals(name)){ return RoleType.ADMIN; } diff --git a/src/main/java/com/quinn/controller/SearchController.java b/src/main/java/com/quinn/controller/SearchController.java index 5306e5f..8b3bad8 100644 --- a/src/main/java/com/quinn/controller/SearchController.java +++ b/src/main/java/com/quinn/controller/SearchController.java @@ -3,8 +3,10 @@ package com.quinn.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.quinn.common.QuinnConstant; +import com.quinn.common.RoleType; import com.quinn.pojo.*; import com.quinn.service.*; +import com.quinn.vo.FindNavReq; import com.quinn.vo.MyPageParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -14,6 +16,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.util.List; /** @@ -25,7 +28,7 @@ import java.util.List; * @since 2022-05-01 */ @Controller -public class SearchController { +public class SearchController extends BaseModelController{ @Resource SourceService sourceService; @@ -39,15 +42,53 @@ public class SearchController { SourceCategoryService sourceCategoryService; @Resource FindService findService; + @Resource + UserService userService; @GetMapping("/search") - public String searchAll(String findWhat,Model model){ + public String searchAll(HttpServletRequest request, String findWhat, Model model){ /** * 为空返回主页 */ if (StringUtils.isEmpty(findWhat)){ return "index"; } + String loginUserId = getLoginUserId(request); + User uid = userService.getOne(new QueryWrapper().eq("uid", loginUserId)); + if (RoleType.ADMIN.getName().equals(uid.getRole())){ + String result = doAdmin(findWhat, model); + if (!QuinnConstant.GUN.equals(result)){ + return result; + } + } + /** + * 正式开始,全局搜索 + */ + MyPageParam myPageParam = new MyPageParam(1, 20); + List findList = findService.listFinds(findWhat, myPageParam); + model.addAttribute("findWhat",findWhat); + // 结果 + model.addAttribute("findList",findList); + model.addAttribute("pageParam",myPageParam); + return "page/allsearch"; + } + + @PostMapping("/search") + public String search(FindNavReq findNavReq, Model model){ + String findWhat = findNavReq.getFindWhat(); + if (findNavReq.getPageNum() < 1){ + findNavReq.setPageNum(1); + } + MyPageParam myPageParam = new MyPageParam(findNavReq.getPageNum(),findNavReq.getLimit()); + List findList = findService.listFinds(findWhat, myPageParam); + model.addAttribute("findWhat",findWhat); + // 结果 + model.addAttribute("findList",findList); + model.addAttribute("pageParam",myPageParam); + return "page/allsearch::user_table_refresh"; + } + + private String doAdmin(String findWhat,Model model){ /** * 新增资源 */ @@ -81,20 +122,9 @@ public class SearchController { } } } - - /** - * 正式开始,全局搜索 - */ - MyPageParam myPageParam = new MyPageParam(1, 10); - List findList = findService.listFinds(findWhat, myPageParam); - model.addAttribute("findWhat",findWhat); - // 结果 - model.addAttribute("findList",findList); - model.addAttribute("pageParam",myPageParam); - return "page/allsearch"; + return QuinnConstant.GUN; } - } diff --git a/src/main/java/com/quinn/service/impl/UserServiceImpl.java b/src/main/java/com/quinn/service/impl/UserServiceImpl.java index 799c2a1..b0f63af 100644 --- a/src/main/java/com/quinn/service/impl/UserServiceImpl.java +++ b/src/main/java/com/quinn/service/impl/UserServiceImpl.java @@ -59,7 +59,7 @@ public class UserServiceImpl extends ServiceImpl implements Us if (roleType == null){ roleType = RoleType.NORMAL; } - SimpleGrantedAuthority authority = new SimpleGrantedAuthority(roleType.getName()); + SimpleGrantedAuthority authority = new SimpleGrantedAuthority(roleType.name()); authList.add(authority); //实例化UserDetails对象 userDetails=new org.springframework.security.core.userdetails.User(s,password, diff --git a/src/main/java/com/quinn/utils/ContentUtil.java b/src/main/java/com/quinn/utils/ContentUtil.java index 9761485..51bfd9a 100644 --- a/src/main/java/com/quinn/utils/ContentUtil.java +++ b/src/main/java/com/quinn/utils/ContentUtil.java @@ -7,20 +7,31 @@ import org.springframework.util.CollectionUtils; import java.util.List; -public interface ContentUtil { +public class ContentUtil { - static String toTextContentFromWangEdit(String wangEdit){ + public static String toTextContentFromWangEdit(String wangEdit){ List decode = JsonUtils.decode(wangEdit, new TypeReference>(){}); StringBuffer sb = new StringBuffer(); decode.forEach(x->{ List children = x.getChildren(); if (!CollectionUtils.isEmpty(children)){ children.forEach(y ->{ - sb.append(y.getText()); + getChildText(sb,y); }); } }); return sb.toString(); } + private static void getChildText(StringBuffer sb, EditText editText){ + List children = editText.getChildren(); + if (!CollectionUtils.isEmpty(children)){ + children.forEach(y ->{ + getChildText(sb,y); + }); + }else { + sb.append(editText.getText()); + } + } + } diff --git a/src/main/java/com/quinn/vo/FindNavReq.java b/src/main/java/com/quinn/vo/FindNavReq.java new file mode 100644 index 0000000..961815d --- /dev/null +++ b/src/main/java/com/quinn/vo/FindNavReq.java @@ -0,0 +1,22 @@ +package com.quinn.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +public class FindNavReq { + + @ApiModelProperty(value = "页码") + private int pageNum; + + @ApiModelProperty(value = "个数") + private int limit; + + @ApiModelProperty(value = "用户编号") + private String findWhat; + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4848f88..3357e56 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,8 @@ spring.profiles.active=dev spring.servlet.multipart.max-file-size= 20MB #设置单次请求文件的总大小 spring.servlet.multipart.max-request-size= 20MB +#设置HTTP POST 请求不限制 +server.tomcat.max-http-form-post-size=-1 oss.accessKeyId=LTAIlbtS4W2Xe4OV oss.accessKeySecret=qWMYkSfmXFtRoIv9q9OCbszcF9U7dX diff --git a/src/main/resources/static/bootstrap/css/bootstrapValidator.css b/src/main/resources/static/bootstrap/css/bootstrapValidator.css new file mode 100755 index 0000000..4347416 --- /dev/null +++ b/src/main/resources/static/bootstrap/css/bootstrapValidator.css @@ -0,0 +1,31 @@ +/** + * BootstrapValidator (http://bootstrapvalidator.com) + * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3 + * + * @author http://twitter.com/nghuuphuoc + * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc + * @license Commercial: http://bootstrapvalidator.com/license/ + * Non-commercial: http://creativecommons.org/licenses/by-nc-nd/3.0/ + */ + +.bv-form .help-block { + margin-bottom: 0; +} +.bv-form .tooltip-inner { + text-align: left; +} +.nav-tabs li.bv-tab-success > a { + color: #3c763d; +} +.nav-tabs li.bv-tab-error > a { + color: #a94442; +} + +.bv-form .bv-icon-no-label { + top: 0; +} + +.bv-form .bv-icon-input-group { + top: 0; + z-index: 100; +} \ No newline at end of file diff --git a/src/main/resources/static/bootstrap/js/bootstrapValidator.js b/src/main/resources/static/bootstrap/js/bootstrapValidator.js new file mode 100755 index 0000000..4760b16 --- /dev/null +++ b/src/main/resources/static/bootstrap/js/bootstrapValidator.js @@ -0,0 +1,2003 @@ +/** + * BootstrapValidator (http://bootstrapvalidator.com) + * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3 + * + * @author https://twitter.com/nghuuphuoc + * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc + * @license Commercial: http://bootstrapvalidator.com/license/ + * Non-commercial: http://creativecommons.org/licenses/by-nc-nd/3.0/ + */ + +if (typeof jQuery === 'undefined') { + throw new Error('BootstrapValidator requires jQuery'); +} + +(function($) { + var version = $.fn.jquery.split(' ')[0].split('.'); + if ((+version[0] < 2 && +version[1] < 9) || (+version[0] === 1 && +version[1] === 9 && +version[2] < 1)) { + throw new Error('BootstrapValidator requires jQuery version 1.9.1 or higher'); + } +}(window.jQuery)); + +(function($) { + var BootstrapValidator = function(form, options) { + this.$form = $(form); + this.options = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, options); + + this.$invalidFields = $([]); // Array of invalid fields + this.$submitButton = null; // The submit button which is clicked to submit form + this.$hiddenButton = null; + + // Validating status + this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED'; + this.STATUS_VALIDATING = 'VALIDATING'; + this.STATUS_INVALID = 'INVALID'; + this.STATUS_VALID = 'VALID'; + + // Determine the event that is fired when user change the field value + // Most modern browsers supports input event except IE 7, 8. + // IE 9 supports input event but the event is still not fired if I press the backspace key. + // Get IE version + // https://gist.github.com/padolsey/527683/#comment-7595 + var ieVersion = (function() { + var v = 3, div = document.createElement('div'), a = div.all || []; + while (div.innerHTML = '', a[0]) {} + return v > 4 ? v : !v; + }()); + + var el = document.createElement('div'); + this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input'; + + // The flag to indicate that the form is ready to submit when a remote/callback validator returns + this._submitIfValid = null; + + // Field elements + this._cacheFields = {}; + + this._init(); + }; + + BootstrapValidator.prototype = { + constructor: BootstrapValidator, + + /** + * Init form + */ + _init: function() { + var that = this, + options = { + autoFocus: this.$form.attr('data-bv-autofocus'), + container: this.$form.attr('data-bv-container'), + events: { + formInit: this.$form.attr('data-bv-events-form-init'), + formError: this.$form.attr('data-bv-events-form-error'), + formSuccess: this.$form.attr('data-bv-events-form-success'), + fieldAdded: this.$form.attr('data-bv-events-field-added'), + fieldRemoved: this.$form.attr('data-bv-events-field-removed'), + fieldInit: this.$form.attr('data-bv-events-field-init'), + fieldError: this.$form.attr('data-bv-events-field-error'), + fieldSuccess: this.$form.attr('data-bv-events-field-success'), + fieldStatus: this.$form.attr('data-bv-events-field-status'), + validatorError: this.$form.attr('data-bv-events-validator-error'), + validatorSuccess: this.$form.attr('data-bv-events-validator-success') + }, + excluded: this.$form.attr('data-bv-excluded'), + feedbackIcons: { + valid: this.$form.attr('data-bv-feedbackicons-valid'), + invalid: this.$form.attr('data-bv-feedbackicons-invalid'), + validating: this.$form.attr('data-bv-feedbackicons-validating') + }, + group: this.$form.attr('data-bv-group'), + live: this.$form.attr('data-bv-live'), + message: this.$form.attr('data-bv-message'), + onError: this.$form.attr('data-bv-onerror'), + onSuccess: this.$form.attr('data-bv-onsuccess'), + submitButtons: this.$form.attr('data-bv-submitbuttons'), + threshold: this.$form.attr('data-bv-threshold'), + trigger: this.$form.attr('data-bv-trigger'), + verbose: this.$form.attr('data-bv-verbose'), + fields: {} + }; + + this.$form + // Disable client side validation in HTML 5 + .attr('novalidate', 'novalidate') + .addClass(this.options.elementClass) + // Disable the default submission first + .on('submit.bv', function(e) { + e.preventDefault(); + that.validate(); + }) + .on('click.bv', this.options.submitButtons, function() { + that.$submitButton = $(this); + // The user just click the submit button + that._submitIfValid = true; + }) + // Find all fields which have either "name" or "data-bv-field" attribute + .find('[name], [data-bv-field]') + .each(function() { + var $field = $(this), + field = $field.attr('name') || $field.attr('data-bv-field'), + opts = that._parseOptions($field); + if (opts) { + $field.attr('data-bv-field', field); + options.fields[field] = $.extend({}, opts, options.fields[field]); + } + }); + + this.options = $.extend(true, this.options, options); + + // When pressing Enter on any field in the form, the first submit button will do its job. + // The form then will be submitted. + // I create a first hidden submit button + this.$hiddenButton = $(' @@ -125,7 +125,7 @@
-返回顶部 +返回顶部 diff --git a/src/main/resources/templates/blog/write.html b/src/main/resources/templates/blog/write.html index 4ffdac1..7ba8986 100644 --- a/src/main/resources/templates/blog/write.html +++ b/src/main/resources/templates/blog/write.html @@ -68,7 +68,7 @@
-返回顶部 +返回顶部 diff --git a/src/main/resources/templates/common/footer.html b/src/main/resources/templates/common/footer.html index 49a3c4c..99a0115 100644 --- a/src/main/resources/templates/common/footer.html +++ b/src/main/resources/templates/common/footer.html @@ -3,7 +3,7 @@ diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index c56cefa..d0465f4 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -97,7 +97,7 @@
-返回顶部 +返回顶部 diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 87625ca..b945b0d 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -8,16 +8,14 @@ - -