app-rawitem.vue 8.5 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
<template>
    <div :class="['app-rawitem', `app-rawtime--${contentType.toLowerCase()}`]">
        <!-- 直接内容类型 -->
        <template v-if="Object.is(contentType, 'RAW')">
            <template v-if="Object.is(renderMode, 'TEXT')">
                <span :style="cssStyle">{{ content }}</span>
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING1')">
                <h1 :style="cssStyle">{{ content }}</h1>
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING2')">
                <h2 :style="cssStyle">{{ content }}</h2>
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING3')">
                <h3 :style="cssStyle">{{ content }}</h3>
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING4')">
                <h4 :style="cssStyle">{{ content }}</h4>
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING5')">
                <h5 :style="cssStyle">{{ content }}</h5>
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING6')">
                <h6 :style="cssStyle">{{ content }}</h6>
            </template>
            <template v-else-if="Object.is(renderMode, 'PARAGRAPH')">
                <p :style="cssStyle">{{ content }}</p>
            </template>
        </template>
        <!-- 图片类型 -->
        <template v-else-if="Object.is(contentType, 'IMAGE')">
32
            <img :style="cssStyle" class="app-rawitem__image" v-if="imgUrl" :src="imgUrl" />
33 34 35 36
            <i :style="cssStyle" v-else :class="imageClass ? imageClass : ''"></i>
        </template>
        <!-- HTML类型 -->
        <template v-else-if="Object.is(contentType, 'HTML')">
37
            <div :style="cssStyle" class="app-rawitem__html" v-html="content" />
38 39 40 41 42
        </template>
        <!-- MARKDOWN类型 -->
        <template v-else-if="Object.is(contentType, 'MARKDOWN')">
            <app-markdown-editor :style="cssStyle" mode="PREVIEWONLY" :itemValue="itemValue"></app-markdown-editor>
        </template>
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
        <!-- VIDEO类型 -->
        <template v-else-if="Object.is(contentType, 'VIDEO')">
            <!-- 视频 -->
            <div :style="cssStyle" class="app-rawitem__video">
                <video
                    :id="playerParams.uuid"
                    :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>
        <!-- PLACEHOLDER类型 -->
        <template v-else-if="Object.is(contentType, 'PLACEHOLDER')">
            <!-- 占位 -->
            <div :style="cssStyle"></div>
        </template>
        <!-- DIVIDER类型 -->
        <template v-else-if="Object.is(contentType, 'DIVIDER')">
            <!-- 分割线 -->
            <app-divider
                class="app-rawitem__divider"
                :style="cssStyle"
                :contentPosition="divider_params.contentPosition"
                :html="divider_params.html"
            ></app-divider>
        </template>
        <!-- INFO,WARNING,ERROR类型 -->
        <!-- 提示 -->
        <template
            v-else-if="
                Object.is(contentType, 'INFO') || Object.is(contentType, 'WARNING') || Object.is(contentType, 'ERROR')
            "
        >
            <app-raw-alert
                class="app-rawitem__alert"
                :type="alert_params.type"
                :title="alert_params.title"
                :showIcon="alert_params.showIcon"
                :closeable="alert_params.closeable"
            ></app-raw-alert>
        </template>
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
    </div>
</template>

<script lang='ts'>
import { Component, Vue, Prop } from 'vue-property-decorator';

@Component({})
export default class AppRawItem extends Vue {
    /**
     * 应用上下文
     *
     * @type {string}
     * @memberof AppRawItem
     */
    @Prop() public context!: any;

    /**
     * 视图参数
     *
     * @type {string}
     * @memberof AppRawItem
     */
    @Prop() public viewparams!: any;

    /**
     * 内容类型
     *
     * @type {string}
     * @memberof AppRawItem
     */
121 122 123 124 125 126 127 128 129 130 131
    @Prop({ default: 'RAW' }) public contentType!:
        | 'RAW'
        | 'HTML'
        | 'IMAGE'
        | 'MARKDOWN'
        | 'VIDEO'
        | 'PLACEHOLDER'
        | 'DIVIDER'
        | 'INFO'
        | 'WARNING'
        | 'ERROR';
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

