app-preset-button.vue 5.8 KB
Newer Older
Shine-zwj's avatar
Shine-zwj committed
1
<template>
Shine-zwj's avatar
Shine-zwj committed
2
    <div :class="curClassName" :style="curStyle">
RedPig97's avatar
RedPig97 committed
3
        <i-button :type="buttonType" :disabled="disabled" :title="curTooltip" :loading="loading" :ghost="buttonGhost"
Shine-zwj's avatar
Shine-zwj committed
4 5 6 7 8 9
            @click="handleClick">
            <div :class="['button-content', iconAlign.toLowerCase()]">
                <span v-if="cssClass || imagePath" class="icon">
                    <i v-if="cssClass" :class="cssClass" />
                    <img v-else :src="imagePath" />
                </span>
RedPig97's avatar
RedPig97 committed
10
                <span v-if="showCaption" class="caption">{{ curCaption }}</span>
Shine-zwj's avatar
Shine-zwj committed
11 12 13
            </div>
        </i-button>
    </div>
Shine-zwj's avatar
Shine-zwj committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
</template>

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

@Component({})
export default class AppPresetButton extends Vue {
    /**
     * 按钮name
     *
     * @type {any}
     * @memberof AppPresetButton
     */
    @Prop() public name!: string;

    /**
Shine-zwj's avatar
Shine-zwj committed
30
     * 加载状态
Shine-zwj's avatar
Shine-zwj committed
31 32 33
     *
     * @memberof AppPresetButton
     */
Shine-zwj's avatar
Shine-zwj committed
34
    @Prop({ default: false }) public loading?: boolean;
Shine-zwj's avatar
Shine-zwj committed
35 36

    /**
Shine-zwj's avatar
Shine-zwj committed
37
     * 布局模型详情
Shine-zwj's avatar
Shine-zwj committed
38
     *
Shine-zwj's avatar
Shine-zwj committed
39
     * @type {*}
Shine-zwj's avatar
Shine-zwj committed
40 41
     * @memberof AppPresetButton
     */
Shine-zwj's avatar
Shine-zwj committed
42
    @Prop() public layoutModelDetails: any;
Shine-zwj's avatar
Shine-zwj committed
43

tony001's avatar
tony001 committed
44 45 46 47 48 49
    /**
     * 下标
     *
     * @type {number}
     * @memberof AppPresetButton
     */
tony001's avatar
tony001 committed
50
    @Prop() public index?: number;
tony001's avatar
tony001 committed
51 52 53 54 55 56 57 58

    /**
     * 项名称
     *
     * @type {*}
     * @memberof AppPresetButton
     */
    get itemName() {
tony001's avatar
tony001 committed
59
        return (this.index || this.index === 0) ? `${this.name}_${this.index}` : this.name;
tony001's avatar
tony001 committed
60 61
    }

Shine-zwj's avatar
Shine-zwj committed
62
    /**
Shine-zwj's avatar
Shine-zwj committed
63
     * 显示标题
Shine-zwj's avatar
Shine-zwj committed
64 65 66
     *
     * @memberof AppPresetButton
     */
Shine-zwj's avatar
Shine-zwj committed
67
    get showCaption() {
tony001's avatar
tony001 committed
68 69 70 71
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.isShowCaption;
        }
Shine-zwj's avatar
Shine-zwj committed
72
    }
Shine-zwj's avatar
Shine-zwj committed
73

RedPig97's avatar
RedPig97 committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    /**
     * 标题
     *
     * @memberof AppLoginButton
     */
    get curCaption() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.caption;
        }
    }

    /**
     * 提示信息
     *
     * @memberof AppLoginButton
     */
    get curTooltip() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.tooltip;
        }
    }

Shine-zwj's avatar
Shine-zwj committed
98
    /**
Shine-zwj's avatar
Shine-zwj committed
99
     * 类名
Shine-zwj's avatar
Shine-zwj committed
100 101 102
     *
     * @memberof AppPresetButton
     */
tony001's avatar
tony001 committed
103 104 105 106 107
    get curClassName() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return `app-preset-button ${this.itemName} ${layoutModel.sysCss}`;
        }
Shine-zwj's avatar
Shine-zwj committed
108
    }
Shine-zwj's avatar
Shine-zwj committed
109 110 111 112 113 114

    /**
     * 图片路径
     *
     * @memberof AppPresetButton
     */
Shine-zwj's avatar
Shine-zwj committed
115
    get imagePath() {
tony001's avatar
tony001 committed
116 117 118 119 120 121 122 123 124
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            let imagePath = '';
            if (layoutModel.sysImage) {
                imagePath = layoutModel.sysImage.imagePath;
            } else if (layoutModel.uiAction) {
                imagePath = layoutModel.uiAction.imagePath;
            }
            return imagePath;
Shine-zwj's avatar
Shine-zwj committed
125 126
        }
    }
