浏览代码

轮播图管理

李志伟 3 年前
父节点
当前提交
fa9e9901ae
共有 7 个文件被更改,包括 357 次插入6 次删除
  1. 46
    0
      src/api/banners.js
  2. 5
    5
      src/api/course.js
  3. 1
    1
      src/api/oss.js
  4. 1
    0
      src/icons/svg/banner.svg
  5. 22
    0
      src/router/index.js
  6. 149
    0
      src/views/banners/edit.vue
  7. 133
    0
      src/views/banners/index.vue

+ 46
- 0
src/api/banners.js 查看文件

@@ -0,0 +1,46 @@
1
+import request from '@/utils/request'
2
+
3
+/**
4
+* 保存轮播图
5
+* @param {*} data
6
+* @returns
7
+*/
8
+export const saveBanner = (data) => request({
9
+  url: '/admin/banner',
10
+  method: 'post',
11
+  data
12
+})
13
+
14
+/**
15
+ * 轮播图列表
16
+ * @param {*} params
17
+ * @returns
18
+ */
19
+export const getBannerList = (params) => request({
20
+  url: '/admin/banner', params
21
+})
22
+
23
+/**
24
+ * 删除轮播图
25
+ * @param {*} data
26
+ * @returns
27
+ */
28
+export const deleteBanner = (id) => request({
29
+  url: `/admin/banner/${id}`, method: 'delete'
30
+})
31
+/**
32
+ * 更新轮播图
33
+ * @param {*} data
34
+ * @returns
35
+ */
36
+export const UpdateBanner = (data, id) => request({
37
+  url: `/admin/banner/${id}`, method: 'put', data
38
+})
39
+/**
40
+ * 查询轮播图详情
41
+ * @param {*} params
42
+ * @returns
43
+ */
44
+export const getBannerDetail = (id) => request({
45
+  url: `/admin/banner/${id}`
46
+})

+ 5
- 5
src/api/course.js 查看文件

@@ -1,7 +1,7 @@
1 1
 import request from '@/utils/request'
2 2
 
3 3
 /**
4
-* 保存班级
4
+* 保存课程
5 5
 * @param {*} data
6 6
 * @returns
7 7
 */
@@ -12,7 +12,7 @@ export const saveCourse = (data) => request({
12 12
 })
13 13
 
14 14
 /**
15
- * 班级列表
15
+ * 课程列表
16 16
  * @param {*} params
17 17
  * @returns
18 18
  */
@@ -21,7 +21,7 @@ export const getCourseList = (params) => request({
21 21
 })
22 22
 
23 23
 /**
24
- * 删除班级
24
+ * 删除课程
25 25
  * @param {*} data
26 26
  * @returns
27 27
  */
@@ -29,7 +29,7 @@ export const deleteCourse = (id) => request({
29 29
   url: `/admin/course/${id}`, method: 'delete'
30 30
 })
31 31
 /**
32
- * 更新班级
32
+ * 更新课程
33 33
  * @param {*} data
34 34
  * @returns
35 35
  */
@@ -37,7 +37,7 @@ export const UpdateCourse = (data, id) => request({
37 37
   url: `/admin/course/${id}`, method: 'put', data
38 38
 })
39 39
 /**
40
- * 查询班级详情
40
+ * 查询课程详情
41 41
  * @param {*} params
42 42
  * @returns
43 43
  */

+ 1
- 1
src/api/oss.js 查看文件

@@ -20,7 +20,7 @@ export function getOSSClient() {
20 20
   }
21 21
 
