Browse Source

轮播图

魏超 5 years ago
parent
commit
907f69f7c1

+ 15
- 6
foyo-service/src/main/java/com/huiju/foyo/controller/TaCarouselPictureController.java View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.huiju.foyo.common.BaseController;
7
+import com.huiju.foyo.common.ConstantFoyo;
7 8
 import com.huiju.foyo.common.ResponseBean;
8 9
 import com.huiju.foyo.model.TaCarouselPicture;
9 10
 import com.huiju.foyo.service.ITaCarouselPictureService;
@@ -18,6 +19,11 @@ import org.springframework.web.bind.annotation.RequestParam;
18 19
 import org.springframework.web.bind.annotation.ResponseBody;
19 20
 import org.springframework.web.bind.annotation.RestController;
20 21
 
22
+import java.time.LocalDateTime;
23
+import java.util.Arrays;
24
+import java.util.Date;
25
+import java.util.List;
26
+
21 27
 /**
22 28
  * <p>
23 29
     * 轮播图  前端控制器
@@ -42,7 +48,7 @@ public class TaCarouselPictureController extends BaseController {
42 48
      * @param pageSize
43 49
      * @return
44 50
      */
45
-    @RequestMapping(value="/taCarouselPicture",method= RequestMethod.GET)
51
+    @RequestMapping(value="/admin/carousel/list",method= RequestMethod.GET)
46 52
     public ResponseBean taCarouselPictureList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
47 53
                                               @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
48 54
         ResponseBean responseBean = new ResponseBean();
