傅行帆 5 vuotta sitten
vanhempi
commit
ad59fd79d5

+ 17
- 0
foyo-service/src/main/java/com/huiju/foyo/controller/TaServiceController.java Näytä tiedosto

7
 import com.huiju.foyo.common.ConstantFoyo;
7
 import com.huiju.foyo.common.ConstantFoyo;
8
 import com.huiju.foyo.common.ResponseBean;
8
 import com.huiju.foyo.common.ResponseBean;
9
 import com.huiju.foyo.model.TaService;
9
 import com.huiju.foyo.model.TaService;
10
+import com.huiju.foyo.model.TaServiceLabel;
11
+import com.huiju.foyo.service.ITaServiceLabelService;
10
 import com.huiju.foyo.service.ITaServiceService;
12
 import com.huiju.foyo.service.ITaServiceService;
11
 import org.slf4j.Logger;
13
 import org.slf4j.Logger;
12
 import org.slf4j.LoggerFactory;
14
 import org.slf4j.LoggerFactory;
41
     @Autowired
43
     @Autowired
42
     public ITaServiceService iTaServiceService;
44
     public ITaServiceService iTaServiceService;
43
 
45
 
46
+    @Autowired
47
+    private ITaServiceLabelService taServiceLabelService;
44
 
48
 
45
     /**
49
     /**
46
      * 分页查询列表
50
      * 分页查询列表
83
             taService.setCreateTime(LocalDateTime.now());
87
             taService.setCreateTime(LocalDateTime.now());
84
             taService.setCreateBy(ConstantFoyo.USER_ADMIN);
88
             taService.setCreateBy(ConstantFoyo.USER_ADMIN);
85
             if (iTaServiceService.save(taService)){
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
                 responseBean.addSuccess(taService);
103
                 responseBean.addSuccess(taService);
87
             }else {
104
             }else {
88
                 responseBean.addError("fail");
105
                 responseBean.addError("fail");

+ 9
- 2
foyo-service/src/main/java/com/huiju/foyo/model/TaService.java Näytä tiedosto

1
 package com.huiju.foyo.model;
1
 package com.huiju.foyo.model;
2
 
2
 
3
 import com.baomidou.mybatisplus.annotation.IdType;
3
 import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableField;
4
 import com.baomidou.mybatisplus.annotation.TableId;
5
 import com.baomidou.mybatisplus.annotation.TableId;
5
 import lombok.Data;
6
 import lombok.Data;
6
 import lombok.EqualsAndHashCode;
7
 import lombok.EqualsAndHashCode;
8
 
9
 
9
 import java.io.Serializable;
10
 import java.io.Serializable;
10
 import java.time.LocalDateTime;
11
 import java.time.LocalDateTime;
12
+import java.util.ArrayList;
13
+import java.util.List;
11
 
14
 
12
 /**
15
 /**
13
  * <p>
16
  * <p>
66
      * 排序
69
      * 排序
67
      */
70
      */
68
     private Integer sort;
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 Näytä tiedosto

18
           <i v-else class="el-icon-plus avatar-uploader-icon"/>
18
           <i v-else class="el-icon-plus avatar-uploader-icon"/>
19
         </el-upload>
19
         </el-upload>
20
       </el-form-item>
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
     </el-form>
40
     </el-form>
22
     <div slot="footer" class="dialog-footer">
41
     <div slot="footer" class="dialog-footer">
23
       <el-button @click="dialogForm('0')">取 消</el-button>
42
       <el-button @click="dialogForm('0')">取 消</el-button>
81
         id: '',
100
         id: '',
82
         serviceName: '',
101
         serviceName: '',
83
         sort: '',
102
         sort: '',
84
-        serviceImageUrl: ''
103
+        serviceImageUrl: '',
104
+        labelList: []
85
       },
105
       },
86
       uploadImgUrl: process.env.BASE_API + '/uploadimage',
106
       uploadImgUrl: process.env.BASE_API + '/uploadimage',
87
       dialogStatus: '',
107
       dialogStatus: '',
92
       bannerPositionArr: [
112
       bannerPositionArr: [
93
         { id: 1, value: '首页banner' },
113
         { id: 1, value: '首页banner' },
94
         { id: 2, value: '服务banner' }
114
         { id: 2, value: '服务banner' }
95
-      ]
115
+      ],
116
+      dynamicTags: [],
117
+      inputVisible: false,
118
+      inputValue: ''
96
     }
119
     }
97
   },
120
   },
98
   computed: {
121
   computed: {
132
     createData() {
155
     createData() {
133
       this.$refs['form'].validate((valid) => {
156
       this.$refs['form'].validate((valid) => {
134
         if (valid) {
157
         if (valid) {
158
+          this.form.labelList = this.dynamicTags
135
           this.$store.dispatch('service/createService', this.form).then((res) => {
159
           this.$store.dispatch('service/createService', this.form).then((res) => {
136
             if (res.data.code === '0') {
160
             if (res.data.code === '0') {
137
               this.$message({
161
               this.$message({
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
 .dialog-footer {
202
 .dialog-footer {
162
   text-align: center;
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
 </style>
220
 </style>
165
 <style>
221
 <style>
166
 .avatar-uploader .el-upload {
222
 .avatar-uploader .el-upload {