22 22
   return getSTSToken().then((sts) => {
23
-    stsInfo = sts
23
+    stsInfo = sts.data
24 24
     client = new OSS({
25 25
       accessKeyId: sts.data.accessKeyId,
26 26
       accessKeySecret: sts.data.accessKeySecret,

+ 1
- 0
src/icons/svg/banner.svg 查看文件

@@ -0,0 +1 @@
1
+<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1645447002957" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1533" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M511.4 844.9m-40 0a40 40 0 1 0 80 0 40 40 0 1 0-80 0Z" p-id="1534"></path><path d="M660 844.9m-40 0a40 40 0 1 0 80 0 40 40 0 1 0-80 0Z" p-id="1535"></path><path d="M362.7 844.9m-40 0a40 40 0 1 0 80 0 40 40 0 1 0-80 0Z" p-id="1536"></path><path d="M898.7 135.7H126.8c-16.5 0-29.8 13.3-29.8 29.8v563.6c0 16.5 13.3 29.8 29.8 29.8h771.9c16.5 0 29.8-13.3 29.8-29.8V165.5c0-16.4-13.4-29.8-29.8-29.8z m-170 104.5c39.8 0 72 32.2 72 72s-32.2 72-72 72-72-32.2-72-72c0-39.7 32.3-72 72-72z m65.1 413.2c-18.7 1.3-41.9 0.9-68.4-3.3-39.3-6.3-78.1-20-115.4-40.6-45.6-25.2-89-61-129.1-106.2-38.8-43.9-65.2-39.1-73.9-37.5-32.6 5.9-70.9 42.4-108 102.6-15.1 24.5-27.3 48.7-36 67.3-8.9 19-30.9 28-50.5 20.5-21.7-8.3-31.9-33.3-22-54.3 9.6-20.6 23-47.1 39.7-74.3 50.8-82.8 105.4-130.1 162.5-140.5 25.9-4.7 51.7-1.8 76.7 8.8 24.9 10.5 48.9 28.8 71.5 54.4 59.6 67.4 124.5 107.8 192.8 120.1 50.5 9.1 84.5-1.4 84.9-1.5l-0.4 0.1 10.8 31.8c8.3 24.6-9 50.8-35.2 52.6z" p-id="1537"></path></svg>

+ 22
- 0
src/router/index.js 查看文件

@@ -105,6 +105,28 @@ export const constantRoutes = [
105 105
     ]
106 106
   },
107 107
 
108
+  // 轮播图
109
+  {
110
+    path: '/banners',
111
+    component: Layout,
112
+    meta: { title: '轮播图管理', icon: 'banner' },
113
+    children: [
114
+      {
115
+        path: 'banners',
116
+        name: '轮播图列表',
117
+        component: () => import('@/views/banners/index'),
118
+        meta: { title: '轮播图列表', icon: 'banner' }
119
+      },
120
+      {
121
+        hidden: true,
122
+        path: 'banners/edit',
123
+        name: 'bannersEdit',
124
+        component: () => import('@/views/banners/edit'),
125
+        meta: { title: '轮播图编辑', icon: 'question' }
126
+      }
127
+    ]
128
+  },
129
+
108 130
   // 照片墙
109 131
   {
110 132
     path: '/photoWall',

+ 149
- 0
src/views/banners/edit.vue 查看文件

@@ -0,0 +1,149 @@
1
+<template>
2
+  <div>
3
+    <el-card class="box-card" style="text-align:center" shadow="never">
4
+      <h2>{{ bannerId ? '修改' : '新建' }}轮播图</h2>
5
+      <el-form
6
+        ref="ruleForm"
7
+        :model="ruleForm"
8
+        :rules="rules"
9
+        label-width="10vw"
10
+        style="width:50%;margin:auto"
11
+        class="demo-ruleForm"
12
+      >
13
+        <el-form-item label="课程名" prop="courseId">
14
+          <el-select v-model="ruleForm.courseId" style="width:100%" filterable placeholder="请选择">
15
+            <el-option
16
+              v-for="item in options"
17
+              :key="item.courseId"
18
+              :label="item.title"
19
+              :value="item.courseId"
20
+            />
21
+          </el-select>
22
+        </el-form-item>
23
+        <el-form-item label="轮播图" prop="thumb">
24
+          <upload-image
25
+            style="float:left"
26
+            :icon="ruleForm.thumb"
27
+            @handleChange="handleChange"
28
+            @handleDeleteIcon="handleDeleteIcon"
29
+          />
30
+        </el-form-item>
31
+        <el-form-item label="轮播图位置" prop="position">
32
+          <el-select v-model="ruleForm.position" style="width:100%" placeholder="请选择">
33
+            <el-option
34
+              v-for="item in positionOptions"
35
+              :key="item.value"
36
+              :label="item.label"
37
+              :value="item.value"
38
+            />
39
+          </el-select>
40
+        </el-form-item>
41
+        <el-form-item label="sortNo" prop="排序">
42
+          <el-input v-model="ruleForm.sortNo" min="0" type="number" />
43
+        </el-form-item>
44
+        <el-form-item label-width="0">
45
+          <el-button
46
+            type="primary"
47
+            @click="submitForm('ruleForm')"
48
+          >{{ !bannerId?'新建轮播图':'修改轮播图' }}</el-button>
49
+          <el-button @click="$router.go(-1)">返回</el-button>
50
+        </el-form-item>
51
+      </el-form>
52
+    </el-card>
53
+  </div>
54
+</template>
55
+
56
+<script>
57
+import { saveBanner, getBannerDetail, UpdateBanner } from '@/api/banners'
58
+import { getCourseList } from '@/api/course'
59
+import UploadImage from '@/components/UploadImage/index.vue'
60
+
61
+export default {
62
+  components: {
63
+    UploadImage
64
+  },
65
+  data() {
66
+    return {
67
+      options: [],
68
+      bannerId: '',
69
+      ruleForm: {
70
+        courseId: undefined,
71
+        thumb: undefined,
72
+        position: undefined,
73
+        sortNo: undefined
74
+      },
75
+      rules: {
76
+        courseId: [
77
+          { required: true, message: '请选择课程', trigger: 'blur' }
78
+        ],
79
+        thumb: [{ required: true, message: '请上传图片', trigger: 'blur' }],
80
+        position: [{ required: true, message: '请选择轮播图位置', trigger: 'blur' }]
81
+      },
82
+      positionOptions: [
83
+        { label: '培训通知', value: 'Training' },
84
+        { label: '精彩锦集', value: 'Wonderful' }
85
+      ]
86
+    }
87
+  },
88
+  mounted() {
89
+    if (this.$route?.query.bannerId) {
90
+      this.bannerId = this.$route.query.bannerId
91
+      getBannerDetail(this.bannerId)
92
+        .then((res) => {
93
+          this.ruleForm = res.data
94
+        })
95
+        .catch((e) => {})
96
+    }
97
+    getCourseList().then((res) => {
98
+      this.options = res.data.records
99
+    })
100
+  },
101
+  methods: {
102
+    handleChange(val) {
103
+      this.ruleForm.thumb = val
104
+    },
105
+    handleDeleteIcon() {
106
+      this.ruleForm.thumb = ''
107
+    },
108
+    submitForm(formName) {
109
+      this.$refs[formName].validate((valid) => {
110
+        if (valid) {
111
+          console.log(this.ruleForm.courseId)
112
+          var title
113
+          this.options.map(item => {
114
+            if (item.courseId === this.ruleForm.courseId) {
115
+              title = item.title
116
+            }
117
+          })
118
+          if (this.bannerId) {
119
+            UpdateBanner({ ...this.ruleForm, title }, this.bannerId)
120
+              .then((res) => {
121
+                this.$message.success('修改成功')
122
+                this.$router.go(-1)
123
+              })
124
+              .catch((e) => {})
125
+          } else {
126
+            saveBanner({ ...this.ruleForm, title })
127
+              .then((e) => {
128
+                this.$message.success('保存成功')
129
+                this.$router.go(-1)
130
+              })
131
+              .catch((e) => {})
132
+          }
133
+        } else {
134
+          return false
135
+        }
136
+      })
137
+    }
138
+  }
139
+}
140
+</script>
141
+
142
+<style scoped >
143
+.demo-ruleForm {
144
+  margin-top: 1em;
145
+}
146
+</style>
147
+
148
+<style lang="scss" scoped>
149
+</style>

+ 133
- 0
src/views/banners/index.vue 查看文件

@@ -0,0 +1,133 @@
1
+<template>
2
+  <div class="body">
3
+    <el-card class="box-card" shadow="never">
4
+      轮播图位置:<el-select v-model="position" placeholder="请选择">
5
+        <el-option
6
+          v-for="item in options"
7
+          :key="item.value"
8
+          :label="item.label"
9
+          :value="item.value"
10
+        />
11
+      </el-select>
12
+      <div style="float:right">
13
+        <el-button type="primary" @click="onSearch">查询</el-button>
14
+        <el-button @click="onReset">重置</el-button>
15
+        <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新建轮播图</el-button>
16
+      </div>
17
+    </el-card>
18
+    <el-table stripe :data="tableData" border style="width: 100%">
19
+      <el-table-column prop="title" label="课程名称" />
20
+      <el-table-column prop="thumb" label="图片">
21
+        <template slot-scope="scope">
22
+          <el-image :src="scope.row.thumb" style="width:100px" />
23
+        </template>
24
+      </el-table-column>
25
+      <el-table-column prop="position" label="位置">
26
+        <template slot-scope="scope">{{ scope.row.position === 'Training' ? '培训通知' : '精彩锦集' }}</template>
27
+      </el-table-column>
28
+      <el-table-column prop="sortNo" label="排序">
29
+        <template slot-scope="scope">{{ scope.row.sortNo ? scope.row.sortNo : 0 }}</template>
30
+      </el-table-column>
31
+      <el-table-column align="center" label="操作" min-width="100" width="280">
32
+        <template slot-scope="scope">
33
+          <el-link :underline="false" style="margin-right:1em" type="primary">
34
+            <router-link
35
+              :to="{path:'banners/edit',query: { bannerId: scope.row.bannerId }}"
36
+            >编辑</router-link>
37
+          </el-link>
38
+          <el-popconfirm
39
+            icon="el-icon-info"
40
+            icon-color="red"
41
+            title="确定要删除该轮播图吗?"
42
+            @onConfirm="handleDelete(scope.row)"
43
+          >
44
+            <el-link slot="reference" :underline="false" type="danger">删除</el-link>
45
+          </el-popconfirm>
46
+        </template>
47
+      </el-table-column>
48
+    </el-table>
49
+    <el-pagination
50
+      v-show="Total!==0"
51
+      style="float:right; margin:20px 0"
52
+      :total="Total"
53
+      :current-page="currentPage"
54
+      :page-size="pageSize"
55
+      :page-sizes="[pageSize, 20, 35,40,50,80,100]"
56
+      layout="total, prev, pager, next, sizes"
57
+      @size-change="handleSizeChange"
58
+      @current-change="handleCurrentChange"
59
+    />
60
+  </div>
61
+</template>
62
+<script>
63
+import { getBannerList, deleteBanner } from '@/api/banners'
64
+export default {
65
+  data() {
66
+    return {
67
+      position: undefined,
68
+      tableData: [],
69
+      options: [
70
+        { label: '培训通知', value: 'Training' },
71
+        { label: '精彩锦集', value: 'Wonderful' }
72
+      ],
73
+      //
74
+      pageSize: 10,
75
+      currentPage: 1,
76
+      Total: 0 // 条目总数
77
+    }
78
+  },
79
+  mounted() {
80
+    this.onSearch()
81
+  },
82
+  methods: {
83
+    // 改变每页显示条数
84
+    handleSizeChange(val) {
85
+      this.pageSize = val
86
+      this.changePagination()
87
+    },
88
+    // 改变页码
89
+    handleCurrentChange(val) {
90
+      this.currentPage = val
91
+      this.changePagination()
92
+    },
93
+    // 改变分页组件重新查询数据
94
+    changePagination() {
95
+      getBannerList({
96
+        position: this.position,
97
+        pageNum: this.currentPage,
98
+        pageSize: this.pageSize
99
+      }).then((res) => {
100
+        this.tableData = res.data.records
101
+      })
102
+    },
103
+
104
+    handleAdd() {
105
+      this.$router.push({ path: 'banners/edit' })
106
+    },
107
+    handleDelete(row) {
108
+      deleteBanner(row.bannerId).then(() => {
109
+        this.onSearch()
110
+      })
111
+    },
112
+    onSearch() {
113
+      getBannerList({
114
+        position: this.position,
115
+        pageNum: this.currentPage,
116
+        pageSize: this.pageSize
117
+      }).then((res) => {
118
+        this.tableData = res.data.records
119
+        this.pageSize = res.data.size
120
+        this.Total = res.data.total
121
+      })
122
+    },
123
+    onReset() {
124
+      this.position = undefined
125
+      this.currentPage = 1
126
+      this.pageSize = 10
127
+      this.onSearch()
128
+    }
129
+  }
130
+}
131
+</script>
132
+<style lang="scss" scoped>
133
+</style>