@@ -67,10 +73,13 @@ public class TaCarouselPictureController extends BaseController {
67 73
      * @param taCarouselPicture 实体对象
68 74
      * @return
69 75
      */
70
-    @RequestMapping(value="/taCarouselPicture",method= RequestMethod.POST)
76
+    @RequestMapping(value="/admin/carousel/add",method= RequestMethod.POST)
71 77
     public ResponseBean taCarouselPictureAdd(@RequestBody TaCarouselPicture taCarouselPicture){
72 78
         ResponseBean responseBean = new ResponseBean();
73 79
         try {
80
+            taCarouselPicture.setCreateBy(ConstantFoyo.USER_ADMIN);
81
+            taCarouselPicture.setCreateTime(LocalDateTime.now());
82
+            taCarouselPicture.setStatus(ConstantFoyo.STATUS_EFFECTIVE);
74 83
             if (iTaCarouselPictureService.save(taCarouselPicture)){
75 84
                 responseBean.addSuccess(taCarouselPicture);
76 85
             }else {
@@ -86,14 +95,14 @@ public class TaCarouselPictureController extends BaseController {
86 95
 
87 96
     /**
88 97
      * 根据id删除对象
89
-     * @param id  实体ID
90 98
      */
91 99
     @ResponseBody
92
-    @RequestMapping(value="/taCarouselPicture/{id}", method= RequestMethod.DELETE)
93
-    public ResponseBean taCarouselPictureDelete(@PathVariable Integer id){
100
+    @RequestMapping(value="/admin/carousel/delete", method= RequestMethod.DELETE)
101
+    public ResponseBean taCarouselPictureDelete(@RequestBody String[] ids){
94 102
         ResponseBean responseBean = new ResponseBean();
95 103
         try {
96
-            if(iTaCarouselPictureService.removeById(id)){
104
+            List<String> idList = Arrays.asList(ids);
105
+            if(iTaCarouselPictureService.removeByIds(idList)){
97 106
                 responseBean.addSuccess("success");
98 107
             }else {
99 108
                 responseBean.addError("fail");

+ 1
- 1
foyo-service/src/main/resources/application.yml View File

@@ -10,5 +10,5 @@ mybatis-plus:
10 10
     db-config:
11 11
       id-type: auto
12 12
   configuration:
13
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #´òÓ¡sqlÓï¾ä,µ÷ÊÔÓÃ
13
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
14 14
   mapper-locations: classpath:mapper/*.xml

+ 25
- 0
vue-element-admin/src/api/carousel.js View File

@@ -0,0 +1,25 @@
1
+import request from '@/utils/request'
2
+
3
+export function carouselList(query) {
4
+  return request({
5
+    url: '/carousel/list',
6
+    method: 'get',
7
+    params: query
8
+  })
9
+}
10
+
11
+export function addCarousel(data) {
12
+  return request({
13
+    url: '/carousel/add',
14
+    method: 'post',
15
+    data
16
+  })
17
+}
18
+
19
+export function deleteCarouselBatch(data) {
20
+  return request({
21
+    url: '/carousel/delete',
22
+    method: 'delete',
23
+    data
24
+  })
25
+}

+ 23
- 0
vue-element-admin/src/router/index.js View File

@@ -91,6 +91,29 @@ export const constantRouterMap = [
91 91
         meta: { title: '添加业务信息', icon: 'table' }
92 92
       }
93 93
     ]
94
+  },
95
+  {
96
+    path: '/carousel',
97
+    component: Layout,
98
+    redirect: '/conmmunity/download',
99
+    name: 'carousel',
100
+    alwaysShow: true,
101
+    meta: { title: '轮播图管理', icon: 'zip' },
102
+    children: [
103
+      {
104
+        path: 'carousel',
105
+        component: () => import('@/views/carousel/index'),
106
+        name: 'carousel-index',
107
+        meta: { title: '轮播图列表', icon: 'carousel' }
108
+      },
109
+      {
110
+        path: '/carousel/edit',
111
+        component: () => import('@/views/carousel/edit'),
112
+        name: 'carousel-edit',
113
+        hidden: true,
114
+        meta: { title: '新增轮播图', icon: 'table' }
115
+      }
116
+    ]
94 117
   }
95 118
 ]
96 119
 

+ 3
- 1
vue-element-admin/src/store/index.js View File

@@ -7,6 +7,7 @@ import tagsView from './modules/tagsView'
7 7
 import user from './modules/user'
8 8
 import getters from './getters'
9 9
 import service from './modules/service'
10
+import carousel from './modules/carousel'
10 11
 
11 12
 Vue.use(Vuex)
12 13
 
@@ -17,7 +18,8 @@ const store = new Vuex.Store({
17 18
     permission,
18 19
     tagsView,
19 20
     user,
20
-    service
21
+    service,
22
+    carousel
21 23
   },
22 24
   getters
23 25
 })

+ 37
- 0
vue-element-admin/src/store/modules/carousel.js View File

@@ -0,0 +1,37 @@
1
+import { carouselList, addCarousel, deleteCarouselBatch } from '@/api/carousel'
2
+
3
+const carousel = {
4
+  namespaced: true,
5
+
6
+  actions: {
7
+    getCarouselList({ commit, state }, data) {
8
+      return new Promise((resolve, reject) => {
9
+        carouselList(data).then(response => {
10
+          resolve(response)
11
+        }).catch(error => {
12
+          reject(error)
13
+        })
14
+      })
15
+    },
16
+    createCarlosel({ commit, state }, data) {
17
+      return new Promise((resolve, reject) => {
18
+        addCarousel(data).then(response => {
19
+          resolve(response)
20
+        }).catch(error => {
21
+          reject(error)
22
+        })
23
+      })
24
+    },
25
+    deleteCarousel({ commit, state }, data) { // 删除轮播图
26
+      return new Promise((resolve, reject) => {
27
+        deleteCarouselBatch(data).then(response => {
28
+          resolve(response)
29
+        }).catch(error => {
30
+          reject(error)
31
+        })
32
+      })
33
+    }
34
+  }
35
+}
36
+
37
+export default carousel

+ 190
- 0
vue-element-admin/src/views/carousel/edit.vue View File

@@ -0,0 +1,190 @@
1
+<template>
2
+  <div id="app" class="app-container">
3
+    <el-form ref="form" :model="form">
4
+      <!-- <el-form-item :label-width="formLabelWidth" label="业务名称">
5
+        <el-input v-model="form.serviceName"/>
6
+      </el-form-item> -->
7
+      <el-form-item :label-width="formLabelWidth" label="权重">
8
+        <el-input v-model="form.sort"/>
9
+      </el-form-item>
10
+      <el-form-item :label-width="formLabelWidth" label="banner图">
11
+        <el-upload
12
+          :action= "uploadImgUrl"
13
+          :show-file-list="false"
14
+          :on-success="handleAvatarSuccess"
15
+          class="avatar-uploader"
16
+          name="uploadFiles">
17
+          <img v-if="imageUrl" :src="imageUrl" class="avatar">
18
+          <i v-else class="el-icon-plus avatar-uploader-icon"/>
19
+        </el-upload>
20
+      </el-form-item>
21
+    </el-form>
22
+    <div slot="footer" class="dialog-footer">
23
+      <el-button @click="dialogForm('0')">取 消</el-button>
24
+      <el-button type="primary" @click="dialogForm('1')">确 定</el-button>
25
+    </div>
26
+  </div>
27
+</template>
28
+
29
+<script>
30
+// import { updateArticle, createBanner } from '@/api/banner' // getBanner
31
+import waves from '@/directive/waves' // Waves directive
32
+import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
33
+const calendarTypeOptions = [
34
+  { key: 'CN', display_name: 'China' },
35
+  { key: 'US', display_name: 'USA' },
36
+  { key: 'JP', display_name: 'Japan' },
37
+  { key: 'EU', display_name: 'Eurozone' }
38
+]
39
+// arr to obj ,such as { CN : "China", US : "USA" }
40
+const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
41
+  acc[cur.key] = cur.display_name
42
+  return acc
43
+}, {})
44
+export default {
45
+  name: 'UpdateBanner',
46
+  components: { Pagination },
47
+  directives: { waves },
48
+  filters: {
49
+    statusFilter(status) {
50
+      const statusMap = {
51
+        published: 'success',
52
+        draft: 'info',
53
+        deleted: 'danger'
54
+      }
55
+      return statusMap[status]
56
+    },
57
+    typeFilter(type) {
58
+      return calendarTypeKeyValue[type]
59
+    }
60
+  },
61
+  data() {
62
+    return {
63
+      tableKey: 0,
64
+      list: null,
65
+      total: 0,
66
+      listLoading: true,
67
+      imageUrl: '', // 图片预览
68
+      importanceOptions: [1, 2, 3],
69
+      calendarTypeOptions,
70
+      communityQuery: {
71
+        pageNum: 1,
72
+        pageSize: 300,
73
+        communityId: undefined,
74
+        communityName: undefined,
75
+        provinceId: undefined,
76
+        cityId: undefined,
77
+        districtId: undefined
78
+      },
79
+      listQuery: [],
80
+      form: {
81
+        id: '',
82
+        serviceName: '',
83
+        sort: '',
84
+        imageUrl: ''
85
+      },
86
+      uploadImgUrl: process.env.BASE_API + '/uploadimage',
87
+      dialogStatus: '',
88
+      downloadLoading: false,
89
+      formLabelWidth: '120px',
90
+      showContentVisible: false,
91
+      showURLVisible: true,
92
+      bannerPositionArr: [
93
+        { id: 1, value: '首页banner' },
94
+        { id: 2, value: '服务banner' }
95
+      ]
96
+    }
97
+  },
98
+  computed: {
99
+  },
100
+  created() {
101
+    this.listQuery = this.$route.params.listQuery
102
+  },
103
+  updated() {
104
+  },
105
+  methods: {
106
+    handleAvatarSuccess(res, file) { // 上传成功回调
107
+      this.imageUrl = URL.createObjectURL(file.raw)
108
+      this.form.imageUrl = res.data[0]
109
+    },
110
+    dialogAddForm() {
111
+      this.dialogFormVisible = true
112
+      this.form.serviceName = ''
113
+      this.form.sort = ''
114
+      this.form.imageUrl = ''
115
+    },
116
+    dialogForm(isVaule) {
117
+      if (isVaule === '0') {
118
+        this.$router.push({ name: 'carousel-index' })
119
+      } else {
120
+        this.createData()
121
+      }
122
+    },
123
+    showContent() {
124
+      if (this.form.bannerType === '1') {
125
+        this.showContentVisible = false
126
+        this.showURLVisible = true
127
+      } else {
128
+        this.showContentVisible = true
129
+        this.showURLVisible = false
130
+      }
131
+    },
132
+    createData() {
133
+      this.$refs['form'].validate((valid) => {
134
+        if (valid) {
135
+          this.$store.dispatch('carousel/createCarlosel', this.form).then((res) => {
136
+            if (res.data.code === '0') {
137
+              this.$message({
138
+                message: res.data.message,
139
+                type: 'success'
140
+              })
141
+              this.$router.push({ name: 'carousel-index' })
142
+            } else {
143
+              this.$message({
144
+                message: res.data.message,
145
+                type: 'warning'
146
+              })
147
+            }
148
+          })
149
+        }
150
+      })
151
+    }
152
+  }
153
+}
154
+</script>
155
+
156
+<style scoped>
157
+.app-container {
158
+  width: 50%;
159
+  margin: auto;
160
+}
161
+.dialog-footer {
162
+  text-align: center;
163
+}
164
+</style>
165
+<style>
166
+.avatar-uploader .el-upload {
167
+  border: 1px dashed #d9d9d9;
168
+  border-radius: 6px;
169
+  cursor: pointer;
170
+  position: relative;
171
+  overflow: hidden;
172
+}
173
+.avatar-uploader .el-upload:hover {
174
+  border-color: #409EFF;
175
+}
176
+.avatar-uploader-icon {
177
+  font-size: 28px;
178
+  color: #8c939d;
179
+  width: 178px;
180
+  height: 178px;
181
+  line-height: 178px;
182
+  text-align: center;
183
+}
184
+.avatar {
185
+  width: 178px;
186
+  height: 178px;
187
+  display: block;
188
+}
189
+</style>
190
+

+ 287
- 0
vue-element-admin/src/views/carousel/index.vue View File

@@ -0,0 +1,287 @@
1
+<template>
2
+  <div class="root">
3
+    <el-form :inline="true" :model="listQuery" class="form-listQuery">
4
+      <!-- <el-form-item label="业务名称">
5
+        <el-input v-model="listQuery.serviceName" placeholder="业务名称" />
6
+      </el-form-item>
7
+      <el-form-item>
8
+        <el-button type="info" @click="clearListQuery">清空</el-button>
9
+        <el-button type="primary" @click="handleFilter">查询</el-button>
10
+      </el-form-item> -->
11
+    </el-form>
12
+    <div class="operation">
13
+      <div>
14
+        <el-button type="primary" @click="addCarousel">新增轮播图</el-button>
15
+        <el-button type="danger" @click="deleteCarousel">删除</el-button>
16
+      </div>
17
+    </div>
18
+    <el-table
19
+      v-loading="listLoading"
20
+      ref="multipleTable"
21
+      :data="carouselList"
22
+      border
23
+      tooltip-effect="dark"
24
+      style="width: 100%; margin-top: 20px;"
25
+      @selection-change="handleSelectionChange">
26
+      <el-table-column type="selection" width="55" align="center"/>
27
+      <!-- <el-table-column label="业务名称" align="center">
28
+        <template slot-scope="scope">
29
+          <span>{{ scope.row.serviceName }}</span>
30
+        </template>
31
+      </el-table-column> -->
32
+      <el-table-column label="业务图片" align="center">
33
+        <template slot-scope="scope">
34
+          <img v-if="scope.row.imageUrl !== ''" :src="scope.row.imageUrl" width="50" height="50">
35
+        </template>
36
+      </el-table-column>
37
+      <el-table-column label="排序" align="center">
38
+        <template slot-scope="scope">
39
+          <span>{{ scope.row.sort }}</span>
40
+        </template>
41
+      </el-table-column>
42
+      <el-table-column label="创建时间" align="center">
43
+        <template slot-scope="scope">
44
+          <span>{{ formatDate(scope.row.createTime) }}</span>
45
+        </template>
46
+      </el-table-column>
47
+    </el-table>
48
+    <div class="block">
49
+      <el-pagination
50
+        :current-page.sync="listQuery.pageNum"
51
+        :page-sizes="[10, 20, 50, 100]"
52
+        :page-size.sync="listQuery.pageSize"
53
+        :total="total"
54
+        layout="total, sizes, prev, pager, next, jumper"
55
+        @size-change="handleSizeChange"
56
+        @current-change="handleCurrentChange"/>
57
+    </div>
58
+  </div>
59
+</template>
60
+
61
+<script>
62
+import waves from '@/directive/waves' // Waves directive
63
+import { parseTime } from '@/utils'
64
+
65
+export default {
66
+  directives: { waves },
67
+  data() {
68
+    var _self = this
69
+    return {
70
+      events: {
71
+        click: (e) => {
72
+          // _self.postData.Coordinate = e.lnglat.lat + ',' + e.lnglat.lng
73
+          _self.detail.longitude = e.lnglat.lng
74
+          _self.detail.latitude = e.lnglat.lat
75
+        }
76
+      },
77
+      markers: [],
78
+      searchOption: {
79
+        city: '南京',
80
+        citylimit: false
81
+      },
82
+      carouselList: [],
83
+      total: 0,
84
+      listLoading: true,
85
+      listQuery: {
86
+        pageNum: 1,
87
+        pageSize: 20
88
+      },
89
+      ids: [], // id集合
90
+      tableKey: 0,
91
+      downloadLoading: false
92
+    }
93
+  },
94
+  created() {
95
+    this.getList()
96
+  },
97
+  methods: {
98
+    setCurrent(item) {
99
+      this.setDetail({ ...item })
100
+    },
101
+    getList() {
102
+      this.listLoading = true
103
+      this.$store.dispatch('carousel/getCarouselList', this.listQuery).then((res) => {
104
+        console.log(res)
105
+        this.carouselList = res.data.data.records
106
+        this.total = res.data.data.total
107
+        this.listLoading = false
108
+      }).catch(() => {
109
+        this.loading = false
110
+        console.log('get list error')
111
+      })
112
+    },
113
+    clearListQuery() {
114
+      this.listQuery.pageNum = 1
115
+      this.listQuery.pageSize = 20
116
+      this.listQuery.billId = undefined
117
+      this.listQuery.billName = undefined
118
+      this.listQuery.billExplain = undefined
119
+      this.getList()
120
+    },
121
+    getInfo(billId, billStatus) {
122
+      if (billStatus === '2') {
123
+        this.$router.push({ name: 'bill-edi', query: { id: billId }})
124
+      } else {
125
+        this.$router.push({ name: 'bill-info', query: { id: billId }})
126
+      }
127
+    },
128
+    addCarousel() {
129
+      this.$router.push({ name: 'carousel-edit' })
130
+    },
131
+    handleFilter() {
132
+      this.listQuery.pageNum = 1
133
+      this.getList()
134
+    },
135
+    handleModifyStatus(row, status) {
136
+      this.$message({
137
+        message: '操作成功',
138
+        type: 'success'
139
+      })
140
+      row.status = status
141
+    },
142
+    sortChange(data) {
143
+      const { prop, order } = data
144
+      if (prop === 'id') {
145
+        this.sortByID(order)
146
+      }
147
+    },
148
+    handleSizeChange(val) {
149
+      // console.log(`每页 ${val} 条`);
150
+      this.listQuery.pageSize = val
151
+      this.getList()
152
+    },
153
+    handleCurrentChange(val) {
154
+      // console.log(`当前页: ${val}`);
155
+      this.listQuery.pageNum = val
156
+      this.getList()
157
+    },
158
+    sortByID(order) {
159
+      if (order === 'ascending') {
160
+        this.listQuery.sort = '+id'
161
+      } else {
162
+        this.listQuery.sort = '-id'
163
+      }
164
+      this.handleFilter()
165
+    },
166
+    handleUpdate(row) {
167
+      this.setCurrent(row)
168
+      this.dialogStatus = 'update'
169
+      this.dialogFormVisible = true
170
+      this.$nextTick(() => {
171
+        this.$refs['dataForm'].clearValidate()
172
+      })
173
+      this.getEditCityList()
174
+      this.getEditDistrictList()
175
+    },
176
+    handleLook(id) {
177
+      this.$router.push({ name: 'transaction-info', params: { id: id }})
178
+    },
179
+    handleCreate() {
180
+      this.resetDetail()
181
+      this.dialogStatus = 'create'
182
+      this.dialogFormVisible = true
183
+      this.$nextTick(() => {
184
+        this.$refs['dataForm'].clearValidate()
185
+      })
186
+    },
187
+    handleDelete(row) {
188
+      this.$notify({
189
+        title: '成功',
190
+        message: '删除成功',
191
+        type: 'success',
192
+        duration: 2000
193
+      })
194
+      const index = this.list.indexOf(row)
195
+      this.list.splice(index, 1)
196
+    },
197
+    handleDownload() {
198
+      this.downloadLoading = true
199
+      import('@/vendor/Export2Excel').then(excel => {
200
+        const tHeader = ['timestamp', 'title', 'type', 'importance', 'status']
201
+        const filterVal = ['timestamp', 'title', 'type', 'importance', 'status']
202
+        const data = this.formatJson(filterVal, this.list)
203
+        excel.export_json_to_excel({
204
+          header: tHeader,
205
+          data,
206
+          filename: 'table-list'
207
+        })
208
+        this.downloadLoading = false
209
+      })
210
+    },
211
+    padDate(value) {
212
+      value = value < 10 ? '0' + value : value
213
+      return value
214
+    },
215
+    formatDate(val) {
216
+      if (val === null) {
217
+        return ''
218
+      }
219
+      var value = new Date(val)
220
+      var year = value.getFullYear()
221
+      var month = this.padDate(value.getMonth() + 1)
222
+      var day = this.padDate(value.getDate())
223
+      var hour = this.padDate(value.getHours())
224
+      var minutes = this.padDate(value.getMinutes())
225
+      var seconds = this.padDate(value.getSeconds())
226
+      return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
227
+    },
228
+    formatJson(filterVal, jsonData) {
229
+      return jsonData.map(v => filterVal.map(j => {
230
+        if (j === 'timestamp') {
231
+          return parseTime(v[j])
232
+        } else {
233
+          return v[j]
234
+        }
235
+      }))
236
+    },
237
+    deleteCarousel() { // 删除
238
+      if (this.ids.length <= 0) {
239
+        this.$message.error('请至少选择一项')
240
+        return
241
+      }
242
+      this.$store.dispatch('carousel/deleteCarousel', this.ids).then(res => {
243
+        const resCode = res.data.code
244
+        if (resCode === '0') {
245
+          this.$message.success('删除成功')
246
+          this.getList()
247
+          return
248
+        }
249
+        this.$message.error(res.data.message)
250
+      }).catch(() => {
251
+        console.log('DeleteBillBeach error')
252
+      })
253
+    },
254
+    handleSelectionChange(val) { // 选择
255
+      console.log(val)
256
+      this.ids = []
257
+
258
+      val.map((item, index) => {
259
+        console.log(item, index)
260
+        this.ids.push(item.id)
261
+      })
262
+    }
263
+  }
264
+}
265
+</script>
266
+
267
+<style scoped>
268
+.root{
269
+  display: flex;
270
+  flex-flow: column;
271
+}
272
+.form-listQuery{
273
+  margin-top: 20px;
274
+  margin-left: 30px;
275
+}
276
+.operation{
277
+  display: flex;
278
+  justify-content: space-between;
279
+  margin-left: 20px;
280
+  margin-right: 20px;
281
+}
282
+.block{
283
+  display: flex;
284
+  justify-content: flex-end;
285
+  margin-top: 10px;
286
+}
287
+</style>