From 3e9cef511a0f32402e914abb28157b516f918391 Mon Sep 17 00:00:00 2001
From: WangHao <43278047@qq.com>
Date: Sun, 10 Oct 2021 21:33:06 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../yunbookmark/SqTagController.java          |  21 ++--
 ruoyi-ui/src/api/bookmark/tag.js              |   9 ++
 ruoyi-ui/src/views/bookmark/tag/usertag.vue   | 113 ++++++++++++++++--
 .../resources/mapper/bookmark/SqTagMapper.xml |   1 +
 4 files changed, 119 insertions(+), 25 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/yunbookmark/SqTagController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/yunbookmark/SqTagController.java
index a4d389416..4f1bacd63 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/yunbookmark/SqTagController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/yunbookmark/SqTagController.java
@@ -7,14 +7,8 @@ import com.ruoyi.common.core.domain.entity.SysUser;
 import org.springframework.beans.BeanUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -55,7 +49,7 @@ public class SqTagController extends BaseController
      * 模糊查书签TAG
      */
     @GetMapping("/listByUserLike")
-    public TableDataInfo listByUserLike(SqTagReq req)
+    public TableDataInfo listByUserLike(SqTag req)
     {
         SqTag sqTag =  new SqTag();
         BeanUtils.copyProperties(req,sqTag);
@@ -70,12 +64,15 @@ public class SqTagController extends BaseController
      * 新增书签_标签
      */
     @PostMapping("/addByUser")
-    public AjaxResult addByUser(SqTagReq req)
+    public AjaxResult addByUser(@RequestBody SqTagReq req)
     {
-        SqTag sqTag =  new SqTag();
+        logger.info("[addByUser] 新增标签入参:"+ req.toString());
+        SqTag sqTag = new SqTag();
         BeanUtils.copyProperties(req,sqTag);
         sqTag.setUserId(getAuthUser().getUserId());
-        return toAjax(sqTagService.insertSqTag(sqTag));
+        logger.info("[addByUser] 新增标签:"+ sqTag.toString());
+        sqTagService.insertSqTag(sqTag);
+        return new AjaxResult(200,"操作成功");
     }
 
     /**
diff --git a/ruoyi-ui/src/api/bookmark/tag.js b/ruoyi-ui/src/api/bookmark/tag.js
index 1cb6dbb53..1abf909b7 100644
--- a/ruoyi-ui/src/api/bookmark/tag.js
+++ b/ruoyi-ui/src/api/bookmark/tag.js
@@ -18,6 +18,15 @@ export function listByUserLike(query) {
   })
 }
 
+// 新增书签管理
+export function addTagByUser(data) {
+  return request({
+    url: '/system/tag/addByUser',
+    method: 'post',
+    data: data
+  })
+}
+
 
 
 
diff --git a/ruoyi-ui/src/views/bookmark/tag/usertag.vue b/ruoyi-ui/src/views/bookmark/tag/usertag.vue
index 29d9abb10..578647b95 100644
--- a/ruoyi-ui/src/views/bookmark/tag/usertag.vue
+++ b/ruoyi-ui/src/views/bookmark/tag/usertag.vue
@@ -5,8 +5,8 @@
         <i class="el-icon-price-tag aside-titleB_childi_two"></i>
         <span >标签管理</span>
         <div style="margin-left: 40%" v-show="eidtTAGText">
-          <i class="el-icon-search" style="font-size: 19px;margin-left: 5px;margin-top: 7px" @click="searchBkTagCk"></i>
-          <i class="el-icon-folder-add" style="font-size: 19px;margin-left: 5px;margin-top: 7px" @click="addBkTagCk"></i>
+          <i class="el-icon-search title-name" @click="searchBkTagCk"></i>
+          <i class="el-icon-folder-add title-name"  @click="addBkTagCk"></i>
         </div>
       </div>
 
@@ -15,10 +15,11 @@
       <div style="display: flex;justify-items: center;align-items: center">
         <el-input
           v-if="!addBkTAG"
-          placeholder="输入书签名字"
-          v-model="input4"
+          placeholder="新增书签的名字"
+          v-model="tagName"
           size="mini"
           style="width: 80%;margin-left: 5%"
+          @keyup.enter.native ="addTag"
         >
           <i slot="prefix" class="el-input__icon el-icon-circle-plus-outline"></i>
         </el-input>
@@ -29,9 +30,10 @@
         <el-input
           v-if="!searchBkTAG"
           placeholder="搜索书签"
-          v-model="input4"
+          v-model="tagName"
           size="mini"
           style="width: 80%;margin-left: 5%"
+          @keyup.enter.native ="search"
         >
           <i slot="prefix" class="el-icon-search" style="margin-left: 5px"></i>
         </el-input>
@@ -48,10 +50,15 @@
 <!--          <el-tag type="info" size="mini">{{item.name}}</el-tag>-->
         </div>
       </div>
-      <div v-if=" !(tagList == undefined ||tagList == null || tagList.length <= 0)" class="aside-title name transition-box" >加载更多</div>
+      <div v-if=" tagList != undefined && tagList != null && total > 8 " class="aside-title name transition-box" >加载更多</div>
 
       <!-- 无标签 -->
-        <div v-if=" tagList == undefined ||tagList == null || tagList.length <= 0" class="aside-title name transition-box" >暂无标签</div>
+        <div v-if=" tagList == undefined ||tagList == null || tagList.length <= 0" class="aside-title name transition-box" >
+
+          暂无标签
+          <span v-if ="tagNameCopy != undefined && tagNameCopy != null && tagNameCopy!=''"> [{{tagNameCopy}}]</span>
+
+        </div>
         </div>
       </el-collapse-transition>
 
@@ -64,7 +71,7 @@
     </div>
 </template>
 <script>
-  import {listByUser,listByUserLike} from "@/api/bookmark/tag";
+  import {listByUser,listByUserLike,addTagByUser} from "@/api/bookmark/tag";
 
     export default {
         name: 'areaTree',
@@ -74,26 +81,97 @@
             return {
               msg:'暂无标签',
               tagList:[],
+              total:0,
               tagParams: {
                 pageNum: 1,
-                pageSize: 8
+                pageSize: 8,
+                name:undefined
               },
 
               addBkTAG:true,//添加书TAG
               searchBkTAG:true,//搜索TAG
               tagListShow:false,//TAGlist
               eidtTAGText:false,//我的TAG
+              tagName:undefined,//新增书签 - 搜索的输入框
+              tagNameCopy:''//用于提示
             }
         },
       created(){
-          this.listByUser();
+        var that = this;
+        that.listByUsers();
       },
         methods: {
+          // 统一的表单重置
+          reset() {
+            this.form = {
+              pageNum: 1,
+              pageSize: 8,
+              name: undefined,
+            };
+          },
+          /**回车搜索**/
+          search(){
+            if (this.tagName == undefined || this.tagName == null ||this.tagName.trim() == ''){
+              this.msgInfo("标签名称不能为空")
+              return;
+            }
+            if (this.tagName.trim().length > 10){
+              this.msgInfo("标签名称太长了")
+              return;
+            }
+            this.reset();
+            this.tagParams.name = this.tagName;
+            console.log("回车搜索",this.tagParams);
+            //初始化
+            this.tagList = null;
+            this.total = 0;
+            listByUserLike(this.tagParams).then(response => {
+              if (response.code === 200) {
+                this.tagList=response.rows;
+                this.total = response.total;
+                if (this.total == 0){
+                  this.tagNameCopy = this.tagName;
+                }
+              }
+            });
+
+          },
+          /**回车新增标签**/
+          addTag(){
+            if (this.tagName == undefined || this.tagName == null ||this.tagName.trim() == ''){
+              this.msgInfo("标签名称不能为空!")
+              return;
+            }
+            if (this.tagName.trim().length > 10){
+              this.msgInfo("标签名称太长了")
+              return;
+            }
+            let tagParams = {
+              name:this.tagName
+            };
+
+            addTagByUser(tagParams).then(response => {
+              if (response.code === 200) {
+                this.msgSuccess("新增标签【"+ this.tagName +"】成功");
+                //新增成功后 重新获取
+                this.reset();
+                this.tagName = undefined;
+                this.listByUsers();
+              }else {
+                this.msgError("新增标签【"+ this.tagName +"】失败,系统错误!");
+              }
+            });
+
+          },
+
           /** 查询书签 */
-          listByUser: function () {
-            listByUser(this.tagParams).then(response => {
+          listByUsers() {
+            var that = this;
+            //初始化
+            listByUser(that.tagParams).then(response => {
                   if (response.code === 200) {
-                    this.tagList=response.rows;
+                    that.tagList=response.rows;
+                    that.total = response.total;
                   }
                 });
           },
@@ -109,6 +187,12 @@
             this.searchBkTAG = this.searchBkTAG?false:true;
             this.addBkTAG = true;
             this.tagListShow = true;
+            if(this.searchBkTAG){
+              console.log("关闭搜索")
+              this.reset();
+              this.tagName = undefined;
+              this.listByUsers();
+            }
           },
           /**搜索书签目录**/
           tagListShowCk(){
@@ -122,6 +206,9 @@
     }
 </script>
 <style scoped>
+  .title-name{
+    font-size: 19px;margin-left: 5px;margin-top: 7px
+  }
   .name{
     padding-left: 50px;
   }
diff --git a/ruoyi-yunbookmark/src/main/resources/mapper/bookmark/SqTagMapper.xml b/ruoyi-yunbookmark/src/main/resources/mapper/bookmark/SqTagMapper.xml
index 8589df921..efbb0b978 100644
--- a/ruoyi-yunbookmark/src/main/resources/mapper/bookmark/SqTagMapper.xml
+++ b/ruoyi-yunbookmark/src/main/resources/mapper/bookmark/SqTagMapper.xml
@@ -33,6 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="url != null  and url != ''"> and url = #{url}</if>
             <if test="status != null "> and status = #{status}</if>
         </where>
+        order by create_time desc
     </select>
 
     <select id="selectSqTagById" parameterType="Long" resultMap="SqTagResult">