市北互联平台前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
1.7 KiB

<template>
<el-dialog :visible.sync="visible" :title="$t('oss.upload')" :close-on-click-modal="false" :close-on-press-escape="false">
<el-upload
:action="url"
:file-list="fileList"
drag
multiple
:before-upload="beforeUploadHandle"
:on-success="successHandle"
class="text-center">
<i class="el-icon-upload"></i>
<div class="el-upload__text" v-html="$t('upload.text')"></div>
<div class="el-upload__tip" slot="tip">{{ $t('upload.tip', { 'format': 'jpg、png、gif' }) }}</div>
</el-upload>
</el-dialog>
</template>
<script>
import Cookies from 'js-cookie'
export default {
data () {
return {
visible: false,
url: '',
num: 0,
fileList: []
}
},
methods: {
init () {
this.visible = true
this.url = `${window.SITE_CONFIG['apiURL']}/oss/file/upload?token=${localStorage.getItem('token')}`
this.num = 0
this.fileList = []
},
// 上传之前
beforeUploadHandle (file) {
if (file.type !== 'image/jpg' && file.type !== 'image/jpeg' && file.type !== 'image/png' && file.type !== 'image/gif') {
this.$message.error(this.$t('upload.tip', { 'format': 'jpg、png、gif' }))
return false
}
this.num++
},
// 上传成功
successHandle (res, file, fileList) {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.fileList = fileList
this.num--
if (this.num === 0) {
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
}
}
}
}
</script>