app-rawitem-video.vue 3.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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
<template>
    <div :class="curClassName" :style="curStyle">
        <video :src="playerParams.path" :autoplay="playerParams.autoplay" :controls="playerParams.showcontrols"
            :loop="playerParams.replay" :muted="playerParams.mute">
            <source :src="playerParams.path" type="video/mp4">
            <source :src="playerParams.path" type="video/ogg">
            <source :src="playerParams.path" type="video/webm">
        </video>
    </div>
</template>

<script lang="ts">
import { Util } from '@/utils';
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
@Component({})
export default class AppRawItemVideo extends Vue {
    /**
    * 名称
    *
    * @type {*}
    * @memberof AppRawItemImage
    */
    @Prop() public name!: string;

    /**
     * 模型
     *
     * @type {*}
     * @memberof AppRawItemImage
     */
    @Prop() public layoutModelDetails!: any;

    /**
     * 视频播放数据
     * @memberof AppRawItemVideo
     */
    @Prop() public videoParmas?: any;

    /**
     * 下标
     *
     * @type {number}
     * @memberof AppRawItemVideo
     */
    @Prop() public index?: number;

    /**
     * 值变更
     *
     * @memberof AppRawItemVideo
     */
    @Watch('videoParmas',{immediate:true,deep:true})
    onVideoParmasChange(newVal: any, oldVal: any) {
        this.handleStaticVideo();
    }

    /**
     * 项名称
     *
     * @type {*}
     * @memberof AppRawItemVideo
     */
    get itemName() {
        return (this.index || this.index === 0) ? `${this.name}_${this.index}` : this.name;
    }

    /**
     * 类名
     *
     * @memberof AppRawItemVideo
     */
    get curClassName() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return `app-rawitem-video ${this.itemName} ${layoutModel.sysCss}`;
        }
    }

    /**
     * 当前容器样式
     * 
     * @memberof AppRawItemVideo
     */
    get curStyle() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.getElementStyle();
        }
    }

    /**
     * 播放器唯一标识
     * @memberof AppRawItemVideo
     */
    public uuid: string = Util.createUUID();

    /**
     * 视频播放参数
     *
     * @type {any}
     * @memberof AppRawItemVideo
     */
    public playerParams = {
        id: this.uuid,
        height: '100%',
        width: '100%',
        path: "",
        mute: 0.8,
        autoplay: false,
        replay: false,
        showcontrols: false
    };

    created(){
        this.handleStaticVideo();
    }

    /**
     * 处理静态视频播放
     *
     * @memberof AppRawItemVideo
     */
    protected handleStaticVideo() {
        if (this.videoParmas && this.videoParmas.length > 0) {
            const rawParams: any = {};
            this.videoParmas.forEach((param: any) => {
                if(param.key == 'autoplay' || param.key == 'replay' ||param.key == 'showcontrols'){
                    rawParams[param.key] = param.value == "1" ? true : false;
                }else{
                    rawParams[param.key] = param.value;
                }
            })
            Object.assign(this.playerParams, rawParams);
        }
    }
}
</script>

<style lang='less'>
@import "./app-rawitem-video.less";
</style>