index.vue 1.01 KB
Newer Older
1 2 3
<template>
    <a-upload :customRequest="customRequest" :showUploadList="showUploadList" v-bind="$attrs">
        <slot>
shuiluo's avatar
shuiluo committed
4
            <a-button> <a-icon type="upload" />{{ $t('user.upload') }}</a-button>
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
        </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>