app-preset-rawitem.vue 9.8 KB
Newer Older
1 2 3 4 5 6
<template>
    <app-rawitem
        v-if="type == 'FIELD_IMAGE' || type == 'FIELD_TEXT_DYNAMIC' || type == 'STATIC_LABEL' || type == 'STATIC_TEXT'"
        class="app-preset-rawitem"
        :rawItemDetail="rawItemDetail"
        :contentType="contentType"
7 8
        :imgUrl="isImg(imgUrl)? imgUrl: ''"
        :imageClass="!isImg(imgUrl)? imgUrl: ''"
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
        :content="value"
        :context="context"
        :viewparams="viewparams"
        :itemValue="value"
    />
    <div class="app-preset-rawitem" v-else-if="type == 'STATIC_VIDEOPLAYER'">
        <app-video :videoParmas="rawParams" />
    </div>
    <app-carousel
        v-else-if="type == 'STATIC_CAROUSEL'"
        class="app-preset-rawitem"
        :data="rawParams"
        :style="getContentStyle(rawItemDetail.cssStyle)"
        :class="getCssName(rawItemDetail)"
    ></app-carousel>
    <app-nav-pos
25
        v-else-if="type == 'NAV_POS' || type == 'NAV_POS_INDEX'"
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 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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        class="app-preset-rawitem"
        :navData="navData"
        :dynaNavMode="detailModel.dynaNavMode"
        :enableCache="detailModel.enableCache"
    ></app-nav-pos>
    <tab-page-exp v-else-if="type == 'NAV_TABS'" class="app-preset-rawitem" :modelService="modelService"></tab-page-exp>
    <app-user v-else-if="type == 'AUTH_USERINFO'"></app-user>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
import { AppServiceBase, ImgurlBase64 } from 'ibiz-core';
import { IPSEditor } from '@ibiz/dynamic-model-api';

@Component({})
export default class AppPresetRawitem extends Vue {
    /**
     * 父项所有数据
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    @Prop() public contextData?: any;

    /**
     * 输入值
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    @Prop() public value!: any;

    /**
     * 名称
     *
     * @type {string}
     * @memberof AppPresetRawitem
     */
    @Prop() public name!: string;

    /**
     * 类型
     *
     * @type {string}
     * @memberof AppPresetRawitem
     */
    @Prop() public type?: string;

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    @Prop() context: any;

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    @Prop() viewparams: any;

    /**
     * 模型
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    @Prop({
        default: () => {
            return {};
        },
    })
    detailModel: any;

    /**
     * 导航数据
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    @Prop() navData: any;

    /**
     * 直接内容模型
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    @Prop() rawItemDetail: any;

    /**
     * 模型服务
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    @Prop() modelService: any;

   /**
     * 编辑器实例
     *
     * @type {IPSEditor}
     * @memberof AppPresetRawitem
     */
    @Prop() editorInstance!: IPSEditor;

    /**
     * 内容类型
     *
     * @type {string}
     * @memberof AppPresetRawitem
     */
    public contentType: string = '';

    /**
     * 直接内容参数
     *
     * @type {*}
     * @memberof AppPresetRawitem
     */
    public rawParams: any = {};

    /**
     * 下载文件路径
     *
     * @memberof AppPresetRawitem
     */
    protected downloadUrl = AppServiceBase.getInstance().getAppEnvironment().ExportFile;

    /**
     * 动态图片路径
     *
     * @memberof AppPresetRawitem
     */
    protected dynaImgUrl: string = '';

    /**
     * 图片路径
     *
     * @memberof AppPresetRawitem
     */
    get imgUrl(): string {
        return this.dynaImgUrl;
    }

    /**
     * Vue生命周期 --- Created
     *
     * @memberof AppPresetRawitem
     */
    created() {
        this.init();
    }

    /**
     * 初始化
     *
     * @memberof AppPresetRawitem
     */
    protected init() {
        switch (this.type) {
            case 'FIELD_IMAGE':
                this.handleDynaImg();
                break;
            case 'FIELD_TEXT_DYNAMIC':
                this.handleDynaText();
                break;
            case 'STATIC_TEXT':
            case 'STATIC_LABEL':
                this.contentType = this.editorInstance?.editorParams?.['CONTENTTYPE'] || 'RAW';
                break;
            case 'NAV_POS':
201
            case 'NAV_POS_INDEX':
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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 263 264 265 266 267 268 269 270 271 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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
                break;
            case 'STATIC_VIDEOPLAYER':
                this.handleStaticVideo();
                break;
            case 'STATIC_CAROUSEL':
                this.handleStaticCarousel();
            case 'NAV_TABS':
                break;
            case 'AUTH_USERINFO':
                break;
            default:
                console.warn(`${this.type}暂未支持`);
                break;
        }
    }

