|
@@ -0,0 +1,135 @@
|
|
|
+<template>
|
|
|
+ <div class="imgBox">
|
|
|
+ <div @click="addImg($event)" class="imgCss">
|
|
|
+ <img src="../../../assets/images/course/imageUpload.png" alt="" />
|
|
|
+ <input type="file" accept="image/*" style="display: none" @change="beforeUpload($event)" />
|
|
|
+ </div>
|
|
|
+ <div class="imgList">
|
|
|
+ <div v-for="(item, index) in imgList" :key="index" class="imgItem">
|
|
|
+ <div class="itemImg" @click="previewImg(pptImgUrl1)">
|
|
|
+ <img :src="item" alt="" />
|
|
|
+ </div>
|
|
|
+ <div class="deleteImg" @click="deleteItem(item)">
|
|
|
+ <img src="../../../assets/images/course/delete.png" alt="" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ imgList: []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ previewImg(url) {
|
|
|
+ this.$hevueImgPreview(url)
|
|
|
+ },
|
|
|
+ addImg(e) {
|
|
|
+ var el = e.currentTarget
|
|
|
+ el.getElementsByTagName('input')[0].click()
|
|
|
+ e.target.value = ''
|
|
|
+ },
|
|
|
+ deleteItem(i) {
|
|
|
+ this.imgList.splice(this.imgList.indexOf(i), 1)
|
|
|
+ this.$forceUpdate()
|
|
|
+ },
|
|
|
+ beforeUpload(event) {
|
|
|
+ var file = event.target.files[0]
|
|
|
+ var credentials = {
|
|
|
+ accessKeyId: 'AKIATLPEDU37QV5CHLMH',
|
|
|
+ secretAccessKey: 'Q2SQw37HfolS7yeaR1Ndpy9Jl4E2YZKUuuy2muZR'
|
|
|
+ } //秘钥形式的登录上传
|
|
|
+ window.AWS.config.update(credentials)
|
|
|
+ window.AWS.config.region = 'cn-northwest-1' //设置区域
|
|
|
+ var bucket = new window.AWS.S3({ params: { Bucket: 'ccrb' } }) //选择桶
|
|
|
+ var _this = this
|
|
|
+ if (file) {
|
|
|
+ var params = {
|
|
|
+ Key:
|
|
|
+ file.name.split('.')[0] +
|
|
|
+ new Date().getTime() +
|
|
|
+ '.' +
|
|
|
+ file.name.split('.')[file.name.split('.').length - 1],
|
|
|
+ ContentType: file.type,
|
|
|
+ Body: file,
|
|
|
+ 'Access-Control-Allow-Credentials': '*',
|
|
|
+ ACL: 'public-read'
|
|
|
+ } //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
|
|
|
+ var options = {
|
|
|
+ partSize: 2048 * 1024 * 1024,
|
|
|
+ queueSize: 2,
|
|
|
+ leavePartsOnError: true
|
|
|
+ }
|
|
|
+ bucket
|
|
|
+ .upload(params, options)
|
|
|
+ .on('httpUploadProgress', function (evt) {
|
|
|
+ //这里可以写进度条
|
|
|
+ })
|
|
|
+ .send(function (err, data) {
|
|
|
+ if (err) {
|
|
|
+ _this.$message.error('上传失败')
|
|
|
+ } else {
|
|
|
+ _this.imgList.push(data.Location)
|
|
|
+ _this.getImage(_this.imgList)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getImage(imageList) {
|
|
|
+ this.$emit('getImage', imageList)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.imgBox {
|
|
|
+ margin: 10px;
|
|
|
+ .imgCss {
|
|
|
+ width: 80px;
|
|
|
+ height: 80px;
|
|
|
+ > img {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .imgList {
|
|
|
+ margin: 10px 0 0 0;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: row;
|
|
|
+ flex-wrap: wrap;
|
|
|
+ align-items: center;
|
|
|
+ .imgItem {
|
|
|
+ position: relative;
|
|
|
+ width: 80px;
|
|
|
+ margin: 0 10px 10px 0;
|
|
|
+ .itemImg {
|
|
|
+ width: 80px;
|
|
|
+ height: 80px;
|
|
|
+ z-index: 1;
|
|
|
+ > img {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ object-fit: cover;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .deleteImg {
|
|
|
+ width: 20px;
|
|
|
+ height: 20px;
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ top: 0;
|
|
|
+ z-index: 9;
|
|
|
+ > img {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|