12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <template>
- <div>
- <el-upload
- ref="upload"
- class="upload-demo"
- :limit="1"
- :data="params"
- :action="action"
- :file-list="fileList"
- :auto-upload="false"
- :headers="headers"
- :on-success="success"
- :accept="accept"
- :before-upload="beforeUpload"
- :on-remove="remove"
- >
- <el-button slot="trigger" size="mini" type="primary">选取文件</el-button>
- <!-- <el-button style="margin-left: 10px;" size="mini" type="success" @click="uploadFile">上传</el-button> -->
- <div slot="tip" class="el-upload__tip">只能上传.doc/.ppt/.pdf文件,且不超过2MB</div>
- </el-upload>
- </div>
- </template>
- <script>
- import { mapGetters } from 'vuex'
- export default {
- props: {
- fileList: {
- type: Array,
- default: () => []
- },
- authUserId: {
- type: Number,
- default: -1
- },
- brandId: {
- type: [Number, String],
- default: 0
- }
- },
- data() {
- return {
- // 图片上传接口
- action: process.env.VUE_APP_UPLOAD_API + '/shop/upload/file',
- accept: '.doc,.ppt,.pdf',
- // 请求参数
- params: {
- authUserId: null,
- brandId: null
- },
- headers: {
- 'X-Token': ''
- },
- showUpload: true
- }
- },
- computed: {
- ...mapGetters(['token'])
- },
- created() {
- this.headers['X-Token'] = this.token
- this.params.brandId = this.brandId || 0
- },
- methods: {
- success(response) {
- this.$emit('success', response)
- },
- error(err, file, fileList) {
- this.$emit('error', err, file, fileList)
- },
- uploadFile() {
- this.params.authUserId = this.authUserId || -1
- this.$refs.upload.submit()
- },
- // 图片上传之前的钩子
- beforeUpload(file) {
- this.params.authUserId = this.authUserId || -1
- const size = file.size
- if (size > 1024 * 2000) {
- this.$message.warning('文件上传大小超出限制(≤2MB)')
- return false
- }
- },
- remove() {
- this.$emit('remove')
- }
- }
- }
- </script>
|