    /**
     * 处理动态图片
     *
     * @memberof AppPresetRawitem
     */
    protected handleDynaImg() {
        this.contentType = this.editorInstance?.editorParams?.['CONTENTTYPE'] || 'IMAGE';
        if (this.value && typeof this.value == 'string') {
            // 默认识别文件对象形式,识别失败则为全路径模式
            try {
                const _files = JSON.parse(this.value);
                const file = _files instanceof Array ? _files[0] : null;
                const url = file && file.id ? `${this.downloadUrl}/${file.id}` : '';
                ImgurlBase64.getInstance()
                .getImgURLOfBase64(url)
                .then((res: any) => {
                    this.dynaImgUrl = res;
                });
            } catch (error) {
                this.dynaImgUrl = this.value;
            }
        }
    }

    /**
     * 处理动态文本
     *
     * @memberof AppPresetRawitem
     */
    protected handleDynaText() {
        this.contentType = this.editorInstance?.editorParams?.['CONTENTTYPE'] || 'RAW';
    }

    /**
     * 处理静态视频播放
     *
     * @memberof AppPresetRawitem
     */
    protected handleStaticVideo() {
        if (this.rawItemDetail && this.rawItemDetail.getPSRawItemParams) {
            const rawParams: any = {};
            this.rawItemDetail.getPSRawItemParams.forEach((param: any) => {
                rawParams[param.key.toLowerCase()] = param.value;
            });
            this.rawParams = rawParams;
        }
    }

    /**
     * 处理静态轮播图
     *
     * @memberof AppPresetRawitem
     */
    protected handleStaticCarousel() {
        let swipeData: any[] = [];
        let swipeConfig: any = {};
        if (this.rawItemDetail && this.rawItemDetail.getPSRawItemParams) {
            // 判断imgsData后两位是否有配置参数
            const imgsData = this.rawItemDetail.getPSRawItemParams;
            const configItem = imgsData.findIndex((item: any) => Object.is(item.key, 'autoplay'));
            if (configItem > -1) {
                // 有配置参数就截掉配置参数
                swipeData = imgsData.slice(0, -2);
                swipeConfig = this.setSwipeConfig(imgsData.slice(-2));
            } else {
                swipeData = imgsData;
                swipeConfig = this.setSwipeConfig(imgsData);
            }
        }
        swipeData = swipeData.map((item: any) => {
            return this.addressProcessing(item);
        });
        this.rawParams = {
            swipeData: swipeData,
            swipeConfig: swipeConfig,
        };
    }

    /**
     * @description 设置轮播图配置
     * @param {*}
     * @memberof AppRawItem
     */
    private setSwipeConfig(data: any) {
        const autoPlay: any = data.find((item: any) => Object.is(item.key, 'autoplay')) || {};
        const timeSpan: any = data.find((item: any) => Object.is(item.key, 'timespan')) || {};
        return {
            isAuto: Object.is(autoPlay?.value, '1') ? true : false,
            timeSpan: Number(timeSpan?.value) || 0,
        };
    }

    /**
     * 处理轮播图地址
     *
     * @memberof AppPresetRawitem
     */
    private addressProcessing(item: any) {
        let _item: any = {};
        _item.linkPath = item.linkPath;
        _item.imgPath = this.getImagePath(item);
        _item.iconClass = this.getImageClass(item) || '';
        return _item;
    }

    /**
     * 获取图片路径
     *
     * @memberof AppPresetRawitem
     */
    public getImagePath(item: any) {
        if (item && item.getPSSysImage && item.getPSSysImage.imagePath) {
            return item.getPSSysImage.imagePath;
        }
    }

    /**
     * @description 获取imageClass
     * @param {*}
     * @memberof AppRawItem
     */
    public getImageClass(item: any) {
        if (item && item.getPSSysImage && item.getPSSysImage.cssClass) {
            return item.getPSSysImage.cssClass;
        }
    }

    /**
     * 获取内容样式
     *
     * @memberof AppPresetRawitem
     */
    public getContentStyle(data: any) {
        if (data && data.cssStyle) {
            const res = data.cssStyle.split('\n');
            const target: string[] = [];
            res.forEach((item: any) => {
                target.push(...item.split(';').filter((value: any) => value));
            });
            return target
                .filter((value: string) => {
                    return value.split(':').length === 2;
                })
                .join(';');
        }
    }

    /**
     * @description 获取cssName
     * @param {*} data
     */
    public getCssName(data: any) {
        if (data && data.getPSSysCss && data.getPSSysCss.cssName) {
            return data.getPSSysCss.cssName;
        }
    }
374 375 376 377 378 379 380 381 382 383

    /**
     * 判断是否为图片路径
     * 
     * @param {string} imgUrl
     */
     public isImg(imgUrl: string) {
        const reg = /^https?:|^http?:|(\.png|\.svg|\.jpg|\.png|\.gif|\.psd|\.tif|\.bmp|\.jpeg)/;
        return reg.test(imgUrl);
    }
384 385 386 387 388
}
</script>
<style lang="less">
@import './app-preset-rawitem.less';
</style>