app-preset-button.vue 4.6 KB
Newer Older
1 2
<template>
    <i-button 
3 4
        :class="curClassName"
        :style="curStyle"
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
        :type="buttonType"
        :disabled="disabled"
        :title="tooltip"
        :loading="loading"
        :ghost="buttonGhost"
        @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>
            <span v-if="showCaption" class="caption">{{ caption }}</span>
        </div>
    </i-button>
</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;

    /**
     * 显示提示
     *
     * @memberof AppPresetButton
     */
    @Prop() public tooltip?: string;

    /**
     * 标题
     *
     * @memberof AppPresetButton
     */
    @Prop() public caption?: string;

    /**
49
     * 加载状态
50 51 52
     *
     * @memberof AppPresetButton
     */
53
    @Prop({ default: false }) public loading?: boolean;
54 55

    /**
56
     * 布局模型详情
57
     *
58
     * @type {*}
59 60
     * @memberof AppPresetButton
     */
61
    @Prop() public layoutModelDetails: any;
62 63

    /**
64
     * 显示标题
65 66 67
     *
     * @memberof AppPresetButton
     */
68 69 70 71
    get showCaption() {
        const layoutModel = this.layoutModelDetails[this.name];
        return layoutModel.isShowCaption;
    }
72 73

    /**
74
     * 类名
75 76 77
     *
     * @memberof AppPresetButton
     */
78 79 80 81
    get curClassName(){
        const layoutModel = this.layoutModelDetails[this.name];
        return `app-preset-button ${this.name} ${layoutModel.sysCss}`;
    }
82 83 84 85 86 87

    /**
     * 图片路径
     *
     * @memberof AppPresetButton
     */
88 89 90 91 92 93 94 95 96 97
    get imagePath() {
        const layoutModel = this.layoutModelDetails[this.name];
        let imagePath = '';
        if (layoutModel.sysImage) {
            imagePath = layoutModel.sysImage.imagePath;
        } else if (layoutModel.uiAction) {
            imagePath = layoutModel.uiAction.imagePath;
        }
        return imagePath;
    }
98 99

    /**
100
     * 图标
101 102 103
     *
     * @memberof AppPresetButton
     */
104 105 106 107 108 109 110 111 112 113
    get cssClass() {
        const layoutModel = this.layoutModelDetails[this.name];
        let cssClass = '';
        if (layoutModel.sysImage) {
            cssClass = layoutModel.sysImage.iconcls;
        } else if (layoutModel.uiAction) {
            cssClass = layoutModel.uiAction.iconcls;
        }
        return cssClass;
    }
114 115

    /**
116 117
     * 当前容器样式
     * 
118 119
     * @memberof AppPresetButton
     */
120 121 122 123
    get curStyle(){
        const layoutModel = this.layoutModelDetails[this.name];
        return layoutModel.getElementStyle();
    }
124 125

    /**
126 127
     * 禁用
     * 
128 129
     * @memberof AppPresetButton
     */
130 131 132 133
    get disabled(){
        const layoutModel = this.layoutModelDetails[this.name];
        return layoutModel.disabled;
    }
134 135 136 137 138 139 140

    /**
     * 按钮类型
     *
     * @memberof AppPresetButton
     */
    get buttonType() {
141 142
        const layoutModel = this.layoutModelDetails[this.name];
        if (Object.is(layoutModel.renderMode, 'LINK')) {
143 144 145
            return 'text';
        } else {
            if (
146 147 148 149
                Object.is(layoutModel.buttonStyle, 'DEFAULT') ||
                Object.is(layoutModel.buttonStyle, 'STYLE2') ||
                Object.is(layoutModel.buttonStyle, 'STYLE3') ||
                Object.is(layoutModel.buttonStyle, 'STYLE4')
150 151
            ) {
                return 'default';
152
            } else if (Object.is(layoutModel.buttonStyle, 'DANGER')) {
153
                return 'error';
154
            } else if (Object.is(layoutModel.buttonStyle, 'INVERSE')) {
155 156
                return 'primary';
            } else {
157
                return layoutModel.buttonStyle.toLowerCase();
158 159 160 161 162
            }
        }
    }

    /**
163
     * 图标方向
164 165 166
     *
     * @memberof AppPresetButton
     */
167 168 169
    get iconAlign() {
        const layoutModel = this.layoutModelDetails[this.name];
        return layoutModel.iconAlign || 'LEFT';
170 171 172
    }

    /**
173
     * 按钮幽灵属性,使按钮背景透明
174 175 176
     *
     * @memberof AppPresetButton
     */
177 178 179
    get buttonGhost() {
        const layoutModel = this.layoutModelDetails[this.name];
        return Object.is(layoutModel.buttonStyle, 'INVERSE');
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    }

    /**
     * 点击按钮
     *
     * @param {*} event
     * @memberof AppPresetButton
     */
    public handleClick(event: any) {
        this.$emit('itemClick', this.name);
    }
}
</script>
<style lang='less'>
@import './app-preset-button.less';
</style>