<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>
