zangbin 2 years ago
parent
commit
92c0919c53

+ 2 - 0
tour-module/src/main/java/com/tour/module/service/IBannerService.java

@@ -18,4 +18,6 @@ public interface IBannerService extends IService<Banner> {
      * @return 列表
      */
     List<Banner> queryList(Banner banner);
+
+    Boolean updateStatus(Long id, Integer status);
 }

+ 13 - 0
tour-module/src/main/java/com/tour/module/service/impl/BannerServiceImpl.java

@@ -1,5 +1,6 @@
 package com.tour.module.service.impl;
 
+import com.tour.common.exception.CustomException;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -11,6 +12,7 @@ import com.tour.module.service.IBannerService;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * 轮播图Service业务层处理
@@ -51,4 +53,15 @@ public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> impleme
         lqw.orderByAsc(Banner::getSort);
         return this.list(lqw);
     }
+
+    @Override
+    public Boolean updateStatus(Long id, Integer status) {
+        Banner banner = baseMapper.selectById(id);
+        if (Objects.isNull(banner)) {
+            throw new CustomException("该banner不存在!");
+        }
+        banner.setStatus(status);
+        baseMapper.updateById(banner);
+        return true;
+    }
 }

+ 7 - 9
tour-oms/src/main/java/com/tour/web/controller/BannerController.java

@@ -6,14 +6,7 @@ import java.util.Arrays;
 import lombok.RequiredArgsConstructor;
 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.web.bind.annotation.*;
 import com.tour.common.annotation.Log;
 import com.tour.common.core.controller.BaseController;
 import com.tour.common.core.domain.Result;
@@ -25,7 +18,7 @@ import com.tour.common.core.page.TableDataInfo;
 
 /**
  * 轮播图Controller
- * 
+ *
  * @author zoe
  * @date 2023-05-23
  */
@@ -97,4 +90,9 @@ public class BannerController extends BaseController {
     public Result remove(@PathVariable Long[] ids) {
         return toAjax(iBannerService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
     }
+
+    @GetMapping("/updateStatus")
+    public Result updateStatus(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
+        return toAjax(iBannerService.updateStatus(id, status) ? 1 : 0);
+    }
 }

+ 39 - 12
web-ui/src/views/module/banner/index.vue

@@ -86,19 +86,26 @@
             <el-input v-model="form.name" placeholder maxlength="25"></el-input>
         </el-form-item>
         <el-form-item label="图片" prop="image">
-            <el-upload class="upload-demo" v-model="form.image" ref="image"
+            <div class="bg90 bg-height marginB10 freePic">
+              <el-upload  
+                        :headers="headers" 
+                        :class="{hideUpload:hideUploadEdit}"
                         :action="caerAction"
+                        :on-preview="handlePictureCardPreview"
+                        :on-remove="handleRemove"
+                        :on-change="handleChange"
+                        :file-list="fileList"
+                        list-type="picture-card"
+                        :on-success="handleSuccess"
                         :before-upload="caerBeforeUpload" 
-                        list-type="picture"
                         :limit="1"
-                        :on-success="handleSuccess"
-                        :headers="headers" 
-                        :on-remove="handleRemove" 
-                        drag >
-            <i class="el-icon-upload">
-                <div class="el-upload__text">将文件拖到此处, 或<em>点击上传</em></div>
-            </i>
+                        >
+                        <i class="el-icon-plus"></i>
             </el-upload>
+            <el-dialog :visible.sync="dialogVisible">
+              <img width="100%" :src="form.image" alt="">
+            </el-dialog>
+            </div>
         </el-form-item>
         <el-form-item label="位置" prop="position">
             <el-select v-model="form.position" placeholder="请选择">
@@ -143,6 +150,7 @@ export default {
   },
   data () {
     return {
+      hideUploadEdit: false,
       positions: [
         {
             id: 1,
@@ -165,8 +173,10 @@ export default {
         Authorization: "Bearer " + getToken(),
       },
       caerAction: process.env.VUE_APP_BASE_API + "/common/upload",
+      fileList: [],
       // 遮罩层
       loading: true,
+      dialogVisible: false,
       // 选中数组
       ids: [],
       // 非单个禁用
@@ -213,10 +223,18 @@ export default {
     this.getList()
   },
   methods: {
+    handlePictureCardPreview(file) {
+      this.dialogVisible = true;
+    },
+    handleChange(file){
+      // 大于1张隐藏
+      this.hideUploadEdit = true
+    },
     handleSuccess(file) {
       this.form.image = file.url;
     },
     handleRemove(file) {
+      this.hideUploadEdit = false
       //刚上传的图片
       this.form.image = '';
     },
@@ -268,16 +286,20 @@ export default {
     },
     // 新增 / 修改
     addOrUpdateHandle (id) {
+      this.fileList=[];
       this.form.id = id
       if(this.form.id != null) {
         this.title = "修改"
         getBanner(id).then(response => {
-            this.form = response.data;
+          this.form = response.data;
+          this.fileList.push({
+            'url': this.form.image   
+          })
         })
       } else {
         this.title = "新增"
       }
-      console.log('form', this.form)
+      // console.log('form', this.form)
       this.open = true;
     },
     updateStatus (id, status) {
@@ -285,7 +307,7 @@ export default {
       if (status === 0) {
         msg = '启动成功'
       }
-      this.$http.get(`/banner/updateStatus?id=` + id + '&status=' + status).then(({ data }) => {
+      this.$http.get(`/module/banner/updateStatus?id=` + id + '&status=' + status).then(({ data }) => {
         if (data.code === 0) {
           this.getList();
           this.$message({
@@ -338,3 +360,8 @@ export default {
   }
 }
 </script>
+<style lang="scss" scoped>
+.freePic ::v-deep .hide .el-upload--picture-card {
+  display: none;
+}
+</style>