傅行帆 hace 5 años
padre
commit
ad59fd79d5

+ 17
- 0
foyo-service/src/main/java/com/huiju/foyo/controller/TaServiceController.java Ver fichero

@@ -7,6 +7,8 @@ import com.huiju.foyo.common.BaseController;
7 7
 import com.huiju.foyo.common.ConstantFoyo;
8 8
 import com.huiju.foyo.common.ResponseBean;
9 9
 import com.huiju.foyo.model.TaService;
10
+import com.huiju.foyo.model.TaServiceLabel;
11
+import com.huiju.foyo.service.ITaServiceLabelService;
10 12
 import com.huiju.foyo.service.ITaServiceService;
11 13
 import org.slf4j.Logger;
12 14
 import org.slf4j.LoggerFactory;
@@ -41,6 +43,8 @@ public class TaServiceController extends BaseController {
41 43
     @Autowired
42 44
     public ITaServiceService iTaServiceService;
43 45
 
46
+    @Autowired
47
+    private ITaServiceLabelService taServiceLabelService;
44 48
 
45 49
     /**
46 50
      * 分页查询列表
@@ -83,6 +87,19 @@ public class TaServiceController extends BaseController {
83 87
             taService.setCreateTime(LocalDateTime.now());
84 88
             taService.setCreateBy(ConstantFoyo.USER_ADMIN);
85 89
             if (iTaServiceService.save(taService)){
90
+                //保存对应的标签
91
+                List<TaServiceLabel> serviceLabelList = new ArrayList<>();
92
+                List<String> labelList = taService.getLabelList();
93
+                labelList.stream().forEach(e -> {
94
+                    TaServiceLabel taServiceLabel = new TaServiceLabel();
95
+                    taServiceLabel.setLabelName(e);
96
+                    taServiceLabel.setServiceId(taService.getId());
97
+                    taServiceLabel.setCreateTime(LocalDateTime.now());
98
+                    taServiceLabel.setCreateBy(ConstantFoyo.USER_ADMIN);
99
+                    serviceLabelList.add(taServiceLabel);
100
+                });
101
+                taServiceLabelService.saveBatch(serviceLabelList);
102
+                
86 103
                 responseBean.addSuccess(taService);
87 104
             }else {
88 105
                 responseBean.addError("fail");

+ 9
- 2
foyo-service/src/main/java/com/huiju/foyo/model/TaService.java Ver fichero

@@ -1,6 +1,7 @@
1 1
 package com.huiju.foyo.model;
2 2
 
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableField;
4 5
 import com.baomidou.mybatisplus.annotation.TableId;
5 6
 import lombok.Data;
6 7
 import lombok.EqualsAndHashCode;
@@ -8,6 +9,8 @@ import lombok.experimental.Accessors;
8 9
 
9 10
 import java.io.Serializable;
10 11
 import java.time.LocalDateTime;
12
+import java.util.ArrayList;
13
+import java.util.List;
11 14
 
12 15
 /**
13 16
  * <p>
@@ -66,6 +69,10 @@ public class TaService implements Serializable {
66 69
      * 排序
67 70
      */
68 71
     private Integer sort;
69
-
70
-
72
+    
73
+    /**
74
+     * 服务标签
75
+     */
76
+    @TableField(exist = false)
77
+    private List<String> labelList = new ArrayList<>();
71 78
 }

+ 58
- 2
vue-element-admin/src/views/service/edit.vue Ver fichero

@@ -18,6 +18,25 @@
18 18
           <i v-else class="el-icon-plus avatar-uploader-icon"/>
19 19
         </el-upload>
20 20
       </el-form-item>
21
+      <el-form-item>
22
+        <el-tag
23
+          v-for="tag in dynamicTags"
24
+          :key="tag"
25
+          :disable-transitions="false"
26
+          closable
27
+          @close="handleClose(tag)">
28
+          {{ tag }}
29
+        </el-tag>
30
+        <el-input
31
+          v-if="inputVisible"
32
+          ref="saveTagInput"
33
+          v-model="inputValue"
34
+          size="small"
35
+          class="input-new-tag"
36
+          @keyup.enter.native="handleInputConfirm"
37
+          @blur="handleInputConfirm"/>
38
+        <el-button v-else class="button-new-tag" closable @click="showInput">+ 添加标签</el-button>
39
+      </el-form-item>
21 40
     </el-form>
22 41
     <div slot="footer" class="dialog-footer">
23 42
       <el-button @click="dialogForm('0')">取 消</el-button>
@@ -81,7 +100,8 @@ export default {
81 100
         id: '',
82 101
         serviceName: '',
83 102
         sort: '',
84
-        serviceImageUrl: ''
103
+        serviceImageUrl: '',
104
+        labelList: []
85 105
       },
86 106
       uploadImgUrl: process.env.BASE_API + '/uploadimage',
87 107
       dialogStatus: '',
@@ -92,7 +112,10 @@ export default {
92 112
       bannerPositionArr: [
93 113
         { id: 1, value: '首页banner' },
94 114
         { id: 2, value: '服务banner' }
95
-      ]
115
+      ],
116
+      dynamicTags: [],
117
+      inputVisible: false,
118
+      inputValue: ''
96 119
     }
97 120
   },
98 121
   computed: {
@@ -132,6 +155,7 @@ export default {
132 155
     createData() {
133 156
       this.$refs['form'].validate((valid) => {
134 157
         if (valid) {
158
+          this.form.labelList = this.dynamicTags
135 159
           this.$store.dispatch('service/createService', this.form).then((res) => {
136 160
             if (res.data.code === '0') {
137 161
               this.$message({
@@ -148,6 +172,23 @@ export default {
148 172
           })
149 173
         }
150 174
       })
175
+    },
176
+    handleClose(tag) {
177
+      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
178
+    },
179
+    showInput() {
180
+      this.inputVisible = true
181
+      this.$nextTick(_ => {
182
+        this.$refs.saveTagInput.$refs.input.focus()
183
+      })
184
+    },
185
+    handleInputConfirm() {
186
+      const inputValue = this.inputValue
187
+      if (inputValue) {
188
+        this.dynamicTags.push(inputValue)
189
+      }
190
+      this.inputVisible = false
191
+      this.inputValue = ''
151 192
     }
152 193
   }
153 194
 }
@@ -161,6 +202,21 @@ export default {
161 202
 .dialog-footer {
162 203
   text-align: center;
163 204
 }
205
+.el-tag + .el-tag {
206
+    margin-left: 10px;
207
+  }
208
+  .button-new-tag {
209
+    margin-left: 10px;
210
+    height: 32px;
211
+    line-height: 30px;
212
+    padding-top: 0;
213
+    padding-bottom: 0;
214
+  }
215
+  .input-new-tag {
216
+    width: 90px;
217
+    margin-left: 10px;
218
+    vertical-align: bottom;
219
+  }
164 220
 </style>
165 221
 <style>
166 222
 .avatar-uploader .el-upload {