app-image-romate.vue 2.0 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
<template>
  <div class='app-image-preview'>
      <el-image :src="data[name]" :previewSrcList="previewList" :disabled="disabled">
      </el-image>
  </div>
</template>
<script lang = 'ts'>
import { Vue, Component, Prop, Watch, Provide } from 'vue-property-decorator';
import { Subject, Unsubscribable } from 'rxjs';

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

    /**
     * 表单状态
     *
     * @type {any}
     * @memberof AppImageRomate
     */
    @Prop() public formState: any;

    /**
     * 图片数据
     *
     * @type {any}
     * @memberof AppImageRomate
     */
    @Prop() public data!: any;

    /**
     * 字段名
     *
     * @type {any}
     * @memberof AppImageRomate
     */
    @Prop() public name: any;

    /**
     * 禁用状态
     *
     * @type {boolean}
     * @memberof AppImageRomate
     */
    @Prop() public disabled: boolean = false;

    /**
     * 预览图片数组
     *
     * @type {boolean}
     * @memberof AppImageRomate
     */
    public previewList:Array<any> = [];

    /**
     * 表单状态事件
     *
     * @private
     * @type {(Unsubscribable | undefined)}
     * @memberof AppImageUpload
     */
    private formStateEvent: Unsubscribable | undefined;

    /**
     * Vue生命周期
     *
     * @type {boolean}
     * @memberof AppImageRomate
     */
    public created() {
        if (this.formState) {
            this.formStateEvent = this.formState.subscribe(($event: any) => {
                // 表单加载完成
                if(this.data && this.name) {
                    this.handleData();
                }
            });
        }
    }

    /**
     * 数据处理
     *
     * @type {boolean}
     * @memberof AppImageRomate
     */
    public handleData() {
        this.previewList.push(this.data[this.name]);
    }  
    
    /**
     * 组件销毁
     *
     * @memberof AppImageRomate
     */
    public destroyed(): void {
        if (this.formStateEvent) {
            this.formStateEvent.unsubscribe();
        }
    }
}

</script>