| | |
| | | <div class="dele" @click="deleItem(index)"> |
| | | <i class="el-icon-close"></i> |
| | | </div> |
| | | <img :src="item.url" v-if="fileType(item.url) === 'img'" /> |
| | | <video controls autoplay :src="item.url" v-else></video> |
| | | <img :src="item.fileurlFull" v-if="fileType(item.fileurlFull) === 'img'" /> |
| | | <video controls autoplay :src="item.fileurlFull" v-else></video> |
| | | </div> |
| | | <div class="file_list_item" :style="{width: width, height: height, cursor: 'pointer'}" @click="$refs.file.click()"> |
| | | <div v-if="list ==null || list.length == 0 || list.length < maxLength" class="file_list_item" :style="{width: width, height: height, cursor: 'pointer'}" @click="$refs.file.click()"> |
| | | <i class="el-icon-plus"></i> |
| | | </div> |
| | | </div> |
| | | <input type="file" ref="file" :accept="accept" @change="getFile" /> |
| | | <input type="file" ref="file" :accept="accept" @change="getFile" /> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import axios from 'axios'; |
| | | export default { |
| | | props: { |
| | | width: { |
| | | type: String, |
| | | default: '90px' |
| | | }, |
| | | height: { |
| | | type: String, |
| | | default: '90px' |
| | | }, |
| | | list: { |
| | | type: Array, |
| | | default: [] |
| | | }, |
| | | accept: { |
| | | type: String, |
| | | default: '' |
| | | }, |
| | | folder: { |
| | | type: String, |
| | | default: '' |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | uploadImgUrl: process.env.VUE_APP_API_PREFIX + '/public/upload' |
| | | } |
| | | }, |
| | | |
| | | methods: { |
| | | fileType(url) { |
| | | if (url.indexOf('.mp4') !== -1) { |
| | | return 'video' |
| | | } else { |
| | | return 'img' |
| | | } |
| | | }, |
| | | getFile(e) { |
| | | if (e.target && e.target.files.length > 0) { |
| | | this.$emit('loading') |
| | | const formdate = new FormData() |
| | | formdate.append('file', e.target.files[0]) |
| | | formdate.append('folder', this.folder) |
| | | axios.post(this.uploadImgUrl, formdate) |
| | | .then(res => { |
| | | this.$emit('success', res.data.data) |
| | | }) |
| | | .catch(e => { |
| | | this.$message.error(e) |
| | | }) |
| | | .finally(() => { |
| | | this.$refs.file.value = null |
| | | }) |
| | | } |
| | | }, |
| | | deleItem(index) { |
| | | this.$emit('dele', index) |
| | | } |
| | | } |
| | | import axios from 'axios' |
| | | export default { |
| | | props: { |
| | | width: { |
| | | type: String, |
| | | default: '90px' |
| | | }, |
| | | height: { |
| | | type: String, |
| | | default: '90px' |
| | | }, |
| | | list: { |
| | | type: Array, |
| | | default: [] |
| | | }, |
| | | accept: { |
| | | type: String, |
| | | default: '' |
| | | }, |
| | | folder: { |
| | | type: String, |
| | | default: '' |
| | | }, |
| | | maxLength: { |
| | | type: Number, |
| | | default: 9999 |
| | | } |
| | | }, |
| | | data () { |
| | | return { |
| | | uploadImgUrl: process.env.VUE_APP_API_PREFIX + '/public/upload' |
| | | } |
| | | }, |
| | | methods: { |
| | | fileType (url) { |
| | | if (url && url.indexOf('.mp4') !== -1) { |
| | | return 'video' |
| | | } else { |
| | | return 'img' |
| | | } |
| | | }, |
| | | getFile (e) { |
| | | if (e.target && e.target.files.length > 0) { |
| | | this.$emit('loading') |
| | | const formdate = new FormData() |
| | | formdate.append('file', e.target.files[0]) |
| | | formdate.append('folder', this.folder) |
| | | axios.post(this.uploadImgUrl, formdate) |
| | | .then(res => { |
| | | this.$emit('success', res.data.data) |
| | | }) |
| | | .catch(e => { |
| | | this.$message.error(e) |
| | | }) |
| | | .finally(() => { |
| | | this.$refs.file.value = null |
| | | }) |
| | | } |
| | | }, |
| | | deleItem (index) { |
| | | this.$emit('dele', index) |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | |
| | | margin: 0 !important; |
| | | } |
| | | .dele { |
| | | z-index: 10000; |
| | | position: absolute; |
| | | right: 0; |
| | | top: 0; |
| | |
| | | } |
| | | } |
| | | </style> |
| | | |