Shine-zwj's avatar
Shine-zwj committed
127 128

    /**
Shine-zwj's avatar
Shine-zwj committed
129
     * 图标
Shine-zwj's avatar
Shine-zwj committed
130 131 132
     *
     * @memberof AppPresetButton
     */
Shine-zwj's avatar
Shine-zwj committed
133
    get cssClass() {
tony001's avatar
tony001 committed
134 135 136 137 138 139 140 141 142
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            let cssClass = '';
            if (layoutModel.sysImage) {
                cssClass = layoutModel.sysImage.iconcls;
            } else if (layoutModel.uiAction) {
                cssClass = layoutModel.uiAction.iconcls;
            }
            return cssClass;
Shine-zwj's avatar
Shine-zwj committed
143 144
        }
    }
Shine-zwj's avatar
Shine-zwj committed
145 146

    /**
Shine-zwj's avatar
Shine-zwj committed
147 148
     * 当前容器样式
     * 
Shine-zwj's avatar
Shine-zwj committed
149 150
     * @memberof AppPresetButton
     */
tony001's avatar
tony001 committed
151 152 153 154 155
    get curStyle() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.getElementStyle();
        }
Shine-zwj's avatar
Shine-zwj committed
156
    }
Shine-zwj's avatar
Shine-zwj committed
157 158

    /**
Shine-zwj's avatar
Shine-zwj committed
159 160
     * 禁用
     * 
Shine-zwj's avatar
Shine-zwj committed
161 162
     * @memberof AppPresetButton
     */
tony001's avatar
tony001 committed
163 164 165 166 167
    get disabled() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.disabled;
        }
Shine-zwj's avatar
Shine-zwj committed
168
    }
Shine-zwj's avatar
Shine-zwj committed
169 170 171 172 173 174 175

    /**
     * 按钮类型
     *
     * @memberof AppPresetButton
     */
    get buttonType() {
tony001's avatar
tony001 committed
176 177 178 179
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            if (Object.is(layoutModel.renderMode, 'LINK')) {
                return 'text';
Shine-zwj's avatar
Shine-zwj committed
180
            } else {
tony001's avatar
tony001 committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194
                if (
                    Object.is(layoutModel.buttonStyle, 'DEFAULT') ||
                    Object.is(layoutModel.buttonStyle, 'STYLE2') ||
                    Object.is(layoutModel.buttonStyle, 'STYLE3') ||
                    Object.is(layoutModel.buttonStyle, 'STYLE4')
                ) {
                    return 'default';
                } else if (Object.is(layoutModel.buttonStyle, 'DANGER')) {
                    return 'error';
                } else if (Object.is(layoutModel.buttonStyle, 'INVERSE')) {
                    return 'primary';
                } else {
                    return layoutModel.buttonStyle.toLowerCase();
                }
Shine-zwj's avatar
Shine-zwj committed
195 196 197 198 199
            }
        }
    }

    /**
Shine-zwj's avatar
Shine-zwj committed
200
     * 图标方向
Shine-zwj's avatar
Shine-zwj committed
201 202 203
     *
     * @memberof AppPresetButton
     */
Shine-zwj's avatar
Shine-zwj committed
204
    get iconAlign() {
tony001's avatar
tony001 committed
205 206 207
        const layoutModel = this.layoutModelDetails[this.itemName];
        if(layoutModel){
            return layoutModel.iconAlign || 'LEFT';
tony001's avatar
tony001 committed
208 209
        }else{
            return 'LEFT';
tony001's avatar
tony001 committed
210
        }
Shine-zwj's avatar
Shine-zwj committed
211 212 213
    }

    /**
Shine-zwj's avatar
Shine-zwj committed
214
     * 按钮幽灵属性,使按钮背景透明
Shine-zwj's avatar
Shine-zwj committed
215 216 217
     *
     * @memberof AppPresetButton
     */
Shine-zwj's avatar
Shine-zwj committed
218
    get buttonGhost() {
tony001's avatar
tony001 committed
219 220 221 222
        const layoutModel = this.layoutModelDetails[this.itemName];
        if(layoutModel){
            return Object.is(layoutModel.buttonStyle, 'INVERSE');
        }
Shine-zwj's avatar
Shine-zwj committed
223 224 225 226 227 228 229 230 231
    }

    /**
     * 点击按钮
     *
     * @param {*} event
     * @memberof AppPresetButton
     */
    public handleClick(event: any) {
232
        this.$emit('itemClick', this.name);
Shine-zwj's avatar
Shine-zwj committed
233 234 235
    }
}
</script>
236 237
<style lang='scss'>
@import './app-preset-button.scss';
Shine-zwj's avatar
Shine-zwj committed
238
</style>