<template>
    <span @click="downloadFile()" ><i class="fa fa-cloud-download" aria-hidden="true"></i> {{ name }}</span>
</template>

<script>
import Base from "@/views/base/Base"
import { delAttament, downloadFile } from '@/api/file'

export default {
    extends: Base,
    data() {
        return {

        }
    },
    props: {
        text: {
            type: String,
            default: '8a2e26f5ca95419a9cd356a4968cebc4.jpg'
        },
        module: {
            type: String,
            default: 'http://localhost:8080/api/file/pub'
        },
        name: {
            type: String,
            default: ''
        }
    },
    methods: {
        downloadFile: function() {
            if (!this.name) {
                alert("暂时无法下载");
            }
            var path = this.module + '/' + this.name;
            var fileName = this.text;
            downloadFile({
                path,
                fileName
            }).then(res => {
                this.download(res);
            }).catch(err => {
                if (err.msg) {
                    alert(err.msg);
                }
                console.log(err);
            });
        }
    }
}
</script>