    /**
     * 直接内容详情
     *
     * @type {*}
     * @memberof AppRawItem
     */
    @Prop() public rawItemDetail: any;

    /**
     * 内容
     *
     * @type {string}
     * @memberof AppRawItem
     */
    @Prop() public content?: string;

    /**
     * 图标
     *
     * @type {string}
     * @memberof AppRawItem
     */
    @Prop() public imageClass?: string;

    /**
     * 图片
     *
     * @type {string}
     * @memberof AppRawItem
     */
    @Prop() public imgUrl?: string;

    /**
     * 编辑器值
     *
     * @type {*}
     * @memberof AppRawItem
     */
    @Prop() public itemValue?: any;

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    /**
     * 直接内容-视频参数
     */
    @Prop({default:()=>{}}) public videoParams?: any;

    /**
     * 直接内容-分割线参数
     */
    @Prop({default:()=>{}}) public dividerParams?: any;

    /**
     * 直接内容-提示参数
     */
    @Prop({default:()=>{}}) public alertParams?: any;

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    /**
     * 内容样式
     */
    public cssStyle?: string;
    /**
     * 绘制模式
     *
     * @type {string}
     * @memberof AppRawItem
     */
    public renderMode:
        | 'TEXT'
        | 'HEADING1'
        | 'HEADING2'
        | 'HEADING3'
        | 'HEADING4'
        | 'HEADING5'
        | 'HEADING6'
        | 'PARAGRAPH'
        | '' = 'TEXT';

    /**
     * 预定义类型
     *
     * @type {string}
     * @memberof AppRawItem
     */
    public predefinedType: string = '';

    /**
218
     *  uuid
219 220 221 222
     *
     * @type {*}
     * @memberof AppRawItem
     */
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    public uuid = this.$util.createUUID();

    /**
     * 视频类型内容参数
     *
     * @type {*}
     * @memberof AppRawItem
     */
    public playerParams: any = {
        id: this.uuid,
        path: '',
        mute: true,
        autoplay: true,
        replay: false,
        showcontrols: true,
    };

    /**
     * 分割线类型参数
     *
     * @type {*}
     * @memberof AppRawItem
     */
    public divider_params: any = {
        contentPosition: 'center',
        html: '',
    };

    /**
     *  消息提示类型参数
     *
     * @type {*}
     * @memberof AppRawItem
     */
    public alert_params: any = {
        type: 'info',
        title: '',
        closeable: true,
        showIcon: false,
    };
263 264 265 266 267 268 269 270 271

    /**
     * 构建之前
     *
     * @type {*}
     * @memberof AppRawItem
     */
    public created() {
        this.cssStyle = this.rawItemDetail && this.rawItemDetail.cssStyle ? this.rawItemDetail.cssStyle : '';
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
        switch (this.contentType) {
            case 'RAW':
                // 直接内容识别绘制模式
                this.renderMode =
                    this.rawItemDetail && this.rawItemDetail.renderMode ? this.rawItemDetail.renderMode : 'TEXT';
                if (
                    this.rawItemDetail &&
                    this.rawItemDetail.predefinedType &&
                    this.rawItemDetail.predefinedType === 'STATIC_LABEL'
                ) {
                    this.cssStyle += 'white-space: nowrap;overflow: hidden;text-overflow: ellipsis;';
                }
                break;
            case 'VIDEO':
                if (this.videoParams) {
                    Object.assign(this.playerParams, this.videoParams);
                }
                break;
            case 'PLACEHOLDER':
                break;
            case 'DIVIDER':
                if (this.dividerParams) {
                    Object.assign(this.divider_params, this.dividerParams);
                }
                break;
            case 'INFO':
            case 'WARNING':
            case 'ERROR':
                this.alert_params.type = this.contentType.toLocaleLowerCase();
                if (this.alertParams) {
                    Object.assign(this.alert_params,this.alertParams);
                }
                break;
305 306 307 308
        }
    }
}
</script>