gcpCertification.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <div class="gcp-certification">
  3. <h2 class="title">GCP证书上传</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="file.url" 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 @click.stop="previewImage(index)"></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="image/*">
  22. <i class="el-icon-plus"></i>
  23. </el-upload>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import Vue from 'vue'
  31. import Viewer from 'v-viewer'
  32. import 'viewerjs/dist/viewer.css'
  33. Vue.use(Viewer)
  34. import { post, checkAndAddUpload } from '../../api'
  35. export default {
  36. name: 'GcpCertification',
  37. data() {
  38. return {
  39. fileList: [],
  40. imageList: [],
  41. imageListTime: null,
  42. }
  43. },
  44. methods: {
  45. uploadGCPImg(file) {
  46. this.imageList.unshift(file.file)
  47. if (this.imageListTime) {
  48. clearTimeout(this.imageListTime)
  49. }
  50. this.imageListTime = setTimeout(() => {
  51. this.batchUploadGCPimg()
  52. }, 500)
  53. },
  54. batchUploadGCPimg() {
  55. for (let i = 0; i < this.imageList.length; i++) {
  56. const formData = new FormData()
  57. formData.append('coverImage', this.imageList[i])
  58. this.fileList.unshift({
  59. name: 'a',
  60. loading: true,
  61. url: '',
  62. imgError: ''
  63. })
  64. this.http.uploadFile(`/gcp-show/uploadAndSave`, formData, res => {
  65. this.fileList[i].url = checkAndAddUpload(res.data.url)
  66. this.fileList[i].name = res.data.id
  67. this.fileList[i].loading = false
  68. }, err => {
  69. this.fileList[i].loading = false
  70. this.fileList[i].imgError = '图片上传失败'
  71. })
  72. }
  73. setTimeout(() => {
  74. this.imageList = []
  75. this.$refs.pictureCardRef.clearFiles()
  76. }, 1500)
  77. },
  78. removeImage(index) {
  79. this.$confirm('此操作将永久删除该图片, 是否继续?', '删除图片', {
  80. confirmButtonText: '确定',
  81. cancelButtonText: '取消',
  82. type: 'warning'
  83. }).then(() => {
  84. post(`/gcp-show/delete`, { id: this.fileList[index].name }).then(res => {
  85. this.$message({
  86. type: 'success',
  87. message: '删除成功!'
  88. })
  89. this.fileList.splice(index, 1)
  90. })
  91. })
  92. },
  93. previewImage(index) {
  94. this.$viewerApi({
  95. images: this.fileList.map(f => f.url),
  96. options: {
  97. initialViewIndex: index,
  98. toolbar: {
  99. zoomIn: 1,
  100. zoomOut: 1,
  101. oneToOne: 1,
  102. reset: 1,
  103. prev: 1,
  104. next: 1,
  105. rotateLeft: 1,
  106. rotateRight: 1,
  107. flipHorizontal: 1,
  108. flipVertical: 1
  109. }
  110. }
  111. })
  112. },
  113. obtainCertificateList() {
  114. post(`/gcp-show/list`, {}).then(res => {
  115. this.fileList = res.data.map(item => {
  116. return {
  117. name: item.id,
  118. url: checkAndAddUpload(item.url),
  119. loading: false,
  120. imgError: ''
  121. }
  122. })
  123. })
  124. }
  125. },
  126. mounted() {
  127. this.obtainCertificateList()
  128. }
  129. }
  130. </script>
  131. <style scoped>
  132. .gcp-certification {
  133. max-width: 1200px;
  134. margin: 0 auto;
  135. padding: 20px;
  136. }
  137. .title {
  138. text-align: center;
  139. margin-bottom: 30px;
  140. color: #333;
  141. }
  142. .upload-area {
  143. display: flex;
  144. flex-wrap: wrap;
  145. margin-bottom: 30px;
  146. }
  147. .upload-height {
  148. height: 70vh;
  149. overflow-y: auto;
  150. }
  151. .hide-upload>>>.el-upload--picture-card {
  152. display: none;
  153. }
  154. .image-list {
  155. display: flex;
  156. flex-wrap: wrap;
  157. gap: 20px;
  158. margin-bottom: 30px;
  159. margin-right: 20px;
  160. }
  161. .image-item {
  162. position: relative;
  163. width: 148px;
  164. height: 148px;
  165. border-radius: 4px;
  166. overflow: hidden;
  167. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  168. transition: all 0.3s;
  169. }
  170. .image-item:hover {
  171. transform: translateY(-5px);
  172. box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.2);
  173. }
  174. .image-item-hover:hover .image-actions {
  175. opacity: 1;
  176. }
  177. .cert-image {
  178. width: 100%;
  179. height: 100%;
  180. object-fit: cover;
  181. cursor: pointer;
  182. }
  183. .image-actions {
  184. position: absolute;
  185. top: 0;
  186. left: 0;
  187. width: 100%;
  188. height: 100%;
  189. display: flex;
  190. justify-content: center;
  191. align-items: center;
  192. background: rgba(0, 0, 0, .5);
  193. gap: 10px;
  194. opacity: 0;
  195. transition: opacity 0.3s;
  196. }
  197. .image-actions-loging {
  198. position: absolute;
  199. top: 0;
  200. left: 0;
  201. width: 100%;
  202. height: 100%;
  203. display: flex;
  204. justify-content: center;
  205. align-items: center;
  206. background: rgba(0, 0, 0, .5);
  207. color: #fff;
  208. }
  209. .submit-area {
  210. text-align: center;
  211. }
  212. </style>