hotTopicCarousel.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div class="gcp-certification">
  3. <h2 class="title">轮播图热点内容</h2>
  4. <div class="upload-height">
  5. <div class="upload-area">
  6. <div class="image-list">
  7. <div v-for="(file, index) in fileList" :key="index" :class="`${!file.loading ? 'image-item-hover' : ''} image-item`">
  8. <img :src="require('../../assets/image/yunketang.png')" class="cert-image" @click="previewImage(index)">
  9. <div class="image-actions" v-if="!file.loading">
  10. <el-button type="danger" icon="el-icon-delete" circle @click.stop="removeImage(index)"></el-button>
  11. <el-button type="primary" icon="el-icon-view" circle></el-button>
  12. </div>
  13. <div class="image-actions-loging" v-if="file.loading">
  14. 文件上传中...
  15. </div>
  16. </div>
  17. </div>
  18. <!-- 上传按钮 -->
  19. <div class="imageUpload">
  20. <el-upload ref="pictureCardRef" action="#" list-type="picture-card" :multiple="true"
  21. :show-file-list="false" :http-request="uploadGCPImg" accept="video/mp4,video/avi,video/x-msvideo">
  22. <i class="el-icon-plus"></i>
  23. </el-upload>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import { post, checkAndAddUpload } from '../../api'
  31. export default {
  32. name: 'GcpCertification',
  33. data() {
  34. return {
  35. fileList: [],
  36. imageList: [],
  37. imageListTime: null,
  38. }
  39. },
  40. methods: {
  41. uploadGCPImg(file) {
  42. this.imageList.unshift(file.file)
  43. if (this.imageListTime) {
  44. clearTimeout(this.imageListTime)
  45. }
  46. this.imageListTime = setTimeout(() => {
  47. this.batchUploadGCPimg()
  48. }, 500)
  49. },
  50. batchUploadGCPimg() {
  51. for (let i = 0; i < this.imageList.length; i++) {
  52. const formData = new FormData()
  53. formData.append('coverImage', this.imageList[i])
  54. this.fileList.unshift({
  55. name: 'a',
  56. loading: true,
  57. url: '',
  58. imgError: ''
  59. })
  60. this.http.uploadFile(`/course-carousel/uploadAndSave`, formData, res => {
  61. this.fileList[i].url = checkAndAddUpload(res.data.courseUrl)
  62. this.fileList[i].name = res.data.id
  63. this.fileList[i].loading = false
  64. }, err => {
  65. this.fileList.splice(i, 1)
  66. this.$message({
  67. type: 'error',
  68. message: '视频上传失败'
  69. })
  70. })
  71. }
  72. setTimeout(() => {
  73. this.imageList = []
  74. this.$refs.pictureCardRef.clearFiles()
  75. }, 1500)
  76. },
  77. removeImage(index) {
  78. this.$confirm('此操作将永久删除该视频, 是否继续?', '删除视频', {
  79. confirmButtonText: '确定',
  80. cancelButtonText: '取消',
  81. type: 'warning'
  82. }).then(() => {
  83. post(`/course-carousel/delete`, { id: this.fileList[index].name }).then(res => {
  84. this.$message({
  85. type: 'success',
  86. message: '删除成功!'
  87. })
  88. this.fileList.splice(index, 1)
  89. })
  90. })
  91. },
  92. obtainCertificateList() {
  93. post(`/course-carousel/list`, {}).then(res => {
  94. this.fileList = res.data.map(item => {
  95. return {
  96. name: item.id,
  97. url: checkAndAddUpload(item.courseUrl),
  98. loading: false,
  99. imgError: ''
  100. }
  101. }).reverse()
  102. })
  103. }
  104. },
  105. mounted() {
  106. this.obtainCertificateList()
  107. }
  108. }
  109. </script>
  110. <style scoped>
  111. .gcp-certification {
  112. max-width: 1200px;
  113. margin: 0 auto;
  114. padding: 20px;
  115. }
  116. .title {
  117. text-align: center;
  118. margin-bottom: 30px;
  119. color: #333;
  120. }
  121. .upload-area {
  122. display: flex;
  123. flex-wrap: wrap;
  124. margin-bottom: 30px;
  125. }
  126. .upload-height {
  127. height: 70vh;
  128. overflow-y: auto;
  129. }
  130. .hide-upload>>>.el-upload--picture-card {
  131. display: none;
  132. }
  133. .image-list {
  134. display: flex;
  135. flex-wrap: wrap;
  136. gap: 20px;
  137. margin-bottom: 30px;
  138. margin-right: 20px;
  139. }
  140. .image-item {
  141. position: relative;
  142. width: 148px;
  143. height: 148px;
  144. border-radius: 4px;
  145. overflow: hidden;
  146. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  147. transition: all 0.3s;
  148. }
  149. .image-item:hover {
  150. transform: translateY(-5px);
  151. box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.2);
  152. }
  153. .image-item-hover:hover .image-actions {
  154. opacity: 1;
  155. }
  156. .cert-image {
  157. width: 100%;
  158. height: 100%;
  159. object-fit: cover;
  160. cursor: pointer;
  161. }
  162. .image-actions {
  163. position: absolute;
  164. top: 0;
  165. left: 0;
  166. width: 100%;
  167. height: 100%;
  168. display: flex;
  169. justify-content: center;
  170. align-items: center;
  171. background: rgba(0, 0, 0, .5);
  172. gap: 10px;
  173. opacity: 0;
  174. transition: opacity 0.3s;
  175. }
  176. .image-actions-loging {
  177. position: absolute;
  178. top: 0;
  179. left: 0;
  180. width: 100%;
  181. height: 100%;
  182. display: flex;
  183. justify-content: center;
  184. align-items: center;
  185. background: rgba(0, 0, 0, .5);
  186. color: #fff;
  187. }
  188. .submit-area {
  189. text-align: center;
  190. }
  191. </style>