app-preset-text.vue 6.5 KB
Newer Older
1
<template>
Shine-zwj's avatar
Shine-zwj committed
2
    <div :class="curClassName" :style="curStyle">
3 4 5
        <!-- 直接内容类型 -->
        <template v-if="Object.is(contentType, 'RAW')">
            <template v-if="Object.is(renderMode, 'TEXT')">
Shine-zwj's avatar
Shine-zwj committed
6
                <span :style="contentStyle">{{ content }}</span>
7 8
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING1')">
Shine-zwj's avatar
Shine-zwj committed
9
                <h1 :style="contentStyle">{{ content }}</h1>
10 11
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING2')">
Shine-zwj's avatar
Shine-zwj committed
12
                <h2 :style="contentStyle">{{ content }}</h2>
13 14
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING3')">
Shine-zwj's avatar
Shine-zwj committed
15
                <h3 :style="contentStyle">{{ content }}</h3>
16 17
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING4')">
Shine-zwj's avatar
Shine-zwj committed
18
                <h4 :style="contentStyle">{{ content }}</h4>
19 20
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING5')">
Shine-zwj's avatar
Shine-zwj committed
21
                <h5 :style="contentStyle">{{ content }}</h5>
22 23
            </template>
            <template v-else-if="Object.is(renderMode, 'HEADING6')">
Shine-zwj's avatar
Shine-zwj committed
24
                <h6 :style="contentStyle">{{ content }}</h6>
25 26
            </template>
            <template v-else-if="Object.is(renderMode, 'PARAGRAPH')">
Shine-zwj's avatar
Shine-zwj committed
27
                <p :style="contentStyle">{{ content }}</p>
28 29 30 31
            </template>
        </template>
        <!-- 图片类型 -->
        <template v-else-if="Object.is(contentType, 'IMAGE')">
Shine-zwj's avatar
Shine-zwj committed
32 33
            <img :style="contentStyle" v-if="imagePath" :src="imagePath" />
            <i :style="contentStyle" v-else :class="cssClass"></i>
34 35 36
        </template>
        <!-- HTML类型 -->
        <template v-else-if="Object.is(contentType, 'HTML')">
Shine-zwj's avatar
Shine-zwj committed
37
            <div :style="contentStyle" v-html="content" />
38 39 40 41
        </template>
        <!-- MARKDOWN类型 -->
        <template v-else-if="Object.is(contentType, 'MARKDOWN')">
            MARKDOWN暂未支持
Shine-zwj's avatar
Shine-zwj committed
42
            <!-- <app-markdown-editor :style="contentStyle" mode="PREVIEWONLY" :itemValue="value"></app-markdown-editor> -->
43 44 45 46 47 48 49 50
        </template>
    </div>
</template>

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

@Component({})
51
export default class AppPresetText extends Vue {
52 53 54 55 56

    /**
     * 输入值
     *
     * @type {*}
57
     * @memberof AppPresetText
58 59 60
     */
    @Prop() public value!: any;

Shine-zwj's avatar
Shine-zwj committed
61 62 63 64 65 66 67 68
    /**
     * 名称
     *
     * @type {string}
     * @memberof AppPresetText
     */
    @Prop() public name!: string;

69
    /**
Shine-zwj's avatar
Shine-zwj committed
70
     * 布局模型详情
71
     *
Shine-zwj's avatar
Shine-zwj committed
72 73
     * @type {*}
     * @memberof AppPresetTitle
74
     */
Shine-zwj's avatar
Shine-zwj committed
75
    @Prop() public layoutModelDetails: any;
76 77

    /**
Shine-zwj's avatar
Shine-zwj committed
78
     * 图标
79
     *
80
     * @memberof AppPresetText
81
     */
Shine-zwj's avatar
Shine-zwj committed
82
    @Prop() public imageClass?: string;
83

tony001's avatar
tony001 committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    /**
     * 下标
     *
     * @type {number}
     * @memberof AppPresetText
     */
    @Prop({ default: 0 }) public index?: number;

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

102
    /**
Shine-zwj's avatar
Shine-zwj committed
103
     * 图片路径
104
     *
105
     * @memberof AppPresetText
106
     */
Shine-zwj's avatar
Shine-zwj committed
107
    get imagePath() {
tony001's avatar
tony001 committed
108 109 110 111 112 113 114
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            let imagePath = '';
            if (layoutModel.sysImage) {
                imagePath = layoutModel.sysImage.imagePath;
            }
            return imagePath;
Shine-zwj's avatar
Shine-zwj committed
115
        }
tony001's avatar
tony001 committed
116

Shine-zwj's avatar
Shine-zwj committed
117
    }
