app-upload-file-info.vue 2.3 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
<template>
  <div class="app-upload-file-info">
      <a class="file-item" v-for="file in files" @click="() => onDownload(file)"><i class="el-icon-document"></i>{{file.name}}</a>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
import { Environment } from '@/environments/environment';
import { CreateElement } from 'vue';
import { Subject, Unsubscribable } from 'rxjs';

@Component({
})
export default class AppUploadFileInfo extends Vue {

    /**
     * 初始化值
     *
     * @type {*}
     * @memberof AppUploadFileInfo
     */
    @Prop() public value?: any;

    /**
     * 数据值变化
     *
     * @param {*} newval
     * @param {*} val
     * @memberof AppUploadFileInfo
     */
    @Watch('value')
    onValueChange(newval: any, val: any) {
        this.dataProcess();
    }

    /**
     * 所属表单项名称
     *
     * @type {string}
     * @memberof AppUploadFileInfo
     */
    @Prop() public name!: string;

    /**
     * 上传文件路径
     *
     * @memberof AppUploadFileInfo
     */
    public uploadUrl = Environment.BaseUrl + Environment.UploadFile;

    /**
     * 下载文件路径
     *
     * @memberof AppUploadFileInfo
     */
    public downloadUrl = Environment.BaseUrl + Environment.ExportFile;

    /**
     * 文件列表
     *
     * @memberof AppUploadFileInfo
     */
    public files = [];

    /**
     * 数据处理
     *
     * @private
     * @memberof AppUploadFileInfo
     */
    private dataProcess(): void {
        if(this.value){
            let files = JSON.parse(this.value);
            if(files.length){
                files.forEach((file: any) => {
                    let url = `${this.downloadUrl}/${file.id}`;
                    file.url = url;
                });
            }else{
              files = []
            }
            this.files =files;
        }
    }

    /**
     * vue 生命周期
     *
     * @memberof AppUploadFileInfo
     */
    public created() {
        this.dataProcess();
    }


    /**
     * 下载文件
     *
     * @param {*} file
     * @memberof AppUploadFileInfo
     */
    public onDownload(file: any) {
        window.open(file.url);
    }

}
</script>

<style lang='less'>
@import './app-upload-file-info.less';
</style>