index.vue 1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<template>
    <a-upload :customRequest="customRequest" :showUploadList="showUploadList" v-bind="$attrs">
        <slot>
            <a-button> <a-icon type="upload" /> 上传 </a-button>
        </slot>
    </a-upload>
</template>

<script>
import { uploadFileApi } from '@/api';

export default {
    props: {
        value: [String, Array],
        modelName: {
            type: String,
            default: 'adminSystem',
        },
        showUploadList: {
            type: [Object, Boolean],
            default: false,
        },
    },
    model: {
        prop: 'value',
        event: 'change',
    },
    methods: {
        async customRequest(info) {
            const { file } = info;
            try {
                const res = await uploadFileApi(this.modelName, file);
                this.$message.success('上传成功');
                this.$emit('change', res.fileSrc);
            } catch (error) {
                this.$message.error('上传失败');
            }
        },
    },
};
</script>