118 119

    /**
Shine-zwj's avatar
Shine-zwj committed
120
     * 图标
121
     *
Shine-zwj's avatar
Shine-zwj committed
122
     * @memberof AppPresetTitle
123
     */
Shine-zwj's avatar
Shine-zwj committed
124
    get cssClass() {
tony001's avatar
tony001 committed
125 126 127 128 129 130 131
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            let cssClass = '';
            if (layoutModel.sysImage) {
                cssClass = layoutModel.sysImage.iconcls;
            }
            return cssClass;
Shine-zwj's avatar
Shine-zwj committed
132
        }
Shine-zwj's avatar
Shine-zwj committed
133 134 135 136 137 138 139 140
    }

    /**
     * 内容类型
     *
     * @memberof AppPresetTitle
     */
    get contentType() {
tony001's avatar
tony001 committed
141 142 143 144
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.contentType || 'RAW';
        }
Shine-zwj's avatar
Shine-zwj committed
145
    }
146 147

    /**
Shine-zwj's avatar
Shine-zwj committed
148
     * 类名
149
     *
Shine-zwj's avatar
Shine-zwj committed
150
     * @memberof AppPresetTitle
151
     */
Shine-zwj's avatar
Shine-zwj committed
152
    get curClassName() {
tony001's avatar
tony001 committed
153 154 155 156
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return `app-preset-text app-preset-text--${this.contentType.toLowerCase()} ${this.itemName} ${layoutModel.sysCss}`;
        }
Shine-zwj's avatar
Shine-zwj committed
157
    }
158 159

    /**
Shine-zwj's avatar
Shine-zwj committed
160 161 162
     * 当前容器样式
     * 
     * @memberof AppPresetTitle
163
     */
Shine-zwj's avatar
Shine-zwj committed
164
    get curStyle() {
tony001's avatar
tony001 committed
165 166 167 168
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.getElementStyle();
        }
Shine-zwj's avatar
Shine-zwj committed
169
    }
170 171

    /**
Shine-zwj's avatar
Shine-zwj committed
172 173 174
     * 绘制模式
     * 
     * @memberof AppPresetTitle
175
     */
Shine-zwj's avatar
Shine-zwj committed
176
    get renderMode() {
tony001's avatar
tony001 committed
177 178 179 180
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.renderMode || 'TEXT';
        }
Shine-zwj's avatar
Shine-zwj committed
181 182
    }

183 184 185
    /**
     * 内容
     *
186
     * @memberof AppPresetText
187
     */
tony001's avatar
tony001 committed
188 189
    get content() {
        const layoutModel = this.layoutModelDetails[this.itemName];
190
        let content = this.value;
tony001's avatar
tony001 committed
191
        if (layoutModel && layoutModel.predefinedType && layoutModel.predefinedType !== 'FIELD_TEXT_DYNAMIC') {
Shine-zwj's avatar
Shine-zwj committed
192
            if (this.contentType == 'RAW') {
Shine-zwj's avatar
Shine-zwj committed
193
                content = layoutModel.rawContent;
Shine-zwj's avatar
Shine-zwj committed
194
            } else if (this.contentType == 'HTML') {
Shine-zwj's avatar
Shine-zwj committed
195 196 197 198 199 200 201 202 203 204 205
                content = layoutModel.htmlContent;
                const items = content.match(/\{{(.+?)\}}/g);
                if (items) {
                    items.forEach((item: string) => {
                        content = content.replace(/\{{(.+?)\}}/, eval(item.substring(2, item.length - 2)));
                    });
                }
                content = content.replaceAll('&lt;', '<');
                content = content.replaceAll('&gt;', '>');
                content = content.replaceAll('&amp;nbsp;', ' ');
                content = content.replaceAll('&nbsp;', ' ');
206 207 208 209 210
            }
        }
        return content;
    }

Shine-zwj's avatar
Shine-zwj committed
211
    /**
Shine-zwj's avatar
Shine-zwj committed
212
     * 内容样式
213
     *
214
     * @memberof AppPresetText
215
     */
tony001's avatar
tony001 committed
216 217 218 219 220 221 222 223
    get contentStyle() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            let contentStyle = layoutModel.contentStyle;
            if (layoutModel.predefinedType === 'STATIC_LABEL') {
                contentStyle += "white-space: nowrap;overflow: hidden;text-overflow: ellipsis;";
            }
            return contentStyle;
224 225 226 227 228 229 230
        }
    }
}
</script>
<style lang="less">
@import './app-preset-text.